⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login.c

📁 ncbi源码
💻 C
📖 第 1 页 / 共 3 页
字号:
    current_pos = 64 + (domain_len+user_name_len+host_name_len)*2;	    tds_put_smallint(tds, 24);  /* lan man resp length */    tds_put_smallint(tds, 24);  /* lan man resp length */    tds_put_int(tds, current_pos);  /* resp offset */    current_pos += 24;    tds_put_smallint(tds, 24);  /* nt resp length */    tds_put_smallint(tds, 24);  /* nt resp length */    tds_put_int(tds, current_pos);  /* nt resp offset */    current_pos = 64;    /* domain */    tds_put_smallint(tds, domain_len*2);    tds_put_smallint(tds, domain_len*2);    tds_put_int(tds, current_pos);    current_pos += domain_len*2;	    /* username */    tds_put_smallint(tds, user_name_len*2);    tds_put_smallint(tds, user_name_len*2);    tds_put_int(tds, current_pos);    current_pos += user_name_len*2;    /* hostname */    tds_put_smallint(tds, host_name_len*2);    tds_put_smallint(tds, host_name_len*2);    tds_put_int(tds, current_pos);    current_pos += host_name_len*2;    /* unknown */    tds_put_smallint(tds, 0);    tds_put_smallint(tds, 0);    tds_put_int(tds, current_pos + (24*2));    /* flags */    tds_put_int(tds,0x8201);    tds7_ascii2unicode(tds,domain, unicode_string, 256);    tds_put_n(tds,unicode_string,domain_len * 2);    tds7_ascii2unicode(tds,user_name, unicode_string, 256);    tds_put_n(tds,unicode_string,user_name_len * 2);    tds7_ascii2unicode(tds,config->host_name, unicode_string, 256);    tds_put_n(tds,unicode_string,host_name_len * 2);    tds_answer_challenge(config->password, challenge, &answer);    tds_put_n(tds, answer.lm_resp, 24);    tds_put_n(tds, answer.nt_resp, 24);	    /* for security reason clear structure */    memset(&answer,0,sizeof(TDSANSWER));    rc=tds_flush_packet(tds);    return rc;#else    return TDS_SUCCEED;#endif}/*** tds7_send_login() -- Send a TDS 7.0 login packet** TDS 7.0 login packet is vastly different and so gets its own function*/int tds7_send_login(TDSSOCKET *tds, TDSCONFIGINFO *config){	    int rc;#if DOMAIN    static const unsigned char magic1_domain[] =    {6,0x7d,0x0f,0xfd,     0xff,0x0,0x0,0x0,  /* Client PID */     /* the 0x80 in the third byte controls whether this is a domain login       * or not  0x80 = yes, 0x00 = no */     0x0,0xe0,0x83,0x0, /* Connection ID of the Primary Server (?) */     0x0,               /* Option Flags 1 */     0x68,              /* Option Flags 2 */     0x01,     0x00,     0x00,0x09,0x04,0x00,     0x00};#endif    static const unsigned char magic1_server[] =    {6,0x83,0xf2,0xf8,  /* Client Program version */     0xff,0x0,0x0,0x0,  /* Client PID */     0x0,0xe0,0x03,0x0, /* Connection ID of the Primary Server (?) */     0x0,               /* Option Flags 1 */     0x88,              /* Option Flags 2 */     0xff,              /* Type Flags     */     0xff,              /* reserved Flags */     0xff,0x36,0x04,0x00,     0x00};    unsigned const char *magic1 = magic1_server;#if 0    /* also seen */    {6,0x7d,0x0f,0xfd,         0xff,0x0,0x0,0x0,         0x0,0xe0,0x83,0x0,         0x0,         0x68,         0x01,         0x00,         0x00,0x09,0x04,0x00,         0x00};#endif    static const unsigned char magic2[] = {0x00,0x40,0x33,0x9a,0x6b,0x50};    /* 0xb4,0x00,0x30,0x00,0xe4,0x00,0x00,0x00; */    static const unsigned char magic3[] = "NTLMSSP";    unsigned char unicode_string[255];    int packet_size;    int current_pos;#if DOMAIN    int domain_login = config->try_domain_login ? 1 : 0;#endif    const char* domain = config->default_domain;    const char* user_name = config->user_name;    const char* p;    int user_name_len = user_name ? strlen(user_name) : 0;    int host_name_len = config->host_name ? strlen(config->host_name) : 0;    int app_name_len = config->app_name ? strlen(config->app_name) : 0;    int password_len = config->password ? strlen(config->password) : 0;    int server_name_len = config->server_name ? strlen(config->server_name) : 0;    int library_len = config->library ? strlen(config->library) : 0;    int language_len = config->language ? strlen(config->language) : 0;    int domain_len = domain ? strlen(domain) : 0;    int auth_len = 0;    /* check override of domain */    if (user_name && (p=strchr(user_name,'\\')) != NULL)        {            domain = user_name;            domain_len = p-user_name;		            user_name = p+1;            user_name_len = strlen(user_name);        }    packet_size = 86 + (                        host_name_len +                        app_name_len +                        server_name_len +                        library_len +                        language_len)*2;#if DOMAIN    if (domain_login) {        magic1 = magic1_domain;        auth_len = 32 + host_name_len + domain_len;        packet_size += auth_len;    } else#endif        packet_size += (user_name_len + password_len)*2;#ifdef NCBI_FTDS	tds_put_int(tds, packet_size);	if (IS_TDS80(tds)) {	  static const unsigned char tds8Version[] = { 0x01, 0x00, 0x00, 0x71 };		tds_put_n(tds, tds8Version, 4);	} else {	  static const unsigned char tds7Version[] = { 0x00, 0x00, 0x00, 0x70 };		tds_put_n(tds, tds7Version, 4);	}#else    tds_put_smallint(tds,packet_size);    tds_put_n(tds,NULL,5);    if (IS_TDS80(tds)) {        tds_put_byte(tds,0x80);    } else {        tds_put_byte(tds,0x70);    }    tds_put_n(tds,NULL,3);       /* rest of TDSVersion which is a 4 byte field    */#endif#ifdef NCBI_FTDS	if(config->block_size < 512 || config->block_size > 1000000) 	  config->block_size= 4096;	tds_put_int(tds, config->block_size);	tds_put_n(tds, magic1, 4);	/* client program version ? */	packet_size= getpid();	tds_put_int(tds, packet_size);	/* process id of this process */	/*tds_put_n(tds, magic1+8, 13);*/#if 1	{	static const unsigned char connection_id[] = { 0x00, 0x00, 0x00, 0x00 };	unsigned char option_flag1 = 0x00;	unsigned char option_flag2 = 0x00;	static const unsigned char sql_type_flag = 0x00;	static const unsigned char reserved_flag = 0x00;	static const unsigned char time_zone[] = { 0x88, 0xff, 0xff, 0xff };	static const unsigned char collation[] = { 0x36, 0x04, 0x00, 0x00 };	tds_put_n(tds, connection_id, 4);	option_flag1 |= 0x80;	/* enable warning messages if SET LANGUAGE issued   */	option_flag1 |= 0x40;	/* change to initial database must succeed          */	option_flag1 |= 0x20;	/* enable warning messages if USE <database> issued */	tds_put_byte(tds, option_flag1);	option_flag2 |= 0x02;	/* client is an ODBC driver                         */	option_flag2 |= 0x01;	/* change to initial language must succeed          */	tds_put_byte(tds, option_flag2);	tds_put_byte(tds, sql_type_flag);	tds_put_byte(tds, reserved_flag);	tds_put_n(tds, time_zone, 4);	tds_put_n(tds, collation, 4);	}#endif	#else    tds_put_n(tds,NULL,4);       /* desired packet size being requested by client */    tds_put_n(tds,magic1,21);#endif    current_pos = 86; /* ? */    /* host name */    tds_put_smallint(tds,current_pos);     tds_put_smallint(tds,host_name_len);    current_pos += host_name_len * 2;#if DOMAIN    if (domain_login) {        tds_put_smallint(tds,0);        tds_put_smallint(tds,0);        tds_put_smallint(tds,0);        tds_put_smallint(tds,0);    } else {#endif        /* username */        tds_put_smallint(tds,current_pos);        tds_put_smallint(tds,user_name_len);        current_pos += user_name_len * 2;        /* password */        tds_put_smallint(tds,current_pos);        tds_put_smallint(tds,password_len);        current_pos += password_len * 2;#if DOMAIN    }#endif    /* app name */    tds_put_smallint(tds,current_pos);    tds_put_smallint(tds,app_name_len);    current_pos += app_name_len * 2;    /* server name */    tds_put_smallint(tds,current_pos);    tds_put_smallint(tds,server_name_len);    current_pos += server_name_len * 2;    /* unknown */    tds_put_smallint(tds,0);     tds_put_smallint(tds,0);     /* library name */    tds_put_smallint(tds,current_pos);    tds_put_smallint(tds,library_len);    current_pos += library_len * 2;    /* language  - kostya@warmcat.excom.spb.su */    tds_put_smallint(tds,current_pos);     tds_put_smallint(tds,language_len);    current_pos += language_len * 2;    /* database name */    tds_put_smallint(tds,current_pos);     tds_put_smallint(tds,0);     /* MAC address */    tds_put_n(tds,magic2,6);    /* authentication stuff */    tds_put_smallint(tds, current_pos);#if DOMAIN    if (domain_login) {        tds_put_smallint(tds, auth_len); /* this matches numbers at end of packet */        current_pos += auth_len;    } else        tds_put_smallint(tds, 0);#else    tds_put_smallint(tds, 0);#endif    /* unknown */    tds_put_smallint(tds, current_pos);    tds_put_smallint(tds, 0);     tds7_ascii2unicode(tds,config->host_name, unicode_string, 255);    tds_put_n(tds,unicode_string,host_name_len * 2);#if DOMAIN    if (!domain_login) {#endif        tds7_ascii2unicode(tds,config->user_name, unicode_string, 255);        tds_put_n(tds,unicode_string,user_name_len * 2);        tds7_ascii2unicode(tds,config->password, unicode_string, 255);        tds7_crypt_pass(unicode_string, password_len * 2, unicode_string);        tds_put_n(tds,unicode_string,password_len * 2);#if DOMAIN    }#endif    tds7_ascii2unicode(tds,config->app_name, unicode_string, 255);    tds_put_n(tds,unicode_string,app_name_len * 2);    tds7_ascii2unicode(tds,config->server_name, unicode_string, 255);    tds_put_n(tds,unicode_string,server_name_len * 2);    tds7_ascii2unicode(tds,config->library, unicode_string, 255);    tds_put_n(tds,unicode_string,library_len * 2);    tds7_ascii2unicode(tds,config->language, unicode_string, 255);    tds_put_n(tds,unicode_string,language_len * 2);#if DOMAIN    if (domain_login) {        /* from here to the end of the packet is the NTLMSSP authentication */        tds_put_n(tds,magic3,8);        /* sequence 1 client -> server */        tds_put_int(tds,1);        /* flags */        tds_put_int(tds,0xb201);        /* domain info */        tds_put_smallint(tds,domain_len);        tds_put_smallint(tds,domain_len);        tds_put_int(tds,32 + host_name_len);        /* hostname info */        tds_put_smallint(tds,host_name_len);        tds_put_smallint(tds,host_name_len);        tds_put_int(tds,32);        /* hostname and domain */        tds_put_n(tds,config->host_name,host_name_len);        tds_put_n(tds,domain,domain_len);    }#endif       tdsdump_off();    rc=tds_flush_packet(tds);    tdsdump_on();       return rc;}/*** tds7_crypt_pass() -- 'encrypt' TDS 7.0 style passwords.** the calling function is responsible for ensuring crypt_pass is at least ** 'len' characters*/unsigned char *tds7_crypt_pass(const unsigned char *clear_pass, int len, unsigned char *crypt_pass){    int i;    unsigned char xormask = 0x5A;    unsigned char hi_nibble,lo_nibble ;    for (i=0;i<len;i++) {        lo_nibble  = (clear_pass[i] ^ xormask) >> 4;        hi_nibble  = (clear_pass[i] ^ xormask) << 4;        crypt_pass[i] = hi_nibble | lo_nibble;    }    return crypt_pass;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -