diff options
-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; } |