From nobody Thu Oct 31 23:28:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644854684; cv=none; d=zohomail.com; s=zohoarc; b=WaMHAR0EMEmwi7VtFWAnlnBz7KedTyQnf6WkFldUgAVTxWkSfW9Acwa5R6qozrcBwrpkybyY8RtF+p9VvP/3jEwfyZ7tv2xyY8zBcvFdTIwE9QpPAdkaaedr+CQ4+vzkHrSs1Sv56TaKyx9uHbtsXsSzDq0Ue7Pg+4k0mxqkEI4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644854684; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TbuT9M9BQybkeK4vpMLIfFGutZ+v7vpbzhMti66Lx+M=; b=cXcgC0K5kSEOhWBkVafoGj8DVbGTu3yf+wbj5GGIVXe7RyMkaPOcLxYDfP80TNQjuaDr6sf3Xq7KeKCPQNqy1MwaFK/DPEG5aUx7IE9dl1a3o81c6F95Vb7cGRkkLNdjkhs1Li4jOUgMo7KXAmr1YMimhVaBFdE0loUK8A1RGU8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1644854684531853.4361128997689; Mon, 14 Feb 2022 08:04:44 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-297-4S22E3vhO1SYkEQp-qAyOA-1; Mon, 14 Feb 2022 11:04:42 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1CEBC1006AA3; Mon, 14 Feb 2022 16:04:37 +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 BCFAE7A54F; Mon, 14 Feb 2022 16:04:36 +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 172051806D1D; Mon, 14 Feb 2022 16:04:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21EG4XNC022389 for ; Mon, 14 Feb 2022 11:04:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id EA6F67CD68; Mon, 14 Feb 2022 16:04:33 +0000 (UTC) Received: from harajuku.usersys.redhat.com.homenet.telecomitalia.it (unknown [10.40.194.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 57E827D5B4 for ; Mon, 14 Feb 2022 16:03:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644854684; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=TbuT9M9BQybkeK4vpMLIfFGutZ+v7vpbzhMti66Lx+M=; b=Blo/f69A9Vip4qGNIASe6CvhWdY+6HHoSYjl8dwkjswQF5lEYWSm6HoxMU2CGjMlKCtYrh 8S6JU2K60i3nKJRwKXJxuqdHMGbD1bzR6AfwIFWrDBuRiQ7pKCyMlWC1grOaNG9A4YAs0w bbKfjs6+lURiuKr0vtAs+JPQv/aqarM= X-MC-Unique: 4S22E3vhO1SYkEQp-qAyOA-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH v2 1/6] virnetclient: Improve spacing of ssh script Date: Mon, 14 Feb 2022 17:03:30 +0100 Message-Id: <20220214160335.174432-2-abologna@redhat.com> In-Reply-To: <20220214160335.174432-1-abologna@redhat.com> References: <20220214160335.174432-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644854706051100001 Content-Type: text/plain; charset="utf-8" This results in the generated script having consistent spacing throughout, instead of having repeated whitespace in some parts and commands that are separated by a semicolon and no spacing at all in others. Signed-off-by: Andrea Bolognani --- src/rpc/virnetclient.c | 12 ++++---- tests/virnetsockettest.c | 60 ++++++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index 2998551cd8..cbefa8f11f 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -436,10 +436,10 @@ virNetClientSSHHelperCommand(virNetClientProxy proxy, =20 nccmd =3D g_strdup_printf( "if '%s' -q 2>&1 | grep \"requires an argument\" >/dev/null 2>&1; = then " - "ARG=3D-q0;" + "ARG=3D-q0; " "else " - "ARG=3D;" - "fi;" + "ARG=3D; " + "fi; " "'%s' $ARG -U %s", netcatPathSafe, netcatPathSafe, socketPath); =20 @@ -451,9 +451,9 @@ virNetClientSSHHelperCommand(virNetClientProxy proxy, case VIR_NET_CLIENT_PROXY_AUTO: return g_strdup_printf("sh -c 'which virt-ssh-helper 1>/dev/null 2= >&1; " "if test $? =3D 0; then " - " %s; " - "else" - " %s; " + "%s; " + "else " + "%s; " "fi'", helpercmd, nccmd); =20 case VIR_NET_CLIENT_PROXY_NETCAT: diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c index 4e8edb05c3..1bd5255d90 100644 --- a/tests/virnetsockettest.c +++ b/tests/virnetsockettest.c @@ -572,10 +572,10 @@ mymain(void) .netcat =3D "nc", .expectOut =3D "-T -e none -- somehost sh -c '" "if 'nc' -q 2>&1 | grep \"requires an argument\" = >/dev/null 2>&1; then " - "ARG=3D-q0;" + "ARG=3D-q0; " "else " - "ARG=3D;" - "fi;" + "ARG=3D; " + "fi; " "'nc' $ARG -U /tmp/socket" "'\n", }; @@ -592,10 +592,10 @@ mymain(void) .path =3D "/tmp/socket", .expectOut =3D "-p 9000 -l fred -T -e none -o BatchMode=3Dyes -- s= omehost sh -c '" "if 'netcat' -q 2>&1 | grep \"requires an argumen= t\" >/dev/null 2>&1; then " - "ARG=3D-q0;" + "ARG=3D-q0; " "else " - "ARG=3D;" - "fi;" + "ARG=3D; " + "fi; " "'netcat' $ARG -U /tmp/socket" "'\n", }; @@ -612,10 +612,10 @@ mymain(void) .path =3D "/tmp/socket", .expectOut =3D "-p 9000 -l fred -T -e none -o StrictHostKeyCheckin= g=3Dno -- somehost sh -c '" "if 'netcat' -q 2>&1 | grep \"requires an argumen= t\" >/dev/null 2>&1; then " - "ARG=3D-q0;" + "ARG=3D-q0; " "else " - "ARG=3D;" - "fi;" + "ARG=3D; " + "fi; " "'netcat' $ARG -U /tmp/socket" "'\n", }; @@ -636,10 +636,10 @@ mymain(void) .netcat =3D "nc", .expectOut =3D "-T -e none -- crashyhost sh -c '" "if 'nc' -q 2>&1 | grep \"requires an argument\" = >/dev/null 2>&1; then " - "ARG=3D-q0;" + "ARG=3D-q0; " "else " - "ARG=3D;" - "fi;" + "ARG=3D; " + "fi; " "'nc' $ARG -U /tmp/socket" "'\n", .dieEarly =3D true, @@ -655,10 +655,10 @@ mymain(void) .noVerify =3D true, .expectOut =3D "-i /root/.ssh/example_key -T -e none -o StrictHost= KeyChecking=3Dno -- example.com sh -c '" "if 'nc' -q 2>&1 | grep \"requires an argument\" = >/dev/null 2>&1; then " - "ARG=3D-q0;" + "ARG=3D-q0; " "else " - "ARG=3D;" - "fi;" + "ARG=3D; " + "fi; " "'nc' $ARG -U /tmp/socket" "'\n", }; @@ -671,10 +671,10 @@ mymain(void) .path =3D "/tmp/socket", .expectOut =3D "-T -e none -- somehost sh -c '" "if '''\\''n c'\\'''' -q 2>&1 | grep \"requires a= n argument\" >/dev/null 2>&1; then " - "ARG=3D-q0;" + "ARG=3D-q0; " "else " - "ARG=3D;" - "fi;" + "ARG=3D; " + "fi; " "'''\\''n c'\\'''' $ARG -U /tmp/socket" "'\n", }; @@ -687,10 +687,10 @@ mymain(void) .path =3D "/tmp/socket", .expectOut =3D "-T -e none -- somehost sh -c '" "if '''\\''n'\\''\\'\\'''\\''c'\\'''' -q 2>&1 | g= rep \"requires an argument\" >/dev/null 2>&1; then " - "ARG=3D-q0;" + "ARG=3D-q0; " "else " - "ARG=3D;" - "fi;" + "ARG=3D; " + "fi; " "'''\\''n'\\''\\'\\'''\\''c'\\'''' $ARG -U /tmp/s= ocket" "'\n", }; @@ -703,10 +703,10 @@ mymain(void) .path =3D "/tmp/socket", .expectOut =3D "-T -e none -- somehost sh -c '" "if '''\\''n\"c'\\'''' -q 2>&1 | grep \"requires = an argument\" >/dev/null 2>&1; then " - "ARG=3D-q0;" + "ARG=3D-q0; " "else " - "ARG=3D;" - "fi;" + "ARG=3D; " + "fi; " "'''\\''n\"c'\\'''' $ARG -U /tmp/socket" "'\n", }; @@ -719,13 +719,13 @@ mymain(void) .expectOut =3D "-T -e none -- somehost sh -c '" "which virt-ssh-helper 1>/dev/null 2>&1; " "if test $? =3D 0; then " - " virt-ssh-helper -r 'qemu:///session'; " - "else" - " if 'nc' -q 2>&1 | grep \"requires an argumen= t\" >/dev/null 2>&1; then " - "ARG=3D-q0;" + "virt-ssh-helper -r 'qemu:///session'; " + "else " + "if 'nc' -q 2>&1 | grep \"requires an argumen= t\" >/dev/null 2>&1; then " + "ARG=3D-q0; " "else " - "ARG=3D;" - "fi;" + "ARG=3D; " + "fi; " "'nc' $ARG -U /tmp/socket; " "fi" "'\n" --=20 2.35.1 From nobody Thu Oct 31 23:28:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644854686; cv=none; d=zohomail.com; s=zohoarc; b=RTofS5v0vY256lanl9iVZ1p9iNmkKW9Se4cnFjPp6cH/stzkdUJLWjZ+BlvpaE4cvuBHCPx7NusiMwV1AUPXnoYDNReaxYSEQ6F6HFmyXhjdJIOs4vDnqY8Sfgeds2DAP43OMWhXu+GQI1qgW6xLKfr/jVs6soT8UlZQxY9fZo0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644854686; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GZNfWYtaQVO8JP1ZNDvmxPHpfTp87aULcK8PVpa1dhw=; b=YrQi6saKnGrkwt19HQpVfSIUmC+/k3QQ+RGVOr6O5b7bfZnKNXsor5yga6VSq3OBrSSJHq7lAVY6tNSfUZY7c1/nKfzNZawV4t+GIDnUt5QXB6lyjYteE0br9ECcKZ03+T9LpdBiUvN3SbV3WZRpVQbWcvueS93U5+GSejzeAnk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1644854686788790.396263855977; Mon, 14 Feb 2022 08:04:46 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-163-veog99JwPB2ih8ZE5jEQ9Q-1; Mon, 14 Feb 2022 11:04:44 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 11CDF18A0F1B; Mon, 14 Feb 2022 16:04:39 +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 E547E7E110; Mon, 14 Feb 2022 16:04:38 +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 AFBC14BB7C; Mon, 14 Feb 2022 16:04:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21EG4YR5022395 for ; Mon, 14 Feb 2022 11:04:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id E7F447D5B4; Mon, 14 Feb 2022 16:04:34 +0000 (UTC) Received: from harajuku.usersys.redhat.com.homenet.telecomitalia.it (unknown [10.40.194.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 550D87CD68 for ; Mon, 14 Feb 2022 16:04:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644854685; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=GZNfWYtaQVO8JP1ZNDvmxPHpfTp87aULcK8PVpa1dhw=; b=XSHN8QD4yvxVY5gHY0gIqBmOLRFEPYBNJBbWzCn/Qs0x3aWqsWcJTFv0tabXeGumVLADSP /I4EAPKxmOHCVGIQvDCjRF2XX9uuG8VTlPS5OCm4B5xwhjYpFl7nWASYdnJJhbIoBnV0Z4 omGBof49keGil/tdpGmeSgAfDaXgZPk= X-MC-Unique: veog99JwPB2ih8ZE5jEQ9Q-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH v2 2/6] virnetclient: Use 'if' consistently Date: Mon, 14 Feb 2022 17:03:31 +0100 Message-Id: <20220214160335.174432-3-abologna@redhat.com> In-Reply-To: <20220214160335.174432-1-abologna@redhat.com> References: <20220214160335.174432-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644854687578100001 Content-Type: text/plain; charset="utf-8" This makes the generated script a bit shorter and removes an unnecessary call to test. Signed-off-by: Andrea Bolognani --- src/rpc/virnetclient.c | 3 +-- tests/virnetsockettest.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index cbefa8f11f..7e7e9d52a6 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -449,8 +449,7 @@ virNetClientSSHHelperCommand(virNetClientProxy proxy, =20 switch (proxy) { case VIR_NET_CLIENT_PROXY_AUTO: - return g_strdup_printf("sh -c 'which virt-ssh-helper 1>/dev/null 2= >&1; " - "if test $? =3D 0; then " + return g_strdup_printf("sh -c 'if which virt-ssh-helper >/dev/null= 2>&1; then " "%s; " "else " "%s; " diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c index 1bd5255d90..adff6a0f9e 100644 --- a/tests/virnetsockettest.c +++ b/tests/virnetsockettest.c @@ -717,8 +717,7 @@ mymain(void) .nodename =3D "somehost", .path =3D "/tmp/socket", .expectOut =3D "-T -e none -- somehost sh -c '" - "which virt-ssh-helper 1>/dev/null 2>&1; " - "if test $? =3D 0; then " + "if which virt-ssh-helper >/dev/null 2>&1; then " "virt-ssh-helper -r 'qemu:///session'; " "else " "if 'nc' -q 2>&1 | grep \"requires an argumen= t\" >/dev/null 2>&1; then " --=20 2.35.1 From nobody Thu Oct 31 23:28:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644854686; cv=none; d=zohomail.com; s=zohoarc; b=GseTpXcoEbUcJLLJLBLWxseNazutTztztiYep2uyBe3v3/bs1wzOouMO9u4HyR6iIuYBGyLj2/bB0S+6MAfsG3tHVBLC++g18D8UtX6RFeMqW1wckbrvLkhE6VBhZwhXBi5MCXlMy0huklCxPGrhTfWy9uKzpn1PsSg+L2c4UGc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644854686; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mJq+HrZDOWvsytzzvDiG8YBR+7Tkb1zkGGH8SzbnCvc=; b=lGDfEPuB7KKYalnRYZrLazEavHCZRGhRW75EsdWkRLgVJGAhVY004tPxXoZQz7he4LmfcCRuExhTYSK+G13ae1Q4tILYXvl01P9vOgbIRN1EYorklRAt9sCJQaiCDfSPEWw8UZwKtmeVnO7rAIscok73k7jrZrrF/z0M7RYlvZI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1644854686800383.5861547181196; Mon, 14 Feb 2022 08:04:46 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-540-IUscmE91OXmegNXB0ZcYkw-1; Mon, 14 Feb 2022 11:04:45 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0FAA8839A45; Mon, 14 Feb 2022 16:04:40 +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 E177878A93; Mon, 14 Feb 2022 16:04:39 +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 B1EC84A705; Mon, 14 Feb 2022 16:04:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21EG4ZX9022403 for ; Mon, 14 Feb 2022 11:04:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id E2B527D5B4; Mon, 14 Feb 2022 16:04:35 +0000 (UTC) Received: from harajuku.usersys.redhat.com.homenet.telecomitalia.it (unknown [10.40.194.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 506A07CD68 for ; Mon, 14 Feb 2022 16:04:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644854686; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=mJq+HrZDOWvsytzzvDiG8YBR+7Tkb1zkGGH8SzbnCvc=; b=F0r8uGhZxYyrmcgGwMTrd9YOJeVjVNln89HfNH5SJEnq86cXUZQjdKIEKTgMH+G7sAMM4b pQUb6yT7WlLGIojg427DK9zJ4dqS6tb5jXVfJx7t678pht5fGrbue/B/REc+8CmbIaba0C 2OoaqoLC4nYhvv4E75fBAP8l/ct+Un4= X-MC-Unique: IUscmE91OXmegNXB0ZcYkw-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH v2 3/6] virnetclient: Handle netcatPath presence all at once Date: Mon, 14 Feb 2022 17:03:32 +0100 Message-Id: <20220214160335.174432-4-abologna@redhat.com> In-Reply-To: <20220214160335.174432-1-abologna@redhat.com> References: <20220214160335.174432-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644854706992100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Andrea Bolognani --- src/rpc/virnetclient.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index 7e7e9d52a6..9c7047c7f8 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -425,13 +425,17 @@ virNetClientSSHHelperCommand(virNetClientProxy proxy, g_autofree char *nccmd =3D NULL; g_autofree char *helpercmd =3D NULL; =20 - /* If user gave a 'netcat' path in the URI, we must - * assume they want the legacy 'nc' based proxy, not - * our new virt-ssh-helper - */ - if (proxy =3D=3D VIR_NET_CLIENT_PROXY_AUTO && - netcatPath !=3D NULL) { - proxy =3D VIR_NET_CLIENT_PROXY_NETCAT; + if (netcatPath) { + if (proxy =3D=3D VIR_NET_CLIENT_PROXY_AUTO) { + /* If user gave a 'netcat' path in the URI, we must + * assume they want the legacy 'nc' based proxy, not + * our new virt-ssh-helper */ + proxy =3D VIR_NET_CLIENT_PROXY_NETCAT; + } else if (proxy =3D=3D VIR_NET_CLIENT_PROXY_NATIVE) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("netcat path not valid with native proxy mode= ")); + return NULL; + } } =20 nccmd =3D g_strdup_printf( @@ -459,11 +463,6 @@ virNetClientSSHHelperCommand(virNetClientProxy proxy, return g_strdup_printf("sh -c '%s'", nccmd); =20 case VIR_NET_CLIENT_PROXY_NATIVE: - if (netcatPath) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("netcat path not valid with native proxy mode= ")); - return NULL; - } return g_strdup_printf("sh -c '%s'", helpercmd); =20 case VIR_NET_CLIENT_PROXY_LAST: --=20 2.35.1 From nobody Thu Oct 31 23:28:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644854698; cv=none; d=zohomail.com; s=zohoarc; b=fYnFNQsYjbuj5/Ds4ABexPtraeosiHZKX0sUVEid+XiWvXpCt1vu1rV/N2KiaeOEPfeWA3RBSBW4i7hnjxmIFQIm6zzPSGCSSSeg2yDtCCR/3K8ljj2l7ec+hjKuOtK9UCtJ90Wgt5lk7yHNajHk80Hqn0R7XO3GfKMWIbWIzZY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644854698; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EjGaueqy35nhmgzUByO805RaYNagaEcWJhKlHxxleDM=; b=JJrkatXNkzzuMEPUbszLFM9rFSls5sTs05bFMcYX84s5J6FGvDwL+dNelOoWED7NBXRG0Ng1owITOr1nJnODLY2qnhsi6ONX8jAvaqV7qsmZdryHOfG43BGh5hkgDbHCyutpQelgWuBNbE4bj/0DZ1B5DKtHqqJQnSryqW2Ux/c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1644854697994113.23338571261024; Mon, 14 Feb 2022 08:04:57 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-478-SustGZ7dNJiN4O0dlqkETg-1; Mon, 14 Feb 2022 11:04:52 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CA6FE1006ACC; Mon, 14 Feb 2022 16:04:42 +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 7AB707E127; Mon, 14 Feb 2022 16:04:42 +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 4A3664A708; Mon, 14 Feb 2022 16:04:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21EG4a03022410 for ; Mon, 14 Feb 2022 11:04:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id E114F7D5B4; Mon, 14 Feb 2022 16:04:36 +0000 (UTC) Received: from harajuku.usersys.redhat.com.homenet.telecomitalia.it (unknown [10.40.194.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4DB697CD68 for ; Mon, 14 Feb 2022 16:04:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644854696; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=EjGaueqy35nhmgzUByO805RaYNagaEcWJhKlHxxleDM=; b=g51cCXJ+RBXuDz2GhVjHsSZ000BzS5Enmrf/kqq5OiR/5pWY0jP50PpY5sAkKujrIwltJO hHAZMSOCqhVJnxqf+O1pDKCsI6OHt6038QOdYCQ6Cd3+5hT1+2yooqImcBKC6sYNLFB1si kp6rCQd1Yw6kq0Mnc/9PXEkk6sKOAvU= X-MC-Unique: SustGZ7dNJiN4O0dlqkETg-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH v2 4/6] virnetclient: Don't unnecessarily quote user-provided values Date: Mon, 14 Feb 2022 17:03:33 +0100 Message-Id: <20220214160335.174432-5-abologna@redhat.com> In-Reply-To: <20220214160335.174432-1-abologna@redhat.com> References: <20220214160335.174432-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644854699592100001 Content-Type: text/plain; charset="utf-8" If the output of virNetClientDoubleEscapeShell() matches its input, then no escaping actually happened and quoting the value in the generated script is unnecessary. With this change, awkward use of quotes such as sh -c 'if 'nc' -q' is completely gone when using the default settings. Closes: https://gitlab.com/libvirt/libvirt/-/issues/273 Signed-off-by: Andrea Bolognani --- src/rpc/virnetclient.c | 36 +++++++++++++++++++++++++++--------- tests/virnetsockettest.c | 28 ++++++++++++++-------------- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index 9c7047c7f8..cd92af1669 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -420,10 +420,12 @@ virNetClientSSHHelperCommand(virNetClientProxy proxy, const char *driverURI, bool readonly) { - g_autofree char *netcatPathSafe =3D virNetClientDoubleEscapeShell(netc= atPath ? netcatPath : "nc"); - g_autofree char *driverURISafe =3D virNetClientDoubleEscapeShell(drive= rURI); + g_autofree char *netcatPathSafe =3D NULL; + g_autofree char *driverURISafe =3D NULL; g_autofree char *nccmd =3D NULL; g_autofree char *helpercmd =3D NULL; + const char *netcatPathQuotes =3D ""; + const char *driverURIQuotes =3D ""; =20 if (netcatPath) { if (proxy =3D=3D VIR_NET_CLIENT_PROXY_AUTO) { @@ -436,20 +438,36 @@ virNetClientSSHHelperCommand(virNetClientProxy proxy, _("netcat path not valid with native proxy mode= ")); return NULL; } + } else { + netcatPath =3D "nc"; + } + + /* Escape user-provided values so that they're safe for use as part + * of our generated shell snippet. If escaping was necessary, we + * will also need to add quotes around all uses of each value */ + netcatPathSafe =3D virNetClientDoubleEscapeShell(netcatPath); + if (STRNEQ(netcatPathSafe, netcatPath)) { + netcatPathQuotes =3D "'"; + } + driverURISafe =3D virNetClientDoubleEscapeShell(driverURI); + if (STRNEQ(driverURISafe, driverURI)) { + driverURIQuotes =3D "'"; } =20 nccmd =3D g_strdup_printf( - "if '%s' -q 2>&1 | grep \"requires an argument\" >/dev/null 2>&1; = then " + "if %s%s%s -q 2>&1 | grep \"requires an argument\" >/dev/null 2>&1= ; then " "ARG=3D-q0; " "else " "ARG=3D; " "fi; " - "'%s' $ARG -U %s", - netcatPathSafe, netcatPathSafe, socketPath); - - helpercmd =3D g_strdup_printf("virt-ssh-helper%s'%s'", - readonly ? " -r " : " ", - driverURISafe); + "%s%s%s $ARG -U %s", + netcatPathQuotes, netcatPathSafe, netcatPathQuotes, + netcatPathQuotes, netcatPathSafe, netcatPathQuotes, + socketPath); + + helpercmd =3D g_strdup_printf("virt-ssh-helper%s %s%s%s", + readonly ? " -r" : "", + driverURIQuotes, driverURISafe, driverURIQ= uotes); =20 switch (proxy) { case VIR_NET_CLIENT_PROXY_AUTO: diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c index adff6a0f9e..09c3ba13ad 100644 --- a/tests/virnetsockettest.c +++ b/tests/virnetsockettest.c @@ -571,12 +571,12 @@ mymain(void) .path =3D "/tmp/socket", .netcat =3D "nc", .expectOut =3D "-T -e none -- somehost sh -c '" - "if 'nc' -q 2>&1 | grep \"requires an argument\" = >/dev/null 2>&1; then " + "if nc -q 2>&1 | grep \"requires an argument\" >/= dev/null 2>&1; then " "ARG=3D-q0; " "else " "ARG=3D; " "fi; " - "'nc' $ARG -U /tmp/socket" + "nc $ARG -U /tmp/socket" "'\n", }; if (virTestRun("SSH test 1", testSocketSSH, &sshData1) < 0) @@ -591,12 +591,12 @@ mymain(void) .noVerify =3D false, .path =3D "/tmp/socket", .expectOut =3D "-p 9000 -l fred -T -e none -o BatchMode=3Dyes -- s= omehost sh -c '" - "if 'netcat' -q 2>&1 | grep \"requires an argumen= t\" >/dev/null 2>&1; then " + "if netcat -q 2>&1 | grep \"requires an argument\= " >/dev/null 2>&1; then " "ARG=3D-q0; " "else " "ARG=3D; " "fi; " - "'netcat' $ARG -U /tmp/socket" + "netcat $ARG -U /tmp/socket" "'\n", }; if (virTestRun("SSH test 2", testSocketSSH, &sshData2) < 0) @@ -611,12 +611,12 @@ mymain(void) .noVerify =3D true, .path =3D "/tmp/socket", .expectOut =3D "-p 9000 -l fred -T -e none -o StrictHostKeyCheckin= g=3Dno -- somehost sh -c '" - "if 'netcat' -q 2>&1 | grep \"requires an argumen= t\" >/dev/null 2>&1; then " + "if netcat -q 2>&1 | grep \"requires an argument\= " >/dev/null 2>&1; then " "ARG=3D-q0; " "else " "ARG=3D; " "fi; " - "'netcat' $ARG -U /tmp/socket" + "netcat $ARG -U /tmp/socket" "'\n", }; if (virTestRun("SSH test 3", testSocketSSH, &sshData3) < 0) @@ -635,12 +635,12 @@ mymain(void) .path =3D "/tmp/socket", .netcat =3D "nc", .expectOut =3D "-T -e none -- crashyhost sh -c '" - "if 'nc' -q 2>&1 | grep \"requires an argument\" = >/dev/null 2>&1; then " + "if nc -q 2>&1 | grep \"requires an argument\" >/= dev/null 2>&1; then " "ARG=3D-q0; " "else " "ARG=3D; " "fi; " - "'nc' $ARG -U /tmp/socket" + "nc $ARG -U /tmp/socket" "'\n", .dieEarly =3D true, }; @@ -654,12 +654,12 @@ mymain(void) .keyfile =3D "/root/.ssh/example_key", .noVerify =3D true, .expectOut =3D "-i /root/.ssh/example_key -T -e none -o StrictHost= KeyChecking=3Dno -- example.com sh -c '" - "if 'nc' -q 2>&1 | grep \"requires an argument\" = >/dev/null 2>&1; then " + "if nc -q 2>&1 | grep \"requires an argument\" >/= dev/null 2>&1; then " "ARG=3D-q0; " "else " "ARG=3D; " "fi; " - "'nc' $ARG -U /tmp/socket" + "nc $ARG -U /tmp/socket" "'\n", }; if (virTestRun("SSH test 6", testSocketSSH, &sshData6) < 0) @@ -718,14 +718,14 @@ mymain(void) .path =3D "/tmp/socket", .expectOut =3D "-T -e none -- somehost sh -c '" "if which virt-ssh-helper >/dev/null 2>&1; then " - "virt-ssh-helper -r 'qemu:///session'; " + "virt-ssh-helper -r qemu:///session; " "else " - "if 'nc' -q 2>&1 | grep \"requires an argumen= t\" >/dev/null 2>&1; then " + "if nc -q 2>&1 | grep \"requires an argument\= " >/dev/null 2>&1; then " "ARG=3D-q0; " "else " "ARG=3D; " "fi; " - "'nc' $ARG -U /tmp/socket; " + "nc $ARG -U /tmp/socket; " "fi" "'\n" }; @@ -736,7 +736,7 @@ mymain(void) .nodename =3D "somehost", .proxy =3D VIR_NET_CLIENT_PROXY_NATIVE, .expectOut =3D "-T -e none -- somehost sh -c '" - "virt-ssh-helper -r 'qemu:///session'" + "virt-ssh-helper -r qemu:///session" "'\n" }; if (virTestRun("SSH test 11", testSocketSSH, &sshData11) < 0) --=20 2.35.1 From nobody Thu Oct 31 23:28:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644854689; cv=none; d=zohomail.com; s=zohoarc; b=KIcxpfdwHMv+sFI7OFFHUBo4FpogmHhSkkqHjf50CrKCiX08OGZKkTa/O4sxTC9zrt2iqEg0ugPLGu/vMtZgurYokhwQ2VZyL7nBlPKUhexXiJCXjF3GZS08OJVFmEos8GONbyajW9WDuxNDr+EhP9gXeCooL4BgQaoRerbD4tE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644854689; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kX1oe8WUSI4Wl1Z7dhk+Smtm6tcCGDad2SohXCa4Sf0=; b=Lxq2HTisSG72rzSP0393sRiQEpMf7Sf0kdLtoRStppUmPsWhS5tKDApurmCs0YU39UHP4jSeUlHPlIKe46mM1cbvm5ZUb7LbKy4SMPAXM738TuX1rUYmdbUwJAJgA01jgiuzwJh7F5nTCb95bZx5wSmCMd2YwptuJgzhVmP8MkQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1644854689885715.4546191735691; Mon, 14 Feb 2022 08:04:49 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-147-jM8ojt7mNQy_C9evPbwZxw-1; Mon, 14 Feb 2022 11:04:46 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 10F85839A42; Mon, 14 Feb 2022 16:04:41 +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 DFC52838D3; Mon, 14 Feb 2022 16:04:40 +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 AFAD81806D2B; Mon, 14 Feb 2022 16:04:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21EG4bIn022416 for ; Mon, 14 Feb 2022 11:04:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id EEF387CD68; Mon, 14 Feb 2022 16:04:37 +0000 (UTC) Received: from harajuku.usersys.redhat.com.homenet.telecomitalia.it (unknown [10.40.194.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4F4DE7E110 for ; Mon, 14 Feb 2022 16:04:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644854688; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=kX1oe8WUSI4Wl1Z7dhk+Smtm6tcCGDad2SohXCa4Sf0=; b=QxuUHl6PYhPRXCuEZnvlD8nWmMJ5ifRSas4mV0JKqDqOpUTNUyUwzt+QptW+t1L9/bcECp sPL5pfNWta1vPjty2zppC49W6YBcFzFKq/kUCYjAiwu/pwrmPgX+/ZVQW7Pw0te64FBzcv 7wQtTZiPxhdwDrXmdMsVcn5Bl3kCtUY= X-MC-Unique: jM8ojt7mNQy_C9evPbwZxw-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH v2 5/6] virnetsockettest: Test more socket paths Date: Mon, 14 Feb 2022 17:03:34 +0100 Message-Id: <20220214160335.174432-6-abologna@redhat.com> In-Reply-To: <20220214160335.174432-1-abologna@redhat.com> References: <20220214160335.174432-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644854691558100001 Content-Type: text/plain; charset="utf-8" While unlikely, the socket path might also contain unusual characters that need special handling. Adjust test cases so that these scenarios are covered. Note that none of these inputs will actually work outside of the test suite at the moment, but we're going to address that in the next commit. Signed-off-by: Andrea Bolognani --- tests/virnetsockettest.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c index 09c3ba13ad..ef7b5c6f59 100644 --- a/tests/virnetsockettest.c +++ b/tests/virnetsockettest.c @@ -668,14 +668,14 @@ mymain(void) struct testSSHData sshData7 =3D { .nodename =3D "somehost", .netcat =3D "n c", - .path =3D "/tmp/socket", + .path =3D "/tmp/sock et", .expectOut =3D "-T -e none -- somehost sh -c '" "if '''\\''n c'\\'''' -q 2>&1 | grep \"requires a= n argument\" >/dev/null 2>&1; then " "ARG=3D-q0; " "else " "ARG=3D; " "fi; " - "'''\\''n c'\\'''' $ARG -U /tmp/socket" + "'''\\''n c'\\'''' $ARG -U /tmp/sock et" "'\n", }; if (virTestRun("SSH test 7", testSocketSSH, &sshData7) < 0) @@ -684,14 +684,14 @@ mymain(void) struct testSSHData sshData8 =3D { .nodename =3D "somehost", .netcat =3D "n'c", - .path =3D "/tmp/socket", + .path =3D "/tmp/sock'et", .expectOut =3D "-T -e none -- somehost sh -c '" "if '''\\''n'\\''\\'\\'''\\''c'\\'''' -q 2>&1 | g= rep \"requires an argument\" >/dev/null 2>&1; then " "ARG=3D-q0; " "else " "ARG=3D; " "fi; " - "'''\\''n'\\''\\'\\'''\\''c'\\'''' $ARG -U /tmp/s= ocket" + "'''\\''n'\\''\\'\\'''\\''c'\\'''' $ARG -U /tmp/s= ock'et" "'\n", }; if (virTestRun("SSH test 8", testSocketSSH, &sshData8) < 0) @@ -700,14 +700,14 @@ mymain(void) struct testSSHData sshData9 =3D { .nodename =3D "somehost", .netcat =3D "n\"c", - .path =3D "/tmp/socket", + .path =3D "/tmp/sock\"et", .expectOut =3D "-T -e none -- somehost sh -c '" "if '''\\''n\"c'\\'''' -q 2>&1 | grep \"requires = an argument\" >/dev/null 2>&1; then " "ARG=3D-q0; " "else " "ARG=3D; " "fi; " - "'''\\''n\"c'\\'''' $ARG -U /tmp/socket" + "'''\\''n\"c'\\'''' $ARG -U /tmp/sock\"et" "'\n", }; if (virTestRun("SSH test 9", testSocketSSH, &sshData9) < 0) --=20 2.35.1 From nobody Thu Oct 31 23:28:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644854712; cv=none; d=zohomail.com; s=zohoarc; b=RfNLqNZtYQnbWCtBuO37w8j0//GtUgfNOJvPxMD+4xE4rwnUWeal2qNH7+29HKqFQqAX7BlU1fyDTyA08Grm6P0zPoDT7G2pMe7qVqRxqXy6wsCvYEPt62hstGANN5MsXomUkBmY9gcIHa/3epU0WLirgnBrmgTegp04p4ngwMI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644854712; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KpjrQK7HCAZ4rRQbiO9C2Xh3Mn5WtQK5x1HXVNQfgBE=; b=Q4UXQplbxh/TIong8CNBcsaFXG3Q5dQT5yinGpQZPtonkCpJRZ2b750yPOoQ4o37rQAgyetcI9Azf6kz85LX2tMmdWS2u2EfkAqmr2hKXNnzn1HLwHsxNxxeBiE33KW6kfH0VFRomBsBx3bE3vBZxNjmfeqxaK4w7PpgrnfQuKQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1644854712067582.0459857757103; Mon, 14 Feb 2022 08:05:12 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-225-0KCsArevOFKY1pXurS8Kng-1; Mon, 14 Feb 2022 11:04:57 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8F60083DD2D; Mon, 14 Feb 2022 16:04:43 +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 6D558838CF; Mon, 14 Feb 2022 16:04:43 +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 3E32D1806D2D; Mon, 14 Feb 2022 16:04:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21EG4cFs022429 for ; Mon, 14 Feb 2022 11:04:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id EB72C7E114; Mon, 14 Feb 2022 16:04:38 +0000 (UTC) Received: from harajuku.usersys.redhat.com.homenet.telecomitalia.it (unknown [10.40.194.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 59EF17CD68 for ; Mon, 14 Feb 2022 16:04:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644854710; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=KpjrQK7HCAZ4rRQbiO9C2Xh3Mn5WtQK5x1HXVNQfgBE=; b=QpGPU/7m+F7MBqaFvtPpON3pukXdMesl5/amTMytrLEpr/chrsFkrIlmZpLVGfEIeZdjfn 0PhBKd6NYclcYc97Rn10cZXkfFyt9RPOB6ayWLkEiC2XWsiyQTO4yu00Cu9TufDPELmW3N SYGValJ9owkyAGiNXKdgG6YGL8OTQAE= X-MC-Unique: 0KCsArevOFKY1pXurS8Kng-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH v2 6/6] virnetclient: Escape socket path Date: Mon, 14 Feb 2022 17:03:35 +0100 Message-Id: <20220214160335.174432-7-abologna@redhat.com> In-Reply-To: <20220214160335.174432-1-abologna@redhat.com> References: <20220214160335.174432-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644854712411100001 Content-Type: text/plain; charset="utf-8" Just like the name of the netcat command and the connection URI, the socket path is a user-provided piece of information that might contain characters that have special meaning for the shell, and as such should be escaped. Signed-off-by: Andrea Bolognani --- src/rpc/virnetclient.c | 10 ++++++++-- tests/virnetsockettest.c | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index cd92af1669..2d31429161 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -422,10 +422,12 @@ virNetClientSSHHelperCommand(virNetClientProxy proxy, { g_autofree char *netcatPathSafe =3D NULL; g_autofree char *driverURISafe =3D NULL; + g_autofree char *socketPathSafe =3D NULL; g_autofree char *nccmd =3D NULL; g_autofree char *helpercmd =3D NULL; const char *netcatPathQuotes =3D ""; const char *driverURIQuotes =3D ""; + const char *socketPathQuotes =3D ""; =20 if (netcatPath) { if (proxy =3D=3D VIR_NET_CLIENT_PROXY_AUTO) { @@ -453,6 +455,10 @@ virNetClientSSHHelperCommand(virNetClientProxy proxy, if (STRNEQ(driverURISafe, driverURI)) { driverURIQuotes =3D "'"; } + socketPathSafe =3D virNetClientDoubleEscapeShell(socketPath); + if (STRNEQ_NULLABLE(socketPathSafe, socketPath)) { + socketPathQuotes =3D "'"; + } =20 nccmd =3D g_strdup_printf( "if %s%s%s -q 2>&1 | grep \"requires an argument\" >/dev/null 2>&1= ; then " @@ -460,10 +466,10 @@ virNetClientSSHHelperCommand(virNetClientProxy proxy, "else " "ARG=3D; " "fi; " - "%s%s%s $ARG -U %s", + "%s%s%s $ARG -U %s%s%s", netcatPathQuotes, netcatPathSafe, netcatPathQuotes, netcatPathQuotes, netcatPathSafe, netcatPathQuotes, - socketPath); + socketPathQuotes, socketPathSafe, socketPathQuotes); =20 helpercmd =3D g_strdup_printf("virt-ssh-helper%s %s%s%s", readonly ? " -r" : "", diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c index ef7b5c6f59..ff75de5a85 100644 --- a/tests/virnetsockettest.c +++ b/tests/virnetsockettest.c @@ -675,7 +675,7 @@ mymain(void) "else " "ARG=3D; " "fi; " - "'''\\''n c'\\'''' $ARG -U /tmp/sock et" + "'''\\''n c'\\'''' $ARG -U '''\\''/tmp/sock et'\\= ''''" "'\n", }; if (virTestRun("SSH test 7", testSocketSSH, &sshData7) < 0) @@ -691,7 +691,7 @@ mymain(void) "else " "ARG=3D; " "fi; " - "'''\\''n'\\''\\'\\'''\\''c'\\'''' $ARG -U /tmp/s= ock'et" + "'''\\''n'\\''\\'\\'''\\''c'\\'''' $ARG -U '''\\'= '/tmp/sock'\\''\\'\\'''\\''et'\\''''" "'\n", }; if (virTestRun("SSH test 8", testSocketSSH, &sshData8) < 0) @@ -707,7 +707,7 @@ mymain(void) "else " "ARG=3D; " "fi; " - "'''\\''n\"c'\\'''' $ARG -U /tmp/sock\"et" + "'''\\''n\"c'\\'''' $ARG -U '''\\''/tmp/sock\"et'= \\''''" "'\n", }; if (virTestRun("SSH test 9", testSocketSSH, &sshData9) < 0) --=20 2.35.1