From nobody Mon Feb 9 12:24:58 2026 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 1501785493842523.7609836627947; Thu, 3 Aug 2017 11:38:13 -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 CDAFDC0587F8; Thu, 3 Aug 2017 18:38:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9C08B792A5; Thu, 3 Aug 2017 18:38:11 +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 490DF180BA82; Thu, 3 Aug 2017 18:38:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v73IZOUr026033 for ; Thu, 3 Aug 2017 14:35:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 145F15D6A4; Thu, 3 Aug 2017 18:35:24 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 06A225D760 for ; Thu, 3 Aug 2017 18:35:21 +0000 (UTC) Received: from mail-qk0-f174.google.com (mail-qk0-f174.google.com [209.85.220.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 079034E049 for ; Thu, 3 Aug 2017 18:35:21 +0000 (UTC) Received: by mail-qk0-f174.google.com with SMTP id d136so12715779qkg.3 for ; Thu, 03 Aug 2017 11:35:20 -0700 (PDT) Received: from dawid-fedora.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id b142sm23906990qka.37.2017.08.03.11.35.19 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2017 11:35:19 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CDAFDC0587F8 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx08.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 CDAFDC0587F8 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UyWKpe6d" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 079034E049 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dzrudy@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 079034E049 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=CHnpCA2KG5QasVVPGgVMrWDWFIdvqbS8IGkqL0z6Qrk=; b=UyWKpe6d5tKL+JKPlzGQTXgU3P9iRU9ZznHLgWJKZFP93cmm8HVKRVPB0vxiTh87wy fSpca17rla0cyXVjLyhd++s5UTDfH3B9yeR6nhozZlY9EeYlJ2dT5xy+/1vHDAfZbxgJ W3j1ucX07eZeLL5x0dDqJ860D8zWYrDGXz7ALKz9bZ7ZFwnJdC6brStWNtyCuOSLF2E0 MJuX22xoFTOW0dCSE+M04T9sH2yNZ9K8l+q+IM55JM0OW8XNxwWeqDOsCJ74DwwtlNMB NcqYPLJ3rX+iNDKHIh5L+EX9e83TjW8cR+tEKF/fttuq7DaJs37TlXHtKo6CBu8l5LNo oBSw== 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=CHnpCA2KG5QasVVPGgVMrWDWFIdvqbS8IGkqL0z6Qrk=; b=rkLgVEZSysWqWAsrMTy4K5u7ADLwg3d0nO84T1VOcnG7MlWjW1nWnVHSNtZfsIKy9/ ARwje8jgvQiTsc+i2lPDbyHj0gxLFUeCjK4fkC4ngRqzQbSHTjM9LJdFxrRx9IsC23qv HcmMOu2Z7q0eqyFd2/MBfqEhceTAUNyr1pUbdk/joK4bn2aGgrfjLMPjEcTdk90O+VnB 7gf33JmbtlTTXj+doTzpqaZ3ULSlCXaJH9AddB397yJiJns4BGCIaSruz9cD8oR/0TOR gD37jonRVZ4A98miBHFxYi+MEykJ42/H/pZvCo+XDheFl6G+3pDT/m+QJyzO3av+P5ze JFNA== X-Gm-Message-State: AHYfb5gsA6ngi+zfmdpzg6edL5ifW7eVp0Kg5ULx7s2qAwz3OJNU6jy+ rQAe6tumuCaKtSSIpyQ= X-Received: by 10.55.23.11 with SMTP id i11mr3441475qkh.295.1501785319936; Thu, 03 Aug 2017 11:35:19 -0700 (PDT) From: Dawid Zamirski To: libvir-list@redhat.com Date: Thu, 3 Aug 2017 14:35:09 -0400 Message-Id: <20170803183509.1250-12-dzrudy@gmail.com> In-Reply-To: <20170803183509.1250-1-dzrudy@gmail.com> References: <20170803183509.1250-1-dzrudy@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 03 Aug 2017 18:35:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 03 Aug 2017 18:35:21 +0000 (UTC) for IP:'209.85.220.174' DOMAIN:'mail-qk0-f174.google.com' HELO:'mail-qk0-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.220.174 mail-qk0-f174.google.com 209.85.220.174 mail-qk0-f174.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [libvirt-php PATCH v2 11/11] 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.32]); Thu, 03 Aug 2017 18:38:12 +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 b20d839..ec73034 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -1145,13 +1145,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