r9800: Add EJS interface to param. tridge, sorry this overlaps a bit
[samba.git] / source / lib / samba3 / samba3.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  Copyright (C) Jelmer Vernooij                       2005
4  *  
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *  
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *  
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19
20 #include "includes.h"
21 #include "lib/samba3/samba3.h"
22
23 struct samba3_domainsecrets *samba3_find_domainsecrets(struct samba3 *db, const char *name)
24 {
25         int i;
26         
27         for (i = 0; i < db->secrets.domain_count; i++) {
28                 if (!strcasecmp_m(db->secrets.domains[i].name, name)) 
29                         return &db->secrets.domains[i];
30         }
31
32         return NULL;
33 }
34
35 NTSTATUS samba3_read(const char *libdir, const char *smbconf, TALLOC_CTX *ctx, struct samba3 **samba3)
36 {
37         struct samba3 *ret;
38         char *dbfile = NULL;
39
40         ret = talloc_zero(ctx, struct samba3);
41
42         if (smbconf) {
43                 ret->configuration = param_init(ret);
44                 param_read(ret->configuration, smbconf);
45         }
46
47         dbfile = talloc_asprintf(ctx, "%s/account_policy.tdb", libdir);
48         samba3_read_account_policy(dbfile, ctx, &ret->policy);
49         talloc_free(dbfile);
50
51         dbfile = talloc_asprintf(ctx, "%s/registry.tdb", libdir);
52         samba3_read_regdb(dbfile, ctx, &ret->registry);
53         talloc_free(dbfile);
54
55         dbfile = talloc_asprintf(ctx, "%s/secrets.tdb", libdir);
56         samba3_read_secrets(dbfile, ctx, &ret->secrets);
57         talloc_free(dbfile);
58
59         dbfile = talloc_asprintf(ctx, "%s/share_info.tdb", libdir);
60         samba3_read_share_info(dbfile, ctx, ret);
61         talloc_free(dbfile);
62
63         dbfile = talloc_asprintf(ctx, "%s/winbindd_idmap.tdb", libdir);
64         samba3_read_idmap(dbfile, ctx, &ret->idmap);
65         talloc_free(dbfile);
66
67         dbfile = talloc_asprintf(ctx, "%s/wins.dat", libdir);
68         samba3_read_winsdb(dbfile, ret, &ret->winsdb_entries, &ret->winsdb_count);
69         talloc_free(dbfile);
70
71         dbfile = talloc_asprintf(ctx, "%s/passdb.tdb", libdir);
72         samba3_read_tdbsam(dbfile, ctx, &ret->samaccounts, &ret->samaccount_count);
73         talloc_free(dbfile);
74
75         dbfile = talloc_asprintf(ctx, "%s/group_mapping.tdb", libdir);
76         samba3_read_grouptdb(dbfile, ctx, &ret->group);
77         talloc_free(dbfile);
78
79         *samba3 = ret;
80
81         return NT_STATUS_OK;
82 }