From nobody Sun Feb 8 05:27:15 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=1570704885; cv=none; d=zoho.com; s=zohoarc; b=IW/dZ9jvCgd3tR5dUaSxVmlu01oSMRZyO65qdmPqG/Hoi3USDJ3Gp2ESQ2AKVJD/dFdEYdc8Y6JCCfWDAWLUEEldIviLghTcqLrfIrFvjUhLKn0dS26v4KIpDyvvvuMbeNxE2+F+In4PtWCbxDORtmufpULLknQOyTYbyQGXpc8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704885; 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; bh=ffMvmf2gzB1sIG1PWTf2YjVWAZ1P394HBpaHsVzicOU=; b=dJ2ghQ6GiZIRtgEc1e53rnn8mMsi3TEGprAXTNGVAAFYxAAxm4/PTV0RDHouOMjKG9qvvDDUbFk2DQ94Dm0hrE7BFLAtqVs8S6j/Fh5tQTsxYq8P3eRoMroKTUeilmOlM/kj3Zreb+QqUXiM6WEFIJA3EKkXMMJTvH9uppzXqgw= 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 1570704885256830.1564691546312; Thu, 10 Oct 2019 03:54:45 -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 B0ACE18C4289; Thu, 10 Oct 2019 10:54:43 +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 834915D713; Thu, 10 Oct 2019 10:54:43 +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 479AD4EE6F; Thu, 10 Oct 2019 10:54:43 +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 x9AAsQxl010415 for ; Thu, 10 Oct 2019 06:54:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4DC5E5C22F; Thu, 10 Oct 2019 10:54:26 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E8035C1B5; Thu, 10 Oct 2019 10:54:25 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:54:03 +0100 Message-Id: <20191010105413.4091-10-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-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: =?UTF-8?q?J=C3=A1n=20Tomko?= Subject: [libvirt] [PATCH v3 09/19] util: use glib base64 encoding/decoding APIs 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Thu, 10 Oct 2019 10:54:44 +0000 (UTC) Replace use of the gnulib base64 module with glib's own base64 API family. Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel P. Berrang=C3=A9 --- bootstrap.conf | 1 - configure.ac | 5 ----- src/conf/virsecretobj.c | 26 ++++---------------------- src/libvirt_private.syms | 1 - src/libxl/libxl_conf.c | 3 +-- src/qemu/qemu_agent.c | 6 ++---- src/qemu/qemu_command.c | 5 ++--- src/qemu/qemu_domain.c | 8 +++----- src/secret/secret_driver.c | 1 - src/storage/storage_backend_rbd.c | 4 +--- src/util/virstring.c | 21 --------------------- src/util/virstring.h | 2 -- tools/virsh-secret.c | 17 ++++------------- 13 files changed, 17 insertions(+), 83 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 7e264b63ad..bb40e978aa 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -20,7 +20,6 @@ gnulib_modules=3D' accept areadlink -base64 bind byteswap c-ctype diff --git a/configure.ac b/configure.ac index 9b4e6fdd6d..acac1bed41 100644 --- a/configure.ac +++ b/configure.ac @@ -911,11 +911,6 @@ test "x$lv_cv_static_analysis" =3D xyes && t=3D1 AC_DEFINE_UNQUOTED([STATIC_ANALYSIS], [$t], [Define to 1 when performing static analysis.]) =20 -# Some GNULIB base64 symbols clash with a kerberos library -AC_DEFINE_UNQUOTED([isbase64],[libvirt_gl_isbase64],[Hack to avoid symbol = clash]) -AC_DEFINE_UNQUOTED([base64_encode],[libvirt_gl_base64_encode],[Hack to avo= id symbol clash]) -AC_DEFINE_UNQUOTED([base64_encode_alloc],[libvirt_gl_base64_encode_alloc],= [Hack to avoid symbol clash]) - GNUmakefile=3DGNUmakefile m4_if(m4_version_compare([2.61a.100], m4_defn([m4_PACKAGE_VERSION])), [1], [], diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index aeae82332b..5bd84d82ed 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -31,7 +31,6 @@ #include "virhash.h" #include "virlog.h" #include "virstring.h" -#include "base64.h" =20 #define VIR_FROM_THIS VIR_FROM_SECRET =20 @@ -698,8 +697,7 @@ virSecretObjSaveData(virSecretObjPtr obj) if (!obj->value) return 0; =20 - if (!(base64 =3D virStringEncodeBase64(obj->value, obj->value_size))) - return -1; + base64 =3D g_base64_encode(obj->value, obj->value_size); =20 if (virFileRewriteStr(obj->base64File, S_IRUSR | S_IWUSR, base64) < 0) return -1; @@ -825,8 +823,6 @@ virSecretLoadValue(virSecretObjPtr obj) int ret =3D -1, fd =3D -1; struct stat st; g_autofree char *contents =3D NULL; - char *value =3D NULL; - size_t value_size; =20 if ((fd =3D open(obj->base64File, O_RDONLY)) =3D=3D -1) { if (errno =3D=3D ENOENT) { @@ -851,7 +847,7 @@ virSecretLoadValue(virSecretObjPtr obj) goto cleanup; } =20 - if (VIR_ALLOC_N(contents, st.st_size) < 0) + if (VIR_ALLOC_N(contents, st.st_size + 1) < 0) goto cleanup; =20 if (saferead(fd, contents, st.st_size) !=3D st.st_size) { @@ -859,29 +855,15 @@ virSecretLoadValue(virSecretObjPtr obj) obj->base64File); goto cleanup; } + contents[st.st_size] =3D '\0'; =20 VIR_FORCE_CLOSE(fd); =20 - if (!base64_decode_alloc(contents, st.st_size, &value, &value_size)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("invalid base64 in '%s'"), - obj->base64File); - goto cleanup; - } - if (value =3D=3D NULL) - goto cleanup; - - obj->value =3D (unsigned char *)value; - value =3D NULL; - obj->value_size =3D value_size; + obj->value =3D g_base64_decode(contents, &obj->value_size); =20 ret =3D 0; =20 cleanup: - if (value !=3D NULL) { - memset(value, 0, value_size); - VIR_FREE(value); - } if (contents !=3D NULL) memset(contents, 0, st.st_size); VIR_FORCE_CLOSE(fd); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 5949cba08d..e88518a1ce 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3069,7 +3069,6 @@ virSkipSpacesBackwards; virStrcpy; virStrdup; virStringBufferIsPrintable; -virStringEncodeBase64; virStringFilterChars; virStringHasCaseSuffix; virStringHasChars; diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index c76704a11d..de56567cf0 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -999,8 +999,7 @@ libxlMakeNetworkDiskSrc(virStorageSourcePtr src, char *= *srcstr) goto cleanup; =20 /* RBD expects an encoded secret */ - if (!(base64secret =3D virStringEncodeBase64(secret, secretlen))) - goto cleanup; + base64secret =3D g_base64_encode(secret, secretlen); } =20 if (!(*srcstr =3D libxlMakeNetworkDiskSrcStr(src, username, base64secr= et))) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 34e1a85d64..0ef8b563f5 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -39,7 +39,6 @@ #include "virtime.h" #include "virobject.h" #include "virstring.h" -#include "base64.h" #include "virenum.h" =20 #define VIR_FROM_THIS VIR_FROM_QEMU @@ -2518,9 +2517,8 @@ qemuAgentSetUserPassword(qemuAgentPtr mon, virJSONValuePtr reply =3D NULL; char *password64 =3D NULL; =20 - if (!(password64 =3D virStringEncodeBase64((unsigned char *)password, - strlen(password)))) - goto cleanup; + password64 =3D g_base64_encode((unsigned char *)password, + strlen(password)); =20 if (!(cmd =3D qemuAgentMakeCommand("guest-set-user-password", "b:crypted", crypted, diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 50cc3bdf7c..0f1625d401 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -837,9 +837,8 @@ qemuBuildRBDSecinfoURI(virBufferPtr buf, =20 switch ((qemuDomainSecretInfoType) secinfo->type) { case VIR_DOMAIN_SECRET_INFO_TYPE_PLAIN: - if (!(base64secret =3D virStringEncodeBase64(secinfo->s.plain.secr= et, - secinfo->s.plain.secret= len))) - return -1; + base64secret =3D g_base64_encode(secinfo->s.plain.secret, + secinfo->s.plain.secretlen); virBufferEscape(buf, '\\', ":", ":id=3D%s", secinfo->s.plain.usern= ame); virBufferEscape(buf, '\\', ":", ":key=3D%s:auth_supported=3Dcephx\\;none", diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index dc7568fe18..35067c851f 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1470,8 +1470,7 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv, goto cleanup; =20 /* Encode the IV and save that since qemu will need it */ - if (!(secinfo->s.aes.iv =3D virStringEncodeBase64(raw_iv, ivlen))) - goto cleanup; + secinfo->s.aes.iv =3D g_base64_encode(raw_iv, ivlen); =20 /* Grab the unencoded secret */ if (virSecretGetSecretString(conn, seclookupdef, usageType, @@ -1488,9 +1487,8 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv, memset(secret, 0, secretlen); =20 /* Now encode the ciphertext and store to be passed to qemu */ - if (!(secinfo->s.aes.ciphertext =3D virStringEncodeBase64(ciphertext, - ciphertextlen)= )) - goto cleanup; + secinfo->s.aes.ciphertext =3D g_base64_encode(ciphertext, + ciphertextlen); =20 ret =3D 0; =20 diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index ed3bd3c751..13f75ee4fa 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -25,7 +25,6 @@ #include =20 #include "internal.h" -#include "base64.h" #include "datatypes.h" #include "driver.h" #include "virlog.h" diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backen= d_rbd.c index c4781debd8..b10ca1503d 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -28,7 +28,6 @@ #include "storage_conf.h" #include "viralloc.h" #include "virlog.h" -#include "base64.h" #include "viruuid.h" #include "virstring.h" #include "virrandom.h" @@ -218,8 +217,7 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDS= tatePtr ptr, &secret_value, &secret_value_size) < = 0) goto cleanup; =20 - if (!(rados_key =3D virStringEncodeBase64(secret_value, secret_val= ue_size))) - goto cleanup; + rados_key =3D g_base64_encode(secret_value, secret_value_size); =20 if (virStorageBackendRBDRADOSConfSet(ptr->cluster, "key", rados_key) < 0) diff --git a/src/util/virstring.c b/src/util/virstring.c index 6b2b6ed24e..0abdcd8b04 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -22,7 +22,6 @@ #include #include =20 -#include "base64.h" #include "c-ctype.h" #include "virstring.h" #include "virthread.h" @@ -1438,26 +1437,6 @@ virStringBufferIsPrintable(const uint8_t *buf, } =20 =20 -/** - * virStringEncodeBase64: - * @buf: buffer of bytes to encode - * @buflen: number of bytes to encode - * - * Encodes @buf to base 64 and returns the resulting string. The caller is - * responsible for freeing the result. - */ -char * -virStringEncodeBase64(const uint8_t *buf, size_t buflen) -{ - char *ret; - - base64_encode_alloc((const char *) buf, buflen, &ret); - if (!ret) - abort(); - - return ret; -} - /** * virStringTrimOptionalNewline: * @str: the string to modify in-place diff --git a/src/util/virstring.h b/src/util/virstring.h index 3ffe51f7b8..af6e234d83 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -291,8 +291,6 @@ void virStringFilterChars(char *str, const char *valid); bool virStringIsPrintable(const char *str); bool virStringBufferIsPrintable(const uint8_t *buf, size_t buflen); =20 -char *virStringEncodeBase64(const uint8_t *buf, size_t buflen); - void virStringTrimOptionalNewline(char *str); =20 int virStringParsePort(const char *str, diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index b34ae12bbe..48058bea05 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -22,7 +22,6 @@ #include "virsh-secret.h" =20 #include "internal.h" -#include "base64.h" #include "virbuffer.h" #include "viralloc.h" #include "virfile.h" @@ -192,7 +191,7 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd) virSecretPtr secret; size_t value_size; const char *base64 =3D NULL; - char *value; + unsigned char *value; int res; bool ret =3D false; =20 @@ -202,16 +201,9 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "base64", &base64) < 0) goto cleanup; =20 - if (!base64_decode_alloc(base64, strlen(base64), &value, &value_size))= { - vshError(ctl, "%s", _("Invalid base64 data")); - goto cleanup; - } - if (value =3D=3D NULL) { - vshError(ctl, "%s", _("Failed to allocate memory")); - goto cleanup; - } + value =3D g_base64_decode(base64, &value_size); =20 - res =3D virSecretSetValue(secret, (unsigned char *)value, value_size, = 0); + res =3D virSecretSetValue(secret, value, value_size, 0); memset(value, 0, value_size); VIR_FREE(value); =20 @@ -267,8 +259,7 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd) if (value =3D=3D NULL) goto cleanup; =20 - if (!(base64 =3D virStringEncodeBase64(value, value_size))) - goto cleanup; + base64 =3D g_base64_encode(value, value_size); =20 vshPrint(ctl, "%s", base64); ret =3D true; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list