From nobody Mon Feb 9 00:53:28 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1564420420; cv=none; d=zoho.com; s=zohoarc; b=enLqvOW9s64HtGd4kHIwHXh/kSfHimKrqP2Ra2M2yhMJPi1+reRgOv2lGrYCq5qQqPtXaVQ//fx7qMjYQNewdb0YaHM1BXR4n0a8n1fiq3Ft2XFZo6SaEKMF7HThMB5RMdF+GKIIZXokO6EQppY+yiM/WTNF1G9D3PyFBShM7bk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564420420; 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=qQQhcbin1Gh722wgdUO+4voyb3vYOh2hpY7MQt7Nosg=; b=bmg13nO4krN6AY8DSQpDBm7JKNte/e8HetlLlwxkWjfxKnm5eixGhu4qlG+yVS0atUkTqMtoB0Uh+NAT/qMNC377FCxKr18N/i8gMfmSYbNGpqu8V26z7jTfLvMZWfwRJGL56QeWgCOvNjCWIKJ78kpEXPNURpZA2+xEhEmEqPA= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass 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 1564420420108457.48211773415096; Mon, 29 Jul 2019 10:13:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DBCA881DE1; Mon, 29 Jul 2019 17:13:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B86035D9C8; Mon, 29 Jul 2019 17:13:38 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 806931972D; Mon, 29 Jul 2019 17:13:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x6THDbfq029032 for ; Mon, 29 Jul 2019 13:13:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7DD505C21F; Mon, 29 Jul 2019 17:13:37 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-51.ams2.redhat.com [10.36.112.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E8C45C1A1; Mon, 29 Jul 2019 17:13:29 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Mon, 29 Jul 2019 18:11:27 +0100 Message-Id: <20190729171130.25484-46-berrange@redhat.com> In-Reply-To: <20190729171130.25484-1-berrange@redhat.com> References: <20190729171130.25484-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Andrea Bolognani Subject: [libvirt] [PATCH v3 45/48] util: make generic identity accessors private 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-Type: text/plain; charset="utf-8" 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 29 Jul 2019 17:13:39 +0000 (UTC) Only expose the type safe getters/setters to other code in preparation for changing the internal storage of data. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Christophe de Dinechin --- src/libvirt_private.syms | 2 -- src/util/viridentity.c | 28 ++++++++++++++++----- src/util/viridentity.h | 25 ------------------- tests/viridentitytest.c | 45 +++++++++------------------------- tests/virnetserverclienttest.c | 45 +++++++++++++++------------------- 5 files changed, 54 insertions(+), 91 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ac357583e4..c7fb8c94e4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2136,7 +2136,6 @@ virHostMemSetParameters; =20 =20 # util/viridentity.h -virIdentityGetAttr; virIdentityGetCurrent; virIdentityGetOSGroupID; virIdentityGetOSGroupName; @@ -2150,7 +2149,6 @@ virIdentityGetSystem; virIdentityGetX509DName; virIdentityIsEqual; virIdentityNew; -virIdentitySetAttr; virIdentitySetCurrent; virIdentitySetOSGroupID; virIdentitySetOSGroupName; diff --git a/src/util/viridentity.c b/src/util/viridentity.c index 2c6c0ee91f..fe0c416bba 100644 --- a/src/util/viridentity.c +++ b/src/util/viridentity.c @@ -41,6 +41,20 @@ =20 VIR_LOG_INIT("util.identity"); =20 +typedef enum { + VIR_IDENTITY_ATTR_OS_USER_NAME, + VIR_IDENTITY_ATTR_OS_USER_ID, + VIR_IDENTITY_ATTR_OS_GROUP_NAME, + VIR_IDENTITY_ATTR_OS_GROUP_ID, + VIR_IDENTITY_ATTR_OS_PROCESS_ID, + VIR_IDENTITY_ATTR_OS_PROCESS_TIME, + VIR_IDENTITY_ATTR_SASL_USER_NAME, + VIR_IDENTITY_ATTR_X509_DISTINGUISHED_NAME, + VIR_IDENTITY_ATTR_SELINUX_CONTEXT, + + VIR_IDENTITY_ATTR_LAST, +} virIdentityAttrType; + struct _virIdentity { virObject parent; =20 @@ -233,9 +247,10 @@ static void virIdentityDispose(void *object) * * Returns: 0 on success, or -1 on error */ -int virIdentitySetAttr(virIdentityPtr ident, - unsigned int attr, - const char *value) +static int +virIdentitySetAttr(virIdentityPtr ident, + unsigned int attr, + const char *value) { int ret =3D -1; VIR_DEBUG("ident=3D%p attribute=3D%u value=3D%s", ident, attr, value); @@ -269,9 +284,10 @@ int virIdentitySetAttr(virIdentityPtr ident, * * Returns 0 on success, -1 on error */ -int virIdentityGetAttr(virIdentityPtr ident, - unsigned int attr, - const char **value) +static int +virIdentityGetAttr(virIdentityPtr ident, + unsigned int attr, + const char **value) { VIR_DEBUG("ident=3D%p attribute=3D%d value=3D%p", ident, attr, value); =20 diff --git a/src/util/viridentity.h b/src/util/viridentity.h index 4b87506373..0925b740d9 100644 --- a/src/util/viridentity.h +++ b/src/util/viridentity.h @@ -26,20 +26,6 @@ typedef struct _virIdentity virIdentity; typedef virIdentity *virIdentityPtr; =20 -typedef enum { - VIR_IDENTITY_ATTR_OS_USER_NAME, - VIR_IDENTITY_ATTR_OS_USER_ID, - VIR_IDENTITY_ATTR_OS_GROUP_NAME, - VIR_IDENTITY_ATTR_OS_GROUP_ID, - VIR_IDENTITY_ATTR_OS_PROCESS_ID, - VIR_IDENTITY_ATTR_OS_PROCESS_TIME, - VIR_IDENTITY_ATTR_SASL_USER_NAME, - VIR_IDENTITY_ATTR_X509_DISTINGUISHED_NAME, - VIR_IDENTITY_ATTR_SELINUX_CONTEXT, - - VIR_IDENTITY_ATTR_LAST, -} virIdentityAttrType; - virIdentityPtr virIdentityGetCurrent(void); int virIdentitySetCurrent(virIdentityPtr ident); =20 @@ -47,17 +33,6 @@ virIdentityPtr virIdentityGetSystem(void); =20 virIdentityPtr virIdentityNew(void); =20 -int virIdentitySetAttr(virIdentityPtr ident, - unsigned int attr, - const char *value) - ATTRIBUTE_NONNULL(1) - ATTRIBUTE_NONNULL(3); - -int virIdentityGetAttr(virIdentityPtr ident, - unsigned int attr, - const char **value) - ATTRIBUTE_NONNULL(1) - ATTRIBUTE_NONNULL(3); =20 bool virIdentityIsEqual(virIdentityPtr identA, virIdentityPtr identB) diff --git a/tests/viridentitytest.c b/tests/viridentitytest.c index 64b511c272..e57b68ec43 100644 --- a/tests/viridentitytest.c +++ b/tests/viridentitytest.c @@ -45,14 +45,11 @@ static int testIdentityAttrs(const void *data ATTRIBUTE= _UNUSED) if (!(ident =3D virIdentityNew())) goto cleanup; =20 - if (virIdentitySetAttr(ident, - VIR_IDENTITY_ATTR_OS_USER_NAME, - "fred") < 0) + if (virIdentitySetOSUserName(ident, "fred") < 0) goto cleanup; =20 - if (virIdentityGetAttr(ident, - VIR_IDENTITY_ATTR_OS_USER_NAME, - &val) < 0) + if (virIdentityGetOSUserName(ident, + &val) < 0) goto cleanup; =20 if (STRNEQ_NULLABLE(val, "fred")) { @@ -60,9 +57,7 @@ static int testIdentityAttrs(const void *data ATTRIBUTE_U= NUSED) goto cleanup; } =20 - if (virIdentityGetAttr(ident, - VIR_IDENTITY_ATTR_OS_GROUP_NAME, - &val) < 0) + if (virIdentityGetOSGroupName(ident, &val) < 0) goto cleanup; =20 if (val !=3D NULL) { @@ -70,16 +65,12 @@ static int testIdentityAttrs(const void *data ATTRIBUTE= _UNUSED) goto cleanup; } =20 - if (virIdentitySetAttr(ident, - VIR_IDENTITY_ATTR_OS_USER_NAME, - "joe") !=3D -1) { + if (virIdentitySetOSUserName(ident, "joe") !=3D -1) { VIR_DEBUG("Unexpectedly overwrote attribute"); goto cleanup; } =20 - if (virIdentityGetAttr(ident, - VIR_IDENTITY_ATTR_OS_USER_NAME, - &val) < 0) + if (virIdentityGetOSUserName(ident, &val) < 0) goto cleanup; =20 if (STRNEQ_NULLABLE(val, "fred")) { @@ -110,9 +101,7 @@ static int testIdentityEqual(const void *data ATTRIBUTE= _UNUSED) goto cleanup; } =20 - if (virIdentitySetAttr(identa, - VIR_IDENTITY_ATTR_OS_USER_NAME, - "fred") < 0) + if (virIdentitySetOSUserName(identa, "fred") < 0) goto cleanup; =20 if (virIdentityIsEqual(identa, identb)) { @@ -120,9 +109,7 @@ static int testIdentityEqual(const void *data ATTRIBUTE= _UNUSED) goto cleanup; } =20 - if (virIdentitySetAttr(identb, - VIR_IDENTITY_ATTR_OS_USER_NAME, - "fred") < 0) + if (virIdentitySetOSUserName(identb, "fred") < 0) goto cleanup; =20 if (!virIdentityIsEqual(identa, identb)) { @@ -130,13 +117,9 @@ static int testIdentityEqual(const void *data ATTRIBUT= E_UNUSED) goto cleanup; } =20 - if (virIdentitySetAttr(identa, - VIR_IDENTITY_ATTR_OS_GROUP_NAME, - "flintstone") < 0) + if (virIdentitySetOSGroupName(identa, "flintstone") < 0) goto cleanup; - if (virIdentitySetAttr(identb, - VIR_IDENTITY_ATTR_OS_GROUP_NAME, - "flintstone") < 0) + if (virIdentitySetOSGroupName(identb, "flintstone") < 0) goto cleanup; =20 if (!virIdentityIsEqual(identa, identb)) { @@ -144,9 +127,7 @@ static int testIdentityEqual(const void *data ATTRIBUTE= _UNUSED) goto cleanup; } =20 - if (virIdentitySetAttr(identb, - VIR_IDENTITY_ATTR_SASL_USER_NAME, - "fred@FLINTSTONE.COM") < 0) + if (virIdentitySetSASLUserName(identb, "fred@FLINTSTONE.COM") < 0) goto cleanup; =20 if (virIdentityIsEqual(identa, identb)) { @@ -181,9 +162,7 @@ static int testIdentityGetSystem(const void *data) goto cleanup; } =20 - if (virIdentityGetAttr(ident, - VIR_IDENTITY_ATTR_SELINUX_CONTEXT, - &val) < 0) + if (virIdentityGetSELinuxContext(ident, &val) < 0) goto cleanup; =20 if (STRNEQ_NULLABLE(val, context)) { diff --git a/tests/virnetserverclienttest.c b/tests/virnetserverclienttest.c index 280bd24227..603afadab4 100644 --- a/tests/virnetserverclienttest.c +++ b/tests/virnetserverclienttest.c @@ -53,9 +53,9 @@ static int testIdentity(const void *opaque ATTRIBUTE_UNUS= ED) virNetServerClientPtr client =3D NULL; virIdentityPtr ident =3D NULL; const char *gotUsername =3D NULL; - const char *gotUserID =3D NULL; + uid_t gotUserID; const char *gotGroupname =3D NULL; - const char *gotGroupID =3D NULL; + gid_t gotGroupID; const char *gotSELinuxContext =3D NULL; =20 if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) < 0) { @@ -85,9 +85,8 @@ static int testIdentity(const void *opaque ATTRIBUTE_UNUS= ED) goto cleanup; } =20 - if (virIdentityGetAttr(ident, - VIR_IDENTITY_ATTR_OS_USER_NAME, - &gotUsername) < 0) { + if (virIdentityGetOSUserName(ident, + &gotUsername) < 0) { fprintf(stderr, "Missing username in identity\n"); goto cleanup; } @@ -97,21 +96,19 @@ static int testIdentity(const void *opaque ATTRIBUTE_UN= USED) goto cleanup; } =20 - if (virIdentityGetAttr(ident, - VIR_IDENTITY_ATTR_OS_USER_ID, - &gotUserID) < 0) { + if (virIdentityGetOSUserID(ident, + &gotUserID) < 0) { fprintf(stderr, "Missing user ID in identity\n"); goto cleanup; } - if (STRNEQ_NULLABLE("666", gotUserID)) { - fprintf(stderr, "Want username '666' got '%s'\n", - NULLSTR(gotUserID)); + if (666 !=3D gotUserID) { + fprintf(stderr, "Want username '666' got '%llu'\n", + (unsigned long long)gotUserID); goto cleanup; } =20 - if (virIdentityGetAttr(ident, - VIR_IDENTITY_ATTR_OS_GROUP_NAME, - &gotGroupname) < 0) { + if (virIdentityGetOSGroupName(ident, + &gotGroupname) < 0) { fprintf(stderr, "Missing groupname in identity\n"); goto cleanup; } @@ -121,27 +118,25 @@ static int testIdentity(const void *opaque ATTRIBUTE_= UNUSED) goto cleanup; } =20 - if (virIdentityGetAttr(ident, - VIR_IDENTITY_ATTR_OS_GROUP_ID, - &gotGroupID) < 0) { + if (virIdentityGetOSGroupID(ident, + &gotGroupID) < 0) { fprintf(stderr, "Missing group ID in identity\n"); goto cleanup; } - if (STRNEQ_NULLABLE("7337", gotGroupID)) { - fprintf(stderr, "Want groupname '7337' got '%s'\n", - NULLSTR(gotGroupID)); + if (7337 !=3D gotGroupID) { + fprintf(stderr, "Want groupname '7337' got '%llu'\n", + (unsigned long long)gotGroupID); goto cleanup; } =20 - if (virIdentityGetAttr(ident, - VIR_IDENTITY_ATTR_SELINUX_CONTEXT, - &gotSELinuxContext) < 0) { + if (virIdentityGetSELinuxContext(ident, + &gotSELinuxContext) < 0) { fprintf(stderr, "Missing SELinux context in identity\n"); goto cleanup; } if (STRNEQ_NULLABLE("foo_u:bar_r:wizz_t:s0-s0:c0.c1023", gotSELinuxCon= text)) { - fprintf(stderr, "Want groupname 'foo_u:bar_r:wizz_t:s0-s0:c0.c1023= ' got '%s'\n", - NULLSTR(gotGroupID)); + fprintf(stderr, "Want SELinux context 'foo_u:bar_r:wizz_t:s0-s0:c0= .c1023' got '%s'\n", + NULLSTR(gotSELinuxContext)); goto cleanup; } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list