From nobody Fri May 3 16:00:45 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496496474177634.1072053497891; Sat, 3 Jun 2017 06:27:54 -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 E1FDFBB9C5; Sat, 3 Jun 2017 13:27:51 +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 97AA619E89; Sat, 3 Jun 2017 13:27:51 +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 169051841C86; Sat, 3 Jun 2017 13:27:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DRfG0008452 for ; Sat, 3 Jun 2017 09:27:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 578CB17F25; Sat, 3 Jun 2017 13:27:41 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14C5E78397 for ; Sat, 3 Jun 2017 13:27:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E1FDFBB9C5 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E1FDFBB9C5 From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:27:30 -0400 Message-Id: <20170603132737.27650-2-jferlan@redhat.com> In-Reply-To: <20170603132737.27650-1-jferlan@redhat.com> References: <20170603132737.27650-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/8] secret: Whitespace modification for secret_driver 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: , MIME-Version: 1.0 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.26]); Sat, 03 Jun 2017 13:27:52 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Ensure two empty lines between functions. Signed-off-by: John Ferlan --- src/secret/secret_driver.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index fc01e6d..a096fdb 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -72,6 +72,7 @@ secretDriverLock(void) virMutexLock(&driver->lock); } =20 + static void secretDriverUnlock(void) { @@ -79,7 +80,6 @@ secretDriverUnlock(void) } =20 =20 - static virSecretObjPtr secretObjFromSecret(virSecretPtr secret) { @@ -109,6 +109,7 @@ secretConnectNumOfSecrets(virConnectPtr conn) conn); } =20 + static int secretConnectListSecrets(virConnectPtr conn, char **uuids, @@ -279,6 +280,7 @@ secretDefineXML(virConnectPtr conn, return ret; } =20 + static char * secretGetXMLDesc(virSecretPtr secret, unsigned int flags) @@ -304,6 +306,7 @@ secretGetXMLDesc(virSecretPtr secret, return ret; } =20 + static int secretSetValue(virSecretPtr secret, const unsigned char *value, @@ -340,6 +343,7 @@ secretSetValue(virSecretPtr secret, return ret; } =20 + static unsigned char * secretGetValue(virSecretPtr secret, size_t *value_size, @@ -377,6 +381,7 @@ secretGetValue(virSecretPtr secret, return ret; } =20 + static int secretUndefine(virSecretPtr secret) { @@ -415,6 +420,7 @@ secretUndefine(virSecretPtr secret) return ret; } =20 + static int secretStateCleanup(void) { @@ -435,6 +441,7 @@ secretStateCleanup(void) return 0; } =20 + static int secretStateInitialize(bool privileged, virStateInhibitCallback callback ATTRIBUTE_UNUSED, @@ -486,6 +493,7 @@ secretStateInitialize(bool privileged, return -1; } =20 + static int secretStateReload(void) { @@ -500,6 +508,7 @@ secretStateReload(void) return 0; } =20 + static int secretConnectSecretEventRegisterAny(virConnectPtr conn, virSecretPtr secret, @@ -521,6 +530,7 @@ secretConnectSecretEventRegisterAny(virConnectPtr conn, return callbackID; } =20 + static int secretConnectSecretEventDeregisterAny(virConnectPtr conn, int callbackID) @@ -565,6 +575,7 @@ static virStateDriver stateDriver =3D { .stateReload =3D secretStateReload, }; =20 + int secretRegister(void) { --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 16:00:45 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 149649646656135.94588298294798; Sat, 3 Jun 2017 06:27:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 76B2580F6B; Sat, 3 Jun 2017 13:27:44 +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 2E7C89100E; Sat, 3 Jun 2017 13:27:44 +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 6DD704A48C; Sat, 3 Jun 2017 13:27:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DRfKO008457 for ; Sat, 3 Jun 2017 09:27:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id C213378371; Sat, 3 Jun 2017 13:27:41 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F26C17F25 for ; Sat, 3 Jun 2017 13:27:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 76B2580F6B Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 76B2580F6B From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:27:31 -0400 Message-Id: <20170603132737.27650-3-jferlan@redhat.com> In-Reply-To: <20170603132737.27650-1-jferlan@redhat.com> References: <20170603132737.27650-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/8] secret: Alter FindByUUID to expect the formatted uuidstr 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: , MIME-Version: 1.0 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 03 Jun 2017 13:27:45 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since we're storing a virUUIDFormat'd string in our Hash Table, let's modify the Lookup API to receive a formatted string as well. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 18 +++++++----------- src/conf/virsecretobj.h | 2 +- src/secret/secret_driver.c | 10 +++++----- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 0311335..62b86b7 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -171,12 +171,8 @@ virSecretObjListDispose(void *obj) */ static virSecretObjPtr virSecretObjListFindByUUIDLocked(virSecretObjListPtr secrets, - const unsigned char *uuid) + const char *uuidstr) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - - virUUIDFormat(uuid, uuidstr); - return virObjectRef(virHashLookup(secrets->objs, uuidstr)); } =20 @@ -184,7 +180,7 @@ virSecretObjListFindByUUIDLocked(virSecretObjListPtr se= crets, /** * virSecretObjFindByUUID: * @secrets: list of secret objects - * @uuid: secret uuid to find + * @uuidstr: secret uuid to find * * This function locks @secrets and finds the secret object which * corresponds to @uuid. @@ -193,12 +189,12 @@ virSecretObjListFindByUUIDLocked(virSecretObjListPtr = secrets, */ virSecretObjPtr virSecretObjListFindByUUID(virSecretObjListPtr secrets, - const unsigned char *uuid) + const char *uuidstr) { virSecretObjPtr obj; =20 virObjectLock(secrets); - obj =3D virSecretObjListFindByUUIDLocked(secrets, uuid); + obj =3D virSecretObjListFindByUUIDLocked(secrets, uuidstr); virObjectUnlock(secrets); if (obj) virObjectLock(obj); @@ -346,13 +342,14 @@ virSecretObjListAdd(virSecretObjListPtr secrets, if (oldDef) *oldDef =3D NULL; =20 + virUUIDFormat(newdef->uuid, uuidstr); + /* Is there a secret already matching this UUID */ - if ((obj =3D virSecretObjListFindByUUIDLocked(secrets, newdef->uuid)))= { + if ((obj =3D virSecretObjListFindByUUIDLocked(secrets, uuidstr))) { virObjectLock(obj); def =3D obj->def; =20 if (STRNEQ_NULLABLE(def->usage_id, newdef->usage_id)) { - virUUIDFormat(def->uuid, uuidstr); virReportError(VIR_ERR_INTERNAL_ERROR, _("a secret with UUID %s is already defined for= " "use with %s"), @@ -390,7 +387,6 @@ virSecretObjListAdd(virSecretObjListPtr secrets, /* Generate the possible configFile and base64File strings * using the configDir, uuidstr, and appropriate suffix */ - virUUIDFormat(newdef->uuid, uuidstr); if (!(configFile =3D virFileBuildPath(configDir, uuidstr, ".xml"))= || !(base64File =3D virFileBuildPath(configDir, uuidstr, ".base64= "))) goto cleanup; diff --git a/src/conf/virsecretobj.h b/src/conf/virsecretobj.h index a355da7..0196813 100644 --- a/src/conf/virsecretobj.h +++ b/src/conf/virsecretobj.h @@ -40,7 +40,7 @@ virSecretObjListNew(void); =20 virSecretObjPtr virSecretObjListFindByUUID(virSecretObjListPtr secrets, - const unsigned char *uuid); + const char *uuidstr); =20 virSecretObjPtr virSecretObjListFindByUsage(virSecretObjListPtr secrets, diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index a096fdb..8ddae57 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -86,8 +86,8 @@ secretObjFromSecret(virSecretPtr secret) virSecretObjPtr obj; char uuidstr[VIR_UUID_STRING_BUFLEN]; =20 - if (!(obj =3D virSecretObjListFindByUUID(driver->secrets, secret->uuid= ))) { - virUUIDFormat(secret->uuid, uuidstr); + virUUIDFormat(secret->uuid, uuidstr); + if (!(obj =3D virSecretObjListFindByUUID(driver->secrets, uuidstr))) { virReportError(VIR_ERR_NO_SECRET, _("no secret with matching uuid '%s'"), uuidstr); return NULL; @@ -148,10 +148,10 @@ secretLookupByUUID(virConnectPtr conn, virSecretPtr ret =3D NULL; virSecretObjPtr obj; virSecretDefPtr def; + char uuidstr[VIR_UUID_STRING_BUFLEN]; =20 - if (!(obj =3D virSecretObjListFindByUUID(driver->secrets, uuid))) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - virUUIDFormat(uuid, uuidstr); + virUUIDFormat(uuid, uuidstr); + if (!(obj =3D virSecretObjListFindByUUID(driver->secrets, uuidstr))) { virReportError(VIR_ERR_NO_SECRET, _("no secret with matching uuid '%s'"), uuidstr); goto cleanup; --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 16:00:45 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496496467043975.2549220484914; Sat, 3 Jun 2017 06:27:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 664EA80F63; Sat, 3 Jun 2017 13:27:44 +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 2C43282497; Sat, 3 Jun 2017 13:27:44 +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 71F9D1841C80; Sat, 3 Jun 2017 13:27:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DRgbJ008465 for ; Sat, 3 Jun 2017 09:27:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3701278371; Sat, 3 Jun 2017 13:27:42 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id E9B8A17F25 for ; Sat, 3 Jun 2017 13:27:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 664EA80F63 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 664EA80F63 From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:27:32 -0400 Message-Id: <20170603132737.27650-4-jferlan@redhat.com> In-Reply-To: <20170603132737.27650-1-jferlan@redhat.com> References: <20170603132737.27650-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/8] secret: Rename variable in virSecretObjListAdd 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: , MIME-Version: 1.0 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 03 Jun 2017 13:27:45 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rename @def to @objdef - it'll make future patches easier. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 62b86b7..e3bcbe5 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -332,7 +332,7 @@ virSecretObjListAdd(virSecretObjListPtr secrets, virSecretDefPtr *oldDef) { virSecretObjPtr obj; - virSecretDefPtr def; + virSecretDefPtr objdef; virSecretObjPtr ret =3D NULL; char uuidstr[VIR_UUID_STRING_BUFLEN]; char *configFile =3D NULL, *base64File =3D NULL; @@ -347,26 +347,26 @@ virSecretObjListAdd(virSecretObjListPtr secrets, /* Is there a secret already matching this UUID */ if ((obj =3D virSecretObjListFindByUUIDLocked(secrets, uuidstr))) { virObjectLock(obj); - def =3D obj->def; + objdef =3D obj->def; =20 - if (STRNEQ_NULLABLE(def->usage_id, newdef->usage_id)) { + if (STRNEQ_NULLABLE(objdef->usage_id, newdef->usage_id)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("a secret with UUID %s is already defined for= " "use with %s"), - uuidstr, def->usage_id); + uuidstr, objdef->usage_id); goto cleanup; } =20 - if (def->isprivate && !newdef->isprivate) { + if (objdef->isprivate && !newdef->isprivate) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot change private flag on existing secre= t")); goto cleanup; } =20 if (oldDef) - *oldDef =3D def; + *oldDef =3D objdef; else - virSecretDefFree(def); + virSecretDefFree(objdef); obj->def =3D newdef; } else { /* No existing secret with same UUID, @@ -375,8 +375,8 @@ virSecretObjListAdd(virSecretObjListPtr secrets, newdef->usage_type, newdef->usage_id))) { virObjectLock(obj); - def =3D obj->def; - virUUIDFormat(def->uuid, uuidstr); + objdef =3D obj->def; + virUUIDFormat(objdef->uuid, uuidstr); virReportError(VIR_ERR_INTERNAL_ERROR, _("a secret with UUID %s already defined for " "use with %s"), --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 16:00:45 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496496477996472.3878541587908; Sat, 3 Jun 2017 06:27:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA15F3B74D; Sat, 3 Jun 2017 13:27:55 +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 8F5B671C24; Sat, 3 Jun 2017 13:27:55 +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 2D82D4A48F; Sat, 3 Jun 2017 13:27:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DRgU9008476 for ; Sat, 3 Jun 2017 09:27:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id A451778371; Sat, 3 Jun 2017 13:27:42 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6164F17F25 for ; Sat, 3 Jun 2017 13:27:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BA15F3B74D Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com BA15F3B74D From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:27:33 -0400 Message-Id: <20170603132737.27650-5-jferlan@redhat.com> In-Reply-To: <20170603132737.27650-1-jferlan@redhat.com> References: <20170603132737.27650-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/8] secret: Clean up virSecretObjListAdd processing 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: , MIME-Version: 1.0 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 03 Jun 2017 13:27:56 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Make use of an error: label to handle the failure and need to call virSecretObjEndAPI for the object to set it to NULL for return. Also rather than an if/else processing - have the initial "if" which is just replacing the @newdef into obj->def goto cleanup, thus allowing the remaining code to be extracted from the else and appear to more inline. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 74 ++++++++++++++++++++++++---------------------= ---- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index e3bcbe5..1bafd0b 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -333,7 +333,6 @@ virSecretObjListAdd(virSecretObjListPtr secrets, { virSecretObjPtr obj; virSecretDefPtr objdef; - virSecretObjPtr ret =3D NULL; char uuidstr[VIR_UUID_STRING_BUFLEN]; char *configFile =3D NULL, *base64File =3D NULL; =20 @@ -354,13 +353,13 @@ virSecretObjListAdd(virSecretObjListPtr secrets, _("a secret with UUID %s is already defined for= " "use with %s"), uuidstr, objdef->usage_id); - goto cleanup; + goto error; } =20 if (objdef->isprivate && !newdef->isprivate) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot change private flag on existing secre= t")); - goto cleanup; + goto error; } =20 if (oldDef) @@ -368,50 +367,51 @@ virSecretObjListAdd(virSecretObjListPtr secrets, else virSecretDefFree(objdef); obj->def =3D newdef; - } else { - /* No existing secret with same UUID, - * try look for matching usage instead */ - if ((obj =3D virSecretObjListFindByUsageLocked(secrets, - newdef->usage_type, - newdef->usage_id))) { - virObjectLock(obj); - objdef =3D obj->def; - virUUIDFormat(objdef->uuid, uuidstr); - virReportError(VIR_ERR_INTERNAL_ERROR, - _("a secret with UUID %s already defined for " - "use with %s"), - uuidstr, newdef->usage_id); - goto cleanup; - } + goto cleanup; + } =20 - /* Generate the possible configFile and base64File strings - * using the configDir, uuidstr, and appropriate suffix - */ - if (!(configFile =3D virFileBuildPath(configDir, uuidstr, ".xml"))= || - !(base64File =3D virFileBuildPath(configDir, uuidstr, ".base64= "))) - goto cleanup; + /* No existing secret with same UUID, + * try to look for matching usage instead */ + if ((obj =3D virSecretObjListFindByUsageLocked(secrets, + newdef->usage_type, + newdef->usage_id))) { + virObjectLock(obj); + objdef =3D obj->def; + virUUIDFormat(objdef->uuid, uuidstr); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("a secret with UUID %s already defined for " + "use with %s"), + uuidstr, newdef->usage_id); + goto error; + } =20 - if (!(obj =3D virSecretObjNew())) - goto cleanup; + /* Generate the possible configFile and base64File strings + * using the configDir, uuidstr, and appropriate suffix + */ + if (!(configFile =3D virFileBuildPath(configDir, uuidstr, ".xml")) || + !(base64File =3D virFileBuildPath(configDir, uuidstr, ".base64"))) + goto cleanup; =20 - if (virHashAddEntry(secrets->objs, uuidstr, obj) < 0) - goto cleanup; + if (!(obj =3D virSecretObjNew())) + goto cleanup; =20 - obj->def =3D newdef; - VIR_STEAL_PTR(obj->configFile, configFile); - VIR_STEAL_PTR(obj->base64File, base64File); - virObjectRef(obj); - } + if (virHashAddEntry(secrets->objs, uuidstr, obj) < 0) + goto error; =20 - ret =3D obj; - obj =3D NULL; + obj->def =3D newdef; + VIR_STEAL_PTR(obj->configFile, configFile); + VIR_STEAL_PTR(obj->base64File, base64File); + virObjectRef(obj); =20 cleanup: - virSecretObjEndAPI(&obj); VIR_FREE(configFile); VIR_FREE(base64File); virObjectUnlock(secrets); - return ret; + return obj; + + error: + virSecretObjEndAPI(&obj); + goto cleanup; } =20 =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 16:00:45 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496496474204783.7964741346603; Sat, 3 Jun 2017 06:27:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DEED1C04B939; Sat, 3 Jun 2017 13:27:51 +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 9D4308249E; Sat, 3 Jun 2017 13:27:51 +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 1CC661841C87; Sat, 3 Jun 2017 13:27:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DRhCH008483 for ; Sat, 3 Jun 2017 09:27:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1A3BC17F25; Sat, 3 Jun 2017 13:27:43 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id CBC3078397 for ; Sat, 3 Jun 2017 13:27:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DEED1C04B939 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DEED1C04B939 From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:27:34 -0400 Message-Id: <20170603132737.27650-6-jferlan@redhat.com> In-Reply-To: <20170603132737.27650-1-jferlan@redhat.com> References: <20170603132737.27650-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/8] secret: Remove need for local configFile and base64File in ObjectAdd 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: , MIME-Version: 1.0 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 03 Jun 2017 13:27:52 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than assign to a local variable, let's just assign directly to the object using the error path for cleanup. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 1bafd0b..c0bcfab 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -334,7 +334,6 @@ virSecretObjListAdd(virSecretObjListPtr secrets, virSecretObjPtr obj; virSecretDefPtr objdef; char uuidstr[VIR_UUID_STRING_BUFLEN]; - char *configFile =3D NULL, *base64File =3D NULL; =20 virObjectLock(secrets); =20 @@ -385,27 +384,23 @@ virSecretObjListAdd(virSecretObjListPtr secrets, goto error; } =20 + if (!(obj =3D virSecretObjNew())) + goto cleanup; + /* Generate the possible configFile and base64File strings * using the configDir, uuidstr, and appropriate suffix */ - if (!(configFile =3D virFileBuildPath(configDir, uuidstr, ".xml")) || - !(base64File =3D virFileBuildPath(configDir, uuidstr, ".base64"))) - goto cleanup; - - if (!(obj =3D virSecretObjNew())) - goto cleanup; + if (!(obj->configFile =3D virFileBuildPath(configDir, uuidstr, ".xml")= ) || + !(obj->base64File =3D virFileBuildPath(configDir, uuidstr, ".base6= 4"))) + goto error; =20 if (virHashAddEntry(secrets->objs, uuidstr, obj) < 0) goto error; =20 obj->def =3D newdef; - VIR_STEAL_PTR(obj->configFile, configFile); - VIR_STEAL_PTR(obj->base64File, base64File); virObjectRef(obj); =20 cleanup: - VIR_FREE(configFile); - VIR_FREE(base64File); virObjectUnlock(secrets); return obj; =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 16:00:45 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496496477832697.4291415478505; Sat, 3 Jun 2017 06:27:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DF28FBB9CD; Sat, 3 Jun 2017 13:27:55 +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 9C28391034; Sat, 3 Jun 2017 13:27:55 +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 34E921841C8A; Sat, 3 Jun 2017 13:27:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DRhJH008488 for ; Sat, 3 Jun 2017 09:27:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 83F2378371; Sat, 3 Jun 2017 13:27:43 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 426CE17F25 for ; Sat, 3 Jun 2017 13:27:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DF28FBB9CD Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DF28FBB9CD From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:27:35 -0400 Message-Id: <20170603132737.27650-7-jferlan@redhat.com> In-Reply-To: <20170603132737.27650-1-jferlan@redhat.com> References: <20170603132737.27650-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 6/8] secret: Have virSecretObjNew consume newdef 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: , MIME-Version: 1.0 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 03 Jun 2017 13:27:56 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move the consumption of @newdef into virSecretObjNew and then handle that in the calling path. Because on error the calling code expects to free @newdef, unset obj->def for the creation failure error paths. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index c0bcfab..ca13cf8 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -87,7 +87,7 @@ virSecretObjOnceInit(void) VIR_ONCE_GLOBAL_INIT(virSecretObj) =20 static virSecretObjPtr -virSecretObjNew(void) +virSecretObjNew(virSecretDefPtr def) { virSecretObjPtr obj; =20 @@ -98,6 +98,7 @@ virSecretObjNew(void) return NULL; =20 virObjectLock(obj); + obj->def =3D def; =20 return obj; } @@ -384,20 +385,23 @@ virSecretObjListAdd(virSecretObjListPtr secrets, goto error; } =20 - if (!(obj =3D virSecretObjNew())) + if (!(obj =3D virSecretObjNew(newdef))) goto cleanup; =20 /* Generate the possible configFile and base64File strings * using the configDir, uuidstr, and appropriate suffix */ if (!(obj->configFile =3D virFileBuildPath(configDir, uuidstr, ".xml")= ) || - !(obj->base64File =3D virFileBuildPath(configDir, uuidstr, ".base6= 4"))) + !(obj->base64File =3D virFileBuildPath(configDir, uuidstr, ".base6= 4"))) { + obj->def =3D NULL; goto error; + } =20 - if (virHashAddEntry(secrets->objs, uuidstr, obj) < 0) + if (virHashAddEntry(secrets->objs, uuidstr, obj) < 0) { + obj->def =3D NULL; goto error; + } =20 - obj->def =3D newdef; virObjectRef(obj); =20 cleanup: --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 16:00:45 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496496481353597.7577543835503; Sat, 3 Jun 2017 06:28:01 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 74EBDBB9D0; Sat, 3 Jun 2017 13:27:59 +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 503758249E; Sat, 3 Jun 2017 13:27:59 +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 041D94A491; Sat, 3 Jun 2017 13:27:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DRhtU008496 for ; Sat, 3 Jun 2017 09:27:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id EF41C78371; Sat, 3 Jun 2017 13:27:43 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABF3117F25 for ; Sat, 3 Jun 2017 13:27:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 74EBDBB9D0 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 74EBDBB9D0 From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:27:36 -0400 Message-Id: <20170603132737.27650-8-jferlan@redhat.com> In-Reply-To: <20170603132737.27650-1-jferlan@redhat.com> References: <20170603132737.27650-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 7/8] secret: Properly handle @def after virSecretObjAdd in driver 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: , MIME-Version: 1.0 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 03 Jun 2017 13:28:00 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since the virSecretObjListAdd technically consumes @def on success, the secretDefineXML should fetch the @def from the object afterwards and manage as an @objdef and set @def =3D NULL immediately. Signed-off-by: John Ferlan --- src/secret/secret_driver.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 8ddae57..32cd8bb 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -210,6 +210,7 @@ secretDefineXML(virConnectPtr conn, { virSecretPtr ret =3D NULL; virSecretObjPtr obj =3D NULL; + virSecretDefPtr objdef; virSecretDefPtr backup =3D NULL; virSecretDefPtr def; virObjectEventPtr event =3D NULL; @@ -225,8 +226,10 @@ secretDefineXML(virConnectPtr conn, if (!(obj =3D virSecretObjListAdd(driver->secrets, def, driver->configDir, &backup))) goto cleanup; + def =3D NULL; + objdef =3D virSecretObjGetDef(obj); =20 - if (!def->isephemeral) { + if (!objdef->isephemeral) { if (backup && backup->isephemeral) { if (virSecretObjSaveData(obj) < 0) goto restore_backup; @@ -248,17 +251,16 @@ secretDefineXML(virConnectPtr conn, /* Saved successfully - drop old values */ virSecretDefFree(backup); =20 - event =3D virSecretEventLifecycleNew(def->uuid, - def->usage_type, - def->usage_id, + event =3D virSecretEventLifecycleNew(objdef->uuid, + objdef->usage_type, + objdef->usage_id, VIR_SECRET_EVENT_DEFINED, 0); =20 ret =3D virGetSecret(conn, - def->uuid, - def->usage_type, - def->usage_id); - def =3D NULL; + objdef->uuid, + objdef->usage_type, + objdef->usage_id); goto cleanup; =20 restore_backup: --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 16:00:45 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496496482046411.9909941456025; Sat, 3 Jun 2017 06:28:02 -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 9FB52142A7B; Sat, 3 Jun 2017 13:27:59 +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 71A3E19E89; Sat, 3 Jun 2017 13:27:59 +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 23CCF180BAF4; Sat, 3 Jun 2017 13:27:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DRiGu008506 for ; Sat, 3 Jun 2017 09:27:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 629AC78371; Sat, 3 Jun 2017 13:27:44 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2188917F25 for ; Sat, 3 Jun 2017 13:27:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9FB52142A7B Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9FB52142A7B From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:27:37 -0400 Message-Id: <20170603132737.27650-9-jferlan@redhat.com> In-Reply-To: <20170603132737.27650-1-jferlan@redhat.com> References: <20170603132737.27650-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 8/8] secret: Handle object list removal and deletion properly 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: , MIME-Version: 1.0 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.39]); Sat, 03 Jun 2017 13:28:00 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than rely on virSecretObjEndAPI to make the final virObjectUnref after the call virSecretObjListRemove, be more explicit by calling virObjectUnref and setting @obj to NULL for secretUndefine and in the error path of secretDefineXML. This also fixes a leak during virSecretLoad if the virSecretLoadValue fails the code jumps to cleanup without setting @ret =3D obj, thus calling virSecretObjListRemove which only accounts for the object reference related to adding the object to the list during virSecretObjListAdd, but does not account for the reference to the object itself as the return of @ret would be NULL so the caller wouldn't call virSecretObjEndAPI on the object recently added thus reducing the refcnt to zero. Thus cleaning up the virSecretLoadValue error path to make it clearer what needs to be done on failure. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 14 ++++++-------- src/secret/secret_driver.c | 9 +++++++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index ca13cf8..26646dd 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -918,7 +918,6 @@ virSecretLoad(virSecretObjListPtr secrets, { virSecretDefPtr def =3D NULL; virSecretObjPtr obj =3D NULL; - virSecretObjPtr ret =3D NULL; =20 if (!(def =3D virSecretDefParseFile(path))) goto cleanup; @@ -930,16 +929,15 @@ virSecretLoad(virSecretObjListPtr secrets, goto cleanup; def =3D NULL; =20 - if (virSecretLoadValue(obj) < 0) - goto cleanup; - - ret =3D obj; - obj =3D NULL; + if (virSecretLoadValue(obj) < 0) { + virSecretObjListRemove(secrets, obj); + virObjectUnref(obj); + obj =3D NULL; + } =20 cleanup: - virSecretObjListRemove(secrets, obj); virSecretDefFree(def); - return ret; + return obj; } =20 =20 diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 32cd8bb..14483fd 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -268,10 +268,13 @@ secretDefineXML(virConnectPtr conn, * the backup. The current def will be handled below. * Otherwise, this is a new secret, thus remove it. */ - if (backup) + if (backup) { virSecretObjSetDef(obj, backup); - else + } else { virSecretObjListRemove(driver->secrets, obj); + virObjectUnref(obj); + obj =3D NULL; + } =20 cleanup: virSecretDefFree(def); @@ -411,6 +414,8 @@ secretUndefine(virSecretPtr secret) virSecretObjDeleteData(obj); =20 virSecretObjListRemove(driver->secrets, obj); + virObjectUnref(obj); + obj =3D NULL; =20 ret =3D 0; =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list