mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-05 04:25:19 +00:00
virsh: add set-user-password command
Expose the virDomainSetUserPassword API in virsh: virsh set-user-password dom user 123456
This commit is contained in:
parent
e8982c88bd
commit
9bcadfabaa
@ -5396,6 +5396,74 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* "set-user-password" command
|
||||||
|
*/
|
||||||
|
static const vshCmdInfo info_set_user_password[] = {
|
||||||
|
{.name = "help",
|
||||||
|
.data = N_("set the user password inside the domain")
|
||||||
|
},
|
||||||
|
{.name = "desc",
|
||||||
|
.data = N_("changes the password of the specified user inside the domain")
|
||||||
|
},
|
||||||
|
{.name = NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
static const vshCmdOptDef opts_set_user_password[] = {
|
||||||
|
{.name = "domain",
|
||||||
|
.type = VSH_OT_DATA,
|
||||||
|
.flags = VSH_OFLAG_REQ,
|
||||||
|
.help = N_("domain name, id or uuid")
|
||||||
|
},
|
||||||
|
{.name = "user",
|
||||||
|
.type = VSH_OT_DATA,
|
||||||
|
.flags = VSH_OFLAG_REQ,
|
||||||
|
.help = N_("the username")
|
||||||
|
},
|
||||||
|
{.name = "password",
|
||||||
|
.type = VSH_OT_DATA,
|
||||||
|
.flags = VSH_OFLAG_REQ,
|
||||||
|
.help = N_("the new password")
|
||||||
|
},
|
||||||
|
{.name = "encrypted",
|
||||||
|
.type = VSH_OT_BOOL,
|
||||||
|
.help = N_("the password is already encrypted")
|
||||||
|
},
|
||||||
|
{.name = NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool
|
||||||
|
cmdSetUserPassword(vshControl *ctl, const vshCmd *cmd)
|
||||||
|
{
|
||||||
|
virDomainPtr dom;
|
||||||
|
const char *name;
|
||||||
|
const char *password = NULL;
|
||||||
|
const char *user = NULL;
|
||||||
|
unsigned int flags = 0;
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
if (vshCommandOptBool(cmd, "encrypted"))
|
||||||
|
flags = VIR_DOMAIN_PASSWORD_ENCRYPTED;
|
||||||
|
|
||||||
|
if (vshCommandOptStringReq(ctl, cmd, "user", &user) < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (vshCommandOptStringReq(ctl, cmd, "password", &password) < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (virDomainSetUserPassword(dom, user, password, flags) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
vshPrint(ctl, _("Password set successfully for %s in %s"), user, name);
|
||||||
|
ret = true;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
virDomainFree(dom);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* "resume" command
|
* "resume" command
|
||||||
*/
|
*/
|
||||||
@ -13207,6 +13275,12 @@ const vshCmdDef domManagementCmds[] = {
|
|||||||
.info = info_screenshot,
|
.info = info_screenshot,
|
||||||
.flags = 0
|
.flags = 0
|
||||||
},
|
},
|
||||||
|
{.name = "set-user-password",
|
||||||
|
.handler = cmdSetUserPassword,
|
||||||
|
.opts = opts_set_user_password,
|
||||||
|
.info = info_set_user_password,
|
||||||
|
.flags = 0
|
||||||
|
},
|
||||||
{.name = "setmaxmem",
|
{.name = "setmaxmem",
|
||||||
.handler = cmdSetmaxmem,
|
.handler = cmdSetmaxmem,
|
||||||
.opts = opts_setmaxmem,
|
.opts = opts_setmaxmem,
|
||||||
|
@ -2015,6 +2015,16 @@ the value from the host, use the B<virsh memtune> command. In order to view
|
|||||||
the current memory in use and the maximum value allowed to set memory, use
|
the current memory in use and the maximum value allowed to set memory, use
|
||||||
the B<virsh dominfo> command.
|
the B<virsh dominfo> command.
|
||||||
|
|
||||||
|
=item B<set-user-password> I<domain> I<user> I<password> [I<--encrypted>]
|
||||||
|
|
||||||
|
Set the password for the I<user> account in the guest domain.
|
||||||
|
|
||||||
|
If I<--encrypted> is specified, the password is assumed to be already
|
||||||
|
encrypted by the method required by the guest OS.
|
||||||
|
|
||||||
|
For QEMU/KVM, this requires the guest agent to be configured
|
||||||
|
and running.
|
||||||
|
|
||||||
=item B<setmaxmem> I<domain> B<size> [[I<--config>] [I<--live>] |
|
=item B<setmaxmem> I<domain> B<size> [[I<--config>] [I<--live>] |
|
||||||
[I<--current>]]
|
[I<--current>]]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user