4 # Copyright Jelmer Vernooij 2005-2007
5 # Released under the GNU GPL v3 or later
11 # Find right directory when running from source tree
12 sys
.path
.insert(0, "bin/python")
17 parser
= optparse
.OptionParser("samba3dump <libdir> [<smb.conf>]")
18 parser
.add_option("--format", type="choice", metavar
="FORMAT",
19 choices
=["full", "summary"])
21 opts
, args
= parser
.parse_args()
23 if opts
.format
is None:
24 opts
.format
= "summary"
26 def print_header(txt
):
30 def 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
51 def print_samba3_sam(samdb
):
52 print_header("SAM Database")
56 def print_samba3_shares(shares
):
57 print_header("Configured shares")
59 print "--- %s ---" % s
.name
61 print "\t%s = %s" % (p
.key
, p
.value
)
64 def print_samba3_secrets(secrets
):
65 print_header("Secrets")
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()
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
))
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
)
93 print "Trusted domains:"
94 for td
in secrets
.trusted_domains():
97 def print_samba3_regdb(regdb
):
98 print_header("Registry")
99 from samba
.registry
import str_regtype
101 for k
in regdb
.keys():
103 for (value_name
, (type, value
)) in regdb
.values(k
).items():
104 print "\"%s\"=%s:%s" % (value_name
, str_regtype(type), value
)
106 def print_samba3_winsdb(winsdb
):
107 print_header("WINS Database")
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])
113 def print_samba3_groupmappings(groupdb
):
114 print_header("Group Mappings")
116 for sid
in groupdb
.groupsids():
117 print "\t--- Group: %s ---" % sid
119 def print_samba3_aliases(groupdb
):
120 for sid
in groupdb
.aliases():
121 print "\t--- Alias: %s ---" % sid
123 def print_samba3_idmapdb(idmapdb
):
124 print_header("Winbindd SID<->GID/UID mappings")
126 print "User High Water Mark: %d" % idmapdb
.get_user_hwm()
127 print "Group High Water Mark: %d\n" % idmapdb
.get_group_hwm()
129 for uid
in idmapdb
.uids():
130 print "%s -> UID %d" % (idmapdb
.get_user_sid(uid
), uid
)
132 for gid
in idmapdb
.gids():
133 print "%s -> GID %d" % (idmapdb
.get_group_sid(gid
), gid
)
135 def 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())
147 def 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())))
160 smbconf
= os
.path
.join(libdir
, "smb.conf")
162 samba3
= samba
.samba3
.Samba3(libdir
, smbconf
)
164 if opts
.format
== "summary":
165 print_samba3_summary(samba3
)
166 elif opts
.format
== "full":