Received: from [140.186.70.92] (port=48331 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pk0cK-0004fB-HD for qemu-devel@nongnu.org; Mon, 31 Jan 2011 15:46:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pk0cH-00070E-KF for qemu-devel@nongnu.org; Mon, 31 Jan 2011 15:44:55 -0500 Received: from e9.ny.us.ibm.com ([32.97.182.139]:54034) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pk0cH-0006vA-Hi for qemu-devel@nongnu.org; Mon, 31 Jan 2011 15:44:53 -0500 Received: from d01dlp02.pok.ibm.com (d01dlp02.pok.ibm.com [9.56.224.85]) by e9.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p0VKJ5UM002343 for ; Mon, 31 Jan 2011 15:19:36 -0500 Received: from d01relay03.pok.ibm.com (d01relay03.pok.ibm.com [9.56.227.235]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 240234DE8040 for ; Mon, 31 Jan 2011 15:43:54 -0500 (EST) Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay03.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p0VKiPaY351154 for ; Mon, 31 Jan 2011 15:44:25 -0500 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p0VKiOH3023876 for ; Mon, 31 Jan 2011 15:44:25 -0500 From: Anthony Liguori Date: Mon, 31 Jan 2011 14:43:19 -0600 Message-Id: <1296506599-7126-1-git-send-email-aliguori@us.ibm.com> Subject: [Qemu-devel] [PATCH] vnc: Fix password expiration through 'change vnc ""' List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Neil Wilson , Gerd Hoffman , Anthony Liguori 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 diff --git a/console.h b/console.h index 3157330..f4e4741 100644 --- a/console.h +++ b/console.h @@ -369,6 +369,7 @@ void vnc_display_init(DisplayState *ds); void vnc_display_close(DisplayState *ds); int vnc_display_open(DisplayState *ds, const char *display); int vnc_display_password(DisplayState *ds, const char *password); +int vnc_display_disable_login(DisplayState *ds); int vnc_display_pw_expire(DisplayState *ds, time_t expires); void do_info_vnc_print(Monitor *mon, const QObject *data); void do_info_vnc(Monitor *mon, QObject **ret_data); diff --git a/monitor.c b/monitor.c index c5f54f4..24ed971 100644 --- a/monitor.c +++ b/monitor.c @@ -1018,6 +1018,13 @@ static int do_quit(Monitor *mon, const QDict *qdict, QObject **ret_data) static int change_vnc_password(const char *password) { + if (!password || !password[0]) { + if (vnc_display_disable_login(NULL)) { + qerror_report(QERR_SET_PASSWD_FAILED); + return -1; + } + } + if (vnc_display_password(NULL, password) < 0) { qerror_report(QERR_SET_PASSWD_FAILED); return -1; @@ -1117,6 +1124,8 @@ static int set_password(Monitor *mon, const QDict *qdict, QObject **ret_data) qerror_report(QERR_INVALID_PARAMETER, "connected"); return -1; } + /* Note that setting an empty password will not disable login through + * this interface. */ rc = vnc_display_password(NULL, password); if (rc != 0) { qerror_report(QERR_SET_PASSWD_FAILED); diff --git a/ui/vnc.c b/ui/vnc.c index 495d6d6..73e7ffa 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -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; } -- 1.7.0.4