Changeset 740 for vendor/current/lib/util/genrand.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/lib/util/genrand.c
r414 r740 363 363 364 364 /** 365 * Generate a random text password. 366 */ 367 368 _PUBLIC_ char *generate_random_password(TALLOC_CTX *mem_ctx, size_t min, size_t max) 369 { 370 char *retstr; 371 /* This list does not include { or } because they cause 372 * problems for our provision (it can create a substring 373 * ${...}, and for Fedora DS (which treats {...} at the start 374 * of a stored password as special 375 * -- Andrew Bartlett 2010-03-11 376 */ 377 const char *c_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_-#.,@$%&!?:;<=>()[]~"; 378 size_t len = max; 379 size_t diff; 380 381 if (min > max) { 382 errno = EINVAL; 383 return NULL; 384 } 385 386 diff = max - min; 387 388 if (diff > 0 ) { 389 size_t tmp; 390 391 generate_random_buffer((uint8_t *)&tmp, sizeof(tmp)); 392 393 tmp %= diff; 394 395 len = min + tmp; 396 } 397 398 again: 399 retstr = generate_random_str_list(mem_ctx, len, c_list); 400 if (!retstr) return NULL; 401 402 /* we need to make sure the random string passes basic quality tests 403 or it might be rejected by windows as a password */ 404 if (len >= 7 && !check_password_quality(retstr)) { 405 talloc_free(retstr); 406 goto again; 407 } 408 409 return retstr; 410 } 411 412 /** 365 413 * Generate an array of unique text strings all of the same length. 366 414 * The returned string will be allocated.
Note:
See TracChangeset
for help on using the changeset viewer.