2 * Unix SMB/Netbios implementation.
4 * account policy storage
5 * Copyright (C) Jean François Micouleau 1998-2001.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 static TDB_CONTEXT *tdb; /* used for driver files */
25 #define DATABASE_VERSION 1
27 /****************************************************************************
28 Open the account policy tdb.
29 ****************************************************************************/
31 BOOL init_account_policy(void)
33 static pid_t local_pid;
34 char *vstring = "INFO/version";
36 if (tdb && local_pid == sys_getpid())
38 tdb = tdb_open_log(lock_path("account_policy.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
40 DEBUG(0,("Failed to open account policy database\n"));
44 local_pid = sys_getpid();
46 /* handle a Samba upgrade */
47 tdb_lock_bystring(tdb, vstring);
48 if (tdb_fetch_int32(tdb, vstring) != DATABASE_VERSION) {
49 tdb_traverse(tdb, tdb_traverse_delete_fn, NULL);
50 tdb_store_int32(tdb, vstring, DATABASE_VERSION);
52 account_policy_set(AP_MIN_PASSWORD_LEN, MINPASSWDLENGTH); /* 5 chars minimum */
53 account_policy_set(AP_PASSWORD_HISTORY, 0); /* don't keep any old password */
54 account_policy_set(AP_USER_MUST_LOGON_TO_CHG_PASS, 0); /* don't force user to logon */
55 account_policy_set(AP_MAX_PASSWORD_AGE, MAX_PASSWORD_AGE); /* 21 days */
56 account_policy_set(AP_MIN_PASSWORD_AGE, 0); /* 0 days */
57 account_policy_set(AP_LOCK_ACCOUNT_DURATION, 0); /* lockout for 0 minutes */
58 account_policy_set(AP_RESET_COUNT_TIME, 0); /* reset immediatly */
59 account_policy_set(AP_BAD_ATTEMPT_LOCKOUT, 0); /* don't lockout */
60 account_policy_set(AP_TIME_TO_LOGOUT, -1); /* don't force logout */
62 tdb_unlock_bystring(tdb, vstring);
67 /****************************************************************************
68 ****************************************************************************/
70 static char *decode_account_policy_name(int field)
73 case AP_MIN_PASSWORD_LEN:
74 return "min password length";
75 case AP_PASSWORD_HISTORY:
76 return "password history";
77 case AP_USER_MUST_LOGON_TO_CHG_PASS:
78 return "user must logon to change password";
79 case AP_MAX_PASSWORD_AGE:
80 return "maximum password age";
81 case AP_MIN_PASSWORD_AGE:
82 return "minimum password age";
83 case AP_LOCK_ACCOUNT_DURATION:
84 return "lockout duration";
85 case AP_RESET_COUNT_TIME:
86 return "reset count minutes";
87 case AP_BAD_ATTEMPT_LOCKOUT:
88 return "bad lockout attempt";
89 case AP_TIME_TO_LOGOUT:
90 return "disconnect time";
92 return "undefined value";
97 /****************************************************************************
98 ****************************************************************************/
99 BOOL account_policy_get(int field, uint32 *value)
103 init_account_policy();
105 fstrcpy(name, decode_account_policy_name(field));
106 *value=tdb_fetch_int32(tdb, name);
107 DEBUG(10,("account_policy_get: %s:%d\n", name, *value));
112 /****************************************************************************
113 ****************************************************************************/
114 BOOL account_policy_set(int field, uint32 value)
118 init_account_policy();
120 fstrcpy(name, decode_account_policy_name(field));
121 if ( tdb_store_int32(tdb, name, value)== -1)
123 DEBUG(10,("account_policy_set: %s:%d\n", name, value));