Ignore:
Timestamp:
May 26, 2009, 9:44:50 AM (16 years ago)
Author:
Herwig Bauernfeind
Message:

Update 3.2 branch to 3.2.6

Location:
branches/samba-3.2.x/source/libnet
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.2.x/source/libnet/libnet_join.c

    r141 r228  
    358358        spn_array[0] = spn;
    359359
    360         if (name_to_fqdn(my_fqdn, r->in.machine_name) &&
    361             !strequal(my_fqdn, r->in.machine_name)) {
    362 
    363                 strlower_m(my_fqdn);
     360        if (!name_to_fqdn(my_fqdn, r->in.machine_name)
     361            || (strchr(my_fqdn, '.') == NULL)) {
     362                fstr_sprintf(my_fqdn, "%s.%s", r->in.machine_name,
     363                        r->out.dns_domain_name);
     364        }
     365
     366        strlower_m(my_fqdn);
     367
     368        if (!strequal(my_fqdn, r->in.machine_name)) {
    364369                spn = talloc_asprintf(mem_ctx, "HOST/%s", my_fqdn);
    365370                if (!spn) {
     
    730735        uint32_t user_rid;
    731736        uint32_t acct_flags = ACB_WSTRUST;
    732         uchar pwbuf[532];
    733         struct MD5Context md5ctx;
    734         uchar md5buffer[16];
    735         DATA_BLOB digested_session_key;
    736         uchar md4_trust_password[16];
    737737        struct samr_Ids user_rids;
    738738        struct samr_Ids name_types;
    739739        union samr_UserInfo user_info;
     740
     741        struct samr_CryptPassword crypt_pwd;
     742        struct samr_CryptPasswordEx crypt_pwd_ex;
    740743
    741744        ZERO_STRUCT(sam_pol);
     
    866869        }
    867870
    868         /* Create a random machine account password and generate the hash */
    869 
    870         E_md4hash(r->in.machine_password, md4_trust_password);
    871         encode_pw_buffer(pwbuf, r->in.machine_password, STR_UNICODE);
    872 
    873         generate_random_buffer((uint8_t*)md5buffer, sizeof(md5buffer));
    874         digested_session_key = data_blob_talloc(mem_ctx, 0, 16);
    875 
    876         MD5Init(&md5ctx);
    877         MD5Update(&md5ctx, md5buffer, sizeof(md5buffer));
    878         MD5Update(&md5ctx, cli->user_session_key.data,
    879                   cli->user_session_key.length);
    880         MD5Final(digested_session_key.data, &md5ctx);
    881 
    882         SamOEMhashBlob(pwbuf, sizeof(pwbuf), &digested_session_key);
    883         memcpy(&pwbuf[516], md5buffer, sizeof(md5buffer));
    884 
    885871        /* Fill in the additional account flags now */
    886872
     
    893879        }
    894880
    895         /* Set password and account flags on machine account */
    896 
    897         ZERO_STRUCT(user_info.info25);
    898 
    899         user_info.info25.info.fields_present = ACCT_NT_PWD_SET |
    900                                                ACCT_LM_PWD_SET |
    901                                                SAMR_FIELD_ACCT_FLAGS;
    902 
    903         user_info.info25.info.acct_flags = acct_flags;
    904         memcpy(&user_info.info25.password.data, pwbuf, sizeof(pwbuf));
     881        /* Set account flags on machine account */
     882        ZERO_STRUCT(user_info.info16);
     883        user_info.info16.acct_flags = acct_flags;
    905884
    906885        status = rpccli_samr_SetUserInfo(pipe_hnd, mem_ctx,
    907886                                         &user_pol,
    908                                          25,
     887                                         16,
    909888                                         &user_info);
    910889
     890        if (!NT_STATUS_IS_OK(status)) {
     891
     892                rpccli_samr_DeleteUser(pipe_hnd, mem_ctx,
     893                                       &user_pol);
     894
     895                libnet_join_set_error_string(mem_ctx, r,
     896                        "Failed to set account flags for machine account (%s)\n",
     897                        nt_errstr(status));
     898                goto done;
     899        }
     900
     901        /* Set password on machine account - first try level 26 */
     902
     903        init_samr_CryptPasswordEx(r->in.machine_password,
     904                                  &cli->user_session_key,
     905                                  &crypt_pwd_ex);
     906
     907        init_samr_user_info26(&user_info.info26, &crypt_pwd_ex,
     908                              PASS_DONT_CHANGE_AT_NEXT_LOGON);
     909
     910        status = rpccli_samr_SetUserInfo2(pipe_hnd, mem_ctx,
     911                                          &user_pol,
     912                                          26,
     913                                          &user_info);
     914
    911915        if (NT_STATUS_EQUAL(status, NT_STATUS(DCERPC_FAULT_INVALID_TAG))) {
    912916
    913                 uchar pwbuf2[516];
    914 
    915                 encode_pw_buffer(pwbuf2, r->in.machine_password, STR_UNICODE);
    916 
    917917                /* retry with level 24 */
    918                 init_samr_user_info24(&user_info.info24, pwbuf2, 24);
    919 
    920                 SamOEMhashBlob(user_info.info24.password.data, 516,
    921                                &cli->user_session_key);
     918
     919                init_samr_CryptPassword(r->in.machine_password,
     920                                        &cli->user_session_key,
     921                                        &crypt_pwd);
     922
     923                init_samr_user_info24(&user_info.info24, &crypt_pwd,
     924                                      PASS_DONT_CHANGE_AT_NEXT_LOGON);
    922925
    923926                status = rpccli_samr_SetUserInfo2(pipe_hnd, mem_ctx,
  • branches/samba-3.2.x/source/libnet/libnet_proto.h

    r139 r228  
    2525NTSTATUS samsync_fix_delta_array(TALLOC_CTX *mem_ctx,
    2626                                 DATA_BLOB *session_key,
    27                                  bool rid_crypt,
    2827                                 enum netr_SamDatabaseID database_id,
    2928                                 struct netr_DELTA_ENUM_ARRAY *r);
  • branches/samba-3.2.x/source/libnet/libnet_samsync.c

    r139 r228  
    3333static NTSTATUS fix_user(TALLOC_CTX *mem_ctx,
    3434                         DATA_BLOB *session_key,
    35                          bool rid_crypt,
    3635                         enum netr_SamDatabaseID database_id,
    3736                         struct netr_DELTA_ENUM *delta)
     
    4241        struct samr_Password lm_hash;
    4342        struct samr_Password nt_hash;
     43        unsigned char zero_buf[16];
    4444
    45         if (rid_crypt) {
    46                 if (user->lm_password_present) {
     45        memset(zero_buf, '\0', sizeof(zero_buf));
     46
     47        /* Note that win2000 may send us all zeros
     48         * for the hashes if it doesn't
     49         * think this channel is secure enough. */
     50        if (user->lm_password_present) {
     51                if (memcmp(user->lmpassword.hash, zero_buf, 16) != 0) {
    4752                        sam_pwd_hash(rid, user->lmpassword.hash, lm_hash.hash, 0);
    48                         user->lmpassword = lm_hash;
     53                } else {
     54                        memset(lm_hash.hash, '\0', sizeof(lm_hash.hash));
    4955                }
     56                user->lmpassword = lm_hash;
     57        }
    5058
    51                 if (user->nt_password_present) {
     59        if (user->nt_password_present) {
     60                if (memcmp(user->ntpassword.hash, zero_buf, 16) != 0) {
    5261                        sam_pwd_hash(rid, user->ntpassword.hash, nt_hash.hash, 0);
    53                         user->ntpassword = nt_hash;
     62                } else {
     63                        memset(nt_hash.hash, '\0', sizeof(nt_hash.hash));
    5464                }
     65                user->ntpassword = nt_hash;
    5566        }
    5667
     
    7283                }
    7384
     85                /* Note that win2000 may send us all zeros
     86                 * for the hashes if it doesn't
     87                 * think this channel is secure enough. */
    7488                if (keys.keys.keys2.lmpassword.length == 16) {
    75                         if (rid_crypt) {
     89                        if (memcmp(keys.keys.keys2.lmpassword.pwd.hash,
     90                                                zero_buf, 16) != 0) {
    7691                                sam_pwd_hash(rid,
    7792                                             keys.keys.keys2.lmpassword.pwd.hash,
    7893                                             lm_hash.hash, 0);
    79                                 user->lmpassword = lm_hash;
    8094                        } else {
    81                                 user->lmpassword = keys.keys.keys2.lmpassword.pwd;
     95                                memset(lm_hash.hash, '\0', sizeof(lm_hash.hash));
    8296                        }
     97                        user->lmpassword = lm_hash;
    8398                        user->lm_password_present = true;
    8499                }
    85100                if (keys.keys.keys2.ntpassword.length == 16) {
    86                         if (rid_crypt) {
     101                        if (memcmp(keys.keys.keys2.ntpassword.pwd.hash,
     102                                                zero_buf, 16) != 0) {
    87103                                sam_pwd_hash(rid,
    88                                              keys.keys.keys2.ntpassword.pwd.hash,
    89                                              nt_hash.hash, 0);
    90                                 user->ntpassword = nt_hash;
     104                                        keys.keys.keys2.ntpassword.pwd.hash,
     105                                        nt_hash.hash, 0);
    91106                        } else {
    92                                 user->ntpassword = keys.keys.keys2.ntpassword.pwd;
     107                                memset(nt_hash.hash, '\0', sizeof(nt_hash.hash));
    93108                        }
     109                        user->ntpassword = nt_hash;
    94110                        user->nt_password_present = true;
    95111                }
     
    129145static NTSTATUS samsync_fix_delta(TALLOC_CTX *mem_ctx,
    130146                                  DATA_BLOB *session_key,
    131                                   bool rid_crypt,
    132147                                  enum netr_SamDatabaseID database_id,
    133148                                  struct netr_DELTA_ENUM *delta)
     
    140155                        status = fix_user(mem_ctx,
    141156                                          session_key,
    142                                           rid_crypt,
    143157                                          database_id,
    144158                                          delta);
     
    165179NTSTATUS samsync_fix_delta_array(TALLOC_CTX *mem_ctx,
    166180                                 DATA_BLOB *session_key,
    167                                  bool rid_crypt,
    168181                                 enum netr_SamDatabaseID database_id,
    169182                                 struct netr_DELTA_ENUM_ARRAY *r)
     
    176189                status = samsync_fix_delta(mem_ctx,
    177190                                           session_key,
    178                                            rid_crypt,
    179191                                           database_id,
    180192                                           &r->delta_enum[i]);
Note: See TracChangeset for help on using the changeset viewer.