From nobody Sun May 19 08:26:02 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=1675675165; cv=none; d=zohomail.com; s=zohoarc; b=WrgjxqjFhUVd5lL/hbxIFroTtArfFegI5xN6/P5Ur7OwLLGvRqtPx53rbJL98iwFD/JDYalQqJIvQHnlVpXLX8gfuzuQQGbS3QGzrhRYnxu8MqPMl6QaE7uYLc0eHsPoqkUa/Bp9e8LJw5EJSP9kV/S2RJkusJ1VWDONcsADLC8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675675165; 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=E/FtwBNHsNfi+ImsFqvjWeZ2VUNbPZ95aasZKBQvULA=; b=ZtFqS1hsAAjkYBsjef6rOeUTMZ3miO61exyFjcSehCxkcMr7ogT3GTs4oeAhMBr23WubhjO+4PIty7V2gQBnuuW9AsZ0H6SvD1Bx2IP3AaHVUo5i7Qj9DQXqlIFfZmf4YdzjLIUwB+Cxs12VtbkGl3XKs3L5jecXP3WT+RLHTbY= 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 1675675165975835.6050855332378; Mon, 6 Feb 2023 01:19:25 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-526-j6r1sttCMU2H8WLdQp1T0g-1; Mon, 06 Feb 2023 04:17:08 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2C6AB830D58; Mon, 6 Feb 2023 09:17:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D647C16020; Mon, 6 Feb 2023 09:17:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id F040119465B6; Mon, 6 Feb 2023 09:17:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A9835194658C for ; Mon, 6 Feb 2023 09:17:02 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 8F4AE492B21; Mon, 6 Feb 2023 09:17:02 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 37A3A492B22 for ; Mon, 6 Feb 2023 09:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675675165; 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=E/FtwBNHsNfi+ImsFqvjWeZ2VUNbPZ95aasZKBQvULA=; b=VDDA/x9MmCDCAkuklLiGyyTWxnTiH+3s5NaOCAqhiMfOi6dcN1KpaitKPUGUVy7ev8QOKz CJ86GOcnGkvcdXBfFRezhAoVZAkkwE2QDYO62SiJqHQbk3VTPcxDyFzml1V1QGnZm+lAiU XSGRjsGIZWQWvGBC46CUIIGZ+zgho3E= X-MC-Unique: j6r1sttCMU2H8WLdQp1T0g-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 01/10] viruri: Search params case insensitively Date: Mon, 6 Feb 2023 10:16:49 +0100 Message-Id: <98d23e1e17e38896064c8128d4b2dca794566cdd.1675674809.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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: 1675675167731100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Our URI handling code (doRemoteOpen() specifically), uses case insensitive parsing of query part of URI. For instance: qemu:///system?socket=3D/some/path qemu:///system?SoCkEt=3D/some/path are the same URI. Even though the latter is probably not used anywhere, let's switch to STRCASEEQ() instead of STREQ() at two places: virURIGetParam() and virURICheckUnixSocket(). Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/util/viruri.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/viruri.c b/src/util/viruri.c index 88bb0cc1f8..53f85ed705 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -371,7 +371,7 @@ virURIGetParam(virURI *uri, const char *name) size_t i; =20 for (i =3D 0; i < uri->paramsCount; i++) { - if (STREQ(uri->params[i].name, name)) + if (STRCASEEQ(uri->params[i].name, name)) return uri->params[i].value; } =20 @@ -403,7 +403,7 @@ virURICheckUnixSocket(virURI *uri) return false; =20 for (i =3D 0; i < uri->paramsCount; i++) { - if (STREQ(uri->params[i].name, "socket")) + if (STRCASEEQ(uri->params[i].name, "socket")) return true; } =20 --=20 2.39.1 From nobody Sun May 19 08:26:02 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=1675675093; cv=none; d=zohomail.com; s=zohoarc; b=nhoP+WSiGbRlzLsDYPhrzenLqR4KgWpHPR7wDFA7mXWjgoUkZZUomgeX1su+8u/75eSC/GUMKgL1J825b23sn/r0gfhGZ21v4/D4rdgy2tWDh/sZoHt8PwPEEyU6HnUONx+QdNC34qgoJBV0DPDRE/uzFUENEr2xcorYicJNwSY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675675093; 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=waN3bpDmdDlLFDHntUsi994zHIboYxEoiUIzrMfB+H8=; b=A+BghACgkHEC6Co0tUsrfVqFh+4lTsMUToji6HWGcStznSd7HFAt03kDGkSIkXXK/zch1yvo65jvglQaZ5cvgpxqn2DQgKtPN9pv3dO0dB2zEAM4a6tGnw/GxN6NrjQRQ33EvRWgoCcWDv6VL4NQO/c3OFUkqv2NtSBHx9VqOhM= 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 1675675093011483.38163701931364; Mon, 6 Feb 2023 01:18:13 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-659-mqQTIa79MravMjbGCbVaYQ-1; Mon, 06 Feb 2023 04:17:10 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8A8D88057A6; Mon, 6 Feb 2023 09:17:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 750EC40C83B6; Mon, 6 Feb 2023 09:17:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 332FA1946A43; Mon, 6 Feb 2023 09:17:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 42D3E1946589 for ; Mon, 6 Feb 2023 09:17:03 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 28B40492B22; Mon, 6 Feb 2023 09:17:03 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id C56D2492B21 for ; Mon, 6 Feb 2023 09:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675675092; 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=waN3bpDmdDlLFDHntUsi994zHIboYxEoiUIzrMfB+H8=; b=i3RPq7MPbiTCI95MzBp7NfiI47HWumHWNTRut1NXjXjriW7WNz3hKX2ObtPsKYH2BPBjuo Bm3rsAJqsmIyEcf/igMx2KAXv1EL/2CVgKvIcqpkd6IMIlENKc2ZXq1vn1USuFkId9v3lK enXnP8flbjiH6SAgEOjh0PsnciL8fW4= X-MC-Unique: mqQTIa79MravMjbGCbVaYQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 02/10] Drop checks for virURIFormat() retval Date: Mon, 6 Feb 2023 10:16:50 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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: 1675675094739100001 Content-Type: text/plain; charset="utf-8"; x-default="true" The virURIFormat() function either returns a string, or aborts (on OOM). There's no way this function can return NULL (as of v7.2.0-rc1~277). Therefore, it doesn't make sense to check its retval against NULL. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/admin/libvirt-admin.c | 6 +----- src/libvirt-host.c | 10 +--------- src/qemu/qemu_block.c | 3 +-- src/qemu/qemu_migration.c | 3 +-- src/remote/remote_driver.c | 3 --- src/storage/storage_backend_gluster.c | 6 +----- src/util/viruri.c | 2 +- tests/viruritest.c | 3 +-- 8 files changed, 7 insertions(+), 29 deletions(-) diff --git a/src/admin/libvirt-admin.c b/src/admin/libvirt-admin.c index 6baaea4ff2..1786a283e5 100644 --- a/src/admin/libvirt-admin.c +++ b/src/admin/libvirt-admin.c @@ -427,17 +427,13 @@ virAdmConnectIsAlive(virAdmConnectPtr conn) char * virAdmConnectGetURI(virAdmConnectPtr conn) { - char *uri =3D NULL; VIR_DEBUG("conn=3D%p", conn); =20 virResetLastError(); =20 virCheckAdmConnectReturn(conn, NULL); =20 - if (!(uri =3D virURIFormat(conn->uri))) - virDispatchError(NULL); - - return uri; + return virURIFormat(conn->uri); } =20 /** diff --git a/src/libvirt-host.c b/src/libvirt-host.c index c02222346c..a2ba347d54 100644 --- a/src/libvirt-host.c +++ b/src/libvirt-host.c @@ -313,21 +313,13 @@ virConnectGetHostname(virConnectPtr conn) char * virConnectGetURI(virConnectPtr conn) { - char *name; VIR_DEBUG("conn=3D%p", conn); =20 virResetLastError(); =20 virCheckConnectReturn(conn, NULL); =20 - if (!(name =3D virURIFormat(conn->uri))) - goto error; - - return name; - - error: - virDispatchError(conn); - return NULL; + return virURIFormat(conn->uri); } =20 =20 diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index c218262691..4c06565e0f 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -407,8 +407,7 @@ qemuBlockStorageSourceGetCURLProps(virStorageSource *sr= c, if (!(uri =3D qemuBlockStorageSourceGetURI(src))) return NULL; =20 - if (!(uristr =3D virURIFormat(uri))) - return NULL; + uristr =3D virURIFormat(uri); =20 if (!onlytarget) { if (src->auth) { diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index f36bb49be5..2720f0b083 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -3777,8 +3777,7 @@ qemuMigrationDstPrepareDirect(virQEMUDriver *driver, /* Send well-formed URI only if uri_in was well-formed */ if (well_formed_uri) { uri->port =3D port; - if (!(*uri_out =3D virURIFormat(uri))) - goto cleanup; + *uri_out =3D virURIFormat(uri); } else { *uri_out =3D g_strdup_printf("%s:%d", uri_in, port); } diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 9fc73f6d88..2e08ff246f 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -843,9 +843,6 @@ doRemoteOpen(virConnectPtr conn, name =3D virURIFormat(&tmpuri); =20 VIR_FREE(tmpuri.query); - - if (!name) - goto failed; } } } else { diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_ba= ckend_gluster.c index 1fe21b4a2b..bdf91e8bd5 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -195,11 +195,7 @@ virStorageBackendGlusterSetMetadata(virStorageBackendG= lusterState *state, =20 tmp =3D state->uri->path; state->uri->path =3D g_strdup_printf("/%s", path); - if (!(vol->target.path =3D virURIFormat(state->uri))) { - VIR_FREE(state->uri->path); - state->uri->path =3D tmp; - return -1; - } + vol->target.path =3D virURIFormat(state->uri); VIR_FREE(state->uri->path); state->uri->path =3D tmp; =20 diff --git a/src/util/viruri.c b/src/util/viruri.c index 53f85ed705..79492e87ce 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -194,7 +194,7 @@ virURIParse(const char *uri) * Wrapper for xmlSaveUri * * This function constructs back everything that @ref virURIParse - * changes after parsing + * changes after parsing. It aborts on error. * * @returns the constructed uri as a string */ diff --git a/tests/viruritest.c b/tests/viruritest.c index cd6ce57371..705e0d5c6e 100644 --- a/tests/viruritest.c +++ b/tests/viruritest.c @@ -118,8 +118,7 @@ static int testURIParse(const void *args) VIR_FREE(uri->query); uri->query =3D virURIFormatParams(uri); =20 - if (!(uristr =3D virURIFormat(uri))) - return -1; + uristr =3D virURIFormat(uri); =20 if (STRNEQ(uristr, data->uri_out)) { VIR_TEST_DEBUG("URI did not roundtrip, expect '%s', actual '%s'", --=20 2.39.1 From nobody Sun May 19 08:26:02 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=1675675103; cv=none; d=zohomail.com; s=zohoarc; b=AuLk5Vj7GQwkaStZ+BvagOllHmwAEdVeaXmsPEMqJUcSSkNYS9tdQLdKnBqDInOVeYaMjf5Te5Ks95GlX4SGGu2vr9I86eK4XtLoyDha1CUbXm6o3mCJJoaEY9GS/IUWN68afb5Bad+qE0XQ91SE94B/ttlm8hHXihK83LJvXJk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675675103; 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=Z9FWAoXPtrDpqhhAbTUgCcviFuRH+BIU+Upq9jsQCwI=; b=DHyjpdK68L62h7BV1nx4CgjhUxuPpELJphk39TfJDMzvBQtQxArOEnvUbMjzrIbIAI0OHe1fsP4fX/JN5UTFwc52Az0HHhHTy+z03cdbZjbpneLQD0OtJm38LPdx3K65VVleoj2Gg4dQ4/w9IigMOXJu1y/LGVPd6MWT6MKtOsc= 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 16756751038701011.0502203056823; Mon, 6 Feb 2023 01:18:23 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-608-G5I0fZ-mNu23pm4t-sN3aQ-1; Mon, 06 Feb 2023 04:17:12 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 00189823DEC; Mon, 6 Feb 2023 09:17:06 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF7024029A63; Mon, 6 Feb 2023 09:17:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6A9CE19465A4; Mon, 6 Feb 2023 09:17:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CAC4319465A3 for ; Mon, 6 Feb 2023 09:17:03 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B7F3A492B22; Mon, 6 Feb 2023 09:17:03 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5FAF4492B21 for ; Mon, 6 Feb 2023 09:17:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675675102; 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=Z9FWAoXPtrDpqhhAbTUgCcviFuRH+BIU+Upq9jsQCwI=; b=EX3PmOjvQWplrFVeUDA2wjpwC/5hPL/u6LaJO0kIdwJugJPtvR+m1LOgHeRHsRvthfTauG 7VvOaxZwvV2Uk3JmEM7K/38LAh15NzLu45geJs7GMn3JbdI6bR7t18ZGvx/yPXIjEkeYjX hrUmCeXtgZRlnClqHJi7nmszRc6WRmY= X-MC-Unique: G5I0fZ-mNu23pm4t-sN3aQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 03/10] doRemoteOpen(): Rename 'failed' label to 'error' Date: Mon, 6 Feb 2023 10:16:51 +0100 Message-Id: <93841b8cce28c29db815bb030022248c04104c6d.1675674809.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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: 1675675104792100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Our own coding style suggest not inventing new names for labels and stick with 'cleanup' (when the path is used in both, successful and unsuccessful returns), or 'error' (when the code below the label is used only upon error). Well, 'failed' label falls into the latter category. Rename it then. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/remote/remote_driver.c | 62 +++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 2e08ff246f..6a226999df 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -709,7 +709,7 @@ remoteConnectSupportsFeatureUnlocked(virConnectPtr conn, virReportError(VIR_ERR_INVALID_ARG, \ _("Failed to parse value of URI component %s"),= \ var->name); \ - goto failed; \ + goto error; \ } \ ARG_VAR =3D tmp =3D=3D 0; \ var->ignore =3D 1; \ @@ -852,13 +852,13 @@ doRemoteOpen(virConnectPtr conn, =20 if (conf && !mode_str && virConfGetValueString(conf, "remote_mode", &mode_str) < 0) - goto failed; + goto error; =20 if (mode_str) { if ((mode =3D remoteDriverModeTypeFromString(mode_str)) < 0) { virReportError(VIR_ERR_INVALID_ARG, _("Unknown remote mode '%s'"), mode_str); - goto failed; + goto error; } } else { if (inside_daemon && !conn->uri->server) { @@ -870,13 +870,13 @@ doRemoteOpen(virConnectPtr conn, =20 if (conf && !proxy_str && virConfGetValueString(conf, "remote_proxy", &proxy_str) < 0) - goto failed; + goto error; =20 if (proxy_str) { if ((proxy =3D virNetClientProxyTypeFromString(proxy_str)) < 0) { virReportError(VIR_ERR_INVALID_ARG, _("Unnkown proxy type '%s'"), proxy_str); - goto failed; + goto error; } } else { /* @@ -924,7 +924,7 @@ doRemoteOpen(virConnectPtr conn, if (transport =3D=3D REMOTE_DRIVER_TRANSPORT_EXT && !command) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("remote_open: for 'ext' transport, command is req= uired")); - goto failed; + goto error; } =20 VIR_DEBUG("Connecting with transport %d", transport); @@ -937,7 +937,7 @@ doRemoteOpen(virConnectPtr conn, if (!sockname && !(sockname =3D remoteGetUNIXSocket(transport, mode, driver_str, flags, &daemon_path))) - goto failed; + goto error; break; =20 case REMOTE_DRIVER_TRANSPORT_TCP: @@ -948,7 +948,7 @@ doRemoteOpen(virConnectPtr conn, case REMOTE_DRIVER_TRANSPORT_LAST: default: virReportEnumRangeError(remoteDriverTransport, transport); - goto failed; + goto error; } =20 VIR_DEBUG("Chosen UNIX socket %s", NULLSTR(sockname)); @@ -958,26 +958,26 @@ doRemoteOpen(virConnectPtr conn, case REMOTE_DRIVER_TRANSPORT_TLS: if (conf && !tls_priority && virConfGetValueString(conf, "tls_priority", &tls_priority) < 0) - goto failed; + goto error; =20 priv->tls =3D virNetTLSContextNewClientPath(pkipath, geteuid() !=3D 0, tls_priority, sanity, verify); if (!priv->tls) - goto failed; + goto error; priv->is_secure =3D 1; G_GNUC_FALLTHROUGH; =20 case REMOTE_DRIVER_TRANSPORT_TCP: priv->client =3D virNetClientNewTCP(priv->hostname, port, AF_UNSPE= C); if (!priv->client) - goto failed; + goto error; =20 if (priv->tls) { VIR_DEBUG("Starting TLS session"); if (virNetClientSetTLSSession(priv->client, priv->tls) < 0) - goto failed; + goto error; } =20 break; @@ -1001,7 +1001,7 @@ doRemoteOpen(virConnectPtr conn, auth, conn->uri); if (!priv->client) - goto failed; + goto error; =20 priv->is_secure =3D 1; break; @@ -1025,7 +1025,7 @@ doRemoteOpen(virConnectPtr conn, auth, conn->uri); if (!priv->client) - goto failed; + goto error; =20 priv->is_secure =3D 1; break; @@ -1034,7 +1034,7 @@ doRemoteOpen(virConnectPtr conn, case REMOTE_DRIVER_TRANSPORT_UNIX: if (!(priv->client =3D virNetClientNewUNIX(sockname, daemon_path))) - goto failed; + goto error; =20 priv->is_secure =3D 1; break; @@ -1055,7 +1055,7 @@ doRemoteOpen(virConnectPtr conn, sockname, name, flags & REMOTE_DRIVER_OPEN= _RO))) - goto failed; + goto error; =20 priv->is_secure =3D 1; break; @@ -1063,7 +1063,7 @@ doRemoteOpen(virConnectPtr conn, case REMOTE_DRIVER_TRANSPORT_EXT: { char const *cmd_argv[] =3D { command, NULL }; if (!(priv->client =3D virNetClientNewExternal(cmd_argv))) - goto failed; + goto error; =20 /* Do not set 'is_secure' flag since we can't guarantee * an external program is secure, and this flag must be @@ -1078,14 +1078,14 @@ doRemoteOpen(virConnectPtr conn, virReportError(VIR_ERR_INVALID_ARG, "%s", _("transport methods unix, ssh and ext are not supp= orted " "under Windows")); - goto failed; + goto error; =20 #endif /* WIN32 */ =20 case REMOTE_DRIVER_TRANSPORT_LAST: default: virReportEnumRangeError(remoteDriverTransport, transport); - goto failed; + goto error; } /* switch (transport) */ =20 =20 @@ -1095,11 +1095,11 @@ doRemoteOpen(virConnectPtr conn, virResetLastError(); } else { if (virNetClientRegisterKeepAlive(priv->client) < 0) - goto failed; + goto error; } =20 if (!(priv->closeCallback =3D virNewConnectCloseCallbackData())) - goto failed; + goto error; /* ref on behalf of netclient */ virObjectRef(priv->closeCallback); virNetClientSetCloseCallback(priv->client, @@ -1111,29 +1111,29 @@ doRemoteOpen(virConnectPtr conn, remoteEvents, G_N_ELEMENTS(remote= Events), conn))) - goto failed; + goto error; if (!(priv->lxcProgram =3D virNetClientProgramNew(LXC_PROGRAM, LXC_PROTOCOL_VERSION, NULL, 0, NULL))) - goto failed; + goto error; if (!(priv->qemuProgram =3D virNetClientProgramNew(QEMU_PROGRAM, QEMU_PROTOCOL_VERSION, qemuEvents, G_N_ELEMENTS(qemuEven= ts), conn))) - goto failed; + goto error; =20 if (virNetClientAddProgram(priv->client, priv->remoteProgram) < 0 || virNetClientAddProgram(priv->client, priv->lxcProgram) < 0 || virNetClientAddProgram(priv->client, priv->qemuProgram) < 0) - goto failed; + goto error; =20 /* Try and authenticate with server */ VIR_DEBUG("Trying authentication"); if (remoteAuthenticate(conn, priv, auth, authtype) =3D=3D -1) - goto failed; + goto error; =20 if (virNetClientKeepAliveIsSupported(priv->client)) { priv->serverKeepAlive =3D remoteConnectSupportsFeatureUnlocked(con= n, @@ -1152,7 +1152,7 @@ doRemoteOpen(virConnectPtr conn, if (call(conn, priv, 0, REMOTE_PROC_CONNECT_OPEN, (xdrproc_t) xdr_remote_connect_open_args, (char *) &args, (xdrproc_t) xdr_void, (char *) NULL) =3D=3D -1) - goto failed; + goto error; } =20 /* Now try and find out what URI the daemon used */ @@ -1165,18 +1165,18 @@ doRemoteOpen(virConnectPtr conn, REMOTE_PROC_CONNECT_GET_URI, (xdrproc_t) xdr_void, (char *) NULL, (xdrproc_t) xdr_remote_connect_get_uri_ret, (char *) &uri= ret) < 0) - goto failed; + goto error; =20 VIR_DEBUG("Auto-probed URI is %s", uriret.uri); conn->uri =3D virURIParse(uriret.uri); VIR_FREE(uriret.uri); if (!conn->uri) - goto failed; + goto error; } =20 /* Set up events */ if (!(priv->eventState =3D virObjectEventStateNew())) - goto failed; + goto error; =20 priv->serverEventFilter =3D remoteConnectSupportsFeatureUnlocked(conn, priv, VIR_DRV_FEATURE_REMOTE_EVENT_CALLBAC= K); @@ -1194,7 +1194,7 @@ doRemoteOpen(virConnectPtr conn, =20 return VIR_DRV_OPEN_SUCCESS; =20 - failed: + error: virObjectUnref(priv->remoteProgram); virObjectUnref(priv->lxcProgram); virObjectUnref(priv->qemuProgram); --=20 2.39.1 From nobody Sun May 19 08:26:02 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=1675675035; cv=none; d=zohomail.com; s=zohoarc; b=Vpz4hlR6knKdH4Qm94UVOTBAntiPJGLB6JzV4GOoHF7DkEFt9ADgJWDP0wnyuSSnrK1C4+ZpFMzZkNmlHnSQ498YaKq5m9qwvLS+ZjBco4TF/kTI3ls/TyyEZbJyG+qwGZMdvTGpNTCMvoQfNtfydW0PfqV9IzAcqcTpB+NBT2M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675675035; 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=MgwFASkVkdojN/4GqTIVYpJ2cWz4TgD3mqp4K12YJDM=; b=W2/E4IoxrrwA//8lN44EtjH+uP/hz8rK2/7e2xEMSXoYgwFSLLEe0oU+hSMYpED7gAlL7YaWYLg/tkeQpy73pDxy8ZTkbe8oiuo1LWlyzNaQEfeJ+Hmv88K+aSSWL/Bepz88LrwxHIaAqmKpz9a94l3n/aXoYMJaXF48gBJpEG0= 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 1675675035501731.0732747665381; Mon, 6 Feb 2023 01:17:15 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-462-bYRa_QisPvSuIJ8mYVDidA-1; Mon, 06 Feb 2023 04:17:11 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 690E11C05ECD; Mon, 6 Feb 2023 09:17:06 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4AEA8404CD81; Mon, 6 Feb 2023 09:17:06 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 30AA9194658F; Mon, 6 Feb 2023 09:17:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5E16B1946A4F for ; Mon, 6 Feb 2023 09:17:04 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 52817492B23; Mon, 6 Feb 2023 09:17:04 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE5D5492B22 for ; Mon, 6 Feb 2023 09:17:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675675034; 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=MgwFASkVkdojN/4GqTIVYpJ2cWz4TgD3mqp4K12YJDM=; b=OusvWASHGFpe8AEqvKhqvkbGpkacL8x05ZLt8oqKUju/qEIfMYOz2XiH9Xp23/KYLhdGQg 6dvy2GH7tGahaQcdT+H/Am4x8CpODXMvCLk96koplvbLo85IgD/0T5Li7bIH5yks0VYbZe XHltaordSR5n/TCcqQjsyvAInVI2dOQ= X-MC-Unique: bYRa_QisPvSuIJ8mYVDidA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 04/10] remote_driver: Expose EXTRACT_URI_ARG_* macros Date: Mon, 6 Feb 2023 10:16:52 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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: 1675675036562100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Almost in all places where an URI is parsed we look for additional argument(s). The remote driver's parsing uses two macros EXTRACT_URI_ARG_STR() and EXTRACT_URI_ARG_BOOL() for that purpose. Expose these so that other places can be rewritten using those macros. Signed-off-by: Michal Privoznik --- po/POTFILES | 1 + src/remote/remote_driver.c | 58 +++++++++++--------------------------- src/util/viruri.h | 23 +++++++++++++++ 3 files changed, 40 insertions(+), 42 deletions(-) diff --git a/po/POTFILES b/po/POTFILES index 4e446aaf40..2d35def639 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -332,6 +332,7 @@ src/util/virtpm.c src/util/virtypedparam-public.c src/util/virtypedparam.c src/util/viruri.c +src/util/viruri.h src/util/virusb.c src/util/virutil.c src/util/virvhba.c diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 6a226999df..c41d5b414f 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -693,30 +693,6 @@ remoteConnectSupportsFeatureUnlocked(virConnectPtr con= n, return rc !=3D -1 && ret.supported; } =20 -/* helper macro to ease extraction of arguments from the URI */ -#define EXTRACT_URI_ARG_STR(ARG_NAME, ARG_VAR) \ - if (STRCASEEQ(var->name, ARG_NAME)) { \ - VIR_FREE(ARG_VAR); \ - ARG_VAR =3D g_strdup(var->value); \ - var->ignore =3D 1; \ - continue; \ - } - -#define EXTRACT_URI_ARG_BOOL(ARG_NAME, ARG_VAR) \ - if (STRCASEEQ(var->name, ARG_NAME)) { \ - int tmp; \ - if (virStrToLong_i(var->value, NULL, 10, &tmp) < 0) { \ - virReportError(VIR_ERR_INVALID_ARG, \ - _("Failed to parse value of URI component %s"),= \ - var->name); \ - goto error; \ - } \ - ARG_VAR =3D tmp =3D=3D 0; \ - var->ignore =3D 1; \ - continue; \ - } - - /* * URIs that this driver needs to handle: * @@ -796,23 +772,23 @@ doRemoteOpen(virConnectPtr conn, if (conn->uri) { for (i =3D 0; i < conn->uri->paramsCount; i++) { virURIParam *var =3D &conn->uri->params[i]; - EXTRACT_URI_ARG_STR("name", name); - EXTRACT_URI_ARG_STR("command", command); - EXTRACT_URI_ARG_STR("socket", sockname); - EXTRACT_URI_ARG_STR("auth", authtype); - EXTRACT_URI_ARG_STR("sshauth", sshauth); - EXTRACT_URI_ARG_STR("netcat", netcat); - EXTRACT_URI_ARG_STR("keyfile", keyfile); - EXTRACT_URI_ARG_STR("pkipath", pkipath); - EXTRACT_URI_ARG_STR("known_hosts", knownHosts); - EXTRACT_URI_ARG_STR("known_hosts_verify", knownHostsVerify); - EXTRACT_URI_ARG_STR("tls_priority", tls_priority); - EXTRACT_URI_ARG_STR("mode", mode_str); - EXTRACT_URI_ARG_STR("proxy", proxy_str); - EXTRACT_URI_ARG_BOOL("no_sanity", sanity); - EXTRACT_URI_ARG_BOOL("no_verify", verify); + VIR_EXTRACT_URI_ARG_STR("name", name); + VIR_EXTRACT_URI_ARG_STR("command", command); + VIR_EXTRACT_URI_ARG_STR("socket", sockname); + VIR_EXTRACT_URI_ARG_STR("auth", authtype); + VIR_EXTRACT_URI_ARG_STR("sshauth", sshauth); + VIR_EXTRACT_URI_ARG_STR("netcat", netcat); + VIR_EXTRACT_URI_ARG_STR("keyfile", keyfile); + VIR_EXTRACT_URI_ARG_STR("pkipath", pkipath); + VIR_EXTRACT_URI_ARG_STR("known_hosts", knownHosts); + VIR_EXTRACT_URI_ARG_STR("known_hosts_verify", knownHostsVerify= ); + VIR_EXTRACT_URI_ARG_STR("tls_priority", tls_priority); + VIR_EXTRACT_URI_ARG_STR("mode", mode_str); + VIR_EXTRACT_URI_ARG_STR("proxy", proxy_str); + VIR_EXTRACT_URI_ARG_BOOL("no_sanity", sanity, error); + VIR_EXTRACT_URI_ARG_BOOL("no_verify", verify, error); #ifndef WIN32 - EXTRACT_URI_ARG_BOOL("no_tty", tty); + VIR_EXTRACT_URI_ARG_BOOL("no_tty", tty, error); #endif =20 if (STRCASEEQ(var->name, "authfile")) { @@ -1206,8 +1182,6 @@ doRemoteOpen(virConnectPtr conn, VIR_FREE(priv->hostname); return VIR_DRV_OPEN_ERROR; } -#undef EXTRACT_URI_ARG_STR -#undef EXTRACT_URI_ARG_BOOL =20 static struct private_data * remoteAllocPrivateData(void) diff --git a/src/util/viruri.h b/src/util/viruri.h index 4f27fa26d2..0e4176c037 100644 --- a/src/util/viruri.h +++ b/src/util/viruri.h @@ -62,3 +62,26 @@ const char *virURIGetParam(virURI *uri, const char *name= ); bool virURICheckUnixSocket(virURI *uri); =20 #define VIR_URI_SERVER(uri) ((uri) && (uri)->server ? (uri)->server : "loc= alhost") + +/* helper macros to ease extraction of arguments from the URI */ +#define VIR_EXTRACT_URI_ARG_STR(ARG_NAME, ARG_VAR) \ + if (STRCASEEQ(var->name, ARG_NAME)) { \ + g_free(ARG_VAR); \ + ARG_VAR =3D g_strdup(var->value); \ + var->ignore =3D 1; \ + continue; \ + } + +#define VIR_EXTRACT_URI_ARG_BOOL(ARG_NAME, ARG_VAR, LABEL) \ + if (STRCASEEQ(var->name, ARG_NAME)) { \ + int tmp; \ + if (virStrToLong_i(var->value, NULL, 10, &tmp) < 0) { \ + virReportError(VIR_ERR_INVALID_ARG, \ + _("Failed to parse value of URI component %s"),= \ + var->name); \ + goto LABEL; \ + } \ + ARG_VAR =3D tmp =3D=3D 0; \ + var->ignore =3D 1; \ + continue; \ + } --=20 2.39.1 From nobody Sun May 19 08:26:02 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=1675675036; cv=none; d=zohomail.com; s=zohoarc; b=ichq+SorIQ74rLp6ORXbDeqX9fVdhhyU0hoXihVqDozTaMWKMs1JgRYtxrSqob8wMBMmY1qBxuXJDB+9Ddi0/YbDkP+r0B2ovrvO5FRlm014yLUHrtJzc1+hzHN5ct2gPUuL9i6oFCq3QDO5c8qPqQlpDOAJfu2xFpBKk6sxzcg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675675036; 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=lpXNVLSdhhdVBMpNlNfKvdNo6rXpPJHyq6FVWdCmWSQ=; b=OXHU5UQJFvGdkpJbS5l7QtHxMzAZjQrvJTGnq4HHvUN1iS/bsA25xPp44q7c6JyM+/JjitiVhFod53kX71ap1uY5ulS0z/VV8W9Yru4vwzOu+KM6XtOuYlB8jZ9ZJTCeM0un8+sCtAH5tgX1FhQ64mG6qrS4dAQyVcLX3Sud710= 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 1675675036652678.9366994712191; Mon, 6 Feb 2023 01:17:16 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-619-Jiha-5wZPHWj2nLC6iseYQ-1; Mon, 06 Feb 2023 04:17:12 -0500 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DA6EF3C0CD4E; Mon, 6 Feb 2023 09:17:06 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB192492B25; Mon, 6 Feb 2023 09:17:06 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A791C19465A3; Mon, 6 Feb 2023 09:17:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 099D0194658C for ; Mon, 6 Feb 2023 09:17:05 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E0EF0492B21; Mon, 6 Feb 2023 09:17:04 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 88AEB492B22 for ; Mon, 6 Feb 2023 09:17:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675675035; 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=lpXNVLSdhhdVBMpNlNfKvdNo6rXpPJHyq6FVWdCmWSQ=; b=bt39L1X0BhujpHlUnWOPhl++MBFa+bA/q395CZqmVSk8t4olyYPq8ZR2GcQQo/3u2YiO/X 05xlFS82fmIbTijEpgCnO0Wo8Ma2CGLjxwqXdlzwNcIs7tykPLXAFfq8GT7CpavhZCJOUD PXJBaRSsYy0xIgi9XgteuON/SRmd6BI= X-MC-Unique: Jiha-5wZPHWj2nLC6iseYQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 05/10] src: Unify URI params parsing Date: Mon, 6 Feb 2023 10:16:53 +0100 Message-Id: <0463f1493435973821228b2eb23d3a02f09bc857.1675674809.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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: 1675675038538100003 Content-Type: text/plain; charset="utf-8"; x-default="true" Now that we have VIR_EXTRACT_URI_ARG_* macros, we can use them in the rest of the places where an URI is parsed. This also unifies behavior wrt to query arguments handling. For instance, our virAdmConnectOpen() accepts "?socket=3D..." but not "?SOCKET=3D" whereas plain virConnectOpen() does accept both. Signed-off-by: Michal Privoznik --- src/admin/libvirt-admin.c | 15 +++--- src/esx/esx_util.c | 96 +++++++++++++++++++-------------------- src/hyperv/hyperv_util.c | 30 ++++++------ src/qemu/qemu_migration.c | 21 ++++----- src/util/virauth.c | 12 ++--- src/util/viruri.h | 12 +++++ 6 files changed, 92 insertions(+), 94 deletions(-) diff --git a/src/admin/libvirt-admin.c b/src/admin/libvirt-admin.c index 1786a283e5..0f2410d18d 100644 --- a/src/admin/libvirt-admin.c +++ b/src/admin/libvirt-admin.c @@ -109,16 +109,13 @@ getSocketPath(virURI *uri) =20 =20 for (i =3D 0; i < uri->paramsCount; i++) { - virURIParam *param =3D &uri->params[i]; + virURIParam *var =3D &uri->params[i]; =20 - if (STREQ(param->name, "socket")) { - g_free(sock_path); - sock_path =3D g_strdup(param->value); - } else { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown URI parameter '%s'"), param->name); - return NULL; - } + VIR_EXTRACT_URI_ARG_STR("socket", sock_path); + + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Unknown URI parameter '%s'"), var->name); + return NULL; } =20 if (!sock_path) { diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c index 89d5517262..8c0f39ecc9 100644 --- a/src/esx/esx_util.c +++ b/src/esx/esx_util.c @@ -40,8 +40,8 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURI *u= ri) { int result =3D -1; size_t i; - int noVerify; - int autoAnswer; + int noVerify =3D -1; + int autoAnswer =3D -1; char *tmp; =20 ESX_VI_CHECK_ARG_LIST(parsedUri); @@ -49,71 +49,39 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURI = *uri) *parsedUri =3D g_new0(esxUtil_ParsedUri, 1); =20 for (i =3D 0; i < uri->paramsCount; i++) { - virURIParam *queryParam =3D &uri->params[i]; + virURIParam *var =3D &uri->params[i]; =20 - if (STRCASEEQ(queryParam->name, "transport")) { - g_free((*parsedUri)->transport); + VIR_EXTRACT_URI_ARG_STR("transport", (*parsedUri)->transport); + VIR_EXTRACT_URI_ARG_STR("vcenter", (*parsedUri)->vCenter); + VIR_EXTRACT_URI_ARG_INT("no_verify", noVerify, cleanup); + VIR_EXTRACT_URI_ARG_INT("auto_answer", autoAnswer, cleanup); =20 - (*parsedUri)->transport =3D g_strdup(queryParam->value); - - if (STRNEQ((*parsedUri)->transport, "http") && - STRNEQ((*parsedUri)->transport, "https")) { - virReportError(VIR_ERR_INVALID_ARG, - _("Query parameter 'transport' has unexpect= ed value " - "'%s' (should be http|https)"), - (*parsedUri)->transport); - goto cleanup; - } - } else if (STRCASEEQ(queryParam->name, "vcenter")) { - g_free((*parsedUri)->vCenter); - - (*parsedUri)->vCenter =3D g_strdup(queryParam->value); - } else if (STRCASEEQ(queryParam->name, "no_verify")) { - if (virStrToLong_i(queryParam->value, NULL, 10, &noVerify) < 0= || - (noVerify !=3D 0 && noVerify !=3D 1)) { - virReportError(VIR_ERR_INVALID_ARG, - _("Query parameter 'no_verify' has unexpect= ed value " - "'%s' (should be 0 or 1)"), queryParam->v= alue); - goto cleanup; - } - - (*parsedUri)->noVerify =3D noVerify !=3D 0; - } else if (STRCASEEQ(queryParam->name, "auto_answer")) { - if (virStrToLong_i(queryParam->value, NULL, 10, &autoAnswer) <= 0 || - (autoAnswer !=3D 0 && autoAnswer !=3D 1)) { - virReportError(VIR_ERR_INVALID_ARG, - _("Query parameter 'auto_answer' has unexpe= cted " - "value '%s' (should be 0 or 1)"), queryPa= ram->value); - goto cleanup; - } - - (*parsedUri)->autoAnswer =3D autoAnswer !=3D 0; - } else if (STRCASEEQ(queryParam->name, "proxy")) { + if (STRCASEEQ(var->name, "proxy")) { /* Expected format: [://][:] */ (*parsedUri)->proxy =3D true; (*parsedUri)->proxy_type =3D CURLPROXY_HTTP; g_clear_pointer(&(*parsedUri)->proxy_hostname, g_free); (*parsedUri)->proxy_port =3D 1080; =20 - if ((tmp =3D STRSKIP(queryParam->value, "http://"))) { + if ((tmp =3D STRSKIP(var->value, "http://"))) { (*parsedUri)->proxy_type =3D CURLPROXY_HTTP; - } else if ((tmp =3D STRSKIP(queryParam->value, "socks://")) || - (tmp =3D STRSKIP(queryParam->value, "socks5://"))) { + } else if ((tmp =3D STRSKIP(var->value, "socks://")) || + (tmp =3D STRSKIP(var->value, "socks5://"))) { (*parsedUri)->proxy_type =3D CURLPROXY_SOCKS5; - } else if ((tmp =3D STRSKIP(queryParam->value, "socks4://"))) { + } else if ((tmp =3D STRSKIP(var->value, "socks4://"))) { (*parsedUri)->proxy_type =3D CURLPROXY_SOCKS4; - } else if ((tmp =3D STRSKIP(queryParam->value, "socks4a://")))= { + } else if ((tmp =3D STRSKIP(var->value, "socks4a://"))) { (*parsedUri)->proxy_type =3D CURLPROXY_SOCKS4A; - } else if ((tmp =3D strstr(queryParam->value, "://"))) { + } else if ((tmp =3D strstr(var->value, "://"))) { *tmp =3D '\0'; =20 virReportError(VIR_ERR_INVALID_ARG, _("Query parameter 'proxy' contains unexpec= ted " "type '%s' (should be (http|socks(|4|4a|5= ))"), - queryParam->value); + var->value); goto cleanup; } else { - tmp =3D queryParam->value; + tmp =3D var->value; } =20 (*parsedUri)->proxy_hostname =3D g_strdup(tmp); @@ -141,7 +109,7 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURI = *uri) } } else { VIR_WARN("Ignoring unexpected query parameter '%s'", - queryParam->name); + var->name); } } =20 @@ -150,6 +118,36 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURI= *uri) if (!(*parsedUri)->transport) (*parsedUri)->transport =3D g_strdup("https"); =20 + if (STRNEQ((*parsedUri)->transport, "http") && + STRNEQ((*parsedUri)->transport, "https")) { + virReportError(VIR_ERR_INVALID_ARG, + _("Query parameter 'transport' has unexpected value= '%s' (should be http|https)"), + (*parsedUri)->transport); + goto cleanup; + } + + if (noVerify >=3D 0) { + if (noVerify !=3D 0 && noVerify !=3D 1) { + virReportError(VIR_ERR_INVALID_ARG, + _("Query parameter 'no_verify' has unexpected v= alue '%d' (should be 0 or 1)"), + noVerify); + goto cleanup; + } + + (*parsedUri)->noVerify =3D noVerify !=3D 0; + } + + if (autoAnswer >=3D 0) { + if (autoAnswer !=3D 0 && autoAnswer !=3D 1) { + virReportError(VIR_ERR_INVALID_ARG, + _("Query parameter 'auto_answer' has unexpected= value '%d' (should be 0 or 1)"), + autoAnswer); + goto cleanup; + } + + (*parsedUri)->autoAnswer =3D autoAnswer !=3D 0; + } + result =3D 0; =20 cleanup: diff --git a/src/hyperv/hyperv_util.c b/src/hyperv/hyperv_util.c index fe71e47285..38daa27743 100644 --- a/src/hyperv/hyperv_util.c +++ b/src/hyperv/hyperv_util.c @@ -45,30 +45,26 @@ hypervParseUri(hypervParsedUri **parsedUri, virURI *uri) *parsedUri =3D g_new0(hypervParsedUri, 1); =20 for (i =3D 0; i < uri->paramsCount; i++) { - virURIParam *queryParam =3D &uri->params[i]; + virURIParam *var =3D &uri->params[i]; =20 - if (STRCASEEQ(queryParam->name, "transport")) { - VIR_FREE((*parsedUri)->transport); + VIR_EXTRACT_URI_ARG_STR("transport", (*parsedUri)->transport); =20 - (*parsedUri)->transport =3D g_strdup(queryParam->value); - - if (STRNEQ((*parsedUri)->transport, "http") && - STRNEQ((*parsedUri)->transport, "https")) { - virReportError(VIR_ERR_INVALID_ARG, - _("Query parameter 'transport' has unexpect= ed value " - "'%s' (should be http|https)"), - (*parsedUri)->transport); - goto cleanup; - } - } else { - VIR_WARN("Ignoring unexpected query parameter '%s'", - queryParam->name); - } + VIR_WARN("Ignoring unexpected query parameter '%s'", + var->name); } =20 if (!(*parsedUri)->transport) (*parsedUri)->transport =3D g_strdup("https"); =20 + if (STRNEQ((*parsedUri)->transport, "http") && + STRNEQ((*parsedUri)->transport, "https")) { + virReportError(VIR_ERR_INVALID_ARG, + _("Query parameter 'transport' has unexpected value= " + "'%s' (should be http|https)"), + (*parsedUri)->transport); + goto cleanup; + } + result =3D 0; =20 cleanup: diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 2720f0b083..3c38be46f7 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2080,7 +2080,7 @@ qemuMigrationSrcGraphicsRelocate(virDomainObj *vm, int type =3D -1; int port =3D -1; int tlsPort =3D -1; - const char *tlsSubject =3D NULL; + g_autofree char *tlsSubject =3D NULL; int rc =3D -1; =20 if (!cookie || (!cookie->graphics && !graphicsuri)) @@ -2101,7 +2101,7 @@ qemuMigrationSrcGraphicsRelocate(virDomainObj *vm, =20 port =3D cookie->graphics->port; tlsPort =3D cookie->graphics->tlsPort; - tlsSubject =3D cookie->graphics->tlsSubject; + tlsSubject =3D g_strdup(cookie->graphics->tlsSubject); } =20 if (uri) { @@ -2119,18 +2119,10 @@ qemuMigrationSrcGraphicsRelocate(virDomainObj *vm, port =3D uri->port; =20 for (i =3D 0; i < uri->paramsCount; i++) { - virURIParam *param =3D uri->params + i; + virURIParam *var =3D &uri->params[i]; =20 - if (STRCASEEQ(param->name, "tlsPort")) { - if (virStrToLong_i(param->value, NULL, 10, &tlsPort) < 0) { - virReportError(VIR_ERR_INVALID_ARG, - _("invalid tlsPort number: %s"), - param->value); - return -1; - } - } else if (STRCASEEQ(param->name, "tlsSubject")) { - tlsSubject =3D param->value; - } + VIR_EXTRACT_URI_ARG_INT("tlsPort", tlsPort, error); + VIR_EXTRACT_URI_ARG_STR("tlsSubject", tlsSubject); } } =20 @@ -2157,6 +2149,9 @@ qemuMigrationSrcGraphicsRelocate(virDomainObj *vm, } =20 return rc; + + error: + return -1; } =20 =20 diff --git a/src/util/virauth.c b/src/util/virauth.c index 7b4a1bd8a5..afebb609a7 100644 --- a/src/util/virauth.c +++ b/src/util/virauth.c @@ -57,13 +57,13 @@ virAuthGetConfigFilePathURI(virURI *uri, =20 if (uri) { for (i =3D 0; i < uri->paramsCount; i++) { - if (STREQ_NULLABLE(uri->params[i].name, "authfile") && - uri->params[i].value) { - VIR_DEBUG("Using path from URI '%s'", uri->params[i].value= ); - *path =3D g_strdup(uri->params[i].value); - return 0; - } + virURIParam *var =3D &uri->params[i]; + + VIR_EXTRACT_URI_ARG_STR("authfile", *path); } + + if (*path) + return 0; } =20 userdir =3D virGetUserConfigDirectory(); diff --git a/src/util/viruri.h b/src/util/viruri.h index 0e4176c037..7e4f95a2b1 100644 --- a/src/util/viruri.h +++ b/src/util/viruri.h @@ -72,6 +72,18 @@ bool virURICheckUnixSocket(virURI *uri); continue; \ } =20 +#define VIR_EXTRACT_URI_ARG_INT(ARG_NAME, ARG_VAR, LABEL) \ + if (STRCASEEQ(var->name, ARG_NAME)) { \ + if (virStrToLong_i(var->value, NULL, 10, &(ARG_VAR)) < 0) { \ + virReportError(VIR_ERR_INVALID_ARG, \ + _("Failed to parse value of URI component %s"),= \ + var->name); \ + goto LABEL; \ + } \ + var->ignore =3D 1; \ + continue; \ + } + #define VIR_EXTRACT_URI_ARG_BOOL(ARG_NAME, ARG_VAR, LABEL) \ if (STRCASEEQ(var->name, ARG_NAME)) { \ int tmp; \ --=20 2.39.1 From nobody Sun May 19 08:26:02 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=1675675203; cv=none; d=zohomail.com; s=zohoarc; b=S0cYipIkIUIhd9mCcVE5uqoVaupjdVquD8O/ZdlaVBeY8woRYk250vRPFv2vL67QH9iznXMj/+kx0a9AzWzr7nxolghqzjPyDzt1ImK2Pk18N3bxkYl8xkLteC6lTywGfw0+kqgUZnYA1Kk3OuxmTYtuHJMOrgsd/jt60gcDOOY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675675203; 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=dfvCqb+S2lm3uWsYNYCi9bWePCGpivg6dJg5gAEfWxg=; b=KRX0k80HtVxRNNgRnXsTO4drVQJTtDvlhEQIRhRSlmVBy/w93uGwMBTyCZvzBJ7lZI3RX+gOiPZxD+nJKOjKi7uRNQS7BbpbTv95ER9G+L+Rc26XZlUv5knucjdTpGcjV3rjJQwGGCwYr6TEkSxsdys7DMDRCwstNehJXOOrJQU= 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 1675675202936429.68905893294993; Mon, 6 Feb 2023 01:20:02 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-660-TP_b5fiHNGmTYGt_ie0YeQ-1; Mon, 06 Feb 2023 04:17:12 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2AD43805233; Mon, 6 Feb 2023 09:17:07 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id F29F9C1602F; Mon, 6 Feb 2023 09:17:06 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E254919465A3; Mon, 6 Feb 2023 09:17:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9932219465B9 for ; Mon, 6 Feb 2023 09:17:05 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 7C109492B27; Mon, 6 Feb 2023 09:17:05 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22C96492B21 for ; Mon, 6 Feb 2023 09:17:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675675202; 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=dfvCqb+S2lm3uWsYNYCi9bWePCGpivg6dJg5gAEfWxg=; b=iPxIof3+AnZV+mUP3iEHadR+aP4D9fYWaniaRB540xl4V6BG48mOZ4Aj8tQ8G49y2SADS3 /QE5csvuBT2lhhCPQzD6o1l8g1QO/el2e9FLFXB+qJsJHLrxp8qr0IbB81lHHZc+HUp244 uEdEzDFAqryd52L81CfiaOPHLVQnOts= X-MC-Unique: TP_b5fiHNGmTYGt_ie0YeQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 06/10] virt-ssh-helper: Accept ?mode= in connection URI Date: Mon, 6 Feb 2023 10:16:54 +0100 Message-Id: <1c5f7f5f2da74e4b82876223db9ad7d27be8a38c.1675674809.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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: 1675675203972100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When split daemons were introduced, we also made connection URI accept new parameter: mode=3D{auto,legacy,direct} so that a client can force connecting to either old, monolithic daemon, or to split daemon (see v5.7.0-rc1~257 for more info). Now, the change was done to the remote driver, but not to virt-ssh-helper. True, our remote driver code still does not pass the 'mode' parameter, but that will be addressed in next commits. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/remote/remote_ssh_helper.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/remote/remote_ssh_helper.c b/src/remote/remote_ssh_helper.c index b4735027be..3b4de7f214 100644 --- a/src/remote/remote_ssh_helper.c +++ b/src/remote/remote_ssh_helper.c @@ -354,6 +354,8 @@ int main(int argc, char **argv) g_autoptr(virURI) uri =3D NULL; g_autofree char *driver =3D NULL; remoteDriverTransport transport; + int mode =3D REMOTE_DRIVER_MODE_AUTO; + g_autofree char *mode_str =3D NULL; gboolean version =3D false; gboolean readonly =3D false; g_autofree char *sock_path =3D NULL; @@ -367,6 +369,7 @@ int main(int argc, char **argv) { NULL, '\0', 0, 0, NULL, NULL, NULL } }; unsigned int flags; + size_t i; =20 context =3D g_option_context_new("URI - libvirt socket proxy"); g_option_context_set_summary(context, @@ -429,8 +432,20 @@ int main(int argc, char **argv) if (readonly) flags |=3D REMOTE_DRIVER_OPEN_RO; =20 + for (i =3D 0; i < uri->paramsCount; i++) { + virURIParam *var =3D &uri->params[i]; + + VIR_EXTRACT_URI_ARG_STR("mode", mode_str); + } + + if (mode_str && + (mode =3D remoteDriverModeTypeFromString(mode_str)) < 0) { + g_printerr(_("%s: unknown remote mode '%s'"), argv[0], mode_str); + exit(EXIT_FAILURE); + } + sock_path =3D remoteGetUNIXSocket(transport, - REMOTE_DRIVER_MODE_AUTO, + mode, driver, flags, &daemon_path); --=20 2.39.1 From nobody Sun May 19 08:26:02 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=1675675151; cv=none; d=zohomail.com; s=zohoarc; b=GBuZwSZsZpLLe15Lm+P/ox1qatwlA8p2yNLFbP8KZR1TXfssOssiBuMu9wTaIBVcY9gNiPgiurIy7X68Bk8E5dLPy2X0IN4IustQ4JvXws/czKT2HDnepH5clTSTa++ukdP4DRU4R7tUN6E2MlfRHd8m+cRbr5NQZSKK/waOylo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675675151; 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=+1hxokLBiaGIfru+1V/TWxEjBj3QRoXX2azwdhKRMwY=; b=XlmYS8Rrz8YeDChp7M4mKqSzdiRFeBFRPkx3tBbzWaTQE8D1Skf8oQA0Zd2JPEpd9J1elVwmaxNL+tOJF6zJn2EH81BZc3Wejt1Nn4MOrC+1EsYO+uwNy6MPkE3i6PF52oBIXJJHxHlOhOxKLSDtctrJmK8OzYevviOik0copHM= 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 1675675151122469.22369607851533; Mon, 6 Feb 2023 01:19:11 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-451-lQlDyF1sO0yb1MEJO41OBQ-1; Mon, 06 Feb 2023 04:17:13 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 84F081C04183; Mon, 6 Feb 2023 09:17:08 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6FE42C15BA0; Mon, 6 Feb 2023 09:17:08 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 60B47194658C; Mon, 6 Feb 2023 09:17:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2FE0C194658D for ; Mon, 6 Feb 2023 09:17:06 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 14556492B23; Mon, 6 Feb 2023 09:17:06 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0D89492B21 for ; Mon, 6 Feb 2023 09:17:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675675150; 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=+1hxokLBiaGIfru+1V/TWxEjBj3QRoXX2azwdhKRMwY=; b=RrQxN0DpYllP47MuGxyaMogxDNOFW5zuiqOeyd8pEHjF3NlCj1rZGUDsc6RTCZumbooF9E lRtS8RUn29tVdBLy8G46WUedwmlW06egpFi3fwYN3hrbeBNys05Y0bCjERH4rDQaQvv8Cf zObZ4DL8mKpPpyRKLrF5oQWOeWlW+aw= X-MC-Unique: lQlDyF1sO0yb1MEJO41OBQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 07/10] virt-ssh-helper: Accept ?socket= in connection URI Date: Mon, 6 Feb 2023 10:16:55 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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: 1675675151825100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Similarly to the previous commit, let's accept "socket" parameter in the connection URI. This change will allow us to use virt-ssh-helper instead of 'nc' in all cases (done in one of future commits). Please note, when the parameter is used it effectively disables automatic daemon spawning and an error is reported. But this is intentional - so that the helper behaves just like regular virConnectOpen() with different transport than ssh, e.g. unix. But this 'change' is acceptable - there's no way for users to make our remote code pass the argument to virt-ssh-helper, yet. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/remote/remote_ssh_helper.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/remote/remote_ssh_helper.c b/src/remote/remote_ssh_helper.c index 3b4de7f214..0eafc70d16 100644 --- a/src/remote/remote_ssh_helper.c +++ b/src/remote/remote_ssh_helper.c @@ -436,6 +436,7 @@ int main(int argc, char **argv) virURIParam *var =3D &uri->params[i]; =20 VIR_EXTRACT_URI_ARG_STR("mode", mode_str); + VIR_EXTRACT_URI_ARG_STR("socket", sock_path); } =20 if (mode_str && @@ -444,11 +445,12 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } =20 - sock_path =3D remoteGetUNIXSocket(transport, - mode, - driver, - flags, - &daemon_path); + if (!sock_path && + !(sock_path =3D remoteGetUNIXSocket(transport, mode, + driver, flags, &daemon_path))) { + g_printerr(_("%s: failed to generate UNIX socket path"), argv[0]); + exit(EXIT_FAILURE); + } =20 if (virNetSocketNewConnectUNIX(sock_path, daemon_path, &sock) < 0) { g_printerr(_("%s: cannot connect to '%s': %s\n"), --=20 2.39.1 From nobody Sun May 19 08:26:02 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=1675675083; cv=none; d=zohomail.com; s=zohoarc; b=CSlBbkbHOCbXhrqJ0Um49qo7+ywg32Hepk4+WfZHKCxD9DYZ7dzK59vFOeu0FWTZmZtRFCHlvkQPERQKvzRATSs7h38ASQ8U7RYEAfbxgEkRfG99d+nteaDpZa91z2Z2W5QjAUZOFKMpKMVQJlnVpNFnXnBmssZ3h/YjxpxpNDA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675675083; 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=Qf4RIpbUEhJay7vjYoYdbIe09KWYu3AaGXV5VKf6RbQ=; b=KrK+4bvcFghsHKdx32Hm4viEH8xUdBP8SVydKFvBYW0iRa7XZKBUz3uRwmPz9vYB5DmB54l0g5Nb7PyG0TReXzqgDMQ1VsWPMhqav0zscntDsC/pnjXkVGt8kCkqp7uunvdLLCla8PCTGIEwSkRAmAprj69GtIj8gCDm+ZuxJUM= 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 1675675083302829.4503596823641; Mon, 6 Feb 2023 01:18:03 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-668-RvbgExzpP1ew_5Bkt4G8dA-1; Mon, 06 Feb 2023 04:17:13 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 82FC785CAB8; Mon, 6 Feb 2023 09:17:07 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 544E7404CD8C; Mon, 6 Feb 2023 09:17:07 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2849719465B9; Mon, 6 Feb 2023 09:17:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AE8B819465B3 for ; Mon, 6 Feb 2023 09:17:06 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A31ED492B22; Mon, 6 Feb 2023 09:17:06 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4AEFD492B23 for ; Mon, 6 Feb 2023 09:17:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675675082; 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=Qf4RIpbUEhJay7vjYoYdbIe09KWYu3AaGXV5VKf6RbQ=; b=aR+iRtG4PqL3etJPUl2yX0hNy5WoI8r7k5QM0yfwCDgpq9LSjMnVUJx6NG4L3IL7tdJQ8m dqY3OqMSImVSFKfK+97i07BHplOEL6jH9mXG5H0avq0oCE7Lg54VBzuLmcf+4k77ICNGzw 9bBOGNj2W5VoVYxk0Fn7tRok//vty0E= X-MC-Unique: RvbgExzpP1ew_5Bkt4G8dA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 08/10] remote_driver: Move URI re-generation into a function Date: Mon, 6 Feb 2023 10:16:56 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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: 1675675084689100002 Content-Type: text/plain; charset="utf-8"; x-default="true" When handling virConnectOpen(), we parse given URI, specifically all those parameters we know, like ?mode, ?socket, ?name, etc. ignoring those we don't recognize yet. Then, we reconstruct the URI back, but ignoring all parameters we've parsed. In other words: qemu:///system?mode=3Dlegacy&foo=3Dbar becomes: qemu:///system?foo=3Dbar The reconstructed URI is then passed to the corresponding driver (QEMU in our example) with intent of it parsing parameters further (or just ignoring them). Now, this URI reconstruction is currently implemented in an else branch. Move it into a separate function so that it can be re-used. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/remote/remote_driver.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index c41d5b414f..7e1a31a5a0 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -693,6 +693,22 @@ remoteConnectSupportsFeatureUnlocked(virConnectPtr con= n, return rc !=3D -1 && ret.supported; } =20 +static char * +remoteConnectFormatURI(virURI *uri, + const char *driver_str) +{ + g_autofree char *query =3D NULL; + virURI tmpuri =3D { + .scheme =3D (char *)driver_str, + .path =3D uri->path, + .fragment =3D uri->fragment, + }; + + query =3D tmpuri.query =3D virURIFormatParams(uri); + + return virURIFormat(&tmpuri); +} + /* * URIs that this driver needs to handle: * @@ -809,16 +825,8 @@ doRemoteOpen(virConnectPtr conn, /* Allow remote serve to probe */ name =3D g_strdup(""); } else { - virURI tmpuri =3D { - .scheme =3D (char *)driver_str, - .query =3D virURIFormatParams(conn->uri), - .path =3D conn->uri->path, - .fragment =3D conn->uri->fragment, - }; + name =3D remoteConnectFormatURI(conn->uri, driver_str); =20 - name =3D virURIFormat(&tmpuri); - - VIR_FREE(tmpuri.query); } } } else { --=20 2.39.1 From nobody Sun May 19 08:26:02 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=1675675085; cv=none; d=zohomail.com; s=zohoarc; b=Z/7qTssv2Hc4sgdUL92POOFj0YsW5RPUzYHau1N74Ip1I5KqGH9e3TFNfWWZkOffzpSe2/YL3pPp/01/yk/QsUuWHVC7INdFUWSr3raywBA+j5PiMfdGuLevZENQmE85rospY9mfAKD3sdmzSvtGmQjTrjZHjozWaFJfKBbsf1k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675675085; 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=TDYoxcyRw79sFvPzMzEgS+kLuyL2Cz6k4u978orwSGI=; b=drXeq3lI6hKlo6E10+QNHiqRM5ldAXvLs3wRXxOof9cGawIFLaUqqb7gBfzKwNeOcHIvPO7vzyE2Ma5j5MzG0nydtxxxw8pJTksId4pp+V2EAQVwLXCq659Mgdk2SuPjQ44VfOAmwRsyorvw3aLsBiX1UVgbV7UT69tVzZ0Nxc0= 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 1675675085829380.46997734477293; Mon, 6 Feb 2023 01:18:05 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-451-UJm2MDZjOZ2bO-8x2fyflQ-1; Mon, 06 Feb 2023 04:17:13 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F34CA85CBDD; Mon, 6 Feb 2023 09:17:08 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB5DD404CD85; Mon, 6 Feb 2023 09:17:08 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 93D9919465B5; Mon, 6 Feb 2023 09:17:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5C4CD19465A8 for ; Mon, 6 Feb 2023 09:17:07 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3FD01492B23; Mon, 6 Feb 2023 09:17:07 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id D9C4A492B27 for ; Mon, 6 Feb 2023 09:17:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675675084; 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=TDYoxcyRw79sFvPzMzEgS+kLuyL2Cz6k4u978orwSGI=; b=GCudjJxzQWFjZKga9sviyCYeGtm52MuFY72x5QOaBc6ADeHcnNPVCOBOWacrp5Slt4iAHz TSZkPj7GQlFeDYgAceTOJbO5V95PsOcW1JuVqXz9ujtYx1d0HZ0UbDF2HvG+/hw4Yt8tMV Pahj4cG4rgJWyHLn6Jc3dXI+PVUM6lk= X-MC-Unique: UJm2MDZjOZ2bO-8x2fyflQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 09/10] viruri: Introduce virURIParamsSetIgnore() Date: Mon, 6 Feb 2023 10:16:57 +0100 Message-Id: <7841e36153fde91f8375d1bac78bcd686b4213ed.1675674809.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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: 1675675086677100005 Content-Type: text/plain; charset="utf-8"; x-default="true" The aim of this helper is to manipulate the .ignore value for given list of parameters. For instance: virURIParamsSetIgnore(uri, false, {"mode", "socket", NULL}); Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/libvirt_private.syms | 1 + src/util/viruri.c | 18 ++++++++++++++++++ src/util/viruri.h | 2 ++ 3 files changed, 21 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 7ca8b472be..97c3d86217 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3560,6 +3560,7 @@ virURIFormat; virURIFormatParams; virURIFree; virURIGetParam; +virURIParamsSetIgnore; virURIParse; virURIResolveAlias; =20 diff --git a/src/util/viruri.c b/src/util/viruri.c index 79492e87ce..85a9355918 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -409,3 +409,21 @@ virURICheckUnixSocket(virURI *uri) =20 return false; } + + +void +virURIParamsSetIgnore(virURI *uri, + bool ignore, + const char *names[]) +{ + size_t i; + + for (i =3D 0; i < uri->paramsCount; i++) { + size_t j; + + for (j =3D 0; names[j]; j++) { + if (STRCASEEQ(uri->params[i].name, names[j])) + uri->params[i].ignore =3D ignore; + } + } +} diff --git a/src/util/viruri.h b/src/util/viruri.h index 7e4f95a2b1..de59e7f0f8 100644 --- a/src/util/viruri.h +++ b/src/util/viruri.h @@ -61,6 +61,8 @@ const char *virURIGetParam(virURI *uri, const char *name); =20 bool virURICheckUnixSocket(virURI *uri); =20 +void virURIParamsSetIgnore(virURI *uri, bool ignore, const char *names[]); + #define VIR_URI_SERVER(uri) ((uri) && (uri)->server ? (uri)->server : "loc= alhost") =20 /* helper macros to ease extraction of arguments from the URI */ --=20 2.39.1 From nobody Sun May 19 08:26:02 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=1675675144; cv=none; d=zohomail.com; s=zohoarc; b=E/6wBnVjqRAXNV38DxEPUvRXzgIwmMOy2+AzZbMImsUZX0FoQXLoaLnL5hbFTLqqc1QkeIi37k8T6ltRooBLD8igLzD8FDxpqL1+ZtwEq10HiXy7I9anx1qIJYjfP43Brj/Qn8/NqyyVAD758CympjURvLL2YWAsKeEFRDeY2m8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675675144; 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=fN8W2+DHjF+smpOG1N8Wh4/HBB90DbH5fdGxTnDa5bw=; b=Rd3gBF8SHc3azREjF1ftapgSXJGe97SkV7S4XdnTd7EZDD0et4uoXb5YFswt9KzTSK/0a52AbP+TgNi6llcV/HUSmmVaUh63dJ5AcV0x0S8r26NRYi6YK4QChp2sW9KLJaDxkPTD39VEH++6cOPmjnjmK5PjSHifE/1NMmHDJFY= 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 1675675144518494.8600989849357; Mon, 6 Feb 2023 01:19:04 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-45-45b7ofgfNdaqKSu0e9_gXQ-1; Mon, 06 Feb 2023 04:17:13 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 308DA1818E6C; Mon, 6 Feb 2023 09:17:10 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A4481121315; Mon, 6 Feb 2023 09:17:10 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CD94A194658C; Mon, 6 Feb 2023 09:17:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D92F01946589 for ; Mon, 6 Feb 2023 09:17:07 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id CCA92492B21; Mon, 6 Feb 2023 09:17:07 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 753F3492B22 for ; Mon, 6 Feb 2023 09:17:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675675143; 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=fN8W2+DHjF+smpOG1N8Wh4/HBB90DbH5fdGxTnDa5bw=; b=Xszl/DJY1iiVYAi4UjnRlA893HBiiITkxrMafj5Vq8ORorjNxA3k6UH4Fyuq+MnNyDJLKY qE9Hrnwc8Pb4Sjj1nIoNcfRJZ9Om/Gq3euO14+aFqNXk6c6X9fSUC1Q4S4UQOZ6XazQnK1 lMUn3KiCB1x6qVIveoEY61O8vbtSbws= X-MC-Unique: 45b7ofgfNdaqKSu0e9_gXQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 10/10] remote: Pass 'mode' and 'socket' URI parameters to virt-ssh-helper Date: Mon, 6 Feb 2023 10:16:58 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: 1675675145763100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Even though we have split daemons for some time now, they are not the default by far. We've made the change ~1.5 year ago (in v7.5.0-rc1~35). Therefore, we have some users that use 'mode=3Dlegacy' parameter in their connection URI. But this parameter is not propagated to virt-ssh-helper (and neither is the 'socket=3D...' parameter). But now that virt-ssh-helper parses those URI parameters, we can pass them onto the remote host. Resolves: https://gitlab.com/libvirt/libvirt/-/issues/433 Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/remote/remote_driver.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 7e1a31a5a0..f8f2dc0636 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -695,18 +695,31 @@ remoteConnectSupportsFeatureUnlocked(virConnectPtr co= nn, =20 static char * remoteConnectFormatURI(virURI *uri, - const char *driver_str) + const char *driver_str, + bool unmask) { + const char *names[] =3D {"mode", "socket", NULL}; g_autofree char *query =3D NULL; + char *ret =3D NULL; virURI tmpuri =3D { .scheme =3D (char *)driver_str, .path =3D uri->path, .fragment =3D uri->fragment, }; =20 + if (unmask) { + virURIParamsSetIgnore(uri, false, names); + } + query =3D tmpuri.query =3D virURIFormatParams(uri); =20 - return virURIFormat(&tmpuri); + ret =3D virURIFormat(&tmpuri); + + if (unmask) { + virURIParamsSetIgnore(uri, true, names); + } + + return ret; } =20 /* @@ -754,6 +767,7 @@ doRemoteOpen(virConnectPtr conn, g_autofree char *mode_str =3D NULL; g_autofree char *daemon_path =3D NULL; g_autofree char *proxy_str =3D NULL; + g_autofree char *virtSshURI =3D NULL; bool sanity =3D true; bool verify =3D true; #ifndef WIN32 @@ -825,7 +839,10 @@ doRemoteOpen(virConnectPtr conn, /* Allow remote serve to probe */ name =3D g_strdup(""); } else { - name =3D remoteConnectFormatURI(conn->uri, driver_str); + name =3D remoteConnectFormatURI(conn->uri, driver_str, fal= se); + + /* Preserve mode and socket parameters. */ + virtSshURI =3D remoteConnectFormatURI(conn->uri, driver_st= r, true); =20 } } @@ -980,7 +997,7 @@ doRemoteOpen(virConnectPtr conn, proxy, netcat, sockname, - name, + virtSshURI ? virtSshURI : na= me, flags & REMOTE_DRIVER_OPEN_R= O, auth, conn->uri); @@ -1004,7 +1021,7 @@ doRemoteOpen(virConnectPtr conn, proxy, netcat, sockname, - name, + virtSshURI ? virtSshURI : nam= e, flags & REMOTE_DRIVER_OPEN_RO, auth, conn->uri); @@ -1037,7 +1054,7 @@ doRemoteOpen(virConnectPtr conn, proxy, netcat, sockname, - name, + virtSshURI ? virtSshURI : = name, flags & REMOTE_DRIVER_OPEN= _RO))) goto error; =20 --=20 2.39.1