Implement the domainSetUserPassword API for setting user password using the guest agent.
Signed-off-by: Roman Bogorodskiy <[email protected]> --- src/bhyve/bhyve_driver.c | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index f99ce3bb8b..d5f22b18bd 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -2466,6 +2466,52 @@ bhyveDomainSetTime(virDomainPtr domain, return ret; } +static int +bhyveDomainSetUserPassword(virDomainPtr domain, + const char *user, + const char *password, + unsigned int flags) +{ + virDomainObj *vm = NULL; + qemuAgent *agent; + int ret = -1; + int rv; + + virCheckFlags(VIR_DOMAIN_PASSWORD_ENCRYPTED, -1); + + if (!(vm = bhyveDomObjFromDomain(domain))) + return ret; + + if (virDomainSetUserPasswordEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + if (virDomainObjBeginAgentJob(vm, VIR_AGENT_JOB_MODIFY) < 0) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto endjob; + + if (bhyveDomainEnsureAgent(vm, true) < 0) + goto endjob; + + agent = bhyveDomainObjEnterAgent(vm); + rv = qemuAgentSetUserPassword(agent, user, password, + flags & VIR_DOMAIN_PASSWORD_ENCRYPTED); + bhyveDomainObjExitAgent(vm, agent); + + if (rv < 0) + goto endjob; + + ret = 0; + + endjob: + virDomainObjEndAgentJob(vm); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + static virHypervisorDriver bhyveHypervisorDriver = { .name = "bhyve", .connectURIProbe = bhyveConnectURIProbe, @@ -2540,6 +2586,7 @@ static virHypervisorDriver bhyveHypervisorDriver = { .domainGetFSInfo = bhyveDomainGetFSInfo, /* 12.5.0 */ .domainGetTime = bhyveDomainGetTime, /* 12.6.0 */ .domainSetTime = bhyveDomainSetTime, /* 12.6.0 */ + .domainSetUserPassword = bhyveDomainSetUserPassword, /* 12.6.0 */ }; -- 2.52.0
