r9621: Bunch of bug fixes. Add 'format' option to samba3dump (text,summary,ldif)
authorJelmer Vernooij <jelmer@samba.org>
Thu, 25 Aug 2005 19:02:03 +0000 (19:02 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:34:35 +0000 (13:34 -0500)
(This used to be commit dc6aab8d4a6d0fe47756c90d3d311b6009d571ff)

source4/lib/ldb/include/ldb.h
source4/lib/samba3/group.c
source4/lib/samba3/idmap.c
source4/lib/samba3/ldb_samba3.c
source4/lib/samba3/policy.c
source4/lib/samba3/registry.c
source4/lib/samba3/samba3.c
source4/lib/samba3/samba3dump.c
source4/lib/samba3/secrets.c
source4/lib/samba3/winsdb.c

index 89e88fd4e975b0e15f5ee78047d2a29f94820b48..46b359b8ba48dd906143c77d3877b66d2d4e3fa7 100644 (file)
@@ -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,
index fc8f8c40b87e1aecab568deeea06e47c7599ed68..68ac5987d04f8e28c094bdb5e3de2fb77464fc26 100644 (file)
@@ -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;
index 1583ad447658206adddbf2b14957364c02109dab..ce3d098d3a59d6e419a15fe4dff4915b94184f20 100644 (file)
@@ -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);
index 53d8964d0db613bb2ec38897b131e5a7a72dd77b..4cfdd3db751f817e1288ae38a09e6118c911aca3 100644 (file)
 #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
  * 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 = {
index bec3eb7d934155fee51aecdeb9e1e5eee205ad9b..cfe6284fc476ba9932085277234714860d2c484f 100644 (file)
@@ -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
 #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);
index 82a08c908872f1c7af72383af9952b6d9fb17ada..5f00a944e69fbd32a2df0f4f8cde74cf5c50ba81 100644 (file)
@@ -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++;
        }
 
index 4eda3bd15466f50668cf6d0a752e1540daa58fda..f8ee24ee3b559e64425b77935acae6d627ac47d4 100644 (file)
@@ -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;
 }
index 88d5cf9369cc9600c786627899582a81f3d09528..b00074be56ec9bf8fb86f0b47f62cfc7431ae28b 100644 (file)
 #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;
index 6b629d1eff8d7a4b6ac7de001e0d2513933d5940..25ab8f5db5783b74db7d273102c5f5daef26008e 100644 (file)
@@ -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 },
 };
 
 
index 7c3253e1011d574a1827781405fbc9a07c13a6db..c6ead1de39cf0d9fb41918f398b1ff19e33f5e02 100644 (file)
@@ -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;
        }