diff options
author | Andrew Tridgell <tridge@samba.org> | 2004-10-26 13:16:50 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:04:47 -0500 |
commit | f493f7be97e9200c28dc69d73e64044140743e0b (patch) | |
tree | 5b91b1486a2a536bc371a3c4c58f275eadcc09b2 /source4/lib | |
parent | e767d8d1b2c1e86e48d827f10f1773b0dab8e565 (diff) | |
download | samba-f493f7be97e9200c28dc69d73e64044140743e0b.tar.gz samba-f493f7be97e9200c28dc69d73e64044140743e0b.tar.bz2 samba-f493f7be97e9200c28dc69d73e64044140743e0b.zip |
r3261: added seek to RAW-SEARCH test
(This used to be commit 05530bfb99011db8a00f5debcf8eec19b5e8a5d6)
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/genrand.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/source4/lib/genrand.c b/source4/lib/genrand.c index adc6d7344e..72e4997596 100644 --- a/source4/lib/genrand.c +++ b/source4/lib/genrand.c @@ -261,27 +261,36 @@ BOOL check_password_quality(const char *s) Use the random number generator to generate a random string. ********************************************************************/ -static char c_list[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_-#.,"; - -char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len) +char *generate_random_str_list(TALLOC_CTX *mem_ctx, size_t len, const char *list) { size_t i; + size_t list_len = strlen(list); char *retstr = talloc(mem_ctx, len + 1); + if (!retstr) return NULL; - if (!retstr) - return NULL; - -again: generate_random_buffer(retstr, len); - for (i = 0; i < len; i++) - retstr[i] = c_list[retstr[i] % (sizeof(c_list)-1) ]; - + for (i = 0; i < len; i++) { + retstr[i] = list[retstr[i] % list_len]; + } retstr[i] = '\0'; + return retstr; +} + +char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len) +{ + char *retstr; + const char *c_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_-#.,"; + +again: + retstr = generate_random_str_list(mem_ctx, len, c_list); + if (!retstr) return NULL; + /* we need to make sure the random string passes basic quality tests or it might be rejected by windows as a password */ if (len >= 7 && !check_password_quality(retstr)) { + talloc_free(retstr); goto again; } |