Revision 7572150c monitor.c

b/monitor.c
34 34
#include "net.h"
35 35
#include "net/slirp.h"
36 36
#include "qemu-char.h"
37
#include "ui/qemu-spice.h"
37 38
#include "sysemu.h"
38 39
#include "monitor.h"
39 40
#include "readline.h"
......
1075 1076
    return ret;
1076 1077
}
1077 1078

  
1079
static int set_password(Monitor *mon, const QDict *qdict, QObject **ret_data)
1080
{
1081
    const char *protocol  = qdict_get_str(qdict, "protocol");
1082
    const char *password  = qdict_get_str(qdict, "password");
1083
    const char *connected = qdict_get_try_str(qdict, "connected");
1084
    int disconnect_if_connected = 0;
1085
    int fail_if_connected = 0;
1086
    int rc;
1087

  
1088
    if (connected) {
1089
        if (strcmp(connected, "fail") == 0) {
1090
            fail_if_connected = 1;
1091
        } else if (strcmp(connected, "disconnect") == 0) {
1092
            disconnect_if_connected = 1;
1093
        } else if (strcmp(connected, "keep") == 0) {
1094
            /* nothing */
1095
        } else {
1096
            qerror_report(QERR_INVALID_PARAMETER, "connected");
1097
            return -1;
1098
        }
1099
    }
1100

  
1101
    if (strcmp(protocol, "spice") == 0) {
1102
        if (!using_spice) {
1103
            /* correct one? spice isn't a device ,,, */
1104
            qerror_report(QERR_DEVICE_NOT_ACTIVE, "spice");
1105
            return -1;
1106
        }
1107
        rc = qemu_spice_set_passwd(password, fail_if_connected,
1108
                                   disconnect_if_connected);
1109
        if (rc != 0) {
1110
            qerror_report(QERR_SET_PASSWD_FAILED);
1111
            return -1;
1112
        }
1113
        return 0;
1114
    }
1115

  
1116
    if (strcmp(protocol, "vnc") == 0) {
1117
        if (fail_if_connected || disconnect_if_connected) {
1118
            /* vnc supports "connected=keep" only */
1119
            qerror_report(QERR_INVALID_PARAMETER, "connected");
1120
            return -1;
1121
        }
1122
        rc = vnc_display_password(NULL, password);
1123
        if (rc != 0) {
1124
            qerror_report(QERR_SET_PASSWD_FAILED);
1125
            return -1;
1126
        }
1127
        return 0;
1128
    }
1129

  
1130
    qerror_report(QERR_INVALID_PARAMETER, "protocol");
1131
    return -1;
1132
}
1133

  
1134
static int expire_password(Monitor *mon, const QDict *qdict, QObject **ret_data)
1135
{
1136
    const char *protocol  = qdict_get_str(qdict, "protocol");
1137
    const char *whenstr = qdict_get_str(qdict, "time");
1138
    time_t when;
1139
    int rc;
1140

  
1141
    if (strcmp(whenstr, "now")) {
1142
        when = 0;
1143
    } else if (strcmp(whenstr, "never")) {
1144
        when = TIME_MAX;
1145
    } else if (whenstr[0] == '+') {
1146
        when = time(NULL) + strtoull(whenstr+1, NULL, 10);
1147
    } else {
1148
        when = strtoull(whenstr, NULL, 10);
1149
    }
1150

  
1151
    if (strcmp(protocol, "spice") == 0) {
1152
        if (!using_spice) {
1153
            /* correct one? spice isn't a device ,,, */
1154
            qerror_report(QERR_DEVICE_NOT_ACTIVE, "spice");
1155
            return -1;
1156
        }
1157
        rc = qemu_spice_set_pw_expire(when);
1158
        if (rc != 0) {
1159
            qerror_report(QERR_SET_PASSWD_FAILED);
1160
            return -1;
1161
        }
1162
        return 0;
1163
    }
1164

  
1165
    if (strcmp(protocol, "vnc") == 0) {
1166
        rc = vnc_display_pw_expire(NULL, when);
1167
        if (rc != 0) {
1168
            qerror_report(QERR_SET_PASSWD_FAILED);
1169
            return -1;
1170
        }
1171
        return 0;
1172
    }
1173

  
1174
    qerror_report(QERR_INVALID_PARAMETER, "protocol");
1175
    return -1;
1176
}
1177

  
1078 1178
static int do_screen_dump(Monitor *mon, const QDict *qdict, QObject **ret_data)
1079 1179
{
1080 1180
    vga_hw_screen_dump(qdict_get_str(qdict, "filename"));

Also available in: Unified diff