bec3eb7d934155fee51aecdeb9e1e5eee205ad9b
[sfrench/samba-autobuild/.git] / source4 / lib / samba3 / policy.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  account policy storage
4  *  Copyright (C) Jean François Micouleau      1998-2001.
5  *  Copyright (C) Andrew Bartlett              2002
6  *  
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.
11  *  
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.
16  *  
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.
20  */
21
22 #include "includes.h"
23 #include "lib/tdb/include/tdbutil.h"
24 #include "lib/samba3/samba3.h"
25 #include "system/filesys.h"
26
27 #define DATABASE_VERSION 2
28
29 /****************************************************************************
30  Open the account policy tdb.
31 ****************************************************************************/
32
33 NTSTATUS samba3_read_account_policy(const char *fn, TALLOC_CTX *ctx, struct samba3_policy *ret)
34 {
35         const char *vstring = "INFO/version";
36         uint32_t version;
37
38         TDB_CONTEXT *tdb = tdb_open(fn, 0, TDB_DEFAULT, O_RDONLY, 0600);
39         if (!tdb) {
40                 DEBUG(0,("Failed to open account policy database\n"));
41                 return NT_STATUS_UNSUCCESSFUL;
42         }
43
44         /* handle a Samba upgrade */
45         if (!tdb_fetch_uint32(tdb, vstring, &version) || version != DATABASE_VERSION) {
46                 tdb_store_uint32(tdb, vstring, DATABASE_VERSION);
47         }
48
49         ret = talloc_zero(ctx, struct samba3_policy);
50
51         tdb_fetch_uint32(tdb, "min password length", &ret->min_password_length);
52         tdb_fetch_uint32(tdb, "password history", &ret->password_history);
53         tdb_fetch_uint32(tdb, "user must logon to change pasword", &ret->user_must_logon_to_change_password);
54         tdb_fetch_uint32(tdb, "maximum password age", &ret->maximum_password_age);
55         tdb_fetch_uint32(tdb, "minimum password age", &ret->minimum_password_age);
56         tdb_fetch_uint32(tdb, "lockout duration", &ret->lockout_duration);
57         tdb_fetch_uint32(tdb, "reset count minutes", &ret->reset_count_minutes);
58         tdb_fetch_uint32(tdb, "bad lockout minutes", &ret->bad_lockout_minutes);
59         tdb_fetch_uint32(tdb, "disconnect time", &ret->disconnect_time);
60         tdb_fetch_uint32(tdb, "refuse machine password change", &ret->refuse_machine_password_change);
61
62         /* FIXME: Read privileges as well */
63
64         tdb_close(tdb);
65
66         return NT_STATUS_OK;
67 }