2 * Unix SMB/CIFS implementation.
3 * Copyright (C) Jelmer Vernooij 2005
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.
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.
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.
21 #include "lib/samba3/samba3.h"
26 struct samba3_share_info *current_share;
29 struct samba3_share_info *samba3_find_share(struct samba3 *db, TALLOC_CTX* ctx, const char *name)
32 for (i = 0; i < db->share_count; i++) {
33 if (!StrCaseCmp(db->shares[i].name, name))
34 return &db->shares[i];
37 db->shares = talloc_realloc(ctx, db->shares, struct samba3_share_info, db->share_count+1);
38 ZERO_STRUCT(db->shares[i]);
39 db->shares[i].name = talloc_strdup(ctx, name);
42 return &db->shares[i];
45 static BOOL samba3_sfunc (const char *name, void *_db)
47 struct smbconf_data *privdat = _db;
49 privdat->current_share = samba3_find_share(privdat->db, privdat->ctx, name);
54 static BOOL samba3_pfunc (const char *name, const char *value, void *_db)
56 struct smbconf_data *privdat = _db;
57 struct samba3_parameter *p;
59 privdat->current_share->parameters =
60 talloc_realloc(privdat->ctx, privdat->current_share->parameters,
61 struct samba3_parameter,
62 privdat->current_share->parameter_count+1);
64 p = &privdat->current_share->parameters[privdat->current_share->parameter_count];
65 p->name = talloc_strdup(privdat->ctx, name);
66 p->value = talloc_strdup(privdat->ctx, value);
68 privdat->current_share->parameter_count++;
73 NTSTATUS samba3_read_smbconf(const char *fn, TALLOC_CTX *ctx, struct samba3 *db)
75 struct smbconf_data privdat;
79 privdat.current_share = samba3_find_share(db, ctx, "global");
81 if (!pm_process( fn, samba3_sfunc, samba3_pfunc, &privdat )) {
82 return NT_STATUS_UNSUCCESSFUL;
88 NTSTATUS samba3_read(const char *smbconf, const char *libdir, TALLOC_CTX *ctx, struct samba3 **samba3)
93 ret = talloc_zero(ctx, struct samba3);
96 samba3_read_smbconf(smbconf, ctx, ret);
98 asprintf(&dbfile, "%s/wins.dat", libdir);
99 samba3_read_winsdb(dbfile, ret, &ret->winsdb_entries, &ret->winsdb_count);
102 asprintf(&dbfile, "%s/passdb.tdb", libdir);
103 samba3_read_tdbsam(dbfile, ctx, &ret->samaccounts, &ret->samaccount_count);
106 asprintf(&dbfile, "%s/group_mapping.tdb", libdir);
107 samba3_read_grouptdb(dbfile, ctx, &ret->group);
110 asprintf(&dbfile, "%s/idmap.tdb", libdir);
111 samba3_read_idmap(dbfile, ctx, &ret->idmap);
114 asprintf(&dbfile, "%s/account_policy.tdb", libdir);
115 samba3_read_account_policy(dbfile, ctx, &ret->policy);
118 asprintf(&dbfile, "%s/registry.tdb", libdir);
119 samba3_read_regdb(dbfile, ctx, &ret->registry);
122 asprintf(&dbfile, "%s/secrets.tdb", libdir);
123 samba3_read_secrets(dbfile, ctx, &ret->secrets);
126 asprintf(&dbfile, "%s/share_info.tdb", libdir);
127 samba3_read_share_info(dbfile, ctx, ret);