Revision c448e855 ui/spice-core.c

b/ui/spice-core.c
22 22
#include "qemu-spice.h"
23 23
#include "qemu-timer.h"
24 24
#include "qemu-queue.h"
25
#include "qemu-x509.h"
25 26
#include "monitor.h"
26 27

  
27 28
/* core bits */
......
141 142
void qemu_spice_init(void)
142 143
{
143 144
    QemuOpts *opts = QTAILQ_FIRST(&qemu_spice_opts.head);
144
    const char *password;
145
    int port;
145
    const char *password, *str, *x509_dir,
146
        *x509_key_password = NULL,
147
        *x509_dh_file = NULL,
148
        *tls_ciphers = NULL;
149
    char *x509_key_file = NULL,
150
        *x509_cert_file = NULL,
151
        *x509_cacert_file = NULL;
152
    int port, tls_port, len;
146 153

  
147 154
    if (!opts) {
148 155
        return;
149 156
    }
150 157
    port = qemu_opt_get_number(opts, "port", 0);
151
    if (!port) {
158
    tls_port = qemu_opt_get_number(opts, "tls-port", 0);
159
    if (!port && !tls_port) {
152 160
        return;
153 161
    }
154 162
    password = qemu_opt_get(opts, "password");
155 163

  
164
    if (tls_port) {
165
        x509_dir = qemu_opt_get(opts, "x509-dir");
166
        if (NULL == x509_dir) {
167
            x509_dir = ".";
168
        }
169
        len = strlen(x509_dir) + 32;
170

  
171
        str = qemu_opt_get(opts, "x509-key-file");
172
        if (str) {
173
            x509_key_file = qemu_strdup(str);
174
        } else {
175
            x509_key_file = qemu_malloc(len);
176
            snprintf(x509_key_file, len, "%s/%s", x509_dir, X509_SERVER_KEY_FILE);
177
        }
178

  
179
        str = qemu_opt_get(opts, "x509-cert-file");
180
        if (str) {
181
            x509_cert_file = qemu_strdup(str);
182
        } else {
183
            x509_cert_file = qemu_malloc(len);
184
            snprintf(x509_cert_file, len, "%s/%s", x509_dir, X509_SERVER_CERT_FILE);
185
        }
186

  
187
        str = qemu_opt_get(opts, "x509-cacert-file");
188
        if (str) {
189
            x509_cacert_file = qemu_strdup(str);
190
        } else {
191
            x509_cacert_file = qemu_malloc(len);
192
            snprintf(x509_cacert_file, len, "%s/%s", x509_dir, X509_CA_CERT_FILE);
193
        }
194

  
195
        x509_key_password = qemu_opt_get(opts, "x509-key-password");
196
        x509_dh_file = qemu_opt_get(opts, "x509-dh-file");
197
        tls_ciphers = qemu_opt_get(opts, "tls-ciphers");
198
    }
199

  
156 200
    spice_server = spice_server_new();
157
    spice_server_set_port(spice_server, port);
201
    if (port) {
202
        spice_server_set_port(spice_server, port);
203
    }
204
    if (tls_port) {
205
        spice_server_set_tls(spice_server, tls_port,
206
                             x509_cacert_file,
207
                             x509_cert_file,
208
                             x509_key_file,
209
                             x509_key_password,
210
                             x509_dh_file,
211
                             tls_ciphers);
212
    }
158 213
    if (password) {
159 214
        spice_server_set_ticket(spice_server, password, 0, 0, 0);
160 215
    }
......
169 224
    using_spice = 1;
170 225

  
171 226
    qemu_spice_input_init();
227

  
228
    qemu_free(x509_key_file);
229
    qemu_free(x509_cert_file);
230
    qemu_free(x509_cacert_file);
172 231
}
173 232

  
174 233
int qemu_spice_add_interface(SpiceBaseInstance *sin)

Also available in: Unified diff