From nobody Thu Apr 25 06:59:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1578670988; cv=none; d=zohomail.com; s=zohoarc; b=iG+9R4XhvVRw8lx52Av6dOB3SbXUGssZaOwdRqmPY5G1kYzE622z6deDxrudo6xfp9Gs5BcdRpvGqOa9FV7v4Q9U917rUWZDTsmOJCGtlVzQnhSIHFRnHYd/cgYQ+RxNVbjfoLNIuIGDdAB+vRbYGw1ai5eOfkZln4lZ4K6IMN4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578670988; h=Content-Type:Content-Transfer-Encoding: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=SMNYzjxF0E+PjsoOYeEV/71bv9DLEKVRxpUaxadlkhQ=; b=K1jjHEzvqIPgICi6ZsiuQt6Z+MxJAGasuLhWuZ1kc5/8fApgVyDwl6JiEDPQrXms1YQd7gv71j3hI5j1bbqIGMJgJpPe29p6z61J5GVplQPdGuBndkoEJtHLw7ZHNujk7oiQS0z4CThPi8qhGOdCFvKfIAyrx8dfpERjDteNgpk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1578670988645271.4616737339053; Fri, 10 Jan 2020 07:43:08 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-170-Xm11dey0NduqvvZ0qOavIw-1; Fri, 10 Jan 2020 10:43:05 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BB9ED800D5E; Fri, 10 Jan 2020 15:42:53 +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 98A4886CD0; Fri, 10 Jan 2020 15:42:53 +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 4F2E081C7C; Fri, 10 Jan 2020 15:42:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00AFgnJJ022580 for ; Fri, 10 Jan 2020 10:42:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id 808C6271BE; Fri, 10 Jan 2020 15:42:49 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09C1B19C6A for ; Fri, 10 Jan 2020 15:42:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578670987; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=SMNYzjxF0E+PjsoOYeEV/71bv9DLEKVRxpUaxadlkhQ=; b=ECyM2a7xq8ytdZ3vqQ2nyq0pcyFxScXEGxnuXOo9ji8xIh4tSVqisAaMtgY4oBVbAWnWVZ gtGsw42G9VkJ8xYjdlhCTrgNZGthY0gUjm2eGqOr29x++y5v7JhDEQCnpxsuBnbjHPveSO zBzxQKG8+GfMcEplzKt6MV60V6aDtBo= From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 16:42:42 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/4] virsh: secret: Allow getting secret's value without base64 encoding 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: Xm11dey0NduqvvZ0qOavIw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Users might want to get the raw value instead of dealing with base64 encoding. This might be useful for redirection to file and also for simple human-readable secrets. Signed-off-by: Peter Krempa Reviewed-by: Daniel P. Berrang=C3=A9 --- docs/manpages/virsh.rst | 6 +++++- tools/virsh-secret.c | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 03364684b5..fcc8ef6758 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -6586,11 +6586,15 @@ secret-get-value .. code-block:: - secret-get-value secret + secret-get-value [--plain] secret Output the value associated with *secret* (specified by its UUID) to stdou= t, encoded using Base64. +If the *--plain* flag is used the value is not base64 encoded, but rather +printed raw. Note that unless virsh is started in quiet mode (*virsh -q*) = it +prints a newline at the end of the command. This newline is not part of the +secret. secret-undefine --------------- diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 9f64be6b14..6d95ed9d5d 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -303,6 +303,10 @@ static const vshCmdOptDef opts_secret_get_value[] =3D { .help =3D N_("secret UUID"), .completer =3D virshSecretUUIDCompleter, }, + {.name =3D "plain", + .type =3D VSH_OT_BOOL, + .help =3D N_("get value without converting to base64") + }, {.name =3D NULL} }; @@ -313,6 +317,7 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd) VIR_AUTODISPOSE_STR base64 =3D NULL; unsigned char *value; size_t value_size; + bool plain =3D vshCommandOptBool(cmd, "plain"); bool ret =3D false; secret =3D virshCommandOptSecret(ctl, cmd, NULL); @@ -323,9 +328,16 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd) if (value =3D=3D NULL) goto cleanup; - base64 =3D g_base64_encode(value, value_size); + if (plain) { + if (fwrite(value, 1, value_size, stdout) !=3D value_size) { + vshError(ctl, "failed to write secret"); + goto cleanup; + } + } else { + base64 =3D g_base64_encode(value, value_size); - vshPrint(ctl, "%s", base64); + vshPrint(ctl, "%s", base64); + } ret =3D true; cleanup: --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list