r9735: More work on generating a valid Samba4 configuration using the
[samba.git] / source4 / scripting / bin / samba3dump
1 #!/bin/sh
2 exec smbscript "$0" ${1+"$@"}
3 /*
4         Dump Samba3 data
5         Copyright Jelmer Vernooij 2005
6         Released under the GNU GPL v2 or later
7 */
8
9 options = GetOptions(ARGV,
10                 "POPT_AUTOHELP",
11                 "POPT_COMMON_SAMBA",
12                 "POPT_COMMON_VERSION",
13                 'format=s',
14                 'quiet', 'blank');
15
16 if (options == undefined) {
17    println("Failed to parse options");
18    return -1;
19 }
20
21 if (options.format == undefined) {
22         options.format = "summary";
23 }
24
25 if (options.format != "summary" && options.format != "full") {
26         printf("Unknown format %s\n", options.format);
27         return -1;
28 }
29
30 libinclude("base.js");
31
32 if (options.ARGV.length != 2) {
33         println("Usage: samba3dump <libdir> <smb.conf>");
34         return -1;
35 }
36
37 function print_header(txt)
38 {
39         printf("\n%s\n", txt);
40         println("==========================================");
41 }
42
43 function print_samba3_policy(pol)
44 {
45         print_header("Account Policies");
46         printf("Min password length: %d\n", pol.min_password_length);
47         printf("Password history length: %d\n", pol.password_history);
48         printf("User must logon to change password: %d\n", pol.user_must_logon_to_change_password);
49         printf("Maximum password age: %d\n", pol.maximum_password_age);
50         printf("Minimum password age: %d\n", pol.minimum_password_age);
51         printf("Lockout duration: %d\n", pol.lockout_duration);
52         printf("Reset Count Minutes: %d\n", pol.reset_count_minutes);
53         printf("Bad Lockout Minutes: %d\n", pol.bad_lockout_minutes);
54         printf("Disconnect Time: %d\n", pol.disconnect_time);
55         printf("Refuse Machine Password Change: %d\n", pol.refuse_machine_password_change);
56 }
57
58 function print_samba3_sam(samba3)
59 {
60         var i;
61         print_header("SAM Database");
62         
63         for (i in samba3.samaccounts) {
64                 var a = samba3.samaccounts[i];
65                 printf("%d: %s\n", a.user_rid, a.username);
66         }
67 }
68
69 function print_samba3_shares(samba3)
70 {
71         var i, j;
72         print_header("Configured shares");
73         for (i in samba3.shares) {
74                 var s = samba3.shares[i];
75                 printf("--- %s ---\n", s.name);
76
77                 for (j in s.parameters) {
78                         var p = s.parameters[j];
79                         printf("\t%s = %s\n", p.name, p.value);
80                 }
81
82                 println("");
83         }
84 }
85
86 function print_samba3_secrets(secrets)
87 {
88         var i;
89         print_header("Secrets");
90
91         println("IPC Credentials:");
92         if (secrets.ipc_cred.username_obtained) 
93                 printf("        User: %s\n", secrets.ipc_cred.get_username);
94         if (secrets.ipc_cred.password_obtained)
95                 printf("        Password: %s\n", secrets.ipc_cred.get_password);
96
97         if (secrets.ipc_cred.domain_obtained)
98                 printf("        Domain: %s\n\n", secrets.ipc_cred.get_domain);
99
100         println("LDAP passwords:");
101         for (i in secrets.ldappws) {
102                 var pw = secrets.ldappws[i];
103                 printf("\t%s -> %s\n", pw.dn, pw.password);
104         }
105         println("");
106
107         println("Domains:");
108         for (i in secrets.domains) {
109                 var d = secrets.domains[i];
110                 printf("\t--- %s ---\n", d.name);
111                 printf("\tSID: %s\n", d.sid);
112                 printf("\tGUID: %s\n", d.guid);
113                 printf("\tPlaintext pwd: %s\n", d.plaintext_pw);
114                 printf("\tLast Changed: %lu\n", d.last_change_time);
115                 printf("\tSecure Channel Type: %d\n\n", d.sec_channel_type);
116         }
117
118         println("Trusted domains:");
119         for (i in secrets.trusted_domains) {
120                 var td = secrets.trusted_domains[i];
121                 for (j = 0; j < td.uni_name_len; j++) {
122                         printf("\t--- %s ---\n", td.uni_name[j]);
123                 }
124                 printf("\tPassword: %s\n", td.pass);
125                 printf("\tModified: %lu\n", td.mod_time);
126                 printf("\tSID: %s\n", td.domain_sid);
127         }
128 }
129
130 function print_samba3_regdb(regdb)
131 {
132         var i, j;
133         print_header("Registry");
134
135         for (i in regdb.keys) {
136                 var k = regdb.keys[i];
137                 printf("%s\n", k.name);
138                 for (j in k.values) {
139                         var v = k.values[j];
140                         printf("\t%s: type %d, length %d\n", v.name, v.type, v.data.length);
141                 }
142         }
143 }
144
145 function print_samba3_winsdb(samba3)
146 {
147         var i;
148         print_header("WINS Database");
149
150         for (i in samba3.winsentries) {
151                 var e = samba3.winsentries[i];
152                 printf("%s, nb_flags: %x, type: %d, ttl: %lu, %d ips, fst: %s\n", e.name, e.nb_flags, e.type, e.ttl, e.ips.length, e.ips[0]);
153         }
154 }
155
156 function print_samba3_groupmappings(groupdb)
157 {
158         print_header("Group Mappings");
159         
160         for (var i in groupdb.groupmappings) {
161                 var g = groupdb.groupmappings[i];
162                 printf("\t--- Group: %s ---\n", g.nt_name);
163                 printf("\tComment: %s\n", g.comment);
164                 printf("\tGID: %d\n", g.gid);
165                 printf("\tSID Name Use: %d\n", g.sid_name_use);
166                 printf("\tSID: %s\n\n", g.sid);
167         }
168 }
169
170 function print_samba3_aliases(groupdb)
171 {
172         var i, j;
173         for (i in groupdb.aliases) {
174                 var a = groupdb.aliases[i];
175                 printf("\t--- Alias: %s ---\n", a.sid);
176                 for (j in a.members) {
177                         printf("\t%s\n", a.members[j]);
178                 }
179         }
180 }
181
182 function print_samba3_idmapdb(idmapdb)
183 {
184         var i;
185         print_header("Winbindd SID<->GID/UID mappings");
186
187         printf("User High Water Mark: %d\n", idmapdb.user_hwm);
188         printf("Group High Water Mark: %d\n\n", idmapdb.group_hwm);
189
190         for (i in idmapdb.mappings) {
191                 var e = idmapdb.mappings[i];
192                 printf("%s -> ", e.sid);
193
194                 if (e.type == e.IDMAP_GROUP) { 
195                         printf("GID %d\n", e.unix_id);
196                 } else {
197                         printf("UID %d\n", e.unix_id);
198                 }
199         }
200 }
201
202 function print_samba3(samba3)
203 {
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_groupmappings(samba3);
211         print_samba3_aliases(samba3);
212         print_samba3_idmapdb(samba3.idmapdb);
213 }
214
215 function print_samba3_summary(samba3)
216 {
217         printf("WINS db entries: %d\n", samba3.winsentries.length);
218         printf("SAM Accounts: %d\n", samba3.samaccounts.length);
219         printf("Registry key count: %d\n", samba3.registry.keys.length);
220         printf("Shares (including [global]): %d\n", samba3.shares.length);
221         printf("Groupmap count: %d\n", samba3.groupmappings.length);
222         printf("Alias count: %d\n", samba3.aliases.length);
223         printf("Idmap count: %d\n", samba3.idmapdb.mappings.length);
224 }
225
226 samba3 = samba3_read(options.ARGV[0], options.ARGV[1]);
227
228 if (options.format == "summary") {
229         print_samba3_summary(samba3);
230 } else if (options.format == "full") {
231         print_samba3(samba3);
232 }
233
234 return 0;