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