WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] xen-upstream-qemu: get vncpassword through xenstore,

To: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>, "ian.jackson" <Ian.Jackson@xxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH] xen-upstream-qemu: get vncpassword through xenstore, enable VNC_AUTH_VNC
From: ZhouPeng <zpengxen@xxxxxxxxx>
Date: Wed, 20 Apr 2011 14:33:33 +0800
Cc: "Xen-Devel \(E-mail\)" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Delivery-date: Tue, 19 Apr 2011 23:34:09 -0700
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to:cc :content-type; bh=dgB3AsYcfwuh2xCFX1DQuWuNeJTjnuPLATY0Ig6Qw4I=; b=UcD6RyllEhjQKVyFlCoe9YtlN5kTQgY1B5zn/WjxZElfeYhRVoPXtqfvkOF81O8nUj InNZzG6yl4+nkt5rKqgS0mJC6DzuqjmgW9ub2vALIPnHGNi24NhdFXhCX8kuNZHjeiYe XRGRI4ueQcDQXAAW4Ucm1dY2f4OEeXbPfftd4=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:cc:content-type; b=ET9skdPe/iFBQIhAtwXMv5q7hksNJ7PqFd3IWobU6vMhaTzhle4PT9V3YdNlammLtT SUttZ1i2LSJ2JMMAsv0OexfJVVnyz848jRIfvU8ISvQQONDGuHk4BjFaykW6DdYzNWoV 4McWzYCi3i7u8DF9aBJJP7j4Sv0hfBmnYpXoU=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
This pacth allows you to use vncpasswd for xen-upstream-qemu

Signed-off-by: Zhou Peng <zhoupeng@xxxxxxxxxxxxxxx>

xen-upstream-qemu: get vncpassword through xenstore, enable VNC_AUTH_VNC

diff --git a/Makefile.objs b/Makefile.objs
index f8cf199..2a012bf 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -157,6 +157,8 @@ common-obj-$(CONFIG_SLIRP) += $(addprefix slirp/,
$(slirp-obj-y))
 common-obj-$(CONFIG_XEN) += xen_backend.o xen_devconfig.o
 common-obj-$(CONFIG_XEN) += xen_console.o xenfb.o xen_disk.o xen_nic.o

+common-obj-$(CONFIG_XEN) += xenstore.o
+
 ######################################################################
 # libuser

diff --git a/vl.c b/vl.c
index 60ec6de..b519690 100644
--- a/vl.c
+++ b/vl.c
@@ -163,6 +163,8 @@ int main(int argc, char **argv)

 #include "ui/qemu-spice.h"

+#include "xenstore.h"
+
 //#define DEBUG_NET
 //#define DEBUG_SLIRP

@@ -3321,7 +3323,11 @@ int main(int argc, char **argv, char **envp)
 #ifdef CONFIG_VNC
     /* init remote displays */
     if (vnc_display) {
+        char password[20];
         vnc_display_init(ds);
+        xenstore_read_vncpasswd(xen_domid, password, sizeof(password));
+        vnc_display_password(ds, password);
+
         if (vnc_display_open(ds, vnc_display) < 0)
             exit(1);

diff --git a/xenstore.c b/xenstore.c
new file mode 100644
index 0000000..0bb2a55
--- /dev/null
+++ b/xenstore.c
@@ -0,0 +1,154 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License.  See the file "COPYING" in the main directory of
+ * this archive for more details.
+ *
+ * Copyright (C) 2006 Christian Limpach
+ * Copyright (C) 2006 XenSource Ltd.
+ * Copyright (C) 2011 Zhou Peng <zhoupeng@xxxxxxxxxxxxxxx>.
+ *
+ */
+
+#include "xenstore.h"
+#include <xs.h>
+
+struct xs_handle *xsh = NULL;
+static FILE *logfile = NULL;
+extern uint32_t xen_domid;
+
+static int pasprintf(char **buf, const char *fmt, ...)
+{
+    va_list ap;
+    int ret = 0;
+
+    if (*buf)
+        free(*buf);
+    va_start(ap, fmt);
+    if (vasprintf(buf, fmt, ap) == -1) {
+        buf = NULL;
+        ret = -1;
+    }
+    va_end(ap);
+    return ret;
+}
+
+static const char *xenstore_get_guest_uuid(void)
+{
+    static char *already_computed = NULL;
+
+    char *domain_path = NULL, *vm_path = NULL, *vm_value = NULL, *p = NULL;
+    unsigned int len;
+
+    if (already_computed)
+        return already_computed;
+
+    if (xsh == NULL)
+        return NULL;
+
+    domain_path = xs_get_domain_path(xsh, xen_domid);
+    if (domain_path == NULL) {
+        fprintf(logfile, "xs_get_domain_path() error. xen_domid
%d.\n", xen_domid);
+        goto out;
+    }
+
+    if (pasprintf(&vm_path, "%s/vm", domain_path) == -1) {
+        fprintf(logfile, "xenstore_get_guest_uuid(): out of memory.\n");
+        goto out;
+    }
+    vm_value = xs_read(xsh, XBT_NULL, vm_path, &len);
+    if (vm_value == NULL) {
+        fprintf(logfile, "xs_read(): uuid get error. %s.\n", vm_path);
+        goto out;
+    }
+
+    if (strtok(vm_value, "/") == NULL) {
+        fprintf(logfile, "failed to parse guest uuid\n");
+        goto out;
+    }
+    p = strtok(NULL, "/");
+    if (p == NULL) {
+        fprintf(logfile, "failed to parse guest uuid\n");
+        goto out;
+    }
+
+    if (pasprintf(&already_computed, "%s", p) == -1) {
+        fprintf(logfile, "xenstore_get_guest_uuid(): out of memory.\n");
+        goto out;
+    }
+
+    fprintf(logfile, "Guest uuid = %s\n", already_computed);
+
+ out:
+    free(domain_path);
+    free(vm_path);
+    free(vm_value);
+
+    return already_computed;
+}
+
+void xenstore_read_vncpasswd(int domid, char *pwbuf, size_t pwbuflen)
+{
+    char *buf = NULL, *path, *uuid = NULL, *passwd = NULL;
+    unsigned int i, len;
+
+    pwbuf[0] = '\0';
+
+    if (xsh == NULL)
+        return;
+
+    path = xs_get_domain_path(xsh, domid);
+    if (path == NULL) {
+        fprintf(logfile, "xs_get_domain_path() error. domid %d.\n", domid);
+        return;
+    }
+
+    pasprintf(&buf, "%s/vm", path);
+    free(path);
+    uuid = xs_read(xsh, XBT_NULL, buf, &len);
+    if (uuid == NULL) {
+        fprintf(logfile, "xs_read(): uuid get error. %s.\n", buf);
+        free(buf);
+        return;
+    }
+
+    pasprintf(&buf, "%s/vncpasswd", uuid);
+    free(uuid);
+    passwd = xs_read(xsh, XBT_NULL, buf, &len);
+    if (passwd == NULL) {
+        fprintf(logfile, "xs_read(): vncpasswd get error. %s.\n", buf);
+        free(buf);
+        return;
+    }
+
+    if (len >= pwbuflen)
+    {
+        fprintf(logfile,
+                "xenstore_read_vncpasswd(): truncated password to
avoid buffer overflow\n");
+        len = pwbuflen - 1;
+    }
+
+    for (i=0; i<len; i++)
+        pwbuf[i] = passwd[i];
+    pwbuf[len] = '\0';
+    passwd[0] = '\0';
+    if (xs_write(xsh, XBT_NULL, buf, passwd, 1) == 0)
+        fprintf(logfile, "xs_write() vncpasswd failed.\n");
+
+    free(passwd);
+    free(buf);
+}
+
+static void xenstore_init(void)
+{
+    logfile = stderr;
+
+    xenstore_get_guest_uuid();
+
+    xsh = xs_daemon_open();
+    if (xsh == NULL) {
+        fprintf(logfile, "Could not contact xenstore for domain config\n");
+        return;
+    }
+}
+
+device_init(xenstore_init);
diff --git a/xenstore.h b/xenstore.h
new file mode 100644
index 0000000..5242f2c
--- /dev/null
+++ b/xenstore.h
@@ -0,0 +1,15 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License.  See the file "COPYING" in the main directory of
+ * this archive for more details.
+ *
+ */
+
+#ifndef XEN_STORE_H
+#define XEN_STORE_H
+
+#include "qemu-common.h"
+
+void xenstore_read_vncpasswd(int domid, char *pwbuf, size_t pwbuflen);
+
+#endif /* XEN_STORE_H */

-- 
Zhou Peng
Operating System Technology Group
Institute of Software, the Chinese Academy of Sciences (ISCAS)

Attachment: xen-upstream-qemu-vncpassword-by-xenstore.diff
Description: Text Data

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel