From e14b9f62ed6d40424938068f18e1d09ca963bb30 Mon Sep 17 00:00:00 2001 From: Anthony Liguori Date: Mon, 31 Jan 2011 14:27:36 -0600 Subject: vnc: Fix password expiration through 'change vnc ""' (v2) commit 52c18be9e99dabe295321153fda7fce9f76647ac introduced a regression in the change vnc password command that changed the behavior of setting the VNC password to an empty string from disabling login to disabling authentication. This commit refactors the code to eliminate this overloaded semantics in vnc_display_password and instead introduces the vnc_display_disable_login. The monitor implementation then determines the behavior of an empty or missing string. Recently, a set_password command was added that allows both the Spice and VNC password to be set. This command has not shown up in a release yet so the behavior is not yet defined. This patch proposes that an empty password be treated as an empty password with no special handling. For specifically disabling login, I believe a new command should be introduced instead of overloading semantics. I'm not sure how Spice handles this but I would recommend that we have Spice and VNC have consistent semantics here for the 0.14.0 release. Reported-by: Neil Wilson Signed-off-by: Anthony Liguori --- v1 -> v2 - Add a proper return to make sure that login is really disabled instead of relying on the VNC server to treat empty passwords specially --- ui/vnc.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'ui') diff --git a/ui/vnc.c b/ui/vnc.c index 495d6d6ef1..8067b313f7 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -2084,7 +2084,7 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) unsigned char key[8]; time_t now = time(NULL); - if (!vs->vd->password || !vs->vd->password[0]) { + if (!vs->vd->password) { VNC_DEBUG("No password configured on server"); goto reject; } @@ -2484,6 +2484,24 @@ void vnc_display_close(DisplayState *ds) #endif } +int vnc_display_disable_login(DisplayState *ds) +{ + VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display; + + if (!vs) { + return -1; + } + + if (vs->password) { + qemu_free(vs->password); + } + + vs->password = NULL; + vs->auth = VNC_AUTH_VNC; + + return 0; +} + int vnc_display_password(DisplayState *ds, const char *password) { VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display; @@ -2492,19 +2510,18 @@ int vnc_display_password(DisplayState *ds, const char *password) return -1; } + if (!password) { + /* This is not the intention of this interface but err on the side + of being safe */ + return vnc_display_disable_login(ds); + } + if (vs->password) { qemu_free(vs->password); vs->password = NULL; } - if (password && password[0]) { - if (!(vs->password = qemu_strdup(password))) - return -1; - if (vs->auth == VNC_AUTH_NONE) { - vs->auth = VNC_AUTH_VNC; - } - } else { - vs->auth = VNC_AUTH_NONE; - } + vs->password = qemu_strdup(password); + vs->auth = VNC_AUTH_VNC; return 0; } -- cgit v1.2.3