2 Unix SMB/CIFS implementation.
3 Samba3 database dump utility
5 Copyright (C) Jelmer Vernooij 2005
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "lib/samba3/samba3.h"
24 #include "lib/cmdline/popt_common.h"
25 #include "lib/ldb/include/ldb.h"
27 static void print_header(const char *txt)
30 printf("\n%s\n", txt);
31 for (i = 0; txt[i]; i++) putchar('=');
35 static NTSTATUS print_samba3_policy(struct samba3_policy *ret)
37 print_header("Account Policies");
38 printf("Min password length: %d\n", ret->min_password_length);
39 printf("Password history length: %d\n", ret->password_history);
40 printf("User must logon to change password: %d\n", ret->user_must_logon_to_change_password);
41 printf("Maximum password age: %d\n", ret->maximum_password_age);
42 printf("Minimum password age: %d\n", ret->minimum_password_age);
43 printf("Lockout duration: %d\n", ret->lockout_duration);
44 printf("Reset Count Minutes: %d\n", ret->reset_count_minutes);
45 printf("Bad Lockout Minutes: %d\n", ret->bad_lockout_minutes);
46 printf("Disconnect Time: %d\n", ret->disconnect_time);
47 printf("Refuse Machine Password Change: %d\n", ret->refuse_machine_password_change);
52 static NTSTATUS print_samba3_sam(struct samba3 *samba3)
54 struct samba3_samaccount *accounts = samba3->samaccounts;
56 print_header("SAM Database");
58 for (i = 0; i < samba3->samaccount_count; i++) {
59 printf("%d: %s\n", accounts[i].user_rid, accounts[i].username);
65 static NTSTATUS print_samba3_shares(struct samba3 *samba3)
68 print_header("Configured shares");
69 for (i = 0; i < samba3->share_count; i++) {
70 struct samba3_share_info *share = &samba3->shares[i];
71 printf("--- %s ---\n", share->name);
73 for (j = 0; j < share->parameter_count; j++) {
74 printf("\t%s = %s\n", share->parameters[j].name, share->parameters[j].value);
83 static NTSTATUS print_samba3_secrets(struct samba3_secrets *secrets)
86 print_header("Secrets");
88 printf("IPC Credentials:\n");
89 if (secrets->ipc_cred->username_obtained)
90 printf(" User: %s\n", cli_credentials_get_username(secrets->ipc_cred));
91 if (secrets->ipc_cred->password_obtained)
92 printf(" Password: %s\n", cli_credentials_get_password(secrets->ipc_cred));
94 if (secrets->ipc_cred->domain_obtained)
95 printf(" Domain: %s\n\n", cli_credentials_get_domain(secrets->ipc_cred));
97 printf("LDAP passwords:\n");
98 for (i = 0; i < secrets->ldappw_count; i++) {
99 printf("\t%s -> %s\n", secrets->ldappws[i].dn, secrets->ldappws[i].password);
103 printf("Domains:\n");
104 for (i = 0; i < secrets->domain_count; i++) {
105 printf("\t--- %s ---\n", secrets->domains[i].name);
106 printf("\tSID: %s\n", dom_sid_string(NULL, &secrets->domains[i].sid));
107 printf("\tGUID: %s\n", GUID_string(NULL, &secrets->domains[i].guid));
108 printf("\tPlaintext pwd: %s\n", secrets->domains[i].plaintext_pw);
109 printf("\tLast Changed: %lu\n", secrets->domains[i].last_change_time);
110 printf("\tSecure Channel Type: %d\n\n", secrets->domains[i].sec_channel_type);
113 printf("Trusted domains:\n");
114 for (i = 0; i < secrets->trusted_domain_count; i++) {
116 for (j = 0; j < secrets->trusted_domains[i].uni_name_len; j++) {
117 printf("\t--- %s ---\n", secrets->trusted_domains[i].uni_name[j]);
119 printf("\tPassword: %s\n", secrets->trusted_domains[i].pass);
120 printf("\tModified: %lu\n", secrets->trusted_domains[i].mod_time);
121 printf("\tSID: %s\n", dom_sid_string(NULL, &secrets->trusted_domains[i].domain_sid));
127 static NTSTATUS print_samba3_regdb(struct samba3_regdb *regdb)
130 print_header("Registry");
132 for (i = 0; i < regdb->key_count; i++) {
134 printf("%s\n", regdb->keys[i].name);
135 for (j = 0; j < regdb->keys[i].value_count; j++) {
136 printf("\t%s: type %d, length %d\n",
137 regdb->keys[i].values[j].name,
138 regdb->keys[i].values[j].type,
139 regdb->keys[i].values[j].data.length);
146 static NTSTATUS print_samba3_winsdb(struct samba3 *samba3)
149 print_header("WINS Database");
151 for (i = 0; i < samba3->winsdb_count; i++) {
152 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);
158 static NTSTATUS print_samba3_groupdb(struct samba3_groupdb *db)
161 print_header("Group Mappings");
163 for (i = 0; i < db->groupmap_count; i++)
165 printf("\t--- Group: %s ---\n", db->groupmappings[i].nt_name);
166 printf("\tComment: %s\n", db->groupmappings[i].comment);
167 printf("\tGID: %d\n", db->groupmappings[i].gid);
168 printf("\tSID Name Use: %d\n", db->groupmappings[i].sid_name_use);
169 printf("\tSID: %s\n\n", dom_sid_string(NULL, db->groupmappings[i].sid));
172 for (i = 0; i < db->alias_count; i++)
175 printf("\t--- Alias: %s ---\n", dom_sid_string(NULL, db->aliases[i].sid));
176 for (j = 0; j < db->aliases[i].member_count; j++) {
177 printf("\t%s\n", dom_sid_string(NULL,db->aliases[i].members[j]));
184 static NTSTATUS print_samba3_idmapdb(struct samba3_idmapdb *db)
187 print_header("Winbindd SID<->GID/UID mappings");
189 printf("User High Water Mark: %d\n", db->user_hwm);
190 printf("Group High Water Mark: %d\n\n", db->group_hwm);
192 for (i = 0; i < db->mapping_count; i++) {
193 printf("%s -> %cID %d",
194 dom_sid_string(NULL, db->mappings[i].sid),
195 (db->mappings[i].type == IDMAP_GROUP)?'G':'U',
196 db->mappings[i].unix_id);
202 static NTSTATUS print_samba3(struct samba3 *samba3)
204 print_samba3_sam(samba3);
205 print_samba3_policy(&samba3->policy);
206 print_samba3_shares(samba3);
207 print_samba3_winsdb(samba3);
208 print_samba3_regdb(&samba3->registry);
209 print_samba3_secrets(&samba3->secrets);
210 print_samba3_groupdb(&samba3->group);
211 print_samba3_idmapdb(&samba3->idmap);
216 static BOOL write_ldif(const char *fn, struct ldb_message **messages, int count)
218 FILE *f = fopen(fn, "w+");
219 struct ldb_ldif ldif;
221 struct ldb_context *ldb = ldb_init(NULL);
224 DEBUG(0, ("Unable to open LDIF file '%s'\n", fn));
229 for (i = 0; i < count; i++) {
230 ldif.changetype = LDB_CHANGETYPE_ADD;
231 ldif.msg = messages[i];
233 ldb_ldif_write_file(ldb, f, &ldif);
243 int main(int argc, char **argv)
246 const char *format = "summary";
248 char *smbconf = NULL;
249 struct samba3 *samba3;
252 struct poptOption long_options[] = {
254 { "format", 0, POPT_ARG_STRING, &format, 'f', "Format to use (one of: summary, text, ldif)" },
259 pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
261 poptSetOtherOptionHelp(pc, "<libdir> <smb.conf>");
263 while((opt = poptGetNextOpt(pc)) != -1) {
266 samba3dump_init_subsystems;
268 mem_ctx = talloc_init("samba3dump_context");
270 libdir = talloc_strdup(mem_ctx, poptGetArg(pc));
271 smbconf = talloc_strdup(mem_ctx, poptGetArg(pc));
273 printf("Reading from libdir '%s', smb.conf file '%s'\n", libdir, smbconf);
275 samba3_read(smbconf, libdir, mem_ctx, &samba3);
277 if (!strcmp(format, "summary")) {
278 printf("WINS db entries: %d\n", samba3->winsdb_count);
279 printf("SAM Accounts: %d\n", samba3->samaccount_count);
280 printf("Registry key count: %d\n", samba3->registry.key_count);
281 printf("Shares (including [global]): %d\n", samba3->share_count);
282 printf("Groupmap count: %d\n", samba3->group.groupmap_count);
283 printf("Alias count: %d\n", samba3->group.alias_count);
284 printf("Idmap count: %d\n", samba3->idmap.mapping_count);
285 } else if (!strcmp(format, "text")) {
286 print_samba3(samba3);
287 } else if (!strcmp(format, "ldif")) {
288 struct ldb_message **msgs;
289 struct ldb_context *ldb = ldb_init(mem_ctx);
291 const char *hives[] = { "hklm", "hkcr", "hku", "hkpd", "hkpt", NULL };
293 for (i = 0; hives[i]; i++) {
296 ret = samba3_upgrade_registry(&samba3->registry, hives[i], ldb, &msgs);
298 printf("Writing %s.ldif\n", hives[i]);
299 asprintf(&fn, "%s.ldif", hives[i]);
300 write_ldif(fn, msgs, ret);
304 ret = samba3_upgrade_sam(samba3, ldb, &msgs);
305 printf("Writing sam.ldif\n");
306 write_ldif("sam.ldif", msgs, ret);
308 ret = samba3_upgrade_winsdb(samba3, ldb, &msgs);
309 printf("Writing wins.ldif\n");
310 write_ldif("wins.ldif", msgs, ret);
312 ret = samba3_upgrade_winbind(samba3, ldb, &msgs);
313 printf("Writing winbind.ldif\n");
314 write_ldif("winbind.ldif", msgs, ret);