Skip to contentSkip to conversation

extend monitor "change vnc password"

PATCH New Nolan 1 participant 1 message Oct 23, 2008

lore
Share & tools
lore

Nolan

author
#0 lore raw

PATCH 1/1 extend monitor "change vnc password"

This patch extends the monitor command "change vnc password" to accept an optional extra argument that is the new password:

(qemu) change vnc password new_pass

the magic string "<unset>" will unset the password, disabling VNC.

If the extra argument is not given, the behavior is to prompt for a password, as before.

This change makes it easier to remotely change the VNC password using scripts like Anthony's "qemu-remote".

monitor.c renamed from monitor.c.orig +10 -4
@@ -447,35 +447,41 @@
         }
     }
     if (eject_device(bs, 0) < 0)
         return;
     bdrv_open2(bs, filename, 0, drv);
     qemu_key_check(bs, filename);
 }
 
-static void do_change_vnc(const char *target)
+static void do_change_vnc(const char *target, const char *fmt)
 {
     if (strcmp(target, "passwd") == 0 ||
 	strcmp(target, "password") == 0) {
-	char password[9];
-	monitor_readline("Password: ", 1, password, sizeof(password)-1);
+	char password[9] = {0, };
+	if (fmt) {
+	    if (strcmp(fmt, "<unset>") != 0) {
+		strncpy(password, fmt, sizeof(password)-1);
+	    }
+	} else {
+	    monitor_readline("Password: ", 1, password, sizeof(password)-1);
+	}
 	password[sizeof(password)-1] = '\0';
 	if (vnc_display_password(NULL, password) < 0)
 	    term_printf("could not set VNC server password\n");
     } else {
 	if (vnc_display_open(NULL, target) < 0)
 	    term_printf("could not start VNC server on %s\n", target);
     }
 }
 
 static void do_change(const char *device, const char *target, const char *fmt)
 {
     if (strcmp(device, "vnc") == 0) {
-	do_change_vnc(target);
+	do_change_vnc(target, fmt);
     } else {
 	do_change_block(device, target, fmt);
     }
 }
 
 static void do_screen_dump(const char *filename)
 {
     vga_hw_screen_dump(filename);