vnc/spice: add set_passwd monitor command.

This patch adds new set_password and expire_password monitor commands
which allows to change and expire the password for spice and vnc
connections.  See the doc update patch chunk for details.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Gerd Hoffmann 2010-10-07 12:22:54 +02:00
parent 3c9405a0f7
commit 7572150c18
5 changed files with 251 additions and 0 deletions

View file

@ -36,6 +36,8 @@
static SpiceServer *spice_server;
static const char *auth = "spice";
static char *auth_passwd;
static time_t auth_expires = TIME_MAX;
int using_spice = 0;
struct SpiceTimer {
@ -599,6 +601,39 @@ int qemu_spice_add_interface(SpiceBaseInstance *sin)
return spice_server_add_interface(spice_server, sin);
}
static int qemu_spice_set_ticket(bool fail_if_conn, bool disconnect_if_conn)
{
time_t lifetime, now = time(NULL);
char *passwd;
if (now < auth_expires) {
passwd = auth_passwd;
lifetime = (auth_expires - now);
if (lifetime > INT_MAX) {
lifetime = INT_MAX;
}
} else {
passwd = NULL;
lifetime = 1;
}
return spice_server_set_ticket(spice_server, passwd, lifetime,
fail_if_conn, disconnect_if_conn);
}
int qemu_spice_set_passwd(const char *passwd,
bool fail_if_conn, bool disconnect_if_conn)
{
free(auth_passwd);
auth_passwd = strdup(passwd);
return qemu_spice_set_ticket(fail_if_conn, disconnect_if_conn);
}
int qemu_spice_set_pw_expire(time_t expires)
{
auth_expires = expires;
return qemu_spice_set_ticket(false, false);
}
static void spice_register_config(void)
{
qemu_add_opts(&qemu_spice_opts);