Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/libcli/auth/smbencrypt.c

    r919 r988  
    117117bool E_deshash(const char *passwd, uint8_t p16[16])
    118118{
    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
    121127        ZERO_STRUCT(dospwd);
    122128
    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
    127148        E_P16((const uint8_t *)dospwd, p16);
    128 
    129         if (strlen(dospwd) > 14) {
    130                 ret = false;
    131         }
    132149
    133150        ZERO_STRUCT(dospwd);
     
    249266/* Does the des encryption. */
    250267
    251 void SMBNTencrypt_hash(const uint8_t nt_hash[16], uint8_t *c8, uint8_t *p24)
     268void SMBNTencrypt_hash(const uint8_t nt_hash[16], const uint8_t *c8, uint8_t *p24)
    252269{
    253270        uint8_t p21[21];
     
    267284/* Does the NT MD4 hash then des encryption. Plaintext version of the above. */
    268285
    269 void SMBNTencrypt(const char *passwd, uint8_t *c8, uint8_t *p24)
     286void SMBNTencrypt(const char *passwd, const uint8_t *c8, uint8_t *p24)
    270287{
    271288        uint8_t nt_hash[16];
     
    371388}
    372389
    373 static DATA_BLOB NTLMv2_generate_client_data(TALLOC_CTX *mem_ctx, const DATA_BLOB *names_blob)
     390static DATA_BLOB NTLMv2_generate_client_data(TALLOC_CTX *mem_ctx,
     391                                             NTTIME nttime,
     392                                             const DATA_BLOB *names_blob)
    374393{
    375394        uint8_t client_chal[8];
    376395        DATA_BLOB response = data_blob(NULL, 0);
    377396        uint8_t long_date[8];
    378         NTTIME nttime;
    379 
    380         unix_to_nt_time(&nttime, time(NULL));
    381397
    382398        generate_random_buffer(client_chal, sizeof(client_chal));
     
    401417                                          const uint8_t ntlm_v2_hash[16],
    402418                                          const DATA_BLOB *server_chal,
     419                                          NTTIME nttime,
    403420                                          const DATA_BLOB *names_blob)
    404421{
     
    417434        /* generate some data to pass into the response function - including
    418435           the hostname and domain name of the server */
    419         ntlmv2_client_data = NTLMv2_generate_client_data(mem_ctx, names_blob);
     436        ntlmv2_client_data = NTLMv2_generate_client_data(mem_ctx, nttime, names_blob);
    420437
    421438        /* Given that data, and the challenge from the server, generate a response */
     
    463480                           const char *user, const char *domain, const uint8_t nt_hash[16],
    464481                           const DATA_BLOB *server_chal,
     482                           const NTTIME *server_timestamp,
    465483                           const DATA_BLOB *names_blob,
    466484                           DATA_BLOB *lm_response, DATA_BLOB *nt_response,
     
    478496
    479497        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
    480507                *nt_response = NTLMv2_generate_response(mem_ctx,
    481                                                         ntlm_v2_hash, server_chal,
     508                                                        ntlm_v2_hash,
     509                                                        server_chal,
     510                                                        *nttime,
    482511                                                        names_blob);
    483512                if (user_session_key) {
     
    493522
    494523        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                }
    497531                if (lm_session_key) {
    498532                        *lm_session_key = data_blob_talloc(mem_ctx, NULL, 16);
     
    519553
    520554        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,
    522557                                     lm_response, nt_response, lm_session_key, user_session_key);
    523558}
     
    611646                }
    612647
    613 #ifdef SAMBA4_INTERNAL_HEIMDAL /* smbtorture4 for make test */
    614648                cmp = strcasecmp_m(a, v);
    615 #else /* smbd */
    616                 cmp = StrCaseCmp(a, v);
    617 #endif
    618649                if (cmp != 0) {
    619650                        DEBUG(2,("%s: NTLMv2_RESPONSE with "
     
    637668                v = av_nb_dn->Value.AvNbDomainName;
    638669
    639 #ifdef SAMBA4_INTERNAL_HEIMDAL /* smbtorture4 for make test */
    640670                cmp = strcasecmp_m(workgroup, v);
    641 #else /* smbd */
    642                 cmp = StrCaseCmp(workgroup, v);
    643 #endif
    644671                if (cmp != 0) {
    645672                        DEBUG(2,("%s: NTLMv2_RESPONSE with "
     
    740767                                   byte_len,
    741768                                   (void *)pp_new_pwrd,
    742                                    new_pw_len,
    743                                    false)) {
     769                                   new_pw_len)) {
    744770                DEBUG(0, ("decode_pw_buffer: failed to convert incoming password\n"));
    745771                return false;
     
    891917
    892918        if (!pwd_buf) {
    893                 return WERR_BAD_PASSWORD;
     919                return WERR_INVALID_PASSWORD;
    894920        }
    895921
    896922        if (session_key->length != 16) {
    897923                DEBUG(10,("invalid session key\n"));
    898                 return WERR_BAD_PASSWORD;
     924                return WERR_INVALID_PASSWORD;
    899925        }
    900926
     
    913939        if (!decode_pw_buffer(mem_ctx, buffer, pwd, &pwd_len, CH_UTF16)) {
    914940                data_blob_free(&confounded_session_key);
    915                 return WERR_BAD_PASSWORD;
     941                return WERR_INVALID_PASSWORD;
    916942        }
    917943
Note: See TracChangeset for help on using the changeset viewer.