~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle-2.0/handshake.cc

  • Committer: Brian Aker
  • Date: 2011-11-04 21:06:16 UTC
  • mto: This revision was merged to the branch mainline in revision 2450.
  • Revision ID: brian@tangent.org-20111104210616-2at42agch94dkwb0
Additional fixes for libdrizzle.

Show diffs side-by-side

added added

removed removed

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