From nobody Mon Feb 9 04:03:44 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.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 1493056891089293.7087474806307; Mon, 24 Apr 2017 11:01:31 -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 136C2C04BD28; Mon, 24 Apr 2017 18:01:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB36477EC5; Mon, 24 Apr 2017 18:01:28 +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 EFC2B5ED67; Mon, 24 Apr 2017 18:00:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3OI0on6004801 for ; Mon, 24 Apr 2017 14:00:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 117F777ED3; Mon, 24 Apr 2017 18:00:50 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-126-74.rdu2.redhat.com [10.10.126.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id B18B3183C0 for ; Mon, 24 Apr 2017 18:00:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 136C2C04BD28 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 136C2C04BD28 From: John Ferlan To: libvir-list@redhat.com Date: Mon, 24 Apr 2017 14:00:22 -0400 Message-Id: <20170424180023.4695-14-jferlan@redhat.com> In-Reply-To: <20170424180023.4695-1-jferlan@redhat.com> References: <20170424180023.4695-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 13/14] secret: Alter configFile/base64File mgmt 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.31]); Mon, 24 Apr 2017 18:01:29 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than being generated during virSecretObjListAdd, generate the file paths in each of the callers and then copy those paths into the object rather than stealing their pointers. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 53 ++++++++++++++++++++++++------------------= ---- src/conf/virsecretobj.h | 3 ++- src/secret/secret_driver.c | 14 ++++++++++-- 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index ae2b287..7a9908d 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -300,7 +300,8 @@ virSecretObjListRemove(virSecretObjListPtr secrets, * virSecretObjListAdd: * @secrets: list of secret objects * @newdef: new secret definition - * @configDir: directory to place secret config files + * @configFile: secret config file + * @base64File: secret data file * @oldDef: Former secret def (e.g. a reload path perhaps) * * Add the new @newdef to the secret obj table hash @@ -310,14 +311,14 @@ virSecretObjListRemove(virSecretObjListPtr secrets, virSecretObjPtr virSecretObjListAdd(virSecretObjListPtr secrets, virSecretDefPtr newdef, - const char *configDir, + const char *configFile, + const char *base64File, virSecretDefPtr *oldDef) { virSecretObjPtr obj; virSecretDefPtr def; virSecretObjPtr ret =3D NULL; char uuidstr[VIR_UUID_STRING_BUFLEN]; - char *configFile =3D NULL, *base64File =3D NULL; =20 virObjectLock(secrets); =20 @@ -366,13 +367,6 @@ virSecretObjListAdd(virSecretObjListPtr secrets, 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; - if (!(obj =3D virSecretObjNew())) goto cleanup; =20 @@ -380,8 +374,10 @@ virSecretObjListAdd(virSecretObjListPtr secrets, goto cleanup; =20 obj->def =3D newdef; - VIR_STEAL_PTR(obj->configFile, configFile); - VIR_STEAL_PTR(obj->base64File, base64File); + if ((VIR_STRDUP(obj->configFile, configFile) < 0) || + (VIR_STRDUP(obj->base64File, base64File) < 0)) + goto cleanup; + virObjectRef(obj); } =20 @@ -390,8 +386,6 @@ virSecretObjListAdd(virSecretObjListPtr secrets, =20 cleanup: virSecretObjEndAPI(&obj); - VIR_FREE(configFile); - VIR_FREE(base64File); virObjectUnlock(secrets); return ret; } @@ -899,21 +893,22 @@ virSecretLoadValue(virSecretObjPtr obj) =20 static virSecretObjPtr virSecretLoad(virSecretObjListPtr secrets, - const char *file, - const char *path, - const char *configDir) + const char *fname, + const char *configFile, + const char *base64File) { virSecretDefPtr def =3D NULL; virSecretObjPtr obj =3D NULL; virSecretObjPtr ret =3D NULL; =20 - if (!(def =3D virSecretDefParseFile(path))) + if (!(def =3D virSecretDefParseFile(configFile))) goto cleanup; =20 - if (virSecretLoadValidateUUID(def, file) < 0) + if (virSecretLoadValidateUUID(def, fname) < 0) goto cleanup; =20 - if (!(obj =3D virSecretObjListAdd(secrets, def, configDir, NULL))) + if (!(obj =3D virSecretObjListAdd(secrets, def, configFile, base64File, + NULL))) goto cleanup; def =3D NULL; =20 @@ -936,6 +931,8 @@ virSecretLoadAllConfigs(virSecretObjListPtr secrets, { DIR *dir =3D NULL; struct dirent *de; + char *configFile =3D NULL; + char *base64File =3D NULL; int rc; =20 if ((rc =3D virDirOpenIfExists(&dir, configDir)) <=3D 0) @@ -944,26 +941,32 @@ virSecretLoadAllConfigs(virSecretObjListPtr secrets, /* Ignore errors reported by readdir or other calls within the * loop (if any). It's better to keep the secrets we managed to find.= */ while (virDirRead(dir, &de, NULL) > 0) { - char *path; virSecretObjPtr obj; =20 + VIR_FREE(configFile); + VIR_FREE(base64File); + if (!virFileHasSuffix(de->d_name, ".xml")) continue; =20 - if (!(path =3D virFileBuildPath(configDir, de->d_name, NULL))) + if (!(configFile =3D virFileBuildPath(configDir, de->d_name, ".xml= "))) + continue; + + if (!(base64File =3D virFileBuildPath(configDir, de->d_name, "base= 64"))) continue; =20 - if (!(obj =3D virSecretLoad(secrets, de->d_name, path, configDir))= ) { + if (!(obj =3D virSecretLoad(secrets, de->d_name, configFile, + base64File))) { VIR_ERROR(_("Error reading secret: %s"), virGetLastErrorMessage()); - VIR_FREE(path); continue; } =20 - VIR_FREE(path); virSecretObjEndAPI(&obj); } =20 + VIR_FREE(configFile); + VIR_FREE(base64File); VIR_DIR_CLOSE(dir); return 0; } diff --git a/src/conf/virsecretobj.h b/src/conf/virsecretobj.h index 092f23c..51adc98 100644 --- a/src/conf/virsecretobj.h +++ b/src/conf/virsecretobj.h @@ -54,7 +54,8 @@ virSecretObjListRemove(virSecretObjListPtr secrets, virSecretObjPtr virSecretObjListAdd(virSecretObjListPtr secrets, virSecretDefPtr newdef, - const char *configDir, + const char *configFile, + const char *base64File, virSecretDefPtr *oldDef); =20 typedef bool diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 8ddae57..3f8671b 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -213,6 +213,9 @@ secretDefineXML(virConnectPtr conn, virSecretDefPtr backup =3D NULL; virSecretDefPtr def; virObjectEventPtr event =3D NULL; + char *configFile =3D NULL; + char *base64File =3D NULL; + char uuidstr[VIR_UUID_STRING_BUFLEN]; =20 virCheckFlags(0, NULL); =20 @@ -222,8 +225,13 @@ secretDefineXML(virConnectPtr conn, if (virSecretDefineXMLEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(obj =3D virSecretObjListAdd(driver->secrets, def, - driver->configDir, &backup))) + virUUIDFormat(def->uuid, uuidstr); + if (!(configFile =3D virFileBuildPath(driver->configDir, uuidstr, ".xm= l")) || + !(base64File =3D virFileBuildPath(driver->configDir, uuidstr, ".ba= se64"))) + goto cleanup; + + if (!(obj =3D virSecretObjListAdd(driver->secrets, def, configFile, + base64File, &backup))) goto cleanup; =20 if (!def->isephemeral) { @@ -272,6 +280,8 @@ secretDefineXML(virConnectPtr conn, virSecretObjListRemove(driver->secrets, obj); =20 cleanup: + VIR_FREE(configFile); + VIR_FREE(base64File); virSecretDefFree(def); virSecretObjEndAPI(&obj); if (event) --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list