1 /* 2 * QEMU VNC display driver: SASL auth protocol 3 * 4 * Copyright (C) 2009 Red Hat, Inc 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 * copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 * THE SOFTWARE. 23 */ 24 25 #include "qemu/osdep.h" 26 #include "qapi/error.h" 27 #include "authz/base.h" 28 #include "vnc.h" 29 #include "trace.h" 30 31 /* 32 * Apple has deprecated sasl.h functions in OS X 10.11. Therefore, 33 * files that use SASL API need to disable -Wdeprecated-declarations. 34 */ 35 #ifdef CONFIG_DARWIN 36 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 37 #endif 38 39 /* Max amount of data we send/recv for SASL steps to prevent DOS */ 40 #define SASL_DATA_MAX_LEN (1024 * 1024) 41 42 43 bool vnc_sasl_server_init(Error **errp) 44 { 45 int saslErr = sasl_server_init(NULL, "qemu"); 46 47 if (saslErr != SASL_OK) { 48 error_setg(errp, "Failed to initialize SASL auth: %s", 49 sasl_errstring(saslErr, NULL, NULL)); 50 return false; 51 } 52 return true; 53 } 54 55 void vnc_sasl_client_cleanup(VncState *vs) 56 { 57 if (vs->sasl.conn) { 58 vs->sasl.runSSF = false; 59 vs->sasl.wantSSF = false; 60 vs->sasl.waitWriteSSF = 0; 61 vs->sasl.encodedLength = vs->sasl.encodedOffset = 0; 62 vs->sasl.encoded = NULL; 63 g_free(vs->sasl.username); 64 g_free(vs->sasl.mechlist); 65 vs->sasl.username = vs->sasl.mechlist = NULL; 66 sasl_dispose(&vs->sasl.conn); 67 vs->sasl.conn = NULL; 68 } 69 } 70 71 72 size_t vnc_client_write_sasl(VncState *vs) 73 { 74 size_t ret; 75 76 VNC_DEBUG("Write SASL: Pending output %p size %zd offset %zd " 77 "Encoded: %p size %d offset %d\n", 78 vs->output.buffer, vs->output.capacity, vs->output.offset, 79 vs->sasl.encoded, vs->sasl.encodedLength, vs->sasl.encodedOffset); 80 81 if (!vs->sasl.encoded) { 82 int err; 83 err = sasl_encode(vs->sasl.conn, 84 (char *)vs->output.buffer, 85 vs->output.offset, 86 (const char **)&vs->sasl.encoded, 87 &vs->sasl.encodedLength); 88 if (err != SASL_OK) 89 return vnc_client_io_error(vs, -1, NULL); 90 91 vs->sasl.encodedRawLength = vs->output.offset; 92 vs->sasl.encodedOffset = 0; 93 } 94 95 ret = vnc_client_write_buf(vs, 96 vs->sasl.encoded + vs->sasl.encodedOffset, 97 vs->sasl.encodedLength - vs->sasl.encodedOffset); 98 if (!ret) 99 return 0; 100 101 vs->sasl.encodedOffset += ret; 102 if (vs->sasl.encodedOffset == vs->sasl.encodedLength) { 103 bool throttled = vs->force_update_offset != 0; 104 size_t offset; 105 if (vs->sasl.encodedRawLength >= vs->force_update_offset) { 106 vs->force_update_offset = 0; 107 } else { 108 vs->force_update_offset -= vs->sasl.encodedRawLength; 109 } 110 if (throttled && vs->force_update_offset == 0) { 111 trace_vnc_client_unthrottle_forced(vs, vs->ioc); 112 } 113 offset = vs->output.offset; 114 buffer_advance(&vs->output, vs->sasl.encodedRawLength); 115 if (offset >= vs->throttle_output_offset && 116 vs->output.offset < vs->throttle_output_offset) { 117 trace_vnc_client_unthrottle_incremental(vs, vs->ioc, 118 vs->output.offset); 119 } 120 vs->sasl.encoded = NULL; 121 vs->sasl.encodedOffset = vs->sasl.encodedLength = 0; 122 } 123 124 /* Can't merge this block with one above, because 125 * someone might have written more unencrypted 126 * data in vs->output while we were processing 127 * SASL encoded output 128 */ 129 if (vs->output.offset == 0) { 130 if (vs->ioc_tag) { 131 g_source_remove(vs->ioc_tag); 132 } 133 vs->ioc_tag = qio_channel_add_watch( 134 vs->ioc, G_IO_IN | G_IO_HUP | G_IO_ERR, 135 vnc_client_io, vs, NULL); 136 } 137 138 return ret; 139 } 140 141 142 size_t vnc_client_read_sasl(VncState *vs) 143 { 144 size_t ret; 145 uint8_t encoded[4096]; 146 const char *decoded; 147 unsigned int decodedLen; 148 int err; 149 150 ret = vnc_client_read_buf(vs, encoded, sizeof(encoded)); 151 if (!ret) 152 return 0; 153 154 err = sasl_decode(vs->sasl.conn, 155 (char *)encoded, ret, 156 &decoded, &decodedLen); 157 158 if (err != SASL_OK) 159 return vnc_client_io_error(vs, -1, NULL); 160 VNC_DEBUG("Read SASL Encoded %p size %ld Decoded %p size %d\n", 161 encoded, ret, decoded, decodedLen); 162 buffer_reserve(&vs->input, decodedLen); 163 buffer_append(&vs->input, decoded, decodedLen); 164 return decodedLen; 165 } 166 167 168 static int vnc_auth_sasl_check_access(VncState *vs) 169 { 170 const void *val; 171 int rv; 172 Error *err = NULL; 173 bool allow; 174 175 rv = sasl_getprop(vs->sasl.conn, SASL_USERNAME, &val); 176 if (rv != SASL_OK) { 177 trace_vnc_auth_fail(vs, vs->auth, "Cannot fetch SASL username", 178 sasl_errstring(rv, NULL, NULL)); 179 return -1; 180 } 181 if (val == NULL) { 182 trace_vnc_auth_fail(vs, vs->auth, "No SASL username set", ""); 183 return -1; 184 } 185 186 vs->sasl.username = g_strdup((const char*)val); 187 trace_vnc_auth_sasl_username(vs, vs->sasl.username); 188 189 if (vs->vd->sasl.authzid == NULL) { 190 trace_vnc_auth_sasl_acl(vs, 1); 191 return 0; 192 } 193 194 allow = qauthz_is_allowed_by_id(vs->vd->sasl.authzid, 195 vs->sasl.username, &err); 196 if (err) { 197 trace_vnc_auth_fail(vs, vs->auth, "Error from authz", 198 error_get_pretty(err)); 199 error_free(err); 200 return -1; 201 } 202 203 trace_vnc_auth_sasl_acl(vs, allow); 204 return allow ? 0 : -1; 205 } 206 207 static int vnc_auth_sasl_check_ssf(VncState *vs) 208 { 209 const void *val; 210 int err, ssf; 211 212 if (!vs->sasl.wantSSF) 213 return 1; 214 215 err = sasl_getprop(vs->sasl.conn, SASL_SSF, &val); 216 if (err != SASL_OK) 217 return 0; 218 219 ssf = *(const int *)val; 220 221 trace_vnc_auth_sasl_ssf(vs, ssf); 222 223 if (ssf < 56) 224 return 0; /* 56 is good for Kerberos */ 225 226 /* Only setup for read initially, because we're about to send an RPC 227 * reply which must be in plain text. When the next incoming RPC 228 * arrives, we'll switch on writes too 229 * 230 * cf qemudClientReadSASL in qemud.c 231 */ 232 vs->sasl.runSSF = 1; 233 234 /* We have a SSF that's good enough */ 235 return 1; 236 } 237 238 /* 239 * Step Msg 240 * 241 * Input from client: 242 * 243 * u32 clientin-length 244 * u8-array clientin-string 245 * 246 * Output to client: 247 * 248 * u32 serverout-length 249 * u8-array serverout-strin 250 * u8 continue 251 */ 252 253 static int protocol_client_auth_sasl_step_len(VncState *vs, uint8_t *data, size_t len); 254 255 static int protocol_client_auth_sasl_step(VncState *vs, uint8_t *data, size_t len) 256 { 257 uint32_t datalen = len; 258 const char *serverout; 259 unsigned int serveroutlen; 260 int err; 261 char *clientdata = NULL; 262 263 /* NB, distinction of NULL vs "" is *critical* in SASL */ 264 if (datalen) { 265 clientdata = (char*)data; 266 clientdata[datalen-1] = '\0'; /* Wire includes '\0', but make sure */ 267 datalen--; /* Don't count NULL byte when passing to _start() */ 268 } 269 270 err = sasl_server_step(vs->sasl.conn, 271 clientdata, 272 datalen, 273 &serverout, 274 &serveroutlen); 275 trace_vnc_auth_sasl_step(vs, data, len, serverout, serveroutlen, err); 276 if (err != SASL_OK && 277 err != SASL_CONTINUE) { 278 trace_vnc_auth_fail(vs, vs->auth, "Cannot step SASL auth", 279 sasl_errdetail(vs->sasl.conn)); 280 sasl_dispose(&vs->sasl.conn); 281 vs->sasl.conn = NULL; 282 goto authabort; 283 } 284 285 if (serveroutlen > SASL_DATA_MAX_LEN) { 286 trace_vnc_auth_fail(vs, vs->auth, "SASL data too long", ""); 287 sasl_dispose(&vs->sasl.conn); 288 vs->sasl.conn = NULL; 289 goto authabort; 290 } 291 292 if (serverout) { 293 vnc_write_u32(vs, serveroutlen + 1); 294 vnc_write(vs, serverout, serveroutlen); 295 vnc_write_u8(vs, '\0'); 296 } else { 297 vnc_write_u32(vs, 0); 298 } 299 300 /* Whether auth is complete */ 301 vnc_write_u8(vs, err == SASL_CONTINUE ? 0 : 1); 302 303 if (err == SASL_CONTINUE) { 304 /* Wait for step length */ 305 vnc_read_when(vs, protocol_client_auth_sasl_step_len, 4); 306 } else { 307 if (!vnc_auth_sasl_check_ssf(vs)) { 308 trace_vnc_auth_fail(vs, vs->auth, "SASL SSF too weak", ""); 309 goto authreject; 310 } 311 312 /* Check the username access control list */ 313 if (vnc_auth_sasl_check_access(vs) < 0) { 314 goto authreject; 315 } 316 317 trace_vnc_auth_pass(vs, vs->auth); 318 vnc_write_u32(vs, 0); /* Accept auth */ 319 /* 320 * Delay writing in SSF encoded mode until pending output 321 * buffer is written 322 */ 323 if (vs->sasl.runSSF) 324 vs->sasl.waitWriteSSF = vs->output.offset; 325 start_client_init(vs); 326 } 327 328 return 0; 329 330 authreject: 331 vnc_write_u32(vs, 1); /* Reject auth */ 332 vnc_write_u32(vs, sizeof("Authentication failed")); 333 vnc_write(vs, "Authentication failed", sizeof("Authentication failed")); 334 vnc_flush(vs); 335 vnc_client_error(vs); 336 return -1; 337 338 authabort: 339 vnc_client_error(vs); 340 return -1; 341 } 342 343 static int protocol_client_auth_sasl_step_len(VncState *vs, uint8_t *data, size_t len) 344 { 345 uint32_t steplen = read_u32(data, 0); 346 347 if (steplen > SASL_DATA_MAX_LEN) { 348 trace_vnc_auth_fail(vs, vs->auth, "SASL step len too large", ""); 349 vnc_client_error(vs); 350 return -1; 351 } 352 353 if (steplen == 0) 354 return protocol_client_auth_sasl_step(vs, NULL, 0); 355 else 356 vnc_read_when(vs, protocol_client_auth_sasl_step, steplen); 357 return 0; 358 } 359 360 /* 361 * Start Msg 362 * 363 * Input from client: 364 * 365 * u32 clientin-length 366 * u8-array clientin-string 367 * 368 * Output to client: 369 * 370 * u32 serverout-length 371 * u8-array serverout-strin 372 * u8 continue 373 */ 374 375 #define SASL_DATA_MAX_LEN (1024 * 1024) 376 377 static int protocol_client_auth_sasl_start(VncState *vs, uint8_t *data, size_t len) 378 { 379 uint32_t datalen = len; 380 const char *serverout; 381 unsigned int serveroutlen; 382 int err; 383 char *clientdata = NULL; 384 385 /* NB, distinction of NULL vs "" is *critical* in SASL */ 386 if (datalen) { 387 clientdata = (char*)data; 388 clientdata[datalen-1] = '\0'; /* Should be on wire, but make sure */ 389 datalen--; /* Don't count NULL byte when passing to _start() */ 390 } 391 392 err = sasl_server_start(vs->sasl.conn, 393 vs->sasl.mechlist, 394 clientdata, 395 datalen, 396 &serverout, 397 &serveroutlen); 398 trace_vnc_auth_sasl_start(vs, data, len, serverout, serveroutlen, err); 399 if (err != SASL_OK && 400 err != SASL_CONTINUE) { 401 trace_vnc_auth_fail(vs, vs->auth, "Cannot start SASL auth", 402 sasl_errdetail(vs->sasl.conn)); 403 sasl_dispose(&vs->sasl.conn); 404 vs->sasl.conn = NULL; 405 goto authabort; 406 } 407 if (serveroutlen > SASL_DATA_MAX_LEN) { 408 trace_vnc_auth_fail(vs, vs->auth, "SASL data too long", ""); 409 sasl_dispose(&vs->sasl.conn); 410 vs->sasl.conn = NULL; 411 goto authabort; 412 } 413 414 if (serverout) { 415 vnc_write_u32(vs, serveroutlen + 1); 416 vnc_write(vs, serverout, serveroutlen); 417 vnc_write_u8(vs, '\0'); 418 } else { 419 vnc_write_u32(vs, 0); 420 } 421 422 /* Whether auth is complete */ 423 vnc_write_u8(vs, err == SASL_CONTINUE ? 0 : 1); 424 425 if (err == SASL_CONTINUE) { 426 /* Wait for step length */ 427 vnc_read_when(vs, protocol_client_auth_sasl_step_len, 4); 428 } else { 429 if (!vnc_auth_sasl_check_ssf(vs)) { 430 trace_vnc_auth_fail(vs, vs->auth, "SASL SSF too weak", ""); 431 goto authreject; 432 } 433 434 /* Check the username access control list */ 435 if (vnc_auth_sasl_check_access(vs) < 0) { 436 goto authreject; 437 } 438 439 trace_vnc_auth_pass(vs, vs->auth); 440 vnc_write_u32(vs, 0); /* Accept auth */ 441 start_client_init(vs); 442 } 443 444 return 0; 445 446 authreject: 447 vnc_write_u32(vs, 1); /* Reject auth */ 448 vnc_write_u32(vs, sizeof("Authentication failed")); 449 vnc_write(vs, "Authentication failed", sizeof("Authentication failed")); 450 vnc_flush(vs); 451 vnc_client_error(vs); 452 return -1; 453 454 authabort: 455 vnc_client_error(vs); 456 return -1; 457 } 458 459 static int protocol_client_auth_sasl_start_len(VncState *vs, uint8_t *data, size_t len) 460 { 461 uint32_t startlen = read_u32(data, 0); 462 463 if (startlen > SASL_DATA_MAX_LEN) { 464 trace_vnc_auth_fail(vs, vs->auth, "SASL start len too large", ""); 465 vnc_client_error(vs); 466 return -1; 467 } 468 469 if (startlen == 0) 470 return protocol_client_auth_sasl_start(vs, NULL, 0); 471 472 vnc_read_when(vs, protocol_client_auth_sasl_start, startlen); 473 return 0; 474 } 475 476 static int protocol_client_auth_sasl_mechname(VncState *vs, uint8_t *data, size_t len) 477 { 478 char *mechname = g_strndup((const char *) data, len); 479 trace_vnc_auth_sasl_mech_choose(vs, mechname); 480 481 if (strncmp(vs->sasl.mechlist, mechname, len) == 0) { 482 if (vs->sasl.mechlist[len] != '\0' && 483 vs->sasl.mechlist[len] != ',') { 484 goto fail; 485 } 486 } else { 487 char *offset = strstr(vs->sasl.mechlist, mechname); 488 if (!offset) { 489 goto fail; 490 } 491 if (offset[-1] != ',' || 492 (offset[len] != '\0'&& 493 offset[len] != ',')) { 494 goto fail; 495 } 496 } 497 498 g_free(vs->sasl.mechlist); 499 vs->sasl.mechlist = mechname; 500 501 vnc_read_when(vs, protocol_client_auth_sasl_start_len, 4); 502 return 0; 503 504 fail: 505 trace_vnc_auth_fail(vs, vs->auth, "Unsupported mechname", mechname); 506 vnc_client_error(vs); 507 g_free(mechname); 508 return -1; 509 } 510 511 static int protocol_client_auth_sasl_mechname_len(VncState *vs, uint8_t *data, size_t len) 512 { 513 uint32_t mechlen = read_u32(data, 0); 514 515 if (mechlen > 100) { 516 trace_vnc_auth_fail(vs, vs->auth, "SASL mechname too long", ""); 517 vnc_client_error(vs); 518 return -1; 519 } 520 if (mechlen < 1) { 521 trace_vnc_auth_fail(vs, vs->auth, "SASL mechname too short", ""); 522 vnc_client_error(vs); 523 return -1; 524 } 525 vnc_read_when(vs, protocol_client_auth_sasl_mechname,mechlen); 526 return 0; 527 } 528 529 static int 530 vnc_socket_ip_addr_string(QIOChannelSocket *ioc, 531 bool local, 532 char **addrstr, 533 Error **errp) 534 { 535 SocketAddress *addr; 536 537 if (local) { 538 addr = qio_channel_socket_get_local_address(ioc, errp); 539 } else { 540 addr = qio_channel_socket_get_remote_address(ioc, errp); 541 } 542 if (!addr) { 543 return -1; 544 } 545 546 if (addr->type != SOCKET_ADDRESS_TYPE_INET) { 547 *addrstr = NULL; 548 qapi_free_SocketAddress(addr); 549 return 0; 550 } 551 *addrstr = g_strdup_printf("%s;%s", addr->u.inet.host, addr->u.inet.port); 552 qapi_free_SocketAddress(addr); 553 return 0; 554 } 555 556 static bool 557 vnc_socket_is_unix(QIOChannelSocket *ioc) 558 { 559 SocketAddress *addr = qio_channel_socket_get_local_address(ioc, NULL); 560 return addr && addr->type == SOCKET_ADDRESS_TYPE_UNIX; 561 } 562 563 void start_auth_sasl(VncState *vs) 564 { 565 const char *mechlist = NULL; 566 sasl_security_properties_t secprops; 567 int err; 568 Error *local_err = NULL; 569 char *localAddr, *remoteAddr; 570 int mechlistlen; 571 572 /* Get local & remote client addresses in form IPADDR;PORT */ 573 if (vnc_socket_ip_addr_string(vs->sioc, true, 574 &localAddr, &local_err) < 0) { 575 trace_vnc_auth_fail(vs, vs->auth, "Cannot format local IP", 576 error_get_pretty(local_err)); 577 goto authabort; 578 } 579 580 if (vnc_socket_ip_addr_string(vs->sioc, false, 581 &remoteAddr, &local_err) < 0) { 582 trace_vnc_auth_fail(vs, vs->auth, "Cannot format remote IP", 583 error_get_pretty(local_err)); 584 g_free(localAddr); 585 goto authabort; 586 } 587 588 err = sasl_server_new("vnc", 589 NULL, /* FQDN - just delegates to gethostname */ 590 NULL, /* User realm */ 591 localAddr, 592 remoteAddr, 593 NULL, /* Callbacks, not needed */ 594 SASL_SUCCESS_DATA, 595 &vs->sasl.conn); 596 g_free(localAddr); 597 g_free(remoteAddr); 598 localAddr = remoteAddr = NULL; 599 600 if (err != SASL_OK) { 601 trace_vnc_auth_fail(vs, vs->auth, "SASL context setup failed", 602 sasl_errstring(err, NULL, NULL)); 603 vs->sasl.conn = NULL; 604 goto authabort; 605 } 606 607 /* Inform SASL that we've got an external SSF layer from TLS/x509 */ 608 if (vs->auth == VNC_AUTH_VENCRYPT && 609 vs->subauth == VNC_AUTH_VENCRYPT_X509SASL) { 610 int keysize; 611 sasl_ssf_t ssf; 612 613 keysize = qcrypto_tls_session_get_key_size(vs->tls, 614 &local_err); 615 if (keysize < 0) { 616 trace_vnc_auth_fail(vs, vs->auth, "cannot TLS get cipher size", 617 error_get_pretty(local_err)); 618 sasl_dispose(&vs->sasl.conn); 619 vs->sasl.conn = NULL; 620 goto authabort; 621 } 622 ssf = keysize * CHAR_BIT; /* tls key size is bytes, sasl wants bits */ 623 624 err = sasl_setprop(vs->sasl.conn, SASL_SSF_EXTERNAL, &ssf); 625 if (err != SASL_OK) { 626 trace_vnc_auth_fail(vs, vs->auth, "cannot set SASL external SSF", 627 sasl_errstring(err, NULL, NULL)); 628 sasl_dispose(&vs->sasl.conn); 629 vs->sasl.conn = NULL; 630 goto authabort; 631 } 632 } else { 633 vs->sasl.wantSSF = !vnc_socket_is_unix(vs->sioc); 634 } 635 636 memset (&secprops, 0, sizeof secprops); 637 /* Inform SASL that we've got an external SSF layer from TLS. 638 * 639 * Disable SSF, if using TLS+x509+SASL only, or UNIX sockets. 640 * TLS without x509 is not sufficiently strong, nor is plain 641 * TCP 642 */ 643 if (vnc_socket_is_unix(vs->sioc) || 644 (vs->auth == VNC_AUTH_VENCRYPT && 645 vs->subauth == VNC_AUTH_VENCRYPT_X509SASL)) { 646 /* If we've got TLS or UNIX domain sock, we don't care about SSF */ 647 secprops.min_ssf = 0; 648 secprops.max_ssf = 0; 649 secprops.maxbufsize = 8192; 650 secprops.security_flags = 0; 651 } else { 652 /* Plain TCP, better get an SSF layer */ 653 secprops.min_ssf = 56; /* Good enough to require kerberos */ 654 secprops.max_ssf = 100000; /* Arbitrary big number */ 655 secprops.maxbufsize = 8192; 656 /* Forbid any anonymous or trivially crackable auth */ 657 secprops.security_flags = 658 SASL_SEC_NOANONYMOUS | SASL_SEC_NOPLAINTEXT; 659 } 660 661 err = sasl_setprop(vs->sasl.conn, SASL_SEC_PROPS, &secprops); 662 if (err != SASL_OK) { 663 trace_vnc_auth_fail(vs, vs->auth, "cannot set SASL security props", 664 sasl_errstring(err, NULL, NULL)); 665 sasl_dispose(&vs->sasl.conn); 666 vs->sasl.conn = NULL; 667 goto authabort; 668 } 669 670 err = sasl_listmech(vs->sasl.conn, 671 NULL, /* Don't need to set user */ 672 "", /* Prefix */ 673 ",", /* Separator */ 674 "", /* Suffix */ 675 &mechlist, 676 NULL, 677 NULL); 678 if (err != SASL_OK) { 679 trace_vnc_auth_fail(vs, vs->auth, "cannot list SASL mechanisms", 680 sasl_errdetail(vs->sasl.conn)); 681 sasl_dispose(&vs->sasl.conn); 682 vs->sasl.conn = NULL; 683 goto authabort; 684 } 685 trace_vnc_auth_sasl_mech_list(vs, mechlist); 686 687 if (g_str_equal(mechlist, "")) { 688 trace_vnc_auth_fail(vs, vs->auth, "no available SASL mechanisms", ""); 689 sasl_dispose(&vs->sasl.conn); 690 vs->sasl.conn = NULL; 691 goto authabort; 692 } 693 694 vs->sasl.mechlist = g_strdup(mechlist); 695 mechlistlen = strlen(mechlist); 696 vnc_write_u32(vs, mechlistlen); 697 vnc_write(vs, mechlist, mechlistlen); 698 vnc_flush(vs); 699 700 vnc_read_when(vs, protocol_client_auth_sasl_mechname_len, 4); 701 702 return; 703 704 authabort: 705 error_free(local_err); 706 vnc_client_error(vs); 707 } 708 709 710