From nobody Mon Apr 29 17:03:01 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15426386081563.216298655867263; Mon, 19 Nov 2018 06:43:28 -0800 (PST) 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 D716D307D971; Mon, 19 Nov 2018 14:43:24 +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 279B860199; Mon, 19 Nov 2018 14:43:22 +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 92275181B9F6; Mon, 19 Nov 2018 14:43:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wAJEAajO031977 for ; Mon, 19 Nov 2018 09:10:36 -0500 Received: by smtp.corp.redhat.com (Postfix) id 791A85D77B; Mon, 19 Nov 2018 14:10:36 +0000 (UTC) Received: from caroline (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2B2E05D772; Mon, 19 Nov 2018 14:10:27 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline (Postfix) with ESMTP id 45D94120027; Mon, 19 Nov 2018 15:10:26 +0100 (CET) From: Martin Kletzander To: libvir-list@redhat.com Date: Mon, 19 Nov 2018 15:10:16 +0100 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: abologna@redhat.com, ptoscano@redhat.com Subject: [libvirt] [PATCH v2] util, qemu: Fix virDoes*Exist usage 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.48]); Mon, 19 Nov 2018 14:43:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Since the functions only return 0 or 1, they should return bool (missed the change in the first commit). That way it's clearer that the check for non-existing group should be either "=3D=3D 0" instead. Fix this by using = proper negation instead. Signed-off-by: Martin Kletzander --- src/qemu/qemu_conf.c | 4 ++-- src/util/virutil.c | 12 ++++++------ src/util/virutil.h | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 32da9a735184..a946b05d5d47 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -193,10 +193,10 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool pr= ivileged) if (virAsprintf(&cfg->swtpmStorageDir, "%s/lib/libvirt/swtpm", LOCALSTATEDIR) < 0) goto error; - if (virDoesUserExist("tss") !=3D 0 || + if (!virDoesUserExist("tss") || virGetUserID("tss", &cfg->swtpm_user) < 0) cfg->swtpm_user =3D 0; /* fall back to root */ - if (virDoesGroupExist("tss") !=3D 0 || + if (!virDoesGroupExist("tss") || virGetGroupID("tss", &cfg->swtpm_group) < 0) cfg->swtpm_group =3D 0; /* fall back to root */ } else { diff --git a/src/util/virutil.c b/src/util/virutil.c index c0783ecb285b..77baaa33f472 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1133,7 +1133,7 @@ virGetGroupID(const char *group, gid_t *gid) /* Silently checks if User @name exists. * Returns if the user exists and fallbacks to false on error. */ -int +bool virDoesUserExist(const char *name) { return virGetUserIDByName(name, NULL, true) =3D=3D 0; @@ -1142,7 +1142,7 @@ virDoesUserExist(const char *name) /* Silently checks if Group @name exists. * Returns if the group exists and fallbacks to false on error. */ -int +bool virDoesGroupExist(const char *name) { return virGetGroupIDByName(name, NULL, true) =3D=3D 0; @@ -1243,16 +1243,16 @@ virGetGroupList(uid_t uid ATTRIBUTE_UNUSED, gid_t g= id ATTRIBUTE_UNUSED, return 0; } =20 -int +bool virDoesUserExist(const char *name ATTRIBUTE_UNUSED) { - return 0; + return false } =20 -int +bool virDoesGroupExist(const char *name ATTRIBUTE_UNUSED) { - return 0; + return false; } =20 # ifdef WIN32 diff --git a/src/util/virutil.h b/src/util/virutil.h index 2407f54efd47..e0ab0da0f2fc 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -152,8 +152,8 @@ int virGetUserID(const char *name, int virGetGroupID(const char *name, gid_t *gid) ATTRIBUTE_RETURN_CHECK; =20 -int virDoesUserExist(const char *name); -int virDoesGroupExist(const char *name); +bool virDoesUserExist(const char *name); +bool virDoesGroupExist(const char *name); =20 =20 bool virIsDevMapperDevice(const char *dev_name) ATTRIBUTE_NONNULL(1); --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list