#include "virtime.h"
#include "virobject.h"
#include "virstring.h"
+#include "base64.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
goto cleanup;
}
+
+
+int
+qemuAgentSetUserPassword(qemuAgentPtr mon,
+ const char *user,
+ const char *password,
+ bool crypted)
+{
+ int ret = -1;
+ virJSONValuePtr cmd = NULL;
+ virJSONValuePtr reply = NULL;
+ char *password64 = NULL;
+
+ base64_encode_alloc(password, strlen(password), &password64);
+ if (!password64) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ if (!(cmd = qemuAgentMakeCommand("guest-set-user-password",
+ "b:crypted", crypted,
+ "s:username", user,
+ "s:password", password64,
+ NULL)))
+ goto cleanup;
+
+ if (qemuAgentCommand(mon, cmd, &reply, true,
+ VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
+ goto cleanup;
+
+ ret = 0;
+
+ cleanup:
+ virJSONValueFree(cmd);
+ virJSONValueFree(reply);
+ VIR_FREE(password64);
+ return ret;
+}
goto cleanup;
}
+
+static int
+qemuDomainSetUserPassword(virDomainPtr dom,
+ const char *user,
+ const char *password,
+ unsigned int flags)
+{
+ virQEMUDriverPtr driver = dom->conn->privateData;
+ qemuDomainObjPrivatePtr priv;
+ virDomainObjPtr vm;
+ int ret = -1;
+ int rv;
+
+ virCheckFlags(VIR_DOMAIN_PASSWORD_ENCRYPTED, -1);
+
+ if (!(vm = qemuDomObjFromDomain(dom)))
+ return ret;
+
+ if (virDomainSetUserPasswordEnsureACL(dom->conn, vm->def) < 0)
+ goto cleanup;
+
+ priv = vm->privateData;
+
+ if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
+ goto cleanup;
+
+ if (!virDomainObjIsActive(vm)) {
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ "%s", _("domain is not running"));
+ goto endjob;
+ }
+
+ if (!qemuDomainAgentAvailable(vm, true))
+ goto endjob;
+
+ qemuDomainObjEnterAgent(vm);
+ rv = qemuAgentSetUserPassword(priv->agent, user, password,
+ flags & VIR_DOMAIN_PASSWORD_ENCRYPTED);
+ qemuDomainObjExitAgent(vm);
+
+ if (rv < 0)
+ goto endjob;
+
+ ret = 0;
+
+ endjob:
+ qemuDomainObjEndJob(driver, vm);
+
+ cleanup:
+ virDomainObjEndAPI(&vm);
+ return ret;
+}
+
+
static virHypervisorDriver qemuHypervisorDriver = {
.name = QEMU_DRIVER_NAME,
.connectOpen = qemuConnectOpen, /* 0.2.0 */
.nodeAllocPages = qemuNodeAllocPages, /* 1.2.9 */
.domainGetFSInfo = qemuDomainGetFSInfo, /* 1.2.11 */
.domainInterfaceAddresses = qemuDomainInterfaceAddresses, /* 1.2.14 */
+ .domainSetUserPassword = qemuDomainSetUserPassword, /* 1.2.16 */
};