Add TALLOC_CTX pointer to generate_random_str(), for consistency with
authorJelmer Vernooij <jelmer@samba.org>
Sun, 19 Oct 2008 08:05:48 +0000 (10:05 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sun, 19 Oct 2008 08:05:48 +0000 (10:05 +0200)
Samba 4.

source3/include/proto.h
source3/lib/genrand.c
source3/libads/util.c
source3/libnet/libnet_join.c
source3/libsmb/trusts_util.c
source3/utils/net_rpc_join.c

index ba84574..8cf960b 100644 (file)
@@ -578,7 +578,7 @@ void gencache_unlock_entry( const char *key );
 void set_rand_reseed_callback(void (*fn)(int *));
 void set_need_random_reseed(void);
 void generate_random_buffer( unsigned char *out, int len);
-char *generate_random_str(size_t len);
+char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len);
 
 /* The following definitions come from lib/iconv.c  */
 
index 57314c5..d3abb3d 100644 (file)
@@ -205,15 +205,11 @@ void generate_random_buffer( unsigned char *out, int len)
 
 static char c_list[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_-#.,";
 
-char *generate_random_str(size_t len)
+char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len)
 {
-       static unsigned char retstr[256];
+       unsigned char *retstr = talloc_zero_array(mem_ctx, unsigned char, len);
        size_t i;
 
-       memset(retstr, '\0', sizeof(retstr));
-
-       if (len > sizeof(retstr)-1)
-               len = sizeof(retstr) -1;
        generate_random_buffer( retstr, len);
        for (i = 0; i < len; i++)
                retstr[i] = c_list[ retstr[i] % (sizeof(c_list)-1) ];
index d23c36f..9866a15 100644 (file)
@@ -33,7 +33,7 @@ ADS_STATUS ads_change_trust_account_password(ADS_STRUCT *ads, char *host_princip
                return ADS_ERROR_SYSTEM(ENOENT);
        }
 
-       new_password = generate_random_str(DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH);
+       new_password = generate_random_str(talloc_tos(), DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH);
     
        ret = kerberos_set_password(ads->auth.kdc_server, host_principal, password, host_principal, new_password, ads->auth.time_offset);
 
index ab8af0b..6935e00 100644 (file)
@@ -775,7 +775,7 @@ static NTSTATUS libnet_join_joindomain_rpc(TALLOC_CTX *mem_ctx,
        ZERO_STRUCT(user_pol);
 
        if (!r->in.machine_password) {
-               r->in.machine_password = talloc_strdup(mem_ctx, generate_random_str(DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH));
+               r->in.machine_password = generate_random_str(mem_ctx, DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH);
                NT_STATUS_HAVE_NO_MEMORY(r->in.machine_password);
        }
 
index 2f336f1..f059569 100644 (file)
@@ -33,13 +33,12 @@ NTSTATUS trust_pw_change_and_store_it(struct rpc_pipe_client *cli, TALLOC_CTX *m
 {
        unsigned char new_trust_passwd_hash[16];
        char *new_trust_passwd;
-       char *str;
        NTSTATUS nt_status;
                
        /* Create a random machine account password */
-       str = generate_random_str(DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH);
+       new_trust_passwd = generate_random_str(mem_ctx, DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH);
 
-       if ((new_trust_passwd = talloc_strdup(mem_ctx, str)) == NULL) {
+       if (new_trust_passwd == NULL) {
                DEBUG(0, ("talloc_strdup failed\n"));
                return NT_STATUS_NO_MEMORY;
        }
index 5bc38f9..2fe464a 100644 (file)
@@ -330,12 +330,8 @@ int net_rpc_join_newstyle(struct net_context *c, int argc, const char **argv)
        
        /* Create a random machine account password */
 
-       { 
-               char *str;
-               str = generate_random_str(DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH);
-               clear_trust_password = SMB_STRDUP(str);
-               E_md4hash(clear_trust_password, md4_trust_password);
-       }
+       clear_trust_password = generate_random_str(talloc_tos(), DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH);
+       E_md4hash(clear_trust_password, md4_trust_password);
 
        /* Set password on machine account */
 
@@ -468,7 +464,7 @@ done:
 
        cli_shutdown(cli);
 
-       SAFE_FREE(clear_trust_password);
+       TALLOC_FREE(clear_trust_password);
 
        return retval;
 }