From nobody Sat Feb 7 21:16:13 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1569271485; cv=none; d=zoho.com; s=zohoarc; b=DB6WVYZ5FlTRWq/kp/HRpCdU37XVuT3Yl1DPiz4naBJnBmi09vkufvSjr8vtJZiiDw/c07ttA8CdB3BJSdaNSfkBBK0Lnj12qgm/oA3bmz787wILAruA01l/iDsclsC7AO8VfRXHeKgQ8Bcol3UJq3gRATOGYgAxANGrq42pvRs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569271485; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=eIPWTa3n08tBHzKvD9soCPeKzZhJxZrjsgrXqMKGrSs=; b=AXY7melZbDA+V9/uQZFeH6qLdPRQLRgBDv4seICP0bpraUzQJFAzMvMyiKDvSc+yCtriFMVOPitsV8ZipyDo+mpimKildrQCioG7G+SxemDf5v83JoL3xaDrF1jNxwc3gRy7gOzDy2WGfUs0EbK1jEVOhPIA68CZG9J0Kb3czaU= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1569271485215211.19057733136322; Mon, 23 Sep 2019 13:44:45 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id B06DC81F31; Mon, 23 Sep 2019 20:44: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 D08ED6017E; Mon, 23 Sep 2019 20:44: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 C78531803518; Mon, 23 Sep 2019 20:44:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8NKibH6031606 for ; Mon, 23 Sep 2019 16:44:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6E3B560166; Mon, 23 Sep 2019 20:44:37 +0000 (UTC) Received: from mx1.redhat.com (ext-mx23.extmail.prod.ext.phx2.redhat.com [10.5.110.64]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 60AAD6012D; Mon, 23 Sep 2019 20:44:37 +0000 (UTC) Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A195F1096908; Mon, 23 Sep 2019 20:44:36 +0000 (UTC) Received: by mail-qt1-f169.google.com with SMTP id c21so18800568qtj.12; Mon, 23 Sep 2019 13:44:36 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c6:df05:2a1f:6ce3:83c3:51c0]) by smtp.gmail.com with ESMTPSA id z13sm5343974qkj.34.2019.09.23.13.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2019 13:44:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=enfxXZjLCTeP7EN75b5HshKjs9PkvkDRWgmCzmPiqX4=; b=niKLYRpeG9yaT6BB1GQXzpuHaFiaXJ/Xqfs374jBI5ea6DhUaBdt7o6QnyErrsCNBC OpTNtqgO1RpsYZvloE07LL/zreeVivJbQgU4gQGhP/MIy4yWRwnlR5rfu0GvlsycrKSO 0D1KPSFFf9KvbRYW4gm//HiJ+81qOH1EdTO3ECq+spk109u3slgAGPu4gv1Ky0RVvjtx siAXRBMHgmDJ/CxfrwbnG8GL19xo06lPyrr3t6ns7ewKuQcIaEfilmR6rqvSZKTtNuGe 46G0zM+vlabB8jE4XHrDkUa4LZRCibiBrbbs4n173pUO8uAkMWa74Vy/Nq3ylU5dNK3V tffA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=enfxXZjLCTeP7EN75b5HshKjs9PkvkDRWgmCzmPiqX4=; b=qAV/7dI9xlFjyBYGUoYbN+65ZLUD6yQoIEe4AvFGA+lNdUPhW1aSI5AjYCWfAr30E+ QLFO22efwT5t9YyWwJvl8vYKM8HrTZGJfxN54SGPLMfgLBkM02hjHWR69KcBUMCf5U9G xiUaBtYcgNwcMCkpZEl1Dk7PPGneAXO2CtN3OXcRSORCF6d7IOV0FTRs4pGVjgHlNRAh 20KTmGWam/d2h3KOr3yfQAlndpSCBqj0U32mcR0y2MYyX9vACyx44qOj+o1ksw4ZdsjJ VrUwOFTQb46Jj7fAheS+dxCn3Xig2I2gcIpE2Dxo0agueGaPtwHGI4ERPRNU//keG0rf 0LOA== X-Gm-Message-State: APjAAAUJcuEQTcvAmyZZ7VrXSV6Pngfx6QG1L0KthaJSHgj0vGiGrGQM SZeIr61NOq0WTqHvcZAY+W2Z/YzI X-Google-Smtp-Source: APXvYqxzxYX/F71eAYQoxxWWTBh0fzyTY4BNQmwJbe+gJUW9r6ERiYTEcKhaiV4Ahzn/rBli4UXxhA== X-Received: by 2002:ac8:5216:: with SMTP id r22mr2066875qtn.281.1569271475885; Mon, 23 Sep 2019 13:44:35 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Mon, 23 Sep 2019 17:44:13 -0300 Message-Id: <20190923204423.23824-2-danielhb413@gmail.com> In-Reply-To: <20190923204423.23824-1-danielhb413@gmail.com> References: <20190923204423.23824-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Mon, 23 Sep 2019 20:44:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Mon, 23 Sep 2019 20:44:36 +0000 (UTC) for IP:'209.85.160.169' DOMAIN:'mail-qt1-f169.google.com' HELO:'mail-qt1-f169.google.com' FROM:'danielhb413@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.131 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS) 209.85.160.169 mail-qt1-f169.google.com 209.85.160.169 mail-qt1-f169.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.64 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v2 01/11] src/driver.c: add virConnectValidateURIPath() 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 23 Sep 2019 20:44:44 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The code to validate the URI path is repeated across several files. This patch creates a common validation code to be used across all of them. Suggested-by: Cole Robinson Signed-off-by: Daniel Henrique Barboza --- src/driver.c | 24 ++++++++++++++++++++++++ src/driver.h | 4 ++++ src/libvirt_private.syms | 1 + 3 files changed, 29 insertions(+) diff --git a/src/driver.c b/src/driver.c index 5e8f68f6df..e627b0c1d7 100644 --- a/src/driver.c +++ b/src/driver.c @@ -269,3 +269,27 @@ virSetConnectStorage(virConnectPtr conn) VIR_DEBUG("Override storage connection with %p", conn); return virThreadLocalSet(&connectStorage, conn); } + +bool +virConnectValidateURIPath(const char *uriPath, + const char *entityName, + bool privileged) +{ + if (privileged) { + if (STRNEQ(uriPath, "/system")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected %s URI path '%s', try %s:///syste= m"), + entityName, uriPath, entityName); + return false; + } + } else { + if (STRNEQ(uriPath, "/session")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected %s URI path '%s', try %s:///sessi= on"), + entityName, uriPath, entityName); + return false; + } + } + + return true; +} diff --git a/src/driver.h b/src/driver.h index f7d667a03c..68c0004d86 100644 --- a/src/driver.h +++ b/src/driver.h @@ -127,3 +127,7 @@ int virSetConnectNWFilter(virConnectPtr conn); int virSetConnectNodeDev(virConnectPtr conn); int virSetConnectSecret(virConnectPtr conn); int virSetConnectStorage(virConnectPtr conn); + +bool virConnectValidateURIPath(const char *uriPath, + const char *entityName, + bool privileged); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 39812227aa..eb9c5c22ee 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1343,6 +1343,7 @@ virStreamClass; =20 =20 # driver.h +virConnectValidateURIPath; virGetConnectInterface; virGetConnectNetwork; virGetConnectNodeDev; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list