[GLUE] Rsync SAMBA_3_0 SVN r25598 in order to create the v3-0-test branch.
[gd/samba/.git] / source / utils / net_domain.c
index 948aa5c19bb9b6abbbcb3e937734680a67720416..5b330d8765ce786b38174c1bd99f2276db17892d 100644 (file)
@@ -180,7 +180,7 @@ NTSTATUS netdom_get_domain_sid( TALLOC_CTX *mem_ctx, struct cli_state *cli,
        if ( !NT_STATUS_IS_OK(status) )
                return status;
 
-       rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);
+       rpccli_lsa_close(pipe_hnd, mem_ctx, &lsa_pol);
        cli_rpc_pipe_close(pipe_hnd); /* Done with this pipe */
 
        /* Bail out if domain didn't get set. */
@@ -209,14 +209,10 @@ NTSTATUS netdom_join_domain( TALLOC_CTX *mem_ctx, struct cli_state *cli,
        uint32 num_rids, *name_types, *user_rids;
        uint32 flags = 0x3e8;
        uint32 acb_info = ACB_WSTRUST;
-       uint32 fields_present;
-       uchar pwbuf[532];
+       uchar pwbuf[516];
        SAM_USERINFO_CTR ctr;
-       SAM_USER_INFO_25 p25;
-       const int infolevel = 25;
-       struct MD5Context md5ctx;
-       uchar md5buffer[16];
-       DATA_BLOB digested_session_key;
+       SAM_USER_INFO_24 p24;
+       SAM_USER_INFO_16 p16;
        uchar md4_trust_password[16];
 
        /* Open the domain */
@@ -287,49 +283,24 @@ NTSTATUS netdom_join_domain( TALLOC_CTX *mem_ctx, struct cli_state *cli,
 
        status = rpccli_samr_open_user(pipe_hnd, mem_ctx, &domain_pol,
                        SEC_RIGHTS_MAXIMUM_ALLOWED, user_rid, &user_pol);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
        
-       /* Create a random machine account password and generate the hash */
+       /* Create a random machine account password */
 
-       E_md4hash(clear_pw, md4_trust_password);
+       E_md4hash( clear_pw, md4_trust_password);
        encode_pw_buffer(pwbuf, clear_pw, STR_UNICODE);
-       
-       generate_random_buffer((uint8*)md5buffer, sizeof(md5buffer));
-       digested_session_key = data_blob_talloc(mem_ctx, 0, 16);
-       
-       MD5Init(&md5ctx);
-       MD5Update(&md5ctx, md5buffer, sizeof(md5buffer));
-       MD5Update(&md5ctx, cli->user_session_key.data, cli->user_session_key.length);
-       MD5Final(digested_session_key.data, &md5ctx);
-       
-       SamOEMhashBlob(pwbuf, sizeof(pwbuf), &digested_session_key);
-       memcpy(&pwbuf[516], md5buffer, sizeof(md5buffer));
-
-       /* Fill in the additional account flags now */
-
-       acb_info |= ACB_PWNOEXP;
-       if ( dom_type == ND_TYPE_AD ) {
-#if !defined(ENCTYPE_ARCFOUR_HMAC)
-               acb_info |= ACB_USE_DES_KEY_ONLY;
-#endif
-               ;;
-       }
 
-       /* Set password and account flags on machine account */
+       /* Set password on machine account */
 
        ZERO_STRUCT(ctr);
-       ZERO_STRUCT(p25);
+       ZERO_STRUCT(p24);
 
-       fields_present = ACCT_NT_PWD_SET | ACCT_LM_PWD_SET | ACCT_FLAGS;
-       init_sam_user_info25P(&p25, fields_present, acb_info, (char *)pwbuf);
+       init_sam_user_info24(&p24, (char *)pwbuf,24);
 
-       ctr.switch_value = infolevel;
-       ctr.info.id25    = &p25;
+       ctr.switch_value = 24;
+       ctr.info.id24 = &p24;
 
-       status = rpccli_samr_set_userinfo2(pipe_hnd, mem_ctx, &user_pol,
-                                          infolevel, &cli->user_session_key, &ctr);
+       status = rpccli_samr_set_userinfo(pipe_hnd, mem_ctx, &user_pol, 
+                       24, &cli->user_session_key, &ctr);
 
        if ( !NT_STATUS_IS_OK(status) ) {
                d_fprintf( stderr, "Failed to set password for machine account (%s)\n", 
@@ -337,6 +308,35 @@ NTSTATUS netdom_join_domain( TALLOC_CTX *mem_ctx, struct cli_state *cli,
                return status;
        }
 
+
+       /* Why do we have to try to (re-)set the ACB to be the same as what
+          we passed in the samr_create_dom_user() call?  When a NT
+          workstation is joined to a domain by an administrator the
+          acb_info is set to 0x80.  For a normal user with "Add
+          workstations to the domain" rights the acb_info is 0x84.  I'm
+          not sure whether it is supposed to make a difference or not.  NT
+          seems to cope with either value so don't bomb out if the set
+          userinfo2 level 0x10 fails.  -tpot */
+
+       ZERO_STRUCT(ctr);
+       ctr.switch_value = 16;
+       ctr.info.id16 = &p16;
+
+       /* Fill in the additional account flags now */
+
+       acb_info |= ACB_PWNOEXP;
+       if ( dom_type == ND_TYPE_AD ) {
+#if !defined(ENCTYPE_ARCFOUR_HMAC)
+               acb_info |= ACB_USE_DES_KEY_ONLY;
+#endif
+               ;;
+       }
+
+       init_sam_user_info16(&p16, acb_info);
+
+       status = rpccli_samr_set_userinfo2(pipe_hnd, mem_ctx, &user_pol, 16, 
+                                       &cli->user_session_key, &ctr);
+
        rpccli_samr_close(pipe_hnd, mem_ctx, &user_pol);
        cli_rpc_pipe_close(pipe_hnd); /* Done with this pipe */