r9554: Do a quick once-over to make the ethereal auto-generated parser code a
[ira/wip.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/policy.h"
25 #include "system/filesys.h"
26
27 #define DATABASE_VERSION 2
28
29 /****************************************************************************
30  Open the account policy tdb.
31 ****************************************************************************/
32
33 struct samba3_policy *samba3_read_account_policy(TALLOC_CTX *ctx, const char *fn)
34 {
35         struct samba3_policy *ret;
36         const char *vstring = "INFO/version";
37         uint32_t version;
38
39         TDB_CONTEXT *tdb = tdb_open(fn, 0, TDB_DEFAULT, O_RDONLY, 0600);
40         if (!tdb) {
41                 DEBUG(0,("Failed to open account policy database\n"));
42                 return NULL;
43         }
44
45         /* handle a Samba upgrade */
46         if (!tdb_fetch_uint32(tdb, vstring, &version) || version != DATABASE_VERSION) {
47                 tdb_store_uint32(tdb, vstring, DATABASE_VERSION);
48         }
49
50         ret = talloc_zero(ctx, struct samba3_policy);
51
52         tdb_fetch_uint32(tdb, "min password length", &ret->min_password_length);
53         tdb_fetch_uint32(tdb, "password history", &ret->password_history);
54         tdb_fetch_uint32(tdb, "user must logon to change pasword", &ret->user_must_logon_to_change_password);
55         tdb_fetch_uint32(tdb, "maximum password age", &ret->maximum_password_age);
56         tdb_fetch_uint32(tdb, "minimum password age", &ret->minimum_password_age);
57         tdb_fetch_uint32(tdb, "lockout duration", &ret->lockout_duration);
58         tdb_fetch_uint32(tdb, "reset count minutes", &ret->reset_count_minutes);
59         tdb_fetch_uint32(tdb, "bad lockout minutes", &ret->bad_lockout_minutes);
60         tdb_fetch_uint32(tdb, "disconnect time", &ret->disconnect_time);
61         tdb_fetch_uint32(tdb, "refuse machine password change", &ret->refuse_machine_password_change);
62
63         tdb_close(tdb);
64
65         return ret;
66 }
67