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 TALLOC_CTX
*mem_ctx
= talloc_new(NULL
);
91 printf(" User: %s\n", cli_credentials_get_username(secrets
->ipc_cred
, mem_ctx
));
94 if (secrets
->ipc_cred
->password_obtained
)
95 printf(" Password: %s\n", cli_credentials_get_password(secrets
->ipc_cred
));
97 if (secrets
->ipc_cred
->domain_obtained
)
98 printf(" Domain: %s\n\n", cli_credentials_get_domain(secrets
->ipc_cred
));
100 printf("LDAP passwords:\n");
101 for (i
= 0; i
< secrets
->ldappw_count
; i
++) {
102 printf("\t%s -> %s\n", secrets
->ldappws
[i
].dn
, secrets
->ldappws
[i
].password
);
106 printf("Domains:\n");
107 for (i
= 0; i
< secrets
->domain_count
; i
++) {
108 printf("\t--- %s ---\n", secrets
->domains
[i
].name
);
109 printf("\tSID: %s\n", dom_sid_string(NULL
, &secrets
->domains
[i
].sid
));
110 printf("\tGUID: %s\n", GUID_string(NULL
, &secrets
->domains
[i
].guid
));
111 printf("\tPlaintext pwd: %s\n", secrets
->domains
[i
].plaintext_pw
);
112 printf("\tLast Changed: %lu\n", secrets
->domains
[i
].last_change_time
);
113 printf("\tSecure Channel Type: %d\n\n", secrets
->domains
[i
].sec_channel_type
);
116 printf("Trusted domains:\n");
117 for (i
= 0; i
< secrets
->trusted_domain_count
; i
++) {
119 for (j
= 0; j
< secrets
->trusted_domains
[i
].uni_name_len
; j
++) {
120 printf("\t--- %s ---\n", secrets
->trusted_domains
[i
].uni_name
[j
]);
122 printf("\tPassword: %s\n", secrets
->trusted_domains
[i
].pass
);
123 printf("\tModified: %lu\n", secrets
->trusted_domains
[i
].mod_time
);
124 printf("\tSID: %s\n", dom_sid_string(NULL
, &secrets
->trusted_domains
[i
].domain_sid
));
130 static NTSTATUS
print_samba3_regdb(struct samba3_regdb
*regdb
)
133 print_header("Registry");
135 for (i
= 0; i
< regdb
->key_count
; i
++) {
137 printf("%s\n", regdb
->keys
[i
].name
);
138 for (j
= 0; j
< regdb
->keys
[i
].value_count
; j
++) {
139 printf("\t%s: type %d, length %d\n",
140 regdb
->keys
[i
].values
[j
].name
,
141 regdb
->keys
[i
].values
[j
].type
,
142 regdb
->keys
[i
].values
[j
].data
.length
);
149 static NTSTATUS
print_samba3_winsdb(struct samba3
*samba3
)
152 print_header("WINS Database");
154 for (i
= 0; i
< samba3
->winsdb_count
; i
++) {
155 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
);
161 static NTSTATUS
print_samba3_groupdb(struct samba3_groupdb
*db
)
164 print_header("Group Mappings");
166 for (i
= 0; i
< db
->groupmap_count
; i
++)
168 printf("\t--- Group: %s ---\n", db
->groupmappings
[i
].nt_name
);
169 printf("\tComment: %s\n", db
->groupmappings
[i
].comment
);
170 printf("\tGID: %d\n", db
->groupmappings
[i
].gid
);
171 printf("\tSID Name Use: %d\n", db
->groupmappings
[i
].sid_name_use
);
172 printf("\tSID: %s\n\n", dom_sid_string(NULL
, db
->groupmappings
[i
].sid
));
175 for (i
= 0; i
< db
->alias_count
; i
++)
178 printf("\t--- Alias: %s ---\n", dom_sid_string(NULL
, db
->aliases
[i
].sid
));
179 for (j
= 0; j
< db
->aliases
[i
].member_count
; j
++) {
180 printf("\t%s\n", dom_sid_string(NULL
,db
->aliases
[i
].members
[j
]));
187 static NTSTATUS
print_samba3_idmapdb(struct samba3_idmapdb
*db
)
190 print_header("Winbindd SID<->GID/UID mappings");
192 printf("User High Water Mark: %d\n", db
->user_hwm
);
193 printf("Group High Water Mark: %d\n\n", db
->group_hwm
);
195 for (i
= 0; i
< db
->mapping_count
; i
++) {
196 printf("%s -> %cID %d",
197 dom_sid_string(NULL
, db
->mappings
[i
].sid
),
198 (db
->mappings
[i
].type
== IDMAP_GROUP
)?'G':'U',
199 db
->mappings
[i
].unix_id
);
205 static NTSTATUS
print_samba3(struct samba3
*samba3
)
207 print_samba3_sam(samba3
);
208 print_samba3_policy(&samba3
->policy
);
209 print_samba3_shares(samba3
);
210 print_samba3_winsdb(samba3
);
211 print_samba3_regdb(&samba3
->registry
);
212 print_samba3_secrets(&samba3
->secrets
);
213 print_samba3_groupdb(&samba3
->group
);
214 print_samba3_idmapdb(&samba3
->idmap
);
219 static BOOL
write_ldif(const char *fn
, struct ldb_message
**messages
, int count
)
221 FILE *f
= fopen(fn
, "w+");
222 struct ldb_ldif ldif
;
224 struct ldb_context
*ldb
= ldb_init(NULL
);
227 DEBUG(0, ("Unable to open LDIF file '%s'\n", fn
));
232 for (i
= 0; i
< count
; i
++) {
233 ldif
.changetype
= LDB_CHANGETYPE_ADD
;
234 ldif
.msg
= messages
[i
];
236 ldb_ldif_write_file(ldb
, f
, &ldif
);
246 int main(int argc
, char **argv
)
249 const char *format
= "summary";
251 char *smbconf
= NULL
;
252 struct samba3
*samba3
;
255 struct poptOption long_options
[] = {
257 { "format", 0, POPT_ARG_STRING
, &format
, 'f', "Format to use (one of: summary, text, ldif)" },
262 pc
= poptGetContext(argv
[0], argc
, (const char **) argv
, long_options
,0);
264 poptSetOtherOptionHelp(pc
, "<libdir> <smb.conf>");
266 while((opt
= poptGetNextOpt(pc
)) != -1) {
269 samba3dump_init_subsystems
;
271 mem_ctx
= talloc_init("samba3dump_context");
273 libdir
= talloc_strdup(mem_ctx
, poptGetArg(pc
));
274 smbconf
= talloc_strdup(mem_ctx
, poptGetArg(pc
));
276 printf("Reading from libdir '%s', smb.conf file '%s'\n", libdir
, smbconf
);
278 samba3_read(smbconf
, libdir
, mem_ctx
, &samba3
);
280 if (!strcmp(format
, "summary")) {
281 printf("WINS db entries: %d\n", samba3
->winsdb_count
);
282 printf("SAM Accounts: %d\n", samba3
->samaccount_count
);
283 printf("Registry key count: %d\n", samba3
->registry
.key_count
);
284 printf("Shares (including [global]): %d\n", samba3
->share_count
);
285 printf("Groupmap count: %d\n", samba3
->group
.groupmap_count
);
286 printf("Alias count: %d\n", samba3
->group
.alias_count
);
287 printf("Idmap count: %d\n", samba3
->idmap
.mapping_count
);
288 } else if (!strcmp(format
, "text")) {
289 print_samba3(samba3
);
290 } else if (!strcmp(format
, "ldif")) {
291 struct ldb_message
**msgs
;
292 struct ldb_context
*ldb
= ldb_init(mem_ctx
);
294 const char *hives
[] = { "hklm", "hkcr", "hku", "hkpd", "hkpt", NULL
};
296 for (i
= 0; hives
[i
]; i
++) {
299 ret
= samba3_upgrade_registry(&samba3
->registry
, hives
[i
], ldb
, &msgs
);
301 printf("Writing %s.ldif\n", hives
[i
]);
302 asprintf(&fn
, "%s.ldif", hives
[i
]);
303 write_ldif(fn
, msgs
, ret
);
307 ret
= samba3_upgrade_sam(samba3
, ldb
, &msgs
);
308 printf("Writing sam.ldif\n");
309 write_ldif("sam.ldif", msgs
, ret
);
311 ret
= samba3_upgrade_winsdb(samba3
, ldb
, &msgs
);
312 printf("Writing wins.ldif\n");
313 write_ldif("wins.ldif", msgs
, ret
);
315 ret
= samba3_upgrade_winbind(samba3
, ldb
, &msgs
);
316 printf("Writing winbind.ldif\n");
317 write_ldif("winbind.ldif", msgs
, ret
);