summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/lib/ldb/include/ldb.h3
-rw-r--r--source4/lib/samba3/group.c12
-rw-r--r--source4/lib/samba3/idmap.c8
-rw-r--r--source4/lib/samba3/ldb_samba3.c52
-rw-r--r--source4/lib/samba3/policy.c19
-rw-r--r--source4/lib/samba3/registry.c9
-rw-r--r--source4/lib/samba3/samba3.c17
-rw-r--r--source4/lib/samba3/samba3dump.c144
-rw-r--r--source4/lib/samba3/secrets.c7
-rw-r--r--source4/lib/samba3/winsdb.c2
10 files changed, 193 insertions, 80 deletions
diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h
index 89e88fd4e9..46b359b8ba 100644
--- a/source4/lib/ldb/include/ldb.h
+++ b/source4/lib/ldb/include/ldb.h
@@ -162,8 +162,7 @@ struct ldb_debug_ops {
#define PRINTF_ATTRIBUTE(a,b)
#endif
-
-/* structues for ldb_parse_tree handling code */
+/* structures for ldb_parse_tree handling code */
enum ldb_parse_op { LDB_OP_AND=1, LDB_OP_OR=2, LDB_OP_NOT=3,
LDB_OP_EQUALITY=4, LDB_OP_SUBSTRING=5,
LDB_OP_GREATER=6, LDB_OP_LESS=7, LDB_OP_PRESENT=8,
diff --git a/source4/lib/samba3/group.c b/source4/lib/samba3/group.c
index fc8f8c40b8..68ac5987d0 100644
--- a/source4/lib/samba3/group.c
+++ b/source4/lib/samba3/group.c
@@ -46,8 +46,9 @@ NTSTATUS samba3_read_grouptdb(const char *file, TALLOC_CTX *ctx, struct samba3_g
int32_t vers_id;
TDB_DATA kbuf, dbuf, newkey;
int ret;
-
- TDB_CONTEXT *tdb = tdb_open(file, 0, TDB_DEFAULT, O_RDONLY, 0600);
+ TDB_CONTEXT *tdb;
+
+ tdb = tdb_open(file, 0, TDB_DEFAULT, O_RDONLY, 0600);
if (!tdb) {
DEBUG(0,("Failed to open group mapping database\n"));
return NT_STATUS_UNSUCCESSFUL;
@@ -61,6 +62,7 @@ NTSTATUS samba3_read_grouptdb(const char *file, TALLOC_CTX *ctx, struct samba3_g
}
if (vers_id != DATABASE_VERSION_V2) {
+ DEBUG(0, ("Group database version mismatch: %d\n", vers_id));
return NT_STATUS_UNSUCCESSFUL;
}
@@ -80,19 +82,17 @@ NTSTATUS samba3_read_grouptdb(const char *file, TALLOC_CTX *ctx, struct samba3_g
if (!dbuf.dptr)
continue;
- map.sid = dom_sid_parse_talloc(tdb, kbuf.dptr+strlen(GROUP_PREFIX));
+ map.sid = dom_sid_parse_talloc(ctx, 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;
}
- db->groupmappings = talloc_realloc(tdb, db->groupmappings, struct samba3_groupmapping, db->groupmap_count+1);
+ db->groupmappings = talloc_realloc(ctx, db->groupmappings, struct samba3_groupmapping, db->groupmap_count+1);
if (!db->groupmappings)
return NT_STATUS_NO_MEMORY;
diff --git a/source4/lib/samba3/idmap.c b/source4/lib/samba3/idmap.c
index 1583ad4476..ce3d098d3a 100644
--- a/source4/lib/samba3/idmap.c
+++ b/source4/lib/samba3/idmap.c
@@ -41,7 +41,6 @@
NTSTATUS samba3_read_idmap( const char *fn, TALLOC_CTX *ctx, struct samba3_idmapdb *idmap )
{
- int32_t version;
TDB_CONTEXT *tdb;
TDB_DATA key, val;
@@ -51,13 +50,6 @@ NTSTATUS samba3_read_idmap( const char *fn, TALLOC_CTX *ctx, struct samba3_idmap
return NT_STATUS_UNSUCCESSFUL;
}
- /* check against earlier versions */
- version = tdb_fetch_int32(tdb, "IDMAP_VERSION");
- if (version != IDMAP_VERSION) {
- DEBUG(0, ("idmap_init: Unable to open idmap database, it's in an old format!\n"));
- return NT_STATUS_INTERNAL_DB_ERROR;
- }
-
idmap->mapping_count = 0;
idmap->mappings = NULL;
idmap->user_hwm = tdb_fetch_int32(tdb, HWM_USER);
diff --git a/source4/lib/samba3/ldb_samba3.c b/source4/lib/samba3/ldb_samba3.c
index 53d8964d0d..4cfdd3db75 100644
--- a/source4/lib/samba3/ldb_samba3.c
+++ b/source4/lib/samba3/ldb_samba3.c
@@ -27,23 +27,17 @@
#include "ldb/include/ldb.h"
#include "ldb/include/ldb_private.h"
-/*
- * gidNumber -> ???
- * sambaSID -> member
- * sambaSIDList -> member (special!)
- */
-
-/* sambaTrustPassword */
-
-/* sambaDomainName -> name */
-
-/* sambaUnixIdPool */
-
-/* sambaIdmapEntry */
-
-/* sambaAccountPolicy: FIXME */
-
-/* sambaSidEntry: FIXME */
+/* FIXME:
+ * sambaSID -> member
+ * sambaSIDList -> member (special!)
+ * sambaDomainName -> name
+ * sambaTrustPassword
+ * sambaUnixIdPool
+ * sambaIdmapEntry
+ * sambaAccountPolicy
+ * sambaSidEntry
+ * sambaAcctFlags -> systemFlags ?
+ * sambaPasswordHistory -> ntPwdHistory*/
/* Not necessary:
* sambaConfig
@@ -54,19 +48,17 @@
* sambaAlgorithmicRidBase
*/
-/* sambaKickoffTime -> ???*/
-/* sambaPwdCanChange -> ???*/
-/* sambaPwdMustChange -> ???*/
-/* sambaAcctFlags -> systemFlags ?*/
-/* sambaHomePath -> ???*/
-/* sambaHomeDrive -> ???*/
-/* sambaLogonScript -> ???*/
-/* sambaProfilePath -> ???*/
-/* sambaUserWorkstations -> ???*/
-/* sambaDomainName -> ???*/
-/* sambaMungedDial -> ???*/
-/* sambaPasswordHistory -> ntPwdHistory*/
-/* sambaLogonHours -> ???*/
+/* Not in Samba4:
+ * sambaKickoffTime
+ * sambaPwdCanChange
+ * sambaPwdMustChange
+ * sambaHomePath
+ * sambaHomeDrive
+ * sambaLogonScript
+ * sambaProfilePath
+ * sambaUserWorkstations
+ * sambaMungedDial
+ * sambaLogonHours */
/* sambaNextRid -> nextRid */
const struct ldb_map_attribute attr_nextRid = {
diff --git a/source4/lib/samba3/policy.c b/source4/lib/samba3/policy.c
index bec3eb7d93..cfe6284fc4 100644
--- a/source4/lib/samba3/policy.c
+++ b/source4/lib/samba3/policy.c
@@ -1,8 +1,7 @@
/*
* Unix SMB/CIFS implementation.
* account policy storage
- * Copyright (C) Jean François Micouleau 1998-2001.
- * Copyright (C) Andrew Bartlett 2002
+ * 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
@@ -24,30 +23,14 @@
#include "lib/samba3/samba3.h"
#include "system/filesys.h"
-#define DATABASE_VERSION 2
-
-/****************************************************************************
- Open the account policy tdb.
-****************************************************************************/
-
NTSTATUS samba3_read_account_policy(const char *fn, TALLOC_CTX *ctx, 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 NT_STATUS_UNSUCCESSFUL;
}
- /* handle a Samba upgrade */
- if (!tdb_fetch_uint32(tdb, vstring, &version) || version != DATABASE_VERSION) {
- tdb_store_uint32(tdb, vstring, DATABASE_VERSION);
- }
-
- ret = talloc_zero(ctx, struct samba3_policy);
-
tdb_fetch_uint32(tdb, "min password length", &ret->min_password_length);
tdb_fetch_uint32(tdb, "password history", &ret->password_history);
tdb_fetch_uint32(tdb, "user must logon to change pasword", &ret->user_must_logon_to_change_password);
diff --git a/source4/lib/samba3/registry.c b/source4/lib/samba3/registry.c
index 82a08c9088..5f00a944e6 100644
--- a/source4/lib/samba3/registry.c
+++ b/source4/lib/samba3/registry.c
@@ -88,6 +88,7 @@ NTSTATUS samba3_read_regdb ( const char *fn, TALLOC_CTX *ctx, struct samba3_regd
if ( !(tdb = tdb_open(fn, 0, TDB_DEFAULT, O_RDONLY, 0600)) )
{
+ DEBUG(0, ("Unable to open registry database %s\n", fn));
return NT_STATUS_UNSUCCESSFUL;
}
@@ -96,8 +97,10 @@ NTSTATUS samba3_read_regdb ( const char *fn, TALLOC_CTX *ctx, struct samba3_regd
db->key_count = 0;
db->keys = NULL;
- if (vers_id > REGVER_V1)
+ if (vers_id != -1 && vers_id >= REGVER_V1) {
+ DEBUG(0, ("Registry version mismatch: %d\n", vers_id));
return NT_STATUS_UNSUCCESSFUL;
+ }
for (kbuf = tdb_firstkey(tdb); kbuf.dptr; kbuf = tdb_nextkey(tdb, kbuf))
{
@@ -106,7 +109,7 @@ NTSTATUS samba3_read_regdb ( const char *fn, TALLOC_CTX *ctx, struct samba3_regd
struct samba3_regkey key;
char *skey;
- if (strncmp(kbuf.dptr, VALUE_PREFIX, strlen(VALUE_PREFIX)))
+ if (strncmp(kbuf.dptr, VALUE_PREFIX, strlen(VALUE_PREFIX)) == 0)
continue;
vbuf = tdb_fetch(tdb, kbuf);
@@ -134,7 +137,7 @@ NTSTATUS samba3_read_regdb ( const char *fn, TALLOC_CTX *ctx, struct samba3_regd
}
db->keys = talloc_realloc(ctx, db->keys, struct samba3_regkey, db->key_count+1);
- db->keys[i] = key;
+ db->keys[db->key_count] = key;
db->key_count++;
}
diff --git a/source4/lib/samba3/samba3.c b/source4/lib/samba3/samba3.c
index 4eda3bd154..f8ee24ee3b 100644
--- a/source4/lib/samba3/samba3.c
+++ b/source4/lib/samba3/samba3.c
@@ -85,14 +85,17 @@ NTSTATUS samba3_read_smbconf(const char *fn, TALLOC_CTX *ctx, struct samba3 *db)
return NT_STATUS_OK;
}
-struct samba3 *samba3_read(const char *libdir, TALLOC_CTX *ctx)
+NTSTATUS samba3_read(const char *smbconf, const char *libdir, TALLOC_CTX *ctx, struct samba3 **samba3)
{
struct samba3 *ret;
char *dbfile;
- ret = talloc(ctx, struct samba3);
-
- asprintf(&dbfile, "%s/winsdb.dat", libdir);
+ ret = talloc_zero(ctx, struct samba3);
+
+ if (smbconf)
+ samba3_read_smbconf(smbconf, ctx, ret);
+
+ asprintf(&dbfile, "%s/wins.dat", libdir);
samba3_read_winsdb(dbfile, ret, &ret->winsdb_entries, &ret->winsdb_count);
SAFE_FREE(dbfile);
@@ -100,7 +103,7 @@ struct samba3 *samba3_read(const char *libdir, TALLOC_CTX *ctx)
samba3_read_tdbsam(dbfile, ctx, &ret->samaccounts, &ret->samaccount_count);
SAFE_FREE(dbfile);
- asprintf(&dbfile, "%s/groupdb.tdb", libdir);
+ asprintf(&dbfile, "%s/group_mapping.tdb", libdir);
samba3_read_grouptdb(dbfile, ctx, &ret->group);
SAFE_FREE(dbfile);
@@ -124,5 +127,7 @@ struct samba3 *samba3_read(const char *libdir, TALLOC_CTX *ctx)
samba3_read_share_info(dbfile, ctx, ret);
SAFE_FREE(dbfile);
- return ret;
+ *samba3 = ret;
+
+ return NT_STATUS_OK;
}
diff --git a/source4/lib/samba3/samba3dump.c b/source4/lib/samba3/samba3dump.c
index 88d5cf9369..b00074be56 100644
--- a/source4/lib/samba3/samba3dump.c
+++ b/source4/lib/samba3/samba3dump.c
@@ -23,17 +23,36 @@
#include "lib/samba3/samba3.h"
#include "lib/cmdline/popt_common.h"
-static NTSTATUS print_policy(struct samba3_policy *ret)
+static void print_header(const char *txt)
{
+ int i;
+ printf("\n%s\n", txt);
+ for (i = 0; txt[i]; i++) putchar('=');
+ putchar('\n');
+}
+
+static NTSTATUS print_samba3_policy(struct samba3_policy *ret)
+{
+ print_header("Account Policies");
printf("Min password length: %d\n", ret->min_password_length);
+ printf("Password history length: %d\n", ret->password_history);
+ printf("User must logon to change password: %d\n", ret->user_must_logon_to_change_password);
+ printf("Maximum password age: %d\n", ret->maximum_password_age);
+ printf("Minimum password age: %d\n", ret->minimum_password_age);
+ printf("Lockout duration: %d\n", ret->lockout_duration);
+ printf("Reset Count Minutes: %d\n", ret->reset_count_minutes);
+ printf("Bad Lockout Minutes: %d\n", ret->bad_lockout_minutes);
+ printf("Disconnect Time: %d\n", ret->disconnect_time);
+ printf("Refuse Machine Password Change: %d\n", ret->refuse_machine_password_change);
return NT_STATUS_OK;
}
-static NTSTATUS print_sam(struct samba3 *samba3)
+static NTSTATUS print_samba3_sam(struct samba3 *samba3)
{
struct samba3_samaccount *accounts = samba3->samaccounts;
uint32_t count = samba3->samaccount_count, i;
+ print_header("SAM Database");
for (i = 0; i < count; i++) {
printf("%d: %s\n", accounts[i].user_rid, accounts[i].username);
@@ -41,15 +60,118 @@ static NTSTATUS print_sam(struct samba3 *samba3)
return NT_STATUS_OK;
}
+
+static NTSTATUS print_samba3_shares(struct samba3 *samba3)
+{
+ int i, j;
+ print_header("Configured shares");
+ for (i = 0; i < samba3->share_count; i++) {
+ struct samba3_share_info *share = &samba3->shares[i];
+ printf("--- %s ---\n", share->name);
+
+ for (j = 0; j < share->parameter_count; j++) {
+ printf("\t%s = %s\n", share->parameters[j].name, share->parameters[j].value);
+ }
+
+ printf("\n");
+ }
+
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS print_samba3_secrets(struct samba3_secrets *secrets)
+{
+ int i;
+ print_header("Secrets");
+
+ printf("IPC Credentials:\n");
+ printf(" User: %s\n", cli_credentials_get_username(secrets->ipc_cred));
+ printf(" Password: %s\n", cli_credentials_get_password(secrets->ipc_cred));
+ printf(" Domain: %s\n\n", cli_credentials_get_domain(secrets->ipc_cred));
+
+ printf("LDAP passwords:\n");
+ for (i = 0; i < secrets->ldappw_count; i++) {
+ printf("\t%s -> %s\n", secrets->ldappws[i].dn, secrets->ldappws[i].password);
+ }
+ printf("\n");
+
+ printf("Domains:\n");
+ for (i = 0; i < secrets->domain_count; i++) {
+ printf("\t--- %s ---\n", secrets->domains[i].name);
+ printf("\tSID: %s\n", dom_sid_string(NULL, &secrets->domains[i].sid));
+ printf("\tGUID: %s\n", GUID_string(NULL, &secrets->domains[i].guid));
+ printf("\tPlaintext pwd: %s\n", secrets->domains[i].plaintext_pw);
+ printf("\tLast Changed: %lu\n", secrets->domains[i].last_change_time);
+ printf("\tSecure Channel Type: %d\n\n", secrets->domains[i].sec_channel_type);
+ }
+
+ printf("Trusted domains:\n");
+ for (i = 0; i < secrets->trusted_domain_count; i++) {
+ int j;
+ for (j = 0; j < secrets->trusted_domains[i].uni_name_len; j++) {
+ printf("\t--- %s ---\n", secrets->trusted_domains[i].uni_name[j]);
+ }
+ printf("\tPassword: %s\n", secrets->trusted_domains[i].pass);
+ printf("\tModified: %lu\n", secrets->trusted_domains[i].mod_time);
+ printf("\tSID: %s\n", dom_sid_string(NULL, &secrets->trusted_domains[i].domain_sid));
+ }
+
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS print_samba3_regdb(struct samba3_regdb *regdb)
+{
+ int i;
+ print_header("Registry");
+
+ for (i = 0; i < regdb->key_count; i++) {
+ int j;
+ printf("%s\n", regdb->keys[i].name);
+ for (j = 0; j < regdb->keys[i].value_count; j++) {
+ printf("\t%s: type %d, length %d\n",
+ regdb->keys[i].values[j].name,
+ regdb->keys[i].values[j].type,
+ regdb->keys[i].values[j].data.length);
+ }
+ }
+
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS print_samba3_winsdb(struct samba3 *samba3)
+{
+ int i;
+ print_header("WINS Database");
+
+ for (i = 0; i < samba3->winsdb_count; i++) {
+ printf("%s, nb_flags: %x, type: %d, ttl: %lu, %d ips\n", samba3->winsdb_entries[i].name, samba3->winsdb_entries[i].nb_flags, samba3->winsdb_entries[i].type, samba3->winsdb_entries[i].ttl, samba3->winsdb_entries[i].ip_count);
+ }
+
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS print_samba3(struct samba3 *samba3)
+{
+ print_samba3_sam(samba3);
+ print_samba3_policy(&samba3->policy);
+ print_samba3_shares(samba3);
+ print_samba3_winsdb(samba3);
+ print_samba3_regdb(&samba3->registry);
+ print_samba3_secrets(&samba3->secrets);
+
+ return NT_STATUS_OK;
+}
int main(int argc, char **argv)
{
int opt;
+ const char *format = "summary";
const char *libdir = "/var/lib/samba";
struct samba3 *samba3;
poptContext pc;
struct poptOption long_options[] = {
POPT_AUTOHELP
+ { "format", 0, POPT_ARG_STRING, &format, 'f', "Format to use (one of: summary, text, ldif)" },
{ "libdir", 0, POPT_ARG_STRING, &libdir, 'l', "Set libdir [/var/lib/samba]", "LIBDIR" },
POPT_COMMON_SAMBA
POPT_TABLEEND
@@ -62,11 +184,21 @@ int main(int argc, char **argv)
while((opt = poptGetNextOpt(pc)) != -1) {
}
- samba3 = samba3_read(libdir, NULL);
-
- print_sam(samba3);
- print_policy(&samba3->policy);
+ samba3_read(poptGetArg(pc), libdir, NULL, &samba3);
+ if (!strcmp(format, "summary")) {
+ printf("WINS db entries: %d\n", samba3->winsdb_count);
+ printf("SAM Accounts: %d\n", samba3->samaccount_count);
+ printf("Registry key count: %d\n", samba3->registry.key_count);
+ printf("Shares (including [global]): %d\n", samba3->share_count);
+ printf("Groupmap count: %d\n", samba3->group.groupmap_count);
+ printf("Alias count: %d\n", samba3->group.alias_count);
+ printf("Idmap count: %d\n", samba3->idmap.mapping_count);
+ } else if (!strcmp(format, "text")) {
+ print_samba3(samba3);
+ } else if (!strcmp(format, "ldif")) {
+ printf("FIXME\n");
+ }
poptFreeContext(pc);
return 0;
diff --git a/source4/lib/samba3/secrets.c b/source4/lib/samba3/secrets.c
index 6b629d1eff..25ab8f5db5 100644
--- a/source4/lib/samba3/secrets.c
+++ b/source4/lib/samba3/secrets.c
@@ -168,6 +168,12 @@ static NTSTATUS machine_acc (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, T
return NT_STATUS_OK;
}
+static NTSTATUS random_seed (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db)
+{
+ /* Ignore */
+ return NT_STATUS_OK;
+}
+
static NTSTATUS domtrust_acc (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db)
{
int idx, len = 0;
@@ -213,6 +219,7 @@ static const struct {
{ "SECRETS/MACHINE_PASSWORD/", machine_password },
{ "SECRETS/$MACHINE.ACC/", machine_acc },
{ "SECRETS/$DOMTRUST.ACC/", domtrust_acc },
+ { "INFO/random_seed", random_seed },
};
diff --git a/source4/lib/samba3/winsdb.c b/source4/lib/samba3/winsdb.c
index 7c3253e101..c6ead1de39 100644
--- a/source4/lib/samba3/winsdb.c
+++ b/source4/lib/samba3/winsdb.c
@@ -34,7 +34,7 @@ NTSTATUS samba3_read_winsdb( const char *fn, TALLOC_CTX *ctx, struct samba3_wins
char *line;
if((fp = x_fopen(fn,O_RDONLY,0)) == NULL) {
- DEBUG(2,("initialise_wins: Can't open wins database file %s. Error was %s\n",
+ DEBUG(0,("initialise_wins: Can't open wins database file %s. Error was %s\n",
fn, strerror(errno) ));
return NT_STATUS_UNSUCCESSFUL;
}