~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle-2.0/handshake.cc

Fix merge issues with 1.0 CC fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 * @brief Handshake Definitions
40
40
 */
41
41
 
42
 
#include "common.h"
 
42
#include <libdrizzle-2.0/common.h>
43
43
 
44
44
/*
45
45
 * Client Definitions
401
401
  con->buffer_ptr+= 1;
402
402
 
403
403
  if (scramble_size == 0)
 
404
  {
404
405
    con->scramble= NULL;
 
406
  }
405
407
  else
406
408
  {
407
409
    if (scramble_size != DRIZZLE_MAX_SCRAMBLE_SIZE)
418
420
    con->buffer_ptr+= DRIZZLE_MAX_SCRAMBLE_SIZE;
419
421
  }
420
422
 
421
 
  /* Look for null-terminated db string. */
422
 
  if ((34 + strlen(con->user) + scramble_size) == con->packet_size)
423
 
    con->db[0]= 0;
 
423
  /* Look for null-terminated schema string. */
 
424
  if ((34 + strlen(con->user) +scramble_size) == con->packet_size)
 
425
  {
 
426
    con->schema[0]= 0;
 
427
  }
424
428
  else
425
429
  {
426
430
    ptr= (uint8_t *)memchr(con->buffer_ptr, 0, con->buffer_size -
428
432
    if (ptr == NULL)
429
433
    {
430
434
      drizzle_set_error(con->drizzle, "drizzle_state_handshake_client_read",
431
 
                        "db string not found");
 
435
                        "schema string not found");
432
436
      return DRIZZLE_RETURN_BAD_HANDSHAKE_PACKET;
433
437
    }
434
438
 
442
446
 
443
447
    if (con->buffer_ptr == ptr)
444
448
    {
445
 
      con->db[0]= 0;
 
449
      con->schema[0]= 0;
446
450
      con->buffer_ptr++;
447
451
    }
448
452
    else
449
453
    {
450
 
      strncpy(con->db, (char *)con->buffer_ptr, DRIZZLE_MAX_DB_SIZE);
451
 
      con->db[DRIZZLE_MAX_DB_SIZE - 1]= 0;
 
454
      strncpy(con->schema, (char *)con->buffer_ptr, DRIZZLE_MAX_DB_SIZE);
 
455
      con->schema[DRIZZLE_MAX_DB_SIZE - 1]= 0;
452
456
      con->buffer_ptr+= ((ptr - con->buffer_ptr) + 1);
453
457
    }
454
458
  }
471
475
{
472
476
  uint8_t *ptr;
473
477
  int capabilities;
474
 
  drizzle_return_t ret;
475
478
 
476
479
  drizzle_log_debug(con->drizzle, "drizzle_state_handshake_client_write");
477
480
 
483
486
                  + strlen(con->user) + 1
484
487
                  + 1   /* Scramble size */
485
488
                  + DRIZZLE_MAX_SCRAMBLE_SIZE
486
 
                  + strlen(con->db) + 1;
 
489
                  + strlen(con->schema) + 1;
487
490
 
488
491
  /* Assume the entire handshake packet will fit in the buffer. */
489
492
  if ((con->packet_size + 4) > DRIZZLE_MAX_BUFFER_SIZE)
501
504
  ptr+= 4;
502
505
 
503
506
  if (con->options & DRIZZLE_CON_MYSQL)
 
507
  {
504
508
    con->capabilities|= DRIZZLE_CAPABILITIES_PROTOCOL_41;
 
509
  }
505
510
 
506
511
  capabilities= con->capabilities & DRIZZLE_CAPABILITIES_CLIENT;
507
512
  if (!(con->options & DRIZZLE_CON_FOUND_ROWS))
523
528
  }
524
529
 
525
530
  capabilities&= ~(DRIZZLE_CAPABILITIES_COMPRESS | DRIZZLE_CAPABILITIES_SSL);
526
 
  if (con->db[0] == 0)
 
531
  if (con->schema[0] == 0)
 
532
  {
527
533
    capabilities&= ~DRIZZLE_CAPABILITIES_CONNECT_WITH_DB;
 
534
  }
528
535
 
529
536
  drizzle_set_byte4(ptr, capabilities);
530
537
  ptr+= 4;
538
545
  memset(ptr, 0, 23);
539
546
  ptr+= 23;
540
547
 
 
548
  drizzle_return_t ret;
541
549
  ptr= drizzle_pack_auth(con, ptr, &ret);
542
550
  if (ret != DRIZZLE_RETURN_OK)
 
551
  {
543
552
    return ret;
 
553
  }
544
554
 
545
555
  con->buffer_size+= (4 + con->packet_size);
546
556
 
562
572
 
563
573
drizzle_return_t drizzle_state_handshake_result_read(drizzle_con_st *con)
564
574
{
565
 
  drizzle_return_t ret;
566
 
  drizzle_result_st result;
 
575
  drizzle_result_st *result;
567
576
 
568
577
  drizzle_log_debug(con->drizzle, "drizzle_state_handshake_result_read");
569
578
 
570
 
  if (drizzle_result_create(con, &result) == NULL)
 
579
  if ((result= drizzle_result_create(con)) == NULL)
 
580
  {
571
581
    return DRIZZLE_RETURN_MEMORY;
572
 
 
573
 
  con->result= &result;
574
 
 
575
 
  ret= drizzle_state_result_read(con);
 
582
  }
 
583
 
 
584
  con->result= result;
 
585
 
 
586
  drizzle_return_t ret= drizzle_state_result_read(con);
576
587
  if (drizzle_state_none(con))
577
588
  {
578
589
    if (ret == DRIZZLE_RETURN_OK)
579
590
    {
580
 
      if (drizzle_result_eof(&result))
 
591
      if (drizzle_result_eof(result))
581
592
      {
582
593
        drizzle_set_error(con->drizzle, "drizzle_state_handshake_result_read",
583
594
                         "old insecure authentication mechanism not supported");
584
595
        ret= DRIZZLE_RETURN_AUTH_FAILED;
585
596
      }
586
597
      else
 
598
      {
587
599
        con->options|= DRIZZLE_CON_READY;
 
600
      }
588
601
    }
589
602
  }
590
603
 
591
 
  drizzle_result_free(&result);
 
604
  drizzle_result_free(result);
592
605
 
593
606
  if (ret == DRIZZLE_RETURN_ERROR_CODE)
 
607
  {
594
608
    return DRIZZLE_RETURN_HANDSHAKE_FAILED;
 
609
  }
595
610
 
596
611
  return ret;
597
612
}