Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/lib/util/genrand.c

    r456 r745  
    369369
    370370/**
     371 * Generate a random text password.
     372 */
     373
     374_PUBLIC_ char *generate_random_password(TALLOC_CTX *mem_ctx, size_t min, size_t max)
     375{
     376        char *retstr;
     377        /* This list does not include { or } because they cause
     378         * problems for our provision (it can create a substring
     379         * ${...}, and for Fedora DS (which treats {...} at the start
     380         * of a stored password as special
     381         *  -- Andrew Bartlett 2010-03-11
     382         */
     383        const char *c_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_-#.,@$%&!?:;<=>()[]~";
     384        size_t len = max;
     385        size_t diff;
     386
     387        if (min > max) {
     388                errno = EINVAL;
     389                return NULL;
     390        }
     391
     392        diff = max - min;
     393
     394        if (diff > 0 ) {
     395                size_t tmp;
     396
     397                generate_random_buffer((uint8_t *)&tmp, sizeof(tmp));
     398
     399                tmp %= diff;
     400
     401                len = min + tmp;
     402        }
     403
     404again:
     405        retstr = generate_random_str_list(mem_ctx, len, c_list);
     406        if (!retstr) return NULL;
     407
     408        /* we need to make sure the random string passes basic quality tests
     409           or it might be rejected by windows as a password */
     410        if (len >= 7 && !check_password_quality(retstr)) {
     411                talloc_free(retstr);
     412                goto again;
     413        }
     414
     415        return retstr;
     416}
     417
     418/**
    371419 * Generate an array of unique text strings all of the same length.
    372420 * The returned string will be allocated.
Note: See TracChangeset for help on using the changeset viewer.