summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2005-08-24 01:52:17 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:34:28 -0500
commit479ef0a3874098bdc90021908b329f6d74aa1b4b (patch)
treee7478177a24c2b2cb241bea5cb8cf0727939b5b0 /source4
parent6622d3be0996c6de2d714a3d32e5b06ffd5db171 (diff)
downloadsamba-479ef0a3874098bdc90021908b329f6d74aa1b4b.tar.gz
samba-479ef0a3874098bdc90021908b329f6d74aa1b4b.tar.bz2
samba-479ef0a3874098bdc90021908b329f6d74aa1b4b.zip
r9557: Some more updates. Use combined function for parsing a set of
samba3 databases (This used to be commit b91a695bd854c6d37ec536edb2db7b6f97fe69dc)
Diffstat (limited to 'source4')
-rw-r--r--source4/include/structs.h5
-rw-r--r--source4/lib/samba3/config.mk4
-rw-r--r--source4/lib/samba3/group.c448
-rw-r--r--source4/lib/samba3/idmap.c2
-rw-r--r--source4/lib/samba3/policy.c12
-rw-r--r--source4/lib/samba3/samba3.c51
-rw-r--r--source4/lib/samba3/samba3.h29
-rw-r--r--source4/lib/samba3/samba3dump.c47
-rw-r--r--source4/lib/samba3/tdbsam.c2
9 files changed, 154 insertions, 446 deletions
diff --git a/source4/include/structs.h b/source4/include/structs.h
index afbf87a83a..3399ecbd3f 100644
--- a/source4/include/structs.h
+++ b/source4/include/structs.h
@@ -273,5 +273,8 @@ struct kdc_server;
struct smb_krb5_context;
struct samba3_samaccount;
-struct samba3_idmap;
+struct samba3_idmapdb;
+struct samba3_groupdb;
struct samba3_winsdb_entry;
+struct samba3_policy;
+struct samba3;
diff --git a/source4/lib/samba3/config.mk b/source4/lib/samba3/config.mk
index 15802d3b8e..5d96e233b4 100644
--- a/source4/lib/samba3/config.mk
+++ b/source4/lib/samba3/config.mk
@@ -6,7 +6,9 @@ INIT_OBJ_FILES = \
lib/samba3/tdbsam.o \
lib/samba3/policy.o \
lib/samba3/idmap.o \
- lib/samba3/winsdb.o
+ lib/samba3/winsdb.o \
+ lib/samba3/samba3.o \
+ lib/samba3/group.o
# lib/samba3/secrets.o
# End SUBSYSTEM LIBSAMBA3
################################################
diff --git a/source4/lib/samba3/group.c b/source4/lib/samba3/group.c
index d7097f596a..fc8f8c40b8 100644
--- a/source4/lib/samba3/group.c
+++ b/source4/lib/samba3/group.c
@@ -24,6 +24,7 @@
#include "lib/samba3/samba3.h"
#include "lib/tdb/include/tdbutil.h"
#include "system/filesys.h"
+#include "pstring.h"
#define DATABASE_VERSION_V1 1 /* native byte format. */
#define DATABASE_VERSION_V2 2 /* le format. */
@@ -37,47 +38,19 @@
*/
#define MEMBEROF_PREFIX "MEMBEROF/"
-#define ENUM_ONLY_MAPPED True
-#define ENUM_ALL_MAPPED False
-
-
-/****************************************************************************
-dump the mapping group mapping to a text file
-****************************************************************************/
-static const char *decode_sid_name_use(enum SID_NAME_USE name_use)
-{
- switch(name_use) {
- case SID_NAME_USER:
- return "User";
- case SID_NAME_DOM_GRP:
- return "Domain group";
- case SID_NAME_DOMAIN:
- return "Domain";
- case SID_NAME_ALIAS:
- return "Local group";
- case SID_NAME_WKN_GRP:
- return "Builtin group";
- case SID_NAME_DELETED:
- return "Deleted";
- case SID_NAME_INVALID:
- return "Invalid";
- case SID_NAME_UNKNOWN:
- default:
- return "Unknown type";
- }
-}
-
/****************************************************************************
Open the group mapping tdb.
****************************************************************************/
-static TDB_CONTEXT *tdbgroup_open(const char *file)
+NTSTATUS samba3_read_grouptdb(const char *file, TALLOC_CTX *ctx, struct samba3_groupdb *db)
{
int32_t vers_id;
+ TDB_DATA kbuf, dbuf, newkey;
+ int ret;
TDB_CONTEXT *tdb = tdb_open(file, 0, TDB_DEFAULT, O_RDONLY, 0600);
if (!tdb) {
DEBUG(0,("Failed to open group mapping database\n"));
- return NULL;
+ return NT_STATUS_UNSUCCESSFUL;
}
/* Cope with byte-reversed older versions of the db. */
@@ -88,396 +61,77 @@ static TDB_CONTEXT *tdbgroup_open(const char *file)
}
if (vers_id != DATABASE_VERSION_V2) {
- return NULL;
- }
-
- return tdb;
-}
-
-/****************************************************************************
- Return the sid and the type of the unix group.
-****************************************************************************/
-
-static BOOL get_group_map_from_sid(TDB_CONTEXT *tdb, struct dom_sid sid, struct samba3_groupmapping *map)
-{
- TDB_DATA kbuf, dbuf;
- const char *key;
- int ret = 0;
-
- /* the key is the SID, retrieving is direct */
-
- kbuf.dptr = talloc_asprintf(tdb, "%s%s", GROUP_PREFIX, dom_sid_string(tdb, &sid));
- kbuf.dsize = strlen(key)+1;
-
- dbuf = tdb_fetch(tdb, kbuf);
- if (!dbuf.dptr)
- return False;
-
- ret = tdb_unpack(tdb, dbuf.dptr, dbuf.dsize, "ddff",
- &map->gid, &map->sid_name_use, &map->nt_name, &map->comment);
-
- SAFE_FREE(dbuf.dptr);
-
- if ( ret == -1 ) {
- DEBUG(3,("get_group_map_from_sid: tdb_unpack failure\n"));
- return False;
+ return NT_STATUS_UNSUCCESSFUL;
}
- map->sid = dom_sid_dup(tdb, &sid);
-
- return True;
-}
-
-/****************************************************************************
- Return the sid and the type of the unix group.
-****************************************************************************/
-
-static BOOL get_group_map_from_gid(TDB_CONTEXT *tdb, gid_t gid, struct samba3_groupmapping *map)
-{
- TDB_DATA kbuf, dbuf, newkey;
- int ret;
-
- /* we need to enumerate the TDB to find the GID */
+ db->groupmappings = NULL;
+ db->groupmap_count = 0;
+ db->aliases = NULL;
+ db->alias_count = 0;
for (kbuf = tdb_firstkey(tdb);
kbuf.dptr;
newkey = tdb_nextkey(tdb, kbuf), safe_free(kbuf.dptr), kbuf=newkey) {
+ struct samba3_groupmapping map;
- if (strncmp(kbuf.dptr, GROUP_PREFIX, strlen(GROUP_PREFIX)) != 0) continue;
-
- dbuf = tdb_fetch(tdb, kbuf);
- if (!dbuf.dptr)
- continue;
+ if (strncmp(kbuf.dptr, GROUP_PREFIX, strlen(GROUP_PREFIX)) == 0)
+ {
+ dbuf = tdb_fetch(tdb, kbuf);
+ if (!dbuf.dptr)
+ continue;
+ map.sid = dom_sid_parse_talloc(tdb, kbuf.dptr+strlen(GROUP_PREFIX));
- map->sid = dom_sid_parse_talloc(tdb, kbuf.dptr+strlen(GROUP_PREFIX));
-
- ret = tdb_unpack(tdb, dbuf.dptr, dbuf.dsize, "ddff",
- &map->gid, &map->sid_name_use, &map->nt_name, &map->comment);
+ ret = tdb_unpack(tdb, dbuf.dptr, dbuf.dsize, "ddff",
+ &map.gid, &map.sid_name_use, &map.nt_name, &map.comment);
- SAFE_FREE(dbuf.dptr);
+ SAFE_FREE(dbuf.dptr);
- if ( ret == -1 ) {
- DEBUG(3,("get_group_map_from_gid: tdb_unpack failure\n"));
- return False;
- }
-
- if (gid==map->gid) {
- SAFE_FREE(kbuf.dptr);
- return True;
- }
- }
+ if ( ret == -1 ) {
+ DEBUG(3,("enum_group_mapping: tdb_unpack failure\n"));
+ continue;
+ }
- return False;
-}
+ db->groupmappings = talloc_realloc(tdb, db->groupmappings, struct samba3_groupmapping, db->groupmap_count+1);
-/****************************************************************************
- Return the sid and the type of the unix group.
-****************************************************************************/
+ if (!db->groupmappings)
+ return NT_STATUS_NO_MEMORY;
-static BOOL get_group_map_from_ntname(TDB_CONTEXT *tdb, const char *name, struct samba3_groupmapping *map)
-{
- TDB_DATA kbuf, dbuf, newkey;
- int ret;
-
- /* we need to enumerate the TDB to find the name */
+ db->groupmappings[db->groupmap_count] = map;
- for (kbuf = tdb_firstkey(tdb);
- kbuf.dptr;
- newkey = tdb_nextkey(tdb, kbuf), safe_free(kbuf.dptr), kbuf=newkey) {
+ db->groupmap_count++;
+ }
- if (strncmp(kbuf.dptr, GROUP_PREFIX, strlen(GROUP_PREFIX)) != 0) continue;
-
- dbuf = tdb_fetch(tdb, kbuf);
- if (!dbuf.dptr)
- continue;
+ if (strncmp(kbuf.dptr, MEMBEROF_PREFIX, strlen(MEMBEROF_PREFIX)) == 0)
+ {
+ struct samba3_alias alias;
+ pstring alias_string;
+ const char *p;
- map->sid = dom_sid_parse_talloc(tdb, kbuf.dptr+strlen(GROUP_PREFIX));
-
- ret = tdb_unpack(tdb, dbuf.dptr, dbuf.dsize, "ddff",
- &map->gid, &map->sid_name_use, &map->nt_name, &map->comment);
+ dbuf = tdb_fetch(tdb, kbuf);
+ if (!dbuf.dptr)
+ continue;
- SAFE_FREE(dbuf.dptr);
-
- if ( ret == -1 ) {
- DEBUG(3,("get_group_map_from_ntname: tdb_unpack failure\n"));
- return False;
- }
+ alias.sid = dom_sid_parse_talloc(ctx, kbuf.dptr+strlen(MEMBEROF_PREFIX));
+ alias.member_count = 0;
+ alias.members = NULL;
- if (StrCaseCmp(name, map->nt_name)==0) {
- SAFE_FREE(kbuf.dptr);
- return True;
- }
- }
+ p = dbuf.dptr;
+ while (next_token(&p, alias_string, " ", sizeof(alias_string))) {
- return False;
-}
+ alias.members = talloc_realloc(ctx, alias.members, struct dom_sid *, alias.member_count+1);
+ alias.members[alias.member_count] = dom_sid_parse_talloc(ctx, alias_string);
+ alias.member_count++;
-/****************************************************************************
- Enumerate the group mapping.
-****************************************************************************/
+ }
-static BOOL enum_group_mapping(TDB_CONTEXT *tdb, enum SID_NAME_USE sid_name_use, struct samba3_groupmapping **rmap,
- int *num_entries, BOOL unix_only)
-{
- TDB_DATA kbuf, dbuf, newkey;
- struct samba3_groupmapping map;
- struct samba3_groupmapping *mapt;
- int ret;
- int entries=0;
-
- *num_entries=0;
- *rmap=NULL;
-
- for (kbuf = tdb_firstkey(tdb);
- kbuf.dptr;
- newkey = tdb_nextkey(tdb, kbuf), safe_free(kbuf.dptr), kbuf=newkey) {
-
- if (strncmp(kbuf.dptr, GROUP_PREFIX, strlen(GROUP_PREFIX)) != 0)
- continue;
-
- dbuf = tdb_fetch(tdb, kbuf);
- if (!dbuf.dptr)
- continue;
-
- map.sid = dom_sid_parse_talloc(tdb, kbuf.dptr+strlen(GROUP_PREFIX));
-
- ret = tdb_unpack(tdb, dbuf.dptr, dbuf.dsize, "ddff",
- &map.gid, &map.sid_name_use, &map.nt_name, &map.comment);
-
- SAFE_FREE(dbuf.dptr);
-
- if ( ret == -1 ) {
- DEBUG(3,("enum_group_mapping: tdb_unpack failure\n"));
- continue;
- }
-
- /* list only the type or everything if UNKNOWN */
- if (sid_name_use!=SID_NAME_UNKNOWN && sid_name_use!=map.sid_name_use) {
- DEBUG(11,("enum_group_mapping: group %s is not of the requested type\n", map.nt_name));
- continue;
+ db->aliases = talloc_realloc(ctx, db->aliases, struct samba3_alias, db->alias_count+1);
+ db->aliases[db->alias_count] = alias;
+ db->alias_count++;
}
-
- if (unix_only==ENUM_ONLY_MAPPED && map.gid==-1) {
- DEBUG(11,("enum_group_mapping: group %s is non mapped\n", map.nt_name));
- continue;
- }
-
- DEBUG(11,("enum_group_mapping: returning group %s of type %s\n", map.nt_name ,decode_sid_name_use(map.sid_name_use)));
-
- mapt = talloc_realloc(tdb, *rmap, struct samba3_groupmapping, entries+1);
- if (!mapt) {
- DEBUG(0,("enum_group_mapping: Unable to enlarge group map!\n"));
- SAFE_FREE(*rmap);
- return False;
- }
- else
- (*rmap) = mapt;
-
- mapt[entries].gid = map.gid;
- mapt[entries].sid = dom_sid_dup(tdb, map.sid);
- mapt[entries].sid_name_use = map.sid_name_use;
- mapt[entries].nt_name = map.nt_name;
- mapt[entries].comment = map.comment;
-
- entries++;
-
- }
-
- *num_entries=entries;
-
- return True;
-}
-
-/* This operation happens on session setup, so it should better be fast. We
- * store a list of aliases a SID is member of hanging off MEMBEROF/SID. */
-
-static NTSTATUS one_alias_membership(TDB_CONTEXT *tdb,
- const struct dom_sid *member, struct dom_sid **sids, int *num)
-{
- TDB_DATA kbuf, dbuf;
- const char *p;
-
- char * key = talloc_asprintf(tdb, "%s%s", MEMBEROF_PREFIX, dom_sid_string(tdb, member));
-
- kbuf.dsize = strlen(key)+1;
- kbuf.dptr = key;
-
- dbuf = tdb_fetch(tdb, kbuf);
-
- if (dbuf.dptr == NULL) {
- return NT_STATUS_OK;
- }
-
- p = dbuf.dptr;
-
- while (next_token(&p, string_sid, " ", sizeof(string_sid))) {
-
- struct dom_sid alias;
-
- if (!string_to_sid(&alias, string_sid))
- continue;
-
- add_sid_to_array_unique(NULL, &alias, sids, num);
-
- if (sids == NULL)
- return NT_STATUS_NO_MEMORY;
- }
-
- SAFE_FREE(dbuf.dptr);
- return NT_STATUS_OK;
-}
-
-static NTSTATUS alias_memberships(TDB_CONTEXT *tdb, const struct dom_sid *members, int num_members,
- struct dom_sid **sids, int *num)
-{
- int i;
-
- *num = 0;
- *sids = NULL;
-
- for (i=0; i<num_members; i++) {
- NTSTATUS status = one_alias_membership(tdb, &members[i], sids, num);
- if (!NT_STATUS_IS_OK(status))
- return status;
- }
- return NT_STATUS_OK;
-}
-
-struct aliasmem_closure {
- const struct dom_sid *alias;
- struct dom_sid **sids;
- int *num;
-};
-
-static int collect_aliasmem(TDB_CONTEXT *tdb_ctx, TDB_DATA key, TDB_DATA data,
- void *state)
-{
- struct aliasmem_closure *closure = (struct aliasmem_closure *)state;
- const char *p;
- fstring alias_string;
-
- if (strncmp(key.dptr, MEMBEROF_PREFIX,
- strlen(MEMBEROF_PREFIX)) != 0)
- return 0;
-
- p = data.dptr;
-
- while (next_token(&p, alias_string, " ", sizeof(alias_string))) {
-
- struct dom_sid alias, member;
- const char *member_string;
-
-
- if (!string_to_sid(&alias, alias_string))
- continue;
-
- if (sid_compare(closure->alias, &alias) != 0)
- continue;
-
- /* Ok, we found the alias we're looking for in the membership
- * list currently scanned. The key represents the alias
- * member. Add that. */
-
- member_string = strchr(key.dptr, '/');
-
- /* Above we tested for MEMBEROF_PREFIX which includes the
- * slash. */
-
- SMB_ASSERT(member_string != NULL);
- member_string += 1;
-
- if (!string_to_sid(&member, member_string))
- continue;
-
- add_sid_to_array(NULL, &member, closure->sids, closure->num);
}
- return 0;
-}
-
-static NTSTATUS enum_aliasmem(TDB_CONTEXT *tdb, const struct dom_sid *alias, struct dom_sid **sids, int *num)
-{
- struct samba3_groupmapping map;
- struct aliasmem_closure closure;
-
- if (!get_group_map_from_sid(*alias, &map))
- return NT_STATUS_NO_SUCH_ALIAS;
-
- if ( (map.sid_name_use != SID_NAME_ALIAS) &&
- (map.sid_name_use != SID_NAME_WKN_GRP) )
- return NT_STATUS_NO_SUCH_ALIAS;
-
- *sids = NULL;
- *num = 0;
+ tdb_close(tdb);
- closure.alias = alias;
- closure.sids = sids;
- closure.num = num;
-
- tdb_traverse(tdb, collect_aliasmem, &closure);
return NT_STATUS_OK;
}
-
-/*
- *
- * High level functions
- * better to use them than the lower ones.
- *
- * we are checking if the group is in the mapping file
- * and if the group is an existing unix group
- *
- */
-
-/* get a domain group from it's SID */
-
-/* get a local (alias) group from it's SID */
-
-static BOOL get_local_group_from_sid(TDB_CONTEXT *tdb, struct dom_sid *sid, struct samba3_groupmapping *map)
-{
- BOOL ret;
-
- /* The group is in the mapping table */
- ret = pdb_getgrsid(map, *sid);
-
- if ( !ret )
- return False;
-
- if ( ( (map->sid_name_use != SID_NAME_ALIAS) &&
- (map->sid_name_use != SID_NAME_WKN_GRP) )
- || (map->gid == -1)
- || (getgrgid(map->gid) == NULL) )
- {
- return False;
- }
-
-#if 1 /* JERRY */
- /* local groups only exist in the group mapping DB so this
- is not necessary */
-
- else {
- /* the group isn't in the mapping table.
- * make one based on the unix information */
- uint32_t alias_rid;
- struct group *grp;
-
- sid_peek_rid(sid, &alias_rid);
- map->gid=pdb_group_rid_to_gid(alias_rid);
-
- grp = getgrgid(map->gid);
- if ( !grp ) {
- DEBUG(3,("get_local_group_from_sid: No unix group for [%ul]\n", map->gid));
- return False;
- }
-
- map->sid_name_use=SID_NAME_ALIAS;
-
- fstrcpy(map->nt_name, grp->gr_name);
- fstrcpy(map->comment, "Local Unix Group");
-
- sid_copy(&map->sid, sid);
- }
-#endif
-
- return True;
-}
diff --git a/source4/lib/samba3/idmap.c b/source4/lib/samba3/idmap.c
index 64d6387ed4..1583ad4476 100644
--- a/source4/lib/samba3/idmap.c
+++ b/source4/lib/samba3/idmap.c
@@ -39,7 +39,7 @@
Initialise idmap database.
*****************************************************************************/
-NTSTATUS samba3_read_idmap( const char *fn, TALLOC_CTX *ctx, struct samba3_idmap *idmap )
+NTSTATUS samba3_read_idmap( const char *fn, TALLOC_CTX *ctx, struct samba3_idmapdb *idmap )
{
int32_t version;
TDB_CONTEXT *tdb;
diff --git a/source4/lib/samba3/policy.c b/source4/lib/samba3/policy.c
index bfb3ac373e..bec3eb7d93 100644
--- a/source4/lib/samba3/policy.c
+++ b/source4/lib/samba3/policy.c
@@ -30,16 +30,15 @@
Open the account policy tdb.
****************************************************************************/
-struct samba3_policy *samba3_read_account_policy(TALLOC_CTX *ctx, const char *fn)
+NTSTATUS samba3_read_account_policy(const char *fn, TALLOC_CTX *ctx, struct samba3_policy *ret)
{
- struct samba3_policy *ret;
const char *vstring = "INFO/version";
uint32_t version;
TDB_CONTEXT *tdb = tdb_open(fn, 0, TDB_DEFAULT, O_RDONLY, 0600);
if (!tdb) {
DEBUG(0,("Failed to open account policy database\n"));
- return NULL;
+ return NT_STATUS_UNSUCCESSFUL;
}
/* handle a Samba upgrade */
@@ -60,10 +59,9 @@ struct samba3_policy *samba3_read_account_policy(TALLOC_CTX *ctx, const char *fn
tdb_fetch_uint32(tdb, "disconnect time", &ret->disconnect_time);
tdb_fetch_uint32(tdb, "refuse machine password change", &ret->refuse_machine_password_change);
+ /* FIXME: Read privileges as well */
+
tdb_close(tdb);
- return ret;
+ return NT_STATUS_OK;
}
-
-
-/* FIXME: Read privileges as well */
diff --git a/source4/lib/samba3/samba3.c b/source4/lib/samba3/samba3.c
new file mode 100644
index 0000000000..37576a8642
--- /dev/null
+++ b/source4/lib/samba3/samba3.c
@@ -0,0 +1,51 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Copyright (C) Jelmer Vernooij 2005
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "includes.h"
+#include "lib/samba3/samba3.h"
+
+struct samba3 *samba3_read(const char *libdir, TALLOC_CTX *ctx)
+{
+ struct samba3 *ret;
+ char *dbfile;
+
+ ret = talloc(ctx, struct samba3);
+
+ asprintf(&dbfile, "%s/winsdb.dat", libdir);
+ samba3_read_winsdb(dbfile, ret, &ret->winsdb_entries, &ret->winsdb_count);
+ SAFE_FREE(dbfile);
+
+ asprintf(&dbfile, "%s/passdb.tdb", libdir);
+ samba3_read_tdbsam(dbfile, ctx, &ret->samaccounts, &ret->samaccount_count);
+ SAFE_FREE(dbfile);
+
+ asprintf(&dbfile, "%s/groupdb.tdb", libdir);
+ samba3_read_grouptdb(dbfile, ctx, &ret->group);
+ SAFE_FREE(dbfile);
+
+ asprintf(&dbfile, "%s/idmap.tdb", libdir);
+ samba3_read_idmap(dbfile, ctx, &ret->idmap);
+ SAFE_FREE(dbfile);
+
+ asprintf(&dbfile, "%s/account_policy.tdb", libdir);
+ samba3_read_account_policy(dbfile, ctx, &ret->policy);
+ SAFE_FREE(dbfile);
+
+ return ret;
+}
diff --git a/source4/lib/samba3/samba3.h b/source4/lib/samba3/samba3.h
index d3e03cf923..adb7b8973a 100644
--- a/source4/lib/samba3/samba3.h
+++ b/source4/lib/samba3/samba3.h
@@ -75,6 +75,20 @@ struct samba3_groupmapping {
const char *comment;
};
+struct samba3_alias {
+ struct dom_sid *sid;
+ uint32_t member_count;
+ struct dom_sid **members;
+};
+
+struct samba3_groupdb {
+ uint32_t groupmap_count;
+ struct samba3_groupmapping *groupmappings;
+
+ uint32_t alias_count;
+ struct samba3_alias *aliases;
+};
+
struct samba3_idmap_mapping
{
enum { IDMAP_GROUP, IDMAP_USER } type;
@@ -82,7 +96,7 @@ struct samba3_idmap_mapping
struct dom_sid *sid;
};
-struct samba3_idmap
+struct samba3_idmapdb
{
/* High water marks */
uint32_t user_hwm;
@@ -116,4 +130,17 @@ struct samba3_policy
uint32_t refuse_machine_password_change;
};
+struct samba3
+{
+ uint32_t winsdb_count;
+ struct samba3_winsdb_entry *winsdb_entries;
+
+ uint32_t samaccount_count;
+ struct samba3_samaccount *samaccounts;
+
+ struct samba3_groupdb group;
+ struct samba3_idmapdb idmap;
+ struct samba3_policy policy;
+};
+
#endif /* _SAMBA3_H */
diff --git a/source4/lib/samba3/samba3dump.c b/source4/lib/samba3/samba3dump.c
index 6bcfce96fa..88d5cf9369 100644
--- a/source4/lib/samba3/samba3dump.c
+++ b/source4/lib/samba3/samba3dump.c
@@ -23,49 +23,18 @@
#include "lib/samba3/samba3.h"
#include "lib/cmdline/popt_common.h"
-static const char *libdir = "/var/lib/samba";
-
-static NTSTATUS print_policy(void)
+static NTSTATUS print_policy(struct samba3_policy *ret)
{
- struct samba3_policy *ret;
- char *policy_file;
- TALLOC_CTX *mem_ctx = talloc_init(NULL);
-
- policy_file = talloc_asprintf(mem_ctx, "%s/account_policy.tdb", libdir);
-
- printf("Opening policy file %s\n", policy_file);
-
- ret = samba3_read_account_policy(mem_ctx, policy_file);
-
- if (ret == NULL)
- return NT_STATUS_UNSUCCESSFUL;
-
printf("Min password length: %d\n", ret->min_password_length);
- talloc_free(mem_ctx);
-
return NT_STATUS_OK;
}
-static NTSTATUS print_sam(void)
+static NTSTATUS print_sam(struct samba3 *samba3)
{
- struct samba3_samaccount *accounts;
- uint32_t count, i;
- char *tdbsam_file;
- NTSTATUS status;
+ struct samba3_samaccount *accounts = samba3->samaccounts;
+ uint32_t count = samba3->samaccount_count, i;
- asprintf(&tdbsam_file, "%s/passdb.tdb", libdir);
-
- printf("Opening TDB sam %s\n", tdbsam_file);
-
- status = samba3_read_tdbsam(NULL, tdbsam_file, &accounts, &count);
- if (NT_STATUS_IS_ERR(status)) {
- fprintf(stderr, "Error reading tdbsam database %s\n", tdbsam_file);
- SAFE_FREE(tdbsam_file);
- return status;
- }
- SAFE_FREE(tdbsam_file);
-
for (i = 0; i < count; i++) {
printf("%d: %s\n", accounts[i].user_rid, accounts[i].username);
}
@@ -76,6 +45,8 @@ static NTSTATUS print_sam(void)
int main(int argc, char **argv)
{
int opt;
+ const char *libdir = "/var/lib/samba";
+ struct samba3 *samba3;
poptContext pc;
struct poptOption long_options[] = {
POPT_AUTOHELP
@@ -91,8 +62,10 @@ int main(int argc, char **argv)
while((opt = poptGetNextOpt(pc)) != -1) {
}
- print_sam();
- print_policy();
+ samba3 = samba3_read(libdir, NULL);
+
+ print_sam(samba3);
+ print_policy(&samba3->policy);
poptFreeContext(pc);
diff --git a/source4/lib/samba3/tdbsam.c b/source4/lib/samba3/tdbsam.c
index aba01d0db6..577b663381 100644
--- a/source4/lib/samba3/tdbsam.c
+++ b/source4/lib/samba3/tdbsam.c
@@ -266,7 +266,7 @@ static BOOL init_sam_from_buffer_v2(TDB_CONTEXT *tdb, struct samba3_samaccount *
return True;
}
-NTSTATUS samba3_read_tdbsam(TALLOC_CTX *ctx, const char *filename, struct samba3_samaccount **accounts, uint32_t *count)
+NTSTATUS samba3_read_tdbsam(const char *filename, TALLOC_CTX *ctx, struct samba3_samaccount **accounts, uint32_t *count)
{
int32_t version;
TDB_CONTEXT *tdb = tdbsam_open(filename, &version);