409
303
#define NET_HEADER_SIZE 4 /* standard header size */
410
304
#define COMP_HEADER_SIZE 3 /* compression header extra size */
412
/* Prototypes to password functions */
419
These functions are used for authentication by client and server and
420
implemented in sql/password.c
423
void randominit(struct rand_struct *, uint32_t seed1, uint32_t seed2);
424
double my_rnd(struct rand_struct *);
425
void create_random_string(char *to, unsigned int length,
426
struct rand_struct *rand_st);
428
void hash_password(uint32_t *to, const char *password, uint32_t password_len);
430
void make_scrambled_password(char *to, const char *password);
431
void scramble(char *to, const char *message, const char *password);
432
bool check_scramble(const char *reply, const char *message,
433
const unsigned char *hash_stage2);
434
void get_salt_from_password(unsigned char *res, const char *password);
435
void make_password_from_salt(char *to, const unsigned char *hash_stage2);
436
char *octet2hex(char *to, const char *str, unsigned int len);
438
/* end of password.c */
440
char *get_tty_password(const char *opt_message);
442
uint32_t net_field_length(unsigned char **packet);
443
uint64_t net_field_length_ll(unsigned char **packet);
444
unsigned char *net_store_length(unsigned char *pkg, uint64_t length);
447
Define-funktions for reading and storing in machine independent format
451
/* Optimized store functions for Intel x86 */
452
#if defined(__i386__)
453
#define sint2korr(A) (*((int16_t *) (A)))
454
#define sint3korr(A) ((int32_t) ((((unsigned char) (A)[2]) & 128) ? \
455
(((uint32_t) 255L << 24) | \
456
(((uint32_t) (unsigned char) (A)[2]) << 16) |\
457
(((uint32_t) (unsigned char) (A)[1]) << 8) | \
458
((uint32_t) (unsigned char) (A)[0])) : \
459
(((uint32_t) (unsigned char) (A)[2]) << 16) |\
460
(((uint32_t) (unsigned char) (A)[1]) << 8) | \
461
((uint32_t) (unsigned char) (A)[0])))
462
#define sint4korr(A) (*((long *) (A)))
463
#define uint2korr(A) (*((uint16_t *) (A)))
464
#if defined(HAVE_purify)
465
#define uint3korr(A) (uint32_t) (((uint32_t) ((unsigned char) (A)[0])) +\
466
(((uint32_t) ((unsigned char) (A)[1])) << 8) +\
467
(((uint32_t) ((unsigned char) (A)[2])) << 16))
472
Please, note, uint3korr reads 4 bytes (not 3) !
473
It means, that you have to provide enough allocated space !
475
#define uint3korr(A) (long) (*((unsigned int *) (A)) & 0xFFFFFF)
476
#endif /* HAVE_purify */
477
#define uint4korr(A) (*((uint32_t *) (A)))
478
#define uint5korr(A) ((uint64_t)(((uint32_t) ((unsigned char) (A)[0])) +\
479
(((uint32_t) ((unsigned char) (A)[1])) << 8) +\
480
(((uint32_t) ((unsigned char) (A)[2])) << 16) +\
481
(((uint32_t) ((unsigned char) (A)[3])) << 24)) +\
482
(((uint64_t) ((unsigned char) (A)[4])) << 32))
483
#define uint6korr(A) ((uint64_t)(((uint32_t) ((unsigned char) (A)[0])) + \
484
(((uint32_t) ((unsigned char) (A)[1])) << 8) + \
485
(((uint32_t) ((unsigned char) (A)[2])) << 16) + \
486
(((uint32_t) ((unsigned char) (A)[3])) << 24)) + \
487
(((uint64_t) ((unsigned char) (A)[4])) << 32) + \
488
(((uint64_t) ((unsigned char) (A)[5])) << 40))
489
#define uint8korr(A) (*((uint64_t *) (A)))
490
#define sint8korr(A) (*((int64_t *) (A)))
491
#define int2store(T,A) *((uint16_t*) (T))= (uint16_t) (A)
492
#define int3store(T,A) do { *(T)= (unsigned char) ((A));\
493
*(T+1)=(unsigned char) (((uint32_t) (A) >> 8));\
494
*(T+2)=(unsigned char) (((A) >> 16)); } while (0)
495
#define int4store(T,A) *((long *) (T))= (long) (A)
496
#define int5store(T,A) do { *(T)= (unsigned char)((A));\
497
*((T)+1)=(unsigned char) (((A) >> 8));\
498
*((T)+2)=(unsigned char) (((A) >> 16));\
499
*((T)+3)=(unsigned char) (((A) >> 24)); \
500
*((T)+4)=(unsigned char) (((A) >> 32)); } while(0)
501
#define int6store(T,A) do { *(T)= (unsigned char)((A)); \
502
*((T)+1)=(unsigned char) (((A) >> 8)); \
503
*((T)+2)=(unsigned char) (((A) >> 16)); \
504
*((T)+3)=(unsigned char) (((A) >> 24)); \
505
*((T)+4)=(unsigned char) (((A) >> 32)); \
506
*((T)+5)=(unsigned char) (((A) >> 40)); } while(0)
507
#define int8store(T,A) *((uint64_t *) (T))= (uint64_t) (A)
513
#define doubleget(V,M) \
514
do { doubleget_union _tmp; \
515
_tmp.m[0] = *((long*)(M)); \
516
_tmp.m[1] = *(((long*) (M))+1); \
517
(V) = _tmp.v; } while(0)
518
#define doublestore(T,V) do { *((long *) T) = ((doubleget_union *)&V)->m[0]; \
519
*(((long *) T)+1) = ((doubleget_union *)&V)->m[1]; \
521
#define float4get(V,M) do { *((float *) &(V)) = *((float*) (M)); } while(0)
522
#define float8get(V,M) doubleget((V),(M))
523
#define float4store(V,M) memcpy(V, (&M), sizeof(float))
524
#define floatstore(T,V) memcpy((T), (&V), sizeof(float))
525
#define floatget(V,M) memcpy(&V, (M), sizeof(float))
526
#define float8store(V,M) doublestore((V),(M))
530
We're here if it's not a IA-32 architecture (Win32 and UNIX IA-32 defines
533
#define sint2korr(A) (int16_t) (((int16_t) ((unsigned char) (A)[0])) +\
534
((int16_t) ((int16_t) (A)[1]) << 8))
535
#define sint3korr(A) ((int32_t) ((((unsigned char) (A)[2]) & 128) ? \
536
(((uint32_t) 255L << 24) | \
537
(((uint32_t) (unsigned char) (A)[2]) << 16) |\
538
(((uint32_t) (unsigned char) (A)[1]) << 8) | \
539
((uint32_t) (unsigned char) (A)[0])) : \
540
(((uint32_t) (unsigned char) (A)[2]) << 16) |\
541
(((uint32_t) (unsigned char) (A)[1]) << 8) | \
542
((uint32_t) (unsigned char) (A)[0])))
543
#define sint4korr(A) (int32_t) (((int32_t) ((unsigned char) (A)[0])) +\
544
(((int32_t) ((unsigned char) (A)[1]) << 8)) +\
545
(((int32_t) ((unsigned char) (A)[2]) << 16)) +\
546
(((int32_t) ((int16_t) (A)[3]) << 24)))
547
#define sint8korr(A) (int64_t) uint8korr(A)
548
#define uint2korr(A) (uint16_t) (((uint16_t) ((unsigned char) (A)[0])) +\
549
((uint16_t) ((unsigned char) (A)[1]) << 8))
550
#define uint3korr(A) (uint32_t) (((uint32_t) ((unsigned char) (A)[0])) +\
551
(((uint32_t) ((unsigned char) (A)[1])) << 8) +\
552
(((uint32_t) ((unsigned char) (A)[2])) << 16))
553
#define uint4korr(A) (uint32_t) (((uint32_t) ((unsigned char) (A)[0])) +\
554
(((uint32_t) ((unsigned char) (A)[1])) << 8) +\
555
(((uint32_t) ((unsigned char) (A)[2])) << 16) +\
556
(((uint32_t) ((unsigned char) (A)[3])) << 24))
557
#define uint5korr(A) ((uint64_t)(((uint32_t) ((unsigned char) (A)[0])) +\
558
(((uint32_t) ((unsigned char) (A)[1])) << 8) +\
559
(((uint32_t) ((unsigned char) (A)[2])) << 16) +\
560
(((uint32_t) ((unsigned char) (A)[3])) << 24)) +\
561
(((uint64_t) ((unsigned char) (A)[4])) << 32))
562
#define uint6korr(A) ((uint64_t)(((uint32_t) ((unsigned char) (A)[0])) + \
563
(((uint32_t) ((unsigned char) (A)[1])) << 8) + \
564
(((uint32_t) ((unsigned char) (A)[2])) << 16) + \
565
(((uint32_t) ((unsigned char) (A)[3])) << 24)) + \
566
(((uint64_t) ((unsigned char) (A)[4])) << 32) + \
567
(((uint64_t) ((unsigned char) (A)[5])) << 40))
568
#define uint8korr(A) ((uint64_t)(((uint32_t) ((unsigned char) (A)[0])) +\
569
(((uint32_t) ((unsigned char) (A)[1])) << 8) +\
570
(((uint32_t) ((unsigned char) (A)[2])) << 16) +\
571
(((uint32_t) ((unsigned char) (A)[3])) << 24)) +\
572
(((uint64_t) (((uint32_t) ((unsigned char) (A)[4])) +\
573
(((uint32_t) ((unsigned char) (A)[5])) << 8) +\
574
(((uint32_t) ((unsigned char) (A)[6])) << 16) +\
575
(((uint32_t) ((unsigned char) (A)[7])) << 24))) <<\
577
#define int2store(T,A) do { uint32_t def_temp= (uint32_t) (A) ;\
578
*((unsigned char*) (T))= (unsigned char)(def_temp); \
579
*((unsigned char*) (T)+1)=(unsigned char)((def_temp >> 8)); \
581
#define int3store(T,A) do { /*lint -save -e734 */\
582
*((unsigned char*)(T))=(unsigned char) ((A));\
583
*((unsigned char*) (T)+1)=(unsigned char) (((A) >> 8));\
584
*((unsigned char*)(T)+2)=(unsigned char) (((A) >> 16)); \
585
/*lint -restore */} while(0)
586
#define int4store(T,A) do { *((char *)(T))=(char) ((A));\
587
*(((char *)(T))+1)=(char) (((A) >> 8));\
588
*(((char *)(T))+2)=(char) (((A) >> 16));\
589
*(((char *)(T))+3)=(char) (((A) >> 24)); } while(0)
590
#define int5store(T,A) do { *((char *)(T))= (char)((A)); \
591
*(((char *)(T))+1)= (char)(((A) >> 8)); \
592
*(((char *)(T))+2)= (char)(((A) >> 16)); \
593
*(((char *)(T))+3)= (char)(((A) >> 24)); \
594
*(((char *)(T))+4)= (char)(((A) >> 32)); \
596
#define int6store(T,A) do { *((char *)(T))= (char)((A)); \
597
*(((char *)(T))+1)= (char)(((A) >> 8)); \
598
*(((char *)(T))+2)= (char)(((A) >> 16)); \
599
*(((char *)(T))+3)= (char)(((A) >> 24)); \
600
*(((char *)(T))+4)= (char)(((A) >> 32)); \
601
*(((char *)(T))+5)= (char)(((A) >> 40)); \
603
#define int8store(T,A) do { uint32_t def_temp= (uint32_t) (A), def_temp2= (uint32_t) ((A) >> 32); \
604
int4store((T),def_temp); \
605
int4store((T+4),def_temp2); } while(0)
606
#ifdef WORDS_BIGENDIAN
607
#define float4store(T,A) do { *(T)= ((unsigned char *) &A)[3];\
608
*((T)+1)=(char) ((unsigned char *) &A)[2];\
609
*((T)+2)=(char) ((unsigned char *) &A)[1];\
610
*((T)+3)=(char) ((unsigned char *) &A)[0]; } while(0)
612
#define float4get(V,M) do { float def_temp;\
613
((unsigned char*) &def_temp)[0]=(M)[3];\
614
((unsigned char*) &def_temp)[1]=(M)[2];\
615
((unsigned char*) &def_temp)[2]=(M)[1];\
616
((unsigned char*) &def_temp)[3]=(M)[0];\
617
(V)=def_temp; } while(0)
618
#define float8store(T,V) do { *(T)= ((unsigned char *) &V)[7];\
619
*((T)+1)=(char) ((unsigned char *) &V)[6];\
620
*((T)+2)=(char) ((unsigned char *) &V)[5];\
621
*((T)+3)=(char) ((unsigned char *) &V)[4];\
622
*((T)+4)=(char) ((unsigned char *) &V)[3];\
623
*((T)+5)=(char) ((unsigned char *) &V)[2];\
624
*((T)+6)=(char) ((unsigned char *) &V)[1];\
625
*((T)+7)=(char) ((unsigned char *) &V)[0]; } while(0)
627
#define float8get(V,M) do { double def_temp;\
628
((unsigned char*) &def_temp)[0]=(M)[7];\
629
((unsigned char*) &def_temp)[1]=(M)[6];\
630
((unsigned char*) &def_temp)[2]=(M)[5];\
631
((unsigned char*) &def_temp)[3]=(M)[4];\
632
((unsigned char*) &def_temp)[4]=(M)[3];\
633
((unsigned char*) &def_temp)[5]=(M)[2];\
634
((unsigned char*) &def_temp)[6]=(M)[1];\
635
((unsigned char*) &def_temp)[7]=(M)[0];\
636
(V) = def_temp; } while(0)
638
#define float4get(V,M) memcpy(&V, (M), sizeof(float))
639
#define float4store(V,M) memcpy(V, (&M), sizeof(float))
641
#if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
642
#define doublestore(T,V) do { *(((char*)T)+0)=(char) ((unsigned char *) &V)[4];\
643
*(((char*)T)+1)=(char) ((unsigned char *) &V)[5];\
644
*(((char*)T)+2)=(char) ((unsigned char *) &V)[6];\
645
*(((char*)T)+3)=(char) ((unsigned char *) &V)[7];\
646
*(((char*)T)+4)=(char) ((unsigned char *) &V)[0];\
647
*(((char*)T)+5)=(char) ((unsigned char *) &V)[1];\
648
*(((char*)T)+6)=(char) ((unsigned char *) &V)[2];\
649
*(((char*)T)+7)=(char) ((unsigned char *) &V)[3]; }\
651
#define doubleget(V,M) do { double def_temp;\
652
((unsigned char*) &def_temp)[0]=(M)[4];\
653
((unsigned char*) &def_temp)[1]=(M)[5];\
654
((unsigned char*) &def_temp)[2]=(M)[6];\
655
((unsigned char*) &def_temp)[3]=(M)[7];\
656
((unsigned char*) &def_temp)[4]=(M)[0];\
657
((unsigned char*) &def_temp)[5]=(M)[1];\
658
((unsigned char*) &def_temp)[6]=(M)[2];\
659
((unsigned char*) &def_temp)[7]=(M)[3];\
660
(V) = def_temp; } while(0)
661
#endif /* __FLOAT_WORD_ORDER */
663
#define float8get(V,M) doubleget((V),(M))
664
#define float8store(V,M) doublestore((V),(M))
665
#endif /* WORDS_BIGENDIAN */
667
#endif /* __i386__ */
670
Macro for reading 32-bit integer from network byte order (big-endian)
671
from unaligned memory location.
673
#define int4net(A) (int32_t) (((uint32_t) ((unsigned char) (A)[3])) |\
674
(((uint32_t) ((unsigned char) (A)[2])) << 8) |\
675
(((uint32_t) ((unsigned char) (A)[1])) << 16) |\
676
(((uint32_t) ((unsigned char) (A)[0])) << 24))
678
Define-funktions for reading and storing in machine format from/to
679
short/long to/from some place in memory V should be a (not
680
register) variable, M is a pointer to byte
683
#ifdef WORDS_BIGENDIAN
685
#define ushortget(V,M) do { V = (uint16_t) (((uint16_t) ((unsigned char) (M)[1]))+\
686
((uint16_t) ((uint16_t) (M)[0]) << 8)); } while(0)
687
#define shortget(V,M) do { V = (short) (((short) ((unsigned char) (M)[1]))+\
688
((short) ((short) (M)[0]) << 8)); } while(0)
689
#define longget(V,M) do { int32_t def_temp;\
690
((unsigned char*) &def_temp)[0]=(M)[0];\
691
((unsigned char*) &def_temp)[1]=(M)[1];\
692
((unsigned char*) &def_temp)[2]=(M)[2];\
693
((unsigned char*) &def_temp)[3]=(M)[3];\
694
(V)=def_temp; } while(0)
695
#define ulongget(V,M) do { uint32_t def_temp;\
696
((unsigned char*) &def_temp)[0]=(M)[0];\
697
((unsigned char*) &def_temp)[1]=(M)[1];\
698
((unsigned char*) &def_temp)[2]=(M)[2];\
699
((unsigned char*) &def_temp)[3]=(M)[3];\
700
(V)=def_temp; } while(0)
701
#define shortstore(T,A) do { uint32_t def_temp=(uint32_t) (A) ;\
702
*(((char*)T)+1)=(char)(def_temp); \
703
*(((char*)T)+0)=(char)(def_temp >> 8); } while(0)
704
#define longstore(T,A) do { *(((char*)T)+3)=((A));\
705
*(((char*)T)+2)=(((A) >> 8));\
706
*(((char*)T)+1)=(((A) >> 16));\
707
*(((char*)T)+0)=(((A) >> 24)); } while(0)
709
#define floatget(V,M) memcpy(&V, (M), sizeof(float))
710
#define floatstore(T, V) memcpy((T), (&V), sizeof(float))
711
#define doubleget(V, M) memcpy(&V, (M), sizeof(double))
712
#define doublestore(T, V) memcpy((T), &V, sizeof(double))
713
#define int64_tget(V, M) memcpy(&V, (M), sizeof(uint64_t))
714
#define int64_tstore(T, V) memcpy((T), &V, sizeof(uint64_t))
718
#define ushortget(V,M) do { V = uint2korr(M); } while(0)
719
#define shortget(V,M) do { V = sint2korr(M); } while(0)
720
#define longget(V,M) do { V = sint4korr(M); } while(0)
721
#define ulongget(V,M) do { V = uint4korr(M); } while(0)
722
#define shortstore(T,V) int2store(T,V)
723
#define longstore(T,V) int4store(T,V)
725
#define floatstore(T,V) memcpy((T), (&V), sizeof(float))
726
#define floatget(V,M) memcpy(&V, (M), sizeof(float))
729
#define doubleget(V, M) memcpy(&V, (M), sizeof(double))
730
#define doublestore(T,V) memcpy((T), &V, sizeof(double))
731
#endif /* doubleget */
732
#define int64_tget(V,M) memcpy(&V, (M), sizeof(uint64_t))
733
#define int64_tstore(T,V) memcpy((T), &V, sizeof(uint64_t))
735
#endif /* WORDS_BIGENDIAN */
742
#define NULL_LENGTH UINT32_MAX /* For net_store_length */
743
#define DRIZZLE_STMT_HEADER 4
744
#define DRIZZLE_LONG_DATA_HEADER 6