summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-10-19 10:05:48 +0200
committerJelmer Vernooij <jelmer@samba.org>2008-10-19 10:05:48 +0200
commit7275952568bbf003299d895b71b246f75851db93 (patch)
tree7ec15c35176685b8a486ae86055b6de36423ca2f
parentb1a1fbcbfb8f7d9b09bd26407ca4185b2cb4a0e3 (diff)
downloadsamba-7275952568bbf003299d895b71b246f75851db93.tar.gz
samba-7275952568bbf003299d895b71b246f75851db93.tar.xz
samba-7275952568bbf003299d895b71b246f75851db93.zip
Add TALLOC_CTX pointer to generate_random_str(), for consistency with
Samba 4.
-rw-r--r--source3/include/proto.h2
-rw-r--r--source3/lib/genrand.c8
-rw-r--r--source3/libads/util.c2
-rw-r--r--source3/libnet/libnet_join.c2
-rw-r--r--source3/libsmb/trusts_util.c5
-rw-r--r--source3/utils/net_rpc_join.c10
6 files changed, 10 insertions, 19 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index ba845746534..8cf960b63a0 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -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 */
diff --git a/source3/lib/genrand.c b/source3/lib/genrand.c
index 57314c55df1..d3abb3d77c6 100644
--- a/source3/lib/genrand.c
+++ b/source3/lib/genrand.c
@@ -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) ];
diff --git a/source3/libads/util.c b/source3/libads/util.c
index d23c36f3269..9866a15285f 100644
--- a/source3/libads/util.c
+++ b/source3/libads/util.c
@@ -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);
diff --git a/source3/libnet/libnet_join.c b/source3/libnet/libnet_join.c
index ab8af0be6be..6935e000dc2 100644
--- a/source3/libnet/libnet_join.c
+++ b/source3/libnet/libnet_join.c
@@ -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);
}
diff --git a/source3/libsmb/trusts_util.c b/source3/libsmb/trusts_util.c
index 2f336f14e6d..f0595695d22 100644
--- a/source3/libsmb/trusts_util.c
+++ b/source3/libsmb/trusts_util.c
@@ -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;
}
diff --git a/source3/utils/net_rpc_join.c b/source3/utils/net_rpc_join.c
index 5bc38f979f4..2fe464a0005 100644
--- a/source3/utils/net_rpc_join.c
+++ b/source3/utils/net_rpc_join.c
@@ -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;
}