diff options
author | Andrew Tridgell <tridge@samba.org> | 2001-11-25 01:36:02 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2001-11-25 01:36:02 +0000 |
commit | a83e7725c4dd1880b14c5018ef321804fc17fdee (patch) | |
tree | 28c617db14d30486e2c4c7bc3ebe86c7266b5abe /source3 | |
parent | cb697dd72a51daa14f174fae4fede2b86e7a7fd2 (diff) | |
download | samba-a83e7725c4dd1880b14c5018ef321804fc17fdee.tar.gz samba-a83e7725c4dd1880b14c5018ef321804fc17fdee.tar.bz2 samba-a83e7725c4dd1880b14c5018ef321804fc17fdee.zip |
use generate_random_str()
(This used to be commit 720c50a7514febdd7cfd6ce40b7b5a0c5cc0abf8)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/utils/net_ads.c | 51 |
1 files changed, 4 insertions, 47 deletions
diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c index 87db4ada34..d9b99c77dc 100644 --- a/source3/utils/net_ads.c +++ b/source3/utils/net_ads.c @@ -23,48 +23,6 @@ #ifdef HAVE_ADS -/* a lame random number generator - used /dev/urandom if possible */ -static unsigned one_random(void) -{ - int fd = -1; - static int initialised; - unsigned ret; - - if (!initialised) { - initialised = 1; - fd = open("/dev/urandom", O_RDONLY); - srandom(time(NULL) ^ getpid()); - } - - if (fd == -1) { - return random(); - } - - read(fd, &ret, sizeof(ret)); - return ret; -} - -/* - * Generate a simple random password of 15 chars - not a cryptographic one - */ -static char *generate_random_password(int len) -{ - int i; - char *pass; - - if (!(pass = malloc(len+1))) - return NULL; - - for (i=0; i<len; ) { - char c = one_random() & 0x7f; - if (!isalnum(c) && !ispunct(c)) continue; - pass[i++] = c; - } - - return pass; -} - - int net_ads_usage(void) { d_printf( @@ -76,8 +34,6 @@ int net_ads_usage(void) return -1; } - - static ADS_STRUCT *ads_startup(void) { ADS_STRUCT *ads; @@ -92,8 +48,6 @@ static ADS_STRUCT *ads_startup(void) return ads; } - - static int net_ads_user(int argc, const char **argv) { ADS_STRUCT *ads; @@ -203,7 +157,8 @@ static int net_ads_join(int argc, const char **argv) return -1; } - password = generate_random_password(15); + password = generate_random_str(15); + password = strdup(password); if (!(ads = ads_startup())) return -1; @@ -226,6 +181,8 @@ static int net_ads_join(int argc, const char **argv) d_printf("Joined '%s' to realm '%s'\n", global_myname, ads->realm); + free(password); + return 0; } |