Changeset 988 for vendor/current/libcli/auth/smbencrypt.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/libcli/auth/smbencrypt.c
r919 r988 117 117 bool E_deshash(const char *passwd, uint8_t p16[16]) 118 118 { 119 bool ret = true; 120 char dospwd[256]; 119 bool ret; 120 uint8_t dospwd[14]; 121 TALLOC_CTX *frame = talloc_stackframe(); 122 123 size_t converted_size; 124 125 char *tmpbuf; 126 121 127 ZERO_STRUCT(dospwd); 122 128 123 /* Password must be converted to DOS charset - null terminated, uppercase. */ 124 push_string(dospwd, passwd, sizeof(dospwd), STR_ASCII|STR_UPPER|STR_TERMINATE); 125 126 /* Only the first 14 chars are considered, password need not be null terminated. */ 129 tmpbuf = strupper_talloc(frame, passwd); 130 if (tmpbuf == NULL) { 131 /* Too many callers don't check this result, we need to fill in the buffer with something */ 132 strlcpy((char *)dospwd, passwd ? passwd : "", sizeof(dospwd)); 133 E_P16(dospwd, p16); 134 talloc_free(frame); 135 return false; 136 } 137 138 ZERO_STRUCT(dospwd); 139 140 ret = convert_string_error(CH_UNIX, CH_DOS, tmpbuf, strlen(tmpbuf), dospwd, sizeof(dospwd), &converted_size); 141 talloc_free(frame); 142 143 /* Only the first 14 chars are considered, password need not 144 * be null terminated. We do this in the error and success 145 * case to avoid returning a fixed 'password' buffer, but 146 * callers should not use it when E_deshash returns false */ 147 127 148 E_P16((const uint8_t *)dospwd, p16); 128 129 if (strlen(dospwd) > 14) {130 ret = false;131 }132 149 133 150 ZERO_STRUCT(dospwd); … … 249 266 /* Does the des encryption. */ 250 267 251 void SMBNTencrypt_hash(const uint8_t nt_hash[16], uint8_t *c8, uint8_t *p24)268 void SMBNTencrypt_hash(const uint8_t nt_hash[16], const uint8_t *c8, uint8_t *p24) 252 269 { 253 270 uint8_t p21[21]; … … 267 284 /* Does the NT MD4 hash then des encryption. Plaintext version of the above. */ 268 285 269 void SMBNTencrypt(const char *passwd, uint8_t *c8, uint8_t *p24)286 void SMBNTencrypt(const char *passwd, const uint8_t *c8, uint8_t *p24) 270 287 { 271 288 uint8_t nt_hash[16]; … … 371 388 } 372 389 373 static DATA_BLOB NTLMv2_generate_client_data(TALLOC_CTX *mem_ctx, const DATA_BLOB *names_blob) 390 static DATA_BLOB NTLMv2_generate_client_data(TALLOC_CTX *mem_ctx, 391 NTTIME nttime, 392 const DATA_BLOB *names_blob) 374 393 { 375 394 uint8_t client_chal[8]; 376 395 DATA_BLOB response = data_blob(NULL, 0); 377 396 uint8_t long_date[8]; 378 NTTIME nttime;379 380 unix_to_nt_time(&nttime, time(NULL));381 397 382 398 generate_random_buffer(client_chal, sizeof(client_chal)); … … 401 417 const uint8_t ntlm_v2_hash[16], 402 418 const DATA_BLOB *server_chal, 419 NTTIME nttime, 403 420 const DATA_BLOB *names_blob) 404 421 { … … 417 434 /* generate some data to pass into the response function - including 418 435 the hostname and domain name of the server */ 419 ntlmv2_client_data = NTLMv2_generate_client_data(mem_ctx, n ames_blob);436 ntlmv2_client_data = NTLMv2_generate_client_data(mem_ctx, nttime, names_blob); 420 437 421 438 /* Given that data, and the challenge from the server, generate a response */ … … 463 480 const char *user, const char *domain, const uint8_t nt_hash[16], 464 481 const DATA_BLOB *server_chal, 482 const NTTIME *server_timestamp, 465 483 const DATA_BLOB *names_blob, 466 484 DATA_BLOB *lm_response, DATA_BLOB *nt_response, … … 478 496 479 497 if (nt_response) { 498 const NTTIME *nttime = server_timestamp; 499 NTTIME _now = 0; 500 501 if (nttime == NULL) { 502 struct timeval tv_now = timeval_current(); 503 _now = timeval_to_nttime(&tv_now); 504 nttime = &_now; 505 } 506 480 507 *nt_response = NTLMv2_generate_response(mem_ctx, 481 ntlm_v2_hash, server_chal, 508 ntlm_v2_hash, 509 server_chal, 510 *nttime, 482 511 names_blob); 483 512 if (user_session_key) { … … 493 522 494 523 if (lm_response) { 495 *lm_response = LMv2_generate_response(mem_ctx, 496 ntlm_v2_hash, server_chal); 524 if (server_timestamp != NULL) { 525 *lm_response = data_blob_talloc_zero(mem_ctx, 24); 526 } else { 527 *lm_response = LMv2_generate_response(mem_ctx, 528 ntlm_v2_hash, 529 server_chal); 530 } 497 531 if (lm_session_key) { 498 532 *lm_session_key = data_blob_talloc(mem_ctx, NULL, 16); … … 519 553 520 554 return SMBNTLMv2encrypt_hash(mem_ctx, 521 user, domain, nt_hash, server_chal, names_blob, 555 user, domain, nt_hash, 556 server_chal, NULL, names_blob, 522 557 lm_response, nt_response, lm_session_key, user_session_key); 523 558 } … … 611 646 } 612 647 613 #ifdef SAMBA4_INTERNAL_HEIMDAL /* smbtorture4 for make test */614 648 cmp = strcasecmp_m(a, v); 615 #else /* smbd */616 cmp = StrCaseCmp(a, v);617 #endif618 649 if (cmp != 0) { 619 650 DEBUG(2,("%s: NTLMv2_RESPONSE with " … … 637 668 v = av_nb_dn->Value.AvNbDomainName; 638 669 639 #ifdef SAMBA4_INTERNAL_HEIMDAL /* smbtorture4 for make test */640 670 cmp = strcasecmp_m(workgroup, v); 641 #else /* smbd */642 cmp = StrCaseCmp(workgroup, v);643 #endif644 671 if (cmp != 0) { 645 672 DEBUG(2,("%s: NTLMv2_RESPONSE with " … … 740 767 byte_len, 741 768 (void *)pp_new_pwrd, 742 new_pw_len, 743 false)) { 769 new_pw_len)) { 744 770 DEBUG(0, ("decode_pw_buffer: failed to convert incoming password\n")); 745 771 return false; … … 891 917 892 918 if (!pwd_buf) { 893 return WERR_ BAD_PASSWORD;919 return WERR_INVALID_PASSWORD; 894 920 } 895 921 896 922 if (session_key->length != 16) { 897 923 DEBUG(10,("invalid session key\n")); 898 return WERR_ BAD_PASSWORD;924 return WERR_INVALID_PASSWORD; 899 925 } 900 926 … … 913 939 if (!decode_pw_buffer(mem_ctx, buffer, pwd, &pwd_len, CH_UTF16)) { 914 940 data_blob_free(&confounded_session_key); 915 return WERR_ BAD_PASSWORD;941 return WERR_INVALID_PASSWORD; 916 942 } 917 943
Note:
See TracChangeset
for help on using the changeset viewer.