source: vendor/3.6.23/source4/scripting/bin/samba3dump

Last change on this file was 740, checked in by Silvan Scherrer, 13 years ago

Samba Server: update vendor to 3.6.0

File size: 5.7 KB
Line 
1#!/usr/bin/env python
2#
3# Dump Samba3 data
4# Copyright Jelmer Vernooij 2005-2007
5# Released under the GNU GPL v3 or later
6#
7
8import optparse
9import os, sys
10
11# Find right directory when running from source tree
12sys.path.insert(0, "bin/python")
13
14import samba
15import samba.samba3
16
17parser = optparse.OptionParser("samba3dump <libdir> [<smb.conf>]")
18parser.add_option("--format", type="choice", metavar="FORMAT",
19 choices=["full", "summary"])
20
21opts, args = parser.parse_args()
22
23if opts.format is None:
24 opts.format = "summary"
25
26def print_header(txt):
27 print "\n%s" % txt
28 print "=" * len(txt)
29
30def print_samba3_policy(pol):
31 print_header("Account Policies")
32 print "Min password length: %d" % pol.min_password_length
33 print "Password history length: %d" % pol.password_history
34 if pol.user_must_logon_to_change_password:
35 print "User must logon to change password: %d" % pol.user_must_logon_to_change_password
36 if pol.maximum_password_age:
37 print "Maximum password age: %d" % pol.maximum_password_age
38 if pol.minimum_password_age:
39 print "Minimum password age: %d" % pol.minimum_password_age
40 if pol.lockout_duration:
41 print "Lockout duration: %d" % pol.lockout_duration
42 if pol.reset_count_minutes:
43 print "Reset Count Minutes: %d" % pol.reset_count_minutes
44 if pol.bad_lockout_minutes:
45 print "Bad Lockout Minutes: %d" % pol.bad_lockout_minutes
46 if pol.disconnect_time:
47 print "Disconnect Time: %d" % pol.disconnect_time
48 if pol.refuse_machine_password_change:
49 print "Refuse Machine Password Change: %d" % pol.refuse_machine_password_change
50
51def print_samba3_sam(samdb):
52 print_header("SAM Database")
53 for user in samdb:
54 print "%s" % user
55
56def print_samba3_shares(shares):
57 print_header("Configured shares")
58 for s in shares:
59 print "--- %s ---" % s.name
60 for p in s:
61 print "\t%s = %s" % (p.key, p.value)
62 print ""
63
64def print_samba3_secrets(secrets):
65 print_header("Secrets")
66
67 if secrets.get_auth_user():
68 print "IPC Credentials:"
69 if secrets.get_auth_user():
70 print " User: %s\n" % secrets.get_auth_user()
71 if secrets.get_auth_password():
72 print " Password: %s\n" % secrets.get_auth_password()
73 if secrets.get_auth_domain():
74 print " Domain: %s\n" % secrets.get_auth_domain()
75
76 if len(list(secrets.ldap_dns())) > 0:
77 print "LDAP passwords:"
78 for dn in secrets.ldap_dns():
79 print "\t%s -> %s" % (dn, secrets.get_ldap_bind_pw(dn))
80 print ""
81
82 print "Domains:"
83 for domain in secrets.domains():
84 print "\t--- %s ---" % domain
85 print "\tSID: %s" % secrets.get_sid(domain)
86 print "\tGUID: %s" % secrets.get_domain_guid(domain)
87 print "\tPlaintext pwd: %s" % secrets.get_machine_password(domain)
88 if secrets.get_machine_last_change_time(domain):
89 print "\tLast Changed: %lu" % secrets.get_machine_last_change_time(domain)
90 if secrets.get_machine_sec_channel_type(domain):
91 print "\tSecure Channel Type: %d\n" % secrets.get_machine_sec_channel_type(domain)
92
93 print "Trusted domains:"
94 for td in secrets.trusted_domains():
95 print td
96
97def print_samba3_regdb(regdb):
98 print_header("Registry")
99 from samba.registry import str_regtype
100
101 for k in regdb.keys():
102 print "[%s]" % k
103 for (value_name, (type, value)) in regdb.values(k).items():
104 print "\"%s\"=%s:%s" % (value_name, str_regtype(type), value)
105
106def print_samba3_winsdb(winsdb):
107 print_header("WINS Database")
108
109 for name in winsdb:
110 (ttl, ips, nb_flags) = winsdb[name]
111 print "%s, nb_flags: %s, ttl: %lu, %d ips, fst: %s" % (name, nb_flags, ttl, len(ips), ips[0])
112
113def print_samba3_groupmappings(groupdb):
114 print_header("Group Mappings")
115
116 for sid in groupdb.groupsids():
117 print "\t--- Group: %s ---" % sid
118
119def print_samba3_aliases(groupdb):
120 for sid in groupdb.aliases():
121 print "\t--- Alias: %s ---" % sid
122
123def print_samba3_idmapdb(idmapdb):
124 print_header("Winbindd SID<->GID/UID mappings")
125
126 print "User High Water Mark: %d" % idmapdb.get_user_hwm()
127 print "Group High Water Mark: %d\n" % idmapdb.get_group_hwm()
128
129 for uid in idmapdb.uids():
130 print "%s -> UID %d" % (idmapdb.get_user_sid(uid), uid)
131
132 for gid in idmapdb.gids():
133 print "%s -> GID %d" % (idmapdb.get_group_sid(gid), gid)
134
135def print_samba3(samba3):
136 print_samba3_policy(samba3.get_policy_db())
137 print_samba3_winsdb(samba3.get_wins_db())
138 print_samba3_regdb(samba3.get_registry())
139 print_samba3_secrets(samba3.get_secrets_db())
140 print_samba3_idmapdb(samba3.get_idmap_db())
141 print_samba3_sam(samba3.get_sam_db())
142 groupdb = samba3.get_groupmapping_db()
143 print_samba3_groupmappings(groupdb)
144 print_samba3_aliases(groupdb)
145 print_samba3_shares(samba3.get_shares())
146
147def print_samba3_summary(samba3):
148 print "WINS db entries: %d" % len(samba3.get_wins_db())
149 print "Registry key count: %d" % len(samba3.get_registry())
150 groupdb = samba3.get_groupmapping_db()
151 print "Groupmap count: %d" % len(list(groupdb.groupsids()))
152 print "Alias count: %d" % len(list(groupdb.aliases()))
153 idmapdb = samba3.get_idmap_db()
154 print "Idmap count: %d" % (len(list(idmapdb.uids())) + len(list(idmapdb.gids())))
155
156libdir = args[0]
157if len(args) > 1:
158 smbconf = args[1]
159else:
160 smbconf = os.path.join(libdir, "smb.conf")
161
162samba3 = samba.samba3.Samba3(libdir, smbconf)
163
164if opts.format == "summary":
165 print_samba3_summary(samba3)
166elif opts.format == "full":
167 print_samba3(samba3)
Note: See TracBrowser for help on using the repository browser.