2007-12-24 04:19:41 +03:00
#!/usr/bin/python
#
2007-12-26 01:36:23 +03:00
# Dump Samba3 data
# Copyright Jelmer Vernooij 2005-2007
# Released under the GNU GPL v3 or later
2007-12-24 04:19:41 +03:00
#
import optparse
import os, sys
2008-05-11 07:45:49 +04:00
# Find right directory when running from source tree
sys.path.insert(0, "bin/python")
2007-12-24 04:19:41 +03:00
import samba
import samba.samba3
2007-12-24 23:16:59 +03:00
parser = optparse.OptionParser("provision <libdir> [<smb.conf>]")
2007-12-24 04:19:41 +03:00
parser.add_option("--format", type="choice", metavar="FORMAT",
2007-12-26 01:36:23 +03:00
choices=["full", "summary"])
2007-12-24 04:19:41 +03:00
opts, args = parser.parse_args()
if opts.format is None:
2007-12-26 01:36:23 +03:00
opts.format = "summary"
2007-12-24 04:19:41 +03:00
def print_header(txt):
2007-12-26 01:36:23 +03:00
print "\n%s" % txt
print "=" * len(txt)
2007-12-24 04:19:41 +03:00
def print_samba3_policy(pol):
2007-12-26 01:36:23 +03:00
print_header("Account Policies")
print "Min password length: %d" % pol.min_password_length
print "Password history length: %d" % pol.password_history
if pol.user_must_logon_to_change_password:
print "User must logon to change password: %d" % pol.user_must_logon_to_change_password
if pol.maximum_password_age:
print "Maximum password age: %d" % pol.maximum_password_age
if pol.minimum_password_age:
print "Minimum password age: %d" % pol.minimum_password_age
if pol.lockout_duration:
print "Lockout duration: %d" % pol.lockout_duration
if pol.reset_count_minutes:
print "Reset Count Minutes: %d" % pol.reset_count_minutes
if pol.bad_lockout_minutes:
print "Bad Lockout Minutes: %d" % pol.bad_lockout_minutes
if pol.disconnect_time:
print "Disconnect Time: %d" % pol.disconnect_time
if pol.refuse_machine_password_change:
print "Refuse Machine Password Change: %d" % pol.refuse_machine_password_change
def print_samba3_sam(samdb):
print_header("SAM Database")
for user in samdb:
print "%s" % user
def print_samba3_shares(shares):
print_header("Configured shares")
for s in shares:
print "--- %s ---" % s.name
for p in s:
print "\t%s = %s" % (p.key, p.value)
print ""
2007-12-24 04:19:41 +03:00
def print_samba3_secrets(secrets):
2007-12-26 01:36:23 +03:00
print_header("Secrets")
if secrets.get_auth_user():
print "IPC Credentials:"
if secrets.get_auth_user():
print " User: %s\n" % secrets.get_auth_user()
if secrets.get_auth_password():
print " Password: %s\n" % secrets.get_auth_password()
if secrets.get_auth_domain():
print " Domain: %s\n" % secrets.get_auth_domain()
if len(list(secrets.ldap_dns())) > 0:
print "LDAP passwords:"
for dn in secrets.ldap_dns():
print "\t%s -> %s" % (dn, secrets.get_ldap_bind_pw(dn))
print ""
print "Domains:"
for domain in secrets.domains():
print "\t--- %s ---" % domain
print "\tSID: %s" % secrets.get_sid(domain)
2007-12-27 05:55:05 +03:00
print "\tGUID: %s" % secrets.get_domain_guid(domain)
2007-12-26 01:36:23 +03:00
print "\tPlaintext pwd: %s" % secrets.get_machine_password(domain)
if secrets.get_machine_last_change_time(domain):
print "\tLast Changed: %lu" % secrets.get_machine_last_change_time(domain)
if secrets.get_machine_sec_channel_type(domain):
print "\tSecure Channel Type: %d\n" % secrets.get_machine_sec_channel_type(domain)
print "Trusted domains:"
for td in secrets.trusted_domains():
print td
2007-12-24 04:19:41 +03:00
def print_samba3_regdb(regdb):
2007-12-26 01:36:23 +03:00
print_header("Registry")
2007-12-27 05:55:05 +03:00
from registry import str_regtype
2007-12-24 04:19:41 +03:00
2007-12-26 01:36:23 +03:00
for k in regdb.keys():
2007-12-27 05:55:05 +03:00
print "[%s]" % k
for (value_name, (type, value)) in regdb.values(k).items():
print "\"%s\"=%s:%s" % (value_name, str_regtype(type), value)
2007-12-24 04:19:41 +03:00
2007-12-24 23:16:59 +03:00
def print_samba3_winsdb(winsdb):
2007-12-26 01:36:23 +03:00
print_header("WINS Database")
2007-12-24 04:19:41 +03:00
2007-12-26 01:36:23 +03:00
for name in winsdb:
(ttl, ips, nb_flags) = winsdb[name]
print "%s, nb_flags: %s, ttl: %lu, %d ips, fst: %s" % (name, nb_flags, ttl, len(ips), ips[0])
2007-12-24 04:19:41 +03:00
def print_samba3_groupmappings(groupdb):
2007-12-26 01:36:23 +03:00
print_header("Group Mappings")
for sid in groupdb.groupsids():
print "\t--- Group: %s ---" % sid
2007-12-24 04:19:41 +03:00
def print_samba3_aliases(groupdb):
2007-12-26 01:36:23 +03:00
for sid in groupdb.aliases():
print "\t--- Alias: %s ---" % sid
2007-12-24 04:19:41 +03:00
def print_samba3_idmapdb(idmapdb):
2007-12-26 01:36:23 +03:00
print_header("Winbindd SID<->GID/UID mappings")
2007-12-24 04:19:41 +03:00
2007-12-26 01:36:23 +03:00
print "User High Water Mark: %d" % idmapdb.get_user_hwm()
print "Group High Water Mark: %d\n" % idmapdb.get_group_hwm()
2007-12-24 04:19:41 +03:00
2007-12-26 01:36:23 +03:00
for uid in idmapdb.uids():
print "%s -> UID %d" % (idmapdb.get_user_sid(uid), uid)
for gid in idmapdb.gids():
print "%s -> GID %d" % (idmapdb.get_group_sid(gid), gid)
2007-12-24 04:19:41 +03:00
def print_samba3(samba3):
2007-12-26 01:36:23 +03:00
print_samba3_policy(samba3.get_policy_db())
print_samba3_winsdb(samba3.get_wins_db())
print_samba3_regdb(samba3.get_registry())
print_samba3_secrets(samba3.get_secrets_db())
print_samba3_idmapdb(samba3.get_idmap_db())
print_samba3_sam(samba3.get_sam_db())
groupdb = samba3.get_groupmapping_db()
print_samba3_groupmappings(groupdb)
print_samba3_aliases(groupdb)
print_samba3_shares(samba3.get_shares())
2007-12-24 04:19:41 +03:00
def print_samba3_summary(samba3):
2007-12-26 01:36:23 +03:00
print "WINS db entries: %d" % len(samba3.get_wins_db())
print "Registry key count: %d" % len(samba3.get_registry())
groupdb = samba3.get_groupmapping_db()
print "Groupmap count: %d" % len(list(groupdb.groupsids()))
print "Alias count: %d" % len(list(groupdb.aliases()))
idmapdb = samba3.get_idmap_db()
print "Idmap count: %d" % (len(list(idmapdb.uids())) + len(list(idmapdb.gids())))
2007-12-24 23:16:59 +03:00
libdir = args[0]
if len(args) > 1:
2007-12-27 05:55:05 +03:00
smbconf = args[1]
2007-12-24 23:16:59 +03:00
else:
2007-12-26 01:36:23 +03:00
smbconf = os.path.join(libdir, "smb.conf")
2007-12-24 23:16:59 +03:00
samba3 = samba.samba3.Samba3(libdir, smbconf)
2007-12-24 04:19:41 +03:00
if opts.format == "summary":
2007-12-26 01:36:23 +03:00
print_samba3_summary(samba3)
2007-12-24 04:19:41 +03:00
elif opts.format == "full":
2007-12-26 01:36:23 +03:00
print_samba3(samba3)