From nobody Sun Feb 8 18:19:25 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554104043351214.08051280782342; Mon, 1 Apr 2019 00:34:03 -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 ACA5081DEB; Mon, 1 Apr 2019 07:34:01 +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 75DA06013A; Mon, 1 Apr 2019 07:34:01 +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 355093FA50; Mon, 1 Apr 2019 07:34:01 +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 x317Xeob013951 for ; Mon, 1 Apr 2019 03:33:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8EDAC60BFC; Mon, 1 Apr 2019 07:33:40 +0000 (UTC) Received: from lpt.redhat.com (ovpn-204-90.brq.redhat.com [10.40.204.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB83F60BE6 for ; Mon, 1 Apr 2019 07:33:39 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 1 Apr 2019 09:33:31 +0200 Message-Id: <20d7d20adc05e7d58579901d560402da68e5a2ae.1554103986.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 14/14] virsh-completer: introduce virshPasswordCompleter 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 01 Apr 2019 07:34:02 +0000 (UTC) Suggest some passwords to the user. Signed-off-by: J=C3=A1n Tomko --- tools/virsh-completer.c | 58 +++++++++++++++++++++++++++++++++++++++++ tools/virsh-completer.h | 4 +++ tools/virsh-domain.c | 1 + 3 files changed, 63 insertions(+) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 5985f09272..0687670d37 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -32,6 +32,7 @@ #include "virutil.h" #include "viralloc.h" #include "virmacaddr.h" +#include "virrandom.h" #include "virstring.h" #include "virxml.h" =20 @@ -936,3 +937,60 @@ virshDomainDeviceAliasCompleter(vshControl *ctl, VIR_STEAL_PTR(ret, tmp); return ret; } + + +const char *builtin_passwords[] =3D { + "hunter2", /* ******* */ + "nbusr123", /* Ke=C4=8F nevie=C5=A1, tak nefu=C5=A1uj */ + "4ezgi4", +}; + + +char ** +virshPasswordCompleter(vshControl *ctl ATTRIBUTE_UNUSED, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + VIR_AUTOFREE(char *) base64 =3D NULL; + VIR_AUTOFREE(unsigned char *) rand =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; + const size_t optimal_passlen =3D 8; /* ought to be enough */ + const char *prefix =3D NULL; + const size_t num =3D 1; + char **ret =3D NULL; + size_t missing; + size_t i; + + virCheckFlags(0, NULL); + + if (VIR_ALLOC_N(tmp, num + ARRAY_CARDINALITY(builtin_passwords) + 1) <= 0) + return NULL; + + ignore_value(vshCommandOptStringQuiet(ctl, cmd, "password", &prefix)); + if (STREQ_NULLABLE(prefix, " ")) + prefix =3D NULL; + + missing =3D optimal_passlen - MIN(strlen(NULLSTR_EMPTY(prefix)), optim= al_passlen); + + if (VIR_ALLOC_N(rand, 7) < 0) + return NULL; + + if (virRandomBytes(rand, 6) < 0) + return NULL; + + if (!(base64 =3D virStringEncodeBase64(rand, 6))) + return NULL; + + base64[missing] =3D '\0'; + + if (virAsprintf(&tmp[0], "%s%s", NULLSTR_EMPTY(prefix), base64) < 0) + return NULL; + + for (i =3D 0; i < ARRAY_CARDINALITY(builtin_passwords); i++) { + if (VIR_STRDUP(tmp[i + 1], builtin_passwords[i]) < 0) + return NULL; + } + + VIR_STEAL_PTR(ret, tmp); + return ret; +} diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 2e2e1edafb..d47a5f4da6 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -110,4 +110,8 @@ char ** virshDomainDeviceAliasCompleter(vshControl *ctl, char ** virshCellnoCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); + +char ** virshPasswordCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); #endif /* LIBVIRT_VIRSH_COMPLETER_H */ diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e8d5404acf..d8978f5bd1 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -5732,6 +5732,7 @@ static const vshCmdOptDef opts_set_user_password[] = =3D { {.name =3D "password", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D virshPasswordCompleter, .help =3D N_("the new password") }, {.name =3D "encrypted", --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list