r2213: Optimisation. Passes masktest against W2K3.
[ira/wip.git] / source3 / lib / account_pol.c
index 07b5e2ecfc649066ff90afbfd0b088a03d036fb1..8d5b963da28f8f948e43a36c25f41d29ab6aa899 100644 (file)
@@ -31,7 +31,7 @@ static TDB_CONTEXT *tdb; /* used for driver files */
 BOOL init_account_policy(void)
 {
        static pid_t local_pid;
-       char *vstring = "INFO/version";
+       const char *vstring = "INFO/version";
        uint32 version;
 
        if (tdb && local_pid == sys_getpid())
@@ -45,7 +45,7 @@ BOOL init_account_policy(void)
        local_pid = sys_getpid();
 
        /* handle a Samba upgrade */
-       tdb_lock_bystring(tdb, vstring);
+       tdb_lock_bystring(tdb, vstring,0);
        if (!tdb_fetch_uint32(tdb, vstring, &version) || version != DATABASE_VERSION) {
                tdb_traverse(tdb, tdb_traverse_delete_fn, NULL);
                tdb_store_uint32(tdb, vstring, DATABASE_VERSION);
@@ -53,10 +53,10 @@ BOOL init_account_policy(void)
                account_policy_set(AP_MIN_PASSWORD_LEN, MINPASSWDLENGTH);   /* 5 chars minimum             */
                account_policy_set(AP_PASSWORD_HISTORY, 0);                 /* don't keep any old password */
                account_policy_set(AP_USER_MUST_LOGON_TO_CHG_PASS, 0);      /* don't force user to logon   */
-               account_policy_set(AP_MAX_PASSWORD_AGE, MAX_PASSWORD_AGE);  /* 21 days                     */
+               account_policy_set(AP_MAX_PASSWORD_AGE, (uint32)-1);        /* don't expire                */
                account_policy_set(AP_MIN_PASSWORD_AGE, 0);                 /* 0 days                      */
-               account_policy_set(AP_LOCK_ACCOUNT_DURATION, 0);            /* lockout for 0 minutes       */
-               account_policy_set(AP_RESET_COUNT_TIME, 0);                 /* reset immediatly            */
+               account_policy_set(AP_LOCK_ACCOUNT_DURATION, 30);           /* lockout for 30 minutes      */
+               account_policy_set(AP_RESET_COUNT_TIME, 30);                /* reset after 30 minutes      */
                account_policy_set(AP_BAD_ATTEMPT_LOCKOUT, 0);              /* don't lockout               */
                account_policy_set(AP_TIME_TO_LOGOUT, -1);                  /* don't force logout          */
        }
@@ -67,7 +67,7 @@ BOOL init_account_policy(void)
 
 static const struct {
        int field;
-       char *string;
+       const char *string;
 } account_policy_names[] = {
        {AP_MIN_PASSWORD_LEN, "min password length"},
        {AP_PASSWORD_HISTORY, "password history"},
@@ -81,6 +81,30 @@ static const struct {
        {0, NULL}
 };
 
+char *account_policy_names_list(void)
+{
+       char *nl, *p;
+       int i;
+       size_t len = 0;
+
+       for (i=0; account_policy_names[i].string; i++) {
+               len += strlen(account_policy_names[i].string) + 1;
+       }
+       len++;
+       nl = malloc(len);
+       if (!nl) {
+               return NULL;
+       }
+       p = nl;
+       for (i=0; account_policy_names[i].string; i++) {
+               memcpy(p, account_policy_names[i].string, strlen(account_policy_names[i].string) + 1);
+               p[strlen(account_policy_names[i].string)] = '\n';
+               p += strlen(account_policy_names[i].string) + 1;
+       }
+       *p = '\0';
+       return nl;
+}
+
 /****************************************************************************
 Get the account policy name as a string from its #define'ed number
 ****************************************************************************/
@@ -111,14 +135,14 @@ int account_policy_name_to_fieldnum(const char *name)
 
 }
 
-
 /****************************************************************************
 ****************************************************************************/
+
 BOOL account_policy_get(int field, uint32 *value)
 {
        fstring name;
 
-       init_account_policy();
+       if(!init_account_policy())return False;
 
        *value = 0;
 
@@ -128,7 +152,7 @@ BOOL account_policy_get(int field, uint32 *value)
                return False;
        }
        if (!tdb_fetch_uint32(tdb, name, value)) {
-               DEBUG(1, ("account_policy_get: tdb_fetch_uint32 failed for feild %d (%s), returning 0", field, name));
+               DEBUG(1, ("account_policy_get: tdb_fetch_uint32 failed for efild %d (%s), returning 0", field, name));
                return False;
        }
        DEBUG(10,("account_policy_get: %s:%d\n", name, *value));
@@ -142,7 +166,7 @@ BOOL account_policy_set(int field, uint32 value)
 {
        fstring name;
 
-       init_account_policy();
+       if(!init_account_policy())return False;
 
        fstrcpy(name, decode_account_policy_name(field));
        if (!*name) {
@@ -151,7 +175,7 @@ BOOL account_policy_set(int field, uint32 value)
        }
 
        if (!tdb_store_uint32(tdb, name, value)) {
-               DEBUG(1, ("tdb_store_uint32 failed for feild %d (%s) on value %u", field, name, value));
+               DEBUG(1, ("tdb_store_uint32 failed for field %d (%s) on value %u", field, name, value));
                return False;
        }
 
@@ -159,4 +183,3 @@ BOOL account_policy_set(int field, uint32 value)
        
        return True;
 }
-