From nobody Fri May 16 04:11:37 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1501624019190522.9871345673769; Tue, 1 Aug 2017 14:46:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1D43D622A6; Tue, 1 Aug 2017 21:46:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E72E863770; Tue, 1 Aug 2017 21:46:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9B5954A467; Tue, 1 Aug 2017 21:46:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v71LkT01007880 for ; Tue, 1 Aug 2017 17:46:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9036218173; Tue, 1 Aug 2017 21:46:29 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7F16818152 for ; Tue, 1 Aug 2017 21:46:27 +0000 (UTC) Received: from mail-qt0-f174.google.com (mail-qt0-f174.google.com [209.85.216.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DB3455DBB9 for ; Tue, 1 Aug 2017 21:46:26 +0000 (UTC) Received: by mail-qt0-f174.google.com with SMTP id t37so17089029qtg.5 for ; Tue, 01 Aug 2017 14:46:26 -0700 (PDT) Received: from dawid-fedora.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id f56sm1892090qta.79.2017.08.01.14.46.25 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 01 Aug 2017 14:46:25 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1D43D622A6 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1D43D622A6 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="as56e+lU" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DB3455DBB9 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dzrudy@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DB3455DBB9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=+cUvqUubkDxb03ijxnnHCDW+Bz6SU/nmb/BImXQcgo0=; b=as56e+lU6x3qJapw2quPBcLOCtC8jW0ThDCeEPU6pkdBYr8dxFfRdlpvWJXFF4QOhp LBsN2Jc1Rsp4yT4XYeahTLk3ElOYmHPyHyUsfZl5E1lWIlwqm3qkC3UHldSllH/03AZs P1oDrjHwo1VXZfVnN0NL+jEuT4+ViZCRG81J8olDyw3JIYyNGjMjo65f4MUQkUYWO16r WovYWd4ozC79MFJQQFfdSwHJD0/cvTWiqOR2M+91lftCZMEQuZfVjf11EmygDx9HAdB+ LLckyn9gSBLjmgNdAM9jwQInNPJHHWXm1MJtYfXtmA/Q1Hd4LlPh2iFBDOYM0R9Y99ZZ qEtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=+cUvqUubkDxb03ijxnnHCDW+Bz6SU/nmb/BImXQcgo0=; b=TKAWyPiWVQfIPyFu0iKPe0tWm8j6KMwz+/+cqWOMywj8o9AK2rJAkBNgOop4/V3t/t 02u9zd3ZFDs38xoy6IHtytNYi6vlJpTbABIsMKvCpXYZUr6/iA1E/ZqCWdXRvy+JiPe2 SKEomAUotm/E+anc4aUia6WYr/8ZLkZtRrfbwNqyQgbAkCIvChju0kZqli0BYT6VyO5+ qU671e7jMtmacyxpE3YUGKCaKqdCM6vt4hz02mFzQsZmgRhZYbcwm86XtDGcFZ+wbIw+ iMXlH/o9FwZYdR1AAkg0QEZS9MRW5F0CAuoyQDFJy/3hkTUg+37Rg22IVJpdKvZV9Pg4 1Ebw== X-Gm-Message-State: AIVw111ADdzbzUeM6mGMBdZRm1/aSOE+hF0Os23F1gOLAlzPEEkDmUxn XraNM7Ezc1qolAXTyFo= X-Received: by 10.200.9.93 with SMTP id z29mr27687744qth.102.1501623985850; Tue, 01 Aug 2017 14:46:25 -0700 (PDT) From: Dawid Zamirski To: libvir-list@redhat.com Date: Tue, 1 Aug 2017 17:46:14 -0400 Message-Id: <20170801214614.8915-14-dzrudy@gmail.com> In-Reply-To: <20170801214614.8915-1-dzrudy@gmail.com> References: <20170801214614.8915-1-dzrudy@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 01 Aug 2017 21:46:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 01 Aug 2017 21:46:27 +0000 (UTC) for IP:'209.85.216.174' DOMAIN:'mail-qt0-f174.google.com' HELO:'mail-qt0-f174.google.com' FROM:'dzrudy@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.43 (DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.216.174 mail-qt0-f174.google.com 209.85.216.174 mail-qt0-f174.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [libvirt-php PATCH 13/13] Fix is_local_connection implementation. X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 01 Aug 2017 21:46:57 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" As it was failing when local host is using FQDN for hostnames. The logic to do so follows libvirt's implementation for the same thing. This fixes an issue where unit tests would falsely fail on workstations that have FQDN hostnames. --- src/libvirt-php.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 4ef06b2..c019d99 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -1146,13 +1146,43 @@ int is_local_connection(virConnectPtr conn) { #ifndef EXTWIN int ret; - char *hostname; + char *lv_hostname =3D NULL, *result =3D NULL; char name[1024]; + struct addrinfo hints, *info =3D NULL; =20 - hostname =3D virConnectGetHostname(conn); + name[1023] =3D '\0'; gethostname(name, 1024); - ret =3D strcmp(name, hostname) =3D=3D 0; - free(hostname); + + if (strcmp(name, "localhost") =3D=3D 0) + return 1; + + lv_hostname =3D virConnectGetHostname(conn); + + /* gethostname gave us FQDN, compare */ + if (strchr(name, '.') && strcmp(name, lv_hostname) =3D=3D 0) + return 1; + + /* need to get FQDN of the local name */ + memset(&hints, 0, sizeof(hints)); + hints.ai_flags =3D AI_CANONNAME|AI_CANONIDN; + hints.ai_family =3D AF_UNSPEC; + + /* could not get FQDN or got localhost, use whatever gethostname gave = us */ + if (getaddrinfo(name, NULL, &hints, &info) !=3D 0 || + info->ai_canonname =3D=3D NULL || + strcmp(info->ai_canonname, "localhost") =3D=3D 0) + result =3D strdup(name); + else + result =3D strdup(info->ai_canonname); + + ret =3D strcmp(result, lv_hostname) =3D=3D 0; + + freeaddrinfo(info); + if (lv_hostname) + free(lv_hostname); + if (result) + free(result); + return ret; #else // Libvirt daemon doesn't work on Windows systems so always return 0 (= FALSE) --=20 2.13.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list