]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemu: wire up virDomainSetUserPassword
authorJán Tomko <jtomko@redhat.com>
Mon, 18 May 2015 10:42:07 +0000 (12:42 +0200)
committerJán Tomko <jtomko@redhat.com>
Thu, 21 May 2015 14:24:02 +0000 (16:24 +0200)
Base-64 encode the password and pass it to the guest agent
via the 'guest-set-user-password' command.

https://bugzilla.redhat.com/show_bug.cgi?id=1174177

src/qemu/qemu_agent.c
src/qemu/qemu_agent.h
src/qemu/qemu_driver.c

index b57a3df65a799e602ef09686cb4b188ca0057710..043695b3ace1e0d603b6de69f552d94d41450acb 100644 (file)
@@ -42,6 +42,7 @@
 #include "virtime.h"
 #include "virobject.h"
 #include "virstring.h"
+#include "base64.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
@@ -2118,3 +2119,41 @@ qemuAgentGetInterfaces(qemuAgentPtr mon,
 
     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;
+}
index 988228bd231d04a662e6be829ffae5ad0ddd692c..7cbf8ebb5e561d3e32872d6c4302cc1ef615ef91 100644 (file)
@@ -114,4 +114,8 @@ int qemuAgentSetTime(qemuAgentPtr mon,
 int qemuAgentGetInterfaces(qemuAgentPtr mon,
                            virDomainInterfacePtr **ifaces);
 
+int qemuAgentSetUserPassword(qemuAgentPtr mon,
+                             const char *user,
+                             const char *password,
+                             bool crypted);
 #endif /* __QEMU_AGENT_H__ */
index b91b78e027387845b91be37a1b4c7085bf2a0bfe..aa0acdef00487931f249a28cf069a801da885882 100644 (file)
@@ -20098,6 +20098,60 @@ qemuGetDHCPInterfaces(virDomainPtr dom,
     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 */
@@ -20304,6 +20358,7 @@ static virHypervisorDriver qemuHypervisorDriver = {
     .nodeAllocPages = qemuNodeAllocPages, /* 1.2.9 */
     .domainGetFSInfo = qemuDomainGetFSInfo, /* 1.2.11 */
     .domainInterfaceAddresses = qemuDomainInterfaceAddresses, /* 1.2.14 */
+    .domainSetUserPassword = qemuDomainSetUserPassword, /* 1.2.16 */
 };