summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2012-09-16 14:18:39 +0200
committerJelmer Vernooij <jelmer@samba.org>2012-09-16 14:20:11 +0200
commit0ff2ea56d97cd8df7abeea8e819d7ec0bfd5b886 (patch)
tree1804f2fb23c7335a52c0300a798e17aa2616a18f
parentebcb6a744791478bfc4be0b94733ace540ab06bc (diff)
downloadsamba-0ff2ea56d97cd8df7abeea8e819d7ec0bfd5b886.tar.gz
samba-0ff2ea56d97cd8df7abeea8e819d7ec0bfd5b886.tar.bz2
samba-0ff2ea56d97cd8df7abeea8e819d7ec0bfd5b886.zip
samba.netcmd: Formatting fixes, break lines.
-rw-r--r--source4/scripting/python/samba/netcmd/delegation.py20
-rw-r--r--source4/scripting/python/samba/netcmd/dns.py137
-rw-r--r--source4/scripting/python/samba/netcmd/domain.py164
-rw-r--r--source4/scripting/python/samba/netcmd/sites.py5
-rw-r--r--source4/scripting/python/samba/netcmd/spn.py31
-rw-r--r--source4/scripting/python/samba/netcmd/testparm.py20
-rw-r--r--source4/scripting/python/samba/netcmd/time.py3
-rw-r--r--source4/scripting/python/samba/netcmd/user.py23
8 files changed, 209 insertions, 194 deletions
diff --git a/source4/scripting/python/samba/netcmd/delegation.py b/source4/scripting/python/samba/netcmd/delegation.py
index 7296624879..25ae2028c4 100644
--- a/source4/scripting/python/samba/netcmd/delegation.py
+++ b/source4/scripting/python/samba/netcmd/delegation.py
@@ -55,7 +55,7 @@ class cmd_delegation_show(Command):
# TODO once I understand how, use the domain info to naildown
# to the correct domain
(cleanedaccount, realm, domain) = _get_user_realm_domain(accountname)
-
+
res = sam.search(expression="sAMAccountName=%s" %
ldb.binary_encode(cleanedaccount),
scope=ldb.SCOPE_SUBTREE,
@@ -63,7 +63,7 @@ class cmd_delegation_show(Command):
if len(res) == 0:
raise CommandError("Unable to find account name '%s'" % accountname)
assert(len(res) == 1)
-
+
uac = int(res[0].get("userAccountControl")[0])
allowed = res[0].get("msDS-AllowedToDelegateTo")
@@ -91,7 +91,8 @@ class cmd_delegation_for_any_service(Command):
takes_args = ["accountname", "onoff"]
- def run(self, accountname, onoff, credopts=None, sambaopts=None, versionopts=None):
+ def run(self, accountname, onoff, credopts=None, sambaopts=None,
+ versionopts=None):
on = False
if onoff == "on":
@@ -133,7 +134,8 @@ class cmd_delegation_for_any_protocol(Command):
takes_args = ["accountname", "onoff"]
- def run(self, accountname, onoff, credopts=None, sambaopts=None, versionopts=None):
+ def run(self, accountname, onoff, credopts=None, sambaopts=None,
+ versionopts=None):
on = False
if onoff == "on":
@@ -175,7 +177,8 @@ class cmd_delegation_add_service(Command):
takes_args = ["accountname", "principal"]
- def run(self, accountname, principal, credopts=None, sambaopts=None, versionopts=None):
+ def run(self, accountname, principal, credopts=None, sambaopts=None,
+ versionopts=None):
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp)
@@ -192,7 +195,7 @@ class cmd_delegation_add_service(Command):
attrs=["msDS-AllowedToDelegateTo"])
if len(res) == 0:
raise CommandError("Unable to find account name '%s'" % accountname)
- assert(len(res) == 1)
+ assert(len(res) == 1)
msg = ldb.Message()
msg.dn = res[0].dn
@@ -218,7 +221,8 @@ class cmd_delegation_del_service(Command):
takes_args = ["accountname", "principal"]
- def run(self, accountname, principal, credopts=None, sambaopts=None, versionopts=None):
+ def run(self, accountname, principal, credopts=None, sambaopts=None,
+ versionopts=None):
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp)
@@ -235,7 +239,7 @@ class cmd_delegation_del_service(Command):
attrs=["msDS-AllowedToDelegateTo"])
if len(res) == 0:
raise CommandError("Unable to find account name '%s'" % accountname)
- assert(len(res) == 1)
+ assert(len(res) == 1)
msg = ldb.Message()
msg.dn = res[0].dn
diff --git a/source4/scripting/python/samba/netcmd/dns.py b/source4/scripting/python/samba/netcmd/dns.py
index 8a79de08d8..b227e96080 100644
--- a/source4/scripting/python/samba/netcmd/dns.py
+++ b/source4/scripting/python/samba/netcmd/dns.py
@@ -35,6 +35,7 @@ def dns_connect(server, lp, creds):
dns_conn = dnsserver.dnsserver(binding_str, lp, creds)
return dns_conn
+
def bool_string(flag):
if flag == 0:
ret = 'FALSE'
@@ -44,6 +45,7 @@ def bool_string(flag):
ret = 'UNKNOWN (0x%x)' % flag
return ret
+
def enum_string(module, enum_defs, value):
ret = None
for e in enum_defs:
@@ -54,6 +56,7 @@ def enum_string(module, enum_defs, value):
ret = 'UNKNOWN (0x%x)' % value
return ret
+
def bitmap_string(module, bitmap_defs, value):
ret = ''
for b in bitmap_defs:
@@ -63,42 +66,50 @@ def bitmap_string(module, bitmap_defs, value):
ret = 'NONE'
return ret
+
def boot_method_string(boot_method):
enum_defs = [ 'DNS_BOOT_METHOD_UNINITIALIZED', 'DNS_BOOT_METHOD_FILE',
'DNS_BOOT_METHOD_REGISTRY', 'DNS_BOOT_METHOD_DIRECTORY' ]
return enum_string(dnsserver, enum_defs, boot_method)
+
def name_check_flag_string(check_flag):
enum_defs = [ 'DNS_ALLOW_RFC_NAMES_ONLY', 'DNS_ALLOW_NONRFC_NAMES',
'DNS_ALLOW_MULTIBYTE_NAMES', 'DNS_ALLOW_ALL_NAMES' ]
return enum_string(dnsserver, enum_defs, check_flag)
+
def zone_type_string(zone_type):
enum_defs = [ 'DNS_ZONE_TYPE_CACHE', 'DNS_ZONE_TYPE_PRIMARY',
'DNS_ZONE_TYPE_SECONDARY', 'DNS_ZONE_TYPE_STUB',
'DNS_ZONE_TYPE_FORWARDER', 'DNS_ZONE_TYPE_SECONDARY_CACHE' ]
return enum_string(dnsp, enum_defs, zone_type)
+
def zone_update_string(zone_update):
enum_defs = [ 'DNS_ZONE_UPDATE_OFF', 'DNS_ZONE_UPDATE_SECURE',
'DNS_ZONE_UPDATE_SECURE' ]
return enum_string(dnsp, enum_defs, zone_update)
+
def zone_secondary_security_string(security):
enum_defs = [ 'DNS_ZONE_SECSECURE_NO_SECURITY', 'DNS_ZONE_SECSECURE_NS_ONLY',
'DNS_ZONE_SECSECURE_LIST_ONLY', 'DNS_ZONE_SECSECURE_NO_XFER' ]
return enum_string(dnsserver, enum_defs, security)
+
def zone_notify_level_string(notify_level):
enum_defs = [ 'DNS_ZONE_NOTIFY_OFF', 'DNS_ZONE_NOTIFY_ALL_SECONDARIES',
'DNS_ZONE_NOTIFY_LIST_ONLY' ]
return enum_string(dnsserver, enum_defs, notify_level)
+
def dp_flags_string(dp_flags):
bitmap_defs = [ 'DNS_DP_AUTOCREATED', 'DNS_DP_LEGACY', 'DNS_DP_DOMAIN_DEFAULT',
'DNS_DP_FOREST_DEFAULT', 'DNS_DP_ENLISTED', 'DNS_DP_DELETED' ]
return bitmap_string(dnsserver, bitmap_defs, dp_flags)
+
def zone_flags_string(flags):
bitmap_defs = [ 'DNS_RPC_ZONE_PAUSED', 'DNS_RPC_ZONE_SHUTDOWN',
'DNS_RPC_ZONE_REVERSE', 'DNS_RPC_ZONE_AUTOCREATED',
@@ -107,6 +118,7 @@ def zone_flags_string(flags):
'DNS_RPC_ZONE_READONLY']
return bitmap_string(dnsserver, bitmap_defs, flags)
+
def ip4_array_string(array):
ret = []
if not array:
@@ -116,6 +128,7 @@ def ip4_array_string(array):
ret.append(addr)
return ret
+
def dns_addr_array_string(array):
ret = []
if not array:
@@ -132,6 +145,7 @@ def dns_addr_array_string(array):
ret.append(addr)
return ret
+
def dns_type_flag(rec_type):
rtype = rec_type.upper()
if rtype == 'A':
@@ -158,6 +172,7 @@ def dns_type_flag(rec_type):
raise CommandError('Unknown type of DNS record %s' % rec_type)
return record_type
+
def dns_client_version(cli_version):
version = cli_version.upper()
if version == 'W2K':
@@ -170,6 +185,7 @@ def dns_client_version(cli_version):
raise CommandError('Unknown client version %s' % cli_version)
return client_version
+
def print_serverinfo(outf, typeid, serverinfo):
outf.write(' dwVersion : 0x%x\n' % serverinfo.dwVersion)
outf.write(' fBootMethod : %s\n' % boot_method_string(serverinfo.fBootMethod))
@@ -384,7 +400,9 @@ class ARecord(dnsserver.DNS_RPC_RECORD):
self._ip_addr = ip_addr[:]
self.data = self._ip_addr
+
class AAAARecord(dnsserver.DNS_RPC_RECORD):
+
def __init__(self, ip6_addr, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
node_flag=0):
super(AAAARecord, self).__init__()
@@ -395,7 +413,9 @@ class AAAARecord(dnsserver.DNS_RPC_RECORD):
self._ip6_addr = ip6_addr[:]
self.data = self._ip6_addr
+
class PTRRecord(dnsserver.DNS_RPC_RECORD):
+
def __init__(self, ptr, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
node_flag=0):
super(PTRRecord, self).__init__()
@@ -409,7 +429,9 @@ class PTRRecord(dnsserver.DNS_RPC_RECORD):
ptr_name.len = len(ptr)
self.data = ptr_name
+
class CNameRecord(dnsserver.DNS_RPC_RECORD):
+
def __init__(self, cname, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
node_flag=0):
super(CNameRecord, self).__init__()
@@ -423,7 +445,9 @@ class CNameRecord(dnsserver.DNS_RPC_RECORD):
cname_name.len = len(cname)
self.data = cname_name
+
class NSRecord(dnsserver.DNS_RPC_RECORD):
+
def __init__(self, dns_server, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
node_flag=0):
super(NSRecord, self).__init__()
@@ -437,7 +461,9 @@ class NSRecord(dnsserver.DNS_RPC_RECORD):
ns.len = len(dns_server)
self.data = ns
+
class MXRecord(dnsserver.DNS_RPC_RECORD):
+
def __init__(self, mail_server, preference, serial=1, ttl=900,
rank=dnsp.DNS_RANK_ZONE, node_flag=0):
super(MXRecord, self).__init__()
@@ -452,7 +478,9 @@ class MXRecord(dnsserver.DNS_RPC_RECORD):
mx.nameExchange.len = len(mail_server)
self.data = mx
+
class SOARecord(dnsserver.DNS_RPC_RECORD):
+
def __init__(self, mname, rname, serial=1, refresh=900, retry=600,
expire=86400, minimum=3600, ttl=3600, rank=dnsp.DNS_RANK_ZONE,
node_flag=dnsp.DNS_RPC_FLAG_AUTH_ZONE_ROOT):
@@ -474,7 +502,9 @@ class SOARecord(dnsserver.DNS_RPC_RECORD):
soa.ZoneAdministratorEmail.len = len(rname)
self.data = soa
+
class SRVRecord(dnsserver.DNS_RPC_RECORD):
+
def __init__(self, target, port, priority=0, weight=100, serial=1, ttl=900,
rank=dnsp.DNS_RANK_ZONE, node_flag=0):
super(SRVRecord, self).__init__()
@@ -491,7 +521,9 @@ class SRVRecord(dnsserver.DNS_RPC_RECORD):
srv.nameTarget.len = len(target)
self.data = srv
+
class TXTRecord(dnsserver.DNS_RPC_RECORD):
+
def __init__(self, slist, serial=1, ttl=900, rank=dnsp.DNS_RANK_ZONE,
node_flag=0):
super(TXTRecord, self).__init__()
@@ -576,16 +608,9 @@ def dns_record_match(dns_conn, server, zone, name, record_type, data):
select_flags = dnsserver.DNS_RPC_VIEW_AUTHORITY_DATA
try:
- buflen, res = dns_conn.DnssrvEnumRecords2(dnsserver.DNS_CLIENT_VERSION_LONGHORN,
- 0,
- server,
- zone,
- name,
- None,
- record_type,
- select_flags,
- None,
- None)
+ buflen, res = dns_conn.DnssrvEnumRecords2(
+ dnsserver.DNS_CLIENT_VERSION_LONGHORN, 0, server, zone, name, None,
+ record_type, select_flags, None, None)
except RuntimeError, e:
return None
@@ -667,18 +692,16 @@ class cmd_serverinfo(Command):
choices=['w2k','dotnet','longhorn'], dest='cli_ver'),
]
- def run(self, server, cli_ver, sambaopts=None, credopts=None, versionopts=None):
+ def run(self, server, cli_ver, sambaopts=None, credopts=None,
+ versionopts=None):
self.lp = sambaopts.get_loadparm()
self.creds = credopts.get_credentials(self.lp)
dns_conn = dns_connect(server, self.lp, self.creds)
client_version = dns_client_version(cli_ver)
- typeid, res = dns_conn.DnssrvQuery2(client_version,
- 0,
- server,
- None,
- 'ServerInfo')
+ typeid, res = dns_conn.DnssrvQuery2(client_version, 0, server,
+ None, 'ServerInfo')
print_serverinfo(self.outf, typeid, res)
@@ -701,17 +724,15 @@ class cmd_zoneinfo(Command):
choices=['w2k','dotnet','longhorn'], dest='cli_ver'),
]
- def run(self, server, zone, cli_ver, sambaopts=None, credopts=None, versionopts=None):
+ def run(self, server, zone, cli_ver, sambaopts=None, credopts=None,
+ versionopts=None):
self.lp = sambaopts.get_loadparm()
self.creds = credopts.get_credentials(self.lp)
dns_conn = dns_connect(server, self.lp, self.creds)
client_version = dns_client_version(cli_ver)
- typeid, res = dns_conn.DnssrvQuery2(client_version,
- 0,
- server,
- zone,
+ typeid, res = dns_conn.DnssrvQuery2(client_version, 0, server, zone,
'ZoneInfo')
print_zoneinfo(self.outf, typeid, res)
@@ -783,9 +804,7 @@ class cmd_zonelist(Command):
client_version = dns_client_version(cli_ver)
typeid, res = dns_conn.DnssrvComplexOperation2(client_version,
- 0,
- server,
- None,
+ 0, server, None,
'EnumZones',
dnsserver.DNSSRV_TYPEID_DWORD,
request_filter)
@@ -850,13 +869,8 @@ class cmd_zonecreate(Command):
zone_create_info.fAging = 0
zone_create_info.dwDpFlags = dnsserver.DNS_DP_DOMAIN_DEFAULT
- res = dns_conn.DnssrvOperation2(client_version,
- 0,
- server,
- None,
- 0,
- 'ZoneCreate',
- typeid,
+ res = dns_conn.DnssrvOperation2(client_version, 0, server, None,
+ 0, 'ZoneCreate', typeid,
zone_create_info)
self.outf.write('Zone %s created successfully\n' % zone)
@@ -874,7 +888,8 @@ class cmd_zonedelete(Command):
"credopts": options.CredentialsOptions,
}
- def run(self, server, zone, sambaopts=None, credopts=None, versionopts=None):
+ def run(self, server, zone, sambaopts=None, credopts=None,
+ versionopts=None):
self.lp = sambaopts.get_loadparm()
self.creds = credopts.get_credentials(self.lp)
@@ -882,11 +897,7 @@ class cmd_zonedelete(Command):
zone = zone.lower()
res = dns_conn.DnssrvOperation2(dnsserver.DNS_CLIENT_VERSION_LONGHORN,
- 0,
- server,
- zone,
- 0,
- 'DeleteZoneFromDs',
+ 0, server, zone, 0, 'DeleteZoneFromDs',
dnsserver.DNSSRV_TYPEID_NULL,
None)
self.outf.write('Zone %s delete successfully\n' % zone)
@@ -922,9 +933,10 @@ class cmd_query(Command):
action='store_true', dest='only_children')
]
- def run(self, server, zone, name, rtype, authority=False, cache=False, glue=False,
- root=False, additional=False, no_children=False, only_children=False,
- sambaopts=None, credopts=None, versionopts=None):
+ def run(self, server, zone, name, rtype, authority=False, cache=False,
+ glue=False, root=False, additional=False, no_children=False,
+ only_children=False, sambaopts=None, credopts=None,
+ versionopts=None):
record_type = dns_type_flag(rtype)
select_flags = 0
@@ -955,16 +967,9 @@ class cmd_query(Command):
self.creds = credopts.get_credentials(self.lp)
dns_conn = dns_connect(server, self.lp, self.creds)
- buflen, res = dns_conn.DnssrvEnumRecords2(dnsserver.DNS_CLIENT_VERSION_LONGHORN,
- 0,
- server,
- zone,
- name,
- None,
- record_type,
- select_flags,
- None,
- None)
+ buflen, res = dns_conn.DnssrvEnumRecords2(
+ dnsserver.DNS_CLIENT_VERSION_LONGHORN, 0, server, zone, name,
+ None, record_type, select_flags, None, None)
print_dnsrecords(self.outf, res)
@@ -981,7 +986,8 @@ class cmd_roothints(Command):
"credopts": options.CredentialsOptions,
}
- def run(self, server, name='.', sambaopts=None, credopts=None, versionopts=None):
+ def run(self, server, name='.', sambaopts=None, credopts=None,
+ versionopts=None):
record_type = dnsp.DNS_TYPE_NS
select_flags = (dnsserver.DNS_RPC_VIEW_ROOT_HINT_DATA |
dnsserver.DNS_RPC_VIEW_ADDITIONAL_DATA)
@@ -990,16 +996,9 @@ class cmd_roothints(Command):
self.creds = credopts.get_credentials(self.lp)
dns_conn = dns_connect(server, self.lp, self.creds)
- buflen, res = dns_conn.DnssrvEnumRecords2(dnsserver.DNS_CLIENT_VERSION_LONGHORN,
- 0,
- server,
- '..RootHints',
- name,
- None,
- record_type,
- select_flags,
- None,
- None)
+ buflen, res = dns_conn.DnssrvEnumRecords2(
+ dnsserver.DNS_CLIENT_VERSION_LONGHORN, 0, server, '..RootHints',
+ name, None, record_type, select_flags, None, None)
print_dnsrecords(self.outf, res)
@@ -1027,7 +1026,8 @@ class cmd_add_record(Command):
"credopts": options.CredentialsOptions,
}
- def run(self, server, zone, name, rtype, data, sambaopts=None, credopts=None, versionopts=None):
+ def run(self, server, zone, name, rtype, data, sambaopts=None,
+ credopts=None, versionopts=None):
if rtype.upper() not in ('A','AAAA','PTR','CNAME','NS','MX','SRV','TXT'):
raise CommandError('Adding record of type %s is not supported' % rtype)
@@ -1039,7 +1039,8 @@ class cmd_add_record(Command):
self.creds = credopts.get_credentials(self.lp)
dns_conn = dns_connect(server, self.lp, self.creds)
- rec_match = dns_record_match(dns_conn, server, zone, name, record_type, data)
+ rec_match = dns_record_match(dns_conn, server, zone, name, record_type,
+ data)
if rec_match is not None:
raise CommandError('Record already exists')
@@ -1047,12 +1048,7 @@ class cmd_add_record(Command):
add_rec_buf.rec = rec
dns_conn.DnssrvUpdateRecord2(dnsserver.DNS_CLIENT_VERSION_LONGHORN,
- 0,
- server,
- zone,
- name,
- add_rec_buf,
- None)
+ 0, server, zone, name, add_rec_buf, None)
self.outf.write('Record added successfully\n')
@@ -1093,7 +1089,8 @@ class cmd_update_record(Command):
self.creds = credopts.get_credentials(self.lp)
dns_conn = dns_connect(server, self.lp, self.creds)
- rec_match = dns_record_match(dns_conn, server, zone, name, record_type, olddata)
+ rec_match = dns_record_match(dns_conn, server, zone, name, record_type,
+ olddata)
if not rec_match:
raise CommandError('Record does not exist')
diff --git a/source4/scripting/python/samba/netcmd/domain.py b/source4/scripting/python/samba/netcmd/domain.py
index 0ace70fc9a..0954f63400 100644
--- a/source4/scripting/python/samba/netcmd/domain.py
+++ b/source4/scripting/python/samba/netcmd/domain.py
@@ -22,8 +22,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-
-
import samba.getopt as options
import ldb
import string
@@ -127,15 +125,16 @@ class cmd_domain_info(Command):
lp = sambaopts.get_loadparm()
try:
res = netcmd_get_domain_infos_via_cldap(lp, None, address)
- print "Forest : %s" % res.forest
- print "Domain : %s" % res.dns_domain
- print "Netbios domain : %s" % res.domain_name
- print "DC name : %s" % res.pdc_dns_name
- print "DC netbios name : %s" % res.pdc_name
- print "Server site : %s" % res.server_site
- print "Client site : %s" % res.client_site
except RuntimeError:
raise CommandError("Invalid IP address '" + address + "'!")
+ self.outf.write("Forest : %s\n" % res.forest)
+ self.outf.write("Domain : %s\n" % res.dns_domain)
+ self.outf.write("Netbios domain : %s\n" % res.domain_name)
+ self.outf.write("DC name : %s\n" % res.pdc_dns_name)
+ self.outf.write("DC netbios name : %s\n" % res.pdc_name)
+ self.outf.write("Server site : %s\n" % res.server_site)
+ self.outf.write("Client site : %s\n" % res.client_site)
+
class cmd_domain_provision(Command):
"""Promotes an existing domain member or NT4 PDC to an AD DC"""
@@ -220,38 +219,38 @@ class cmd_domain_provision(Command):
takes_args = []
def run(self, sambaopts=None, credopts=None, versionopts=None,
- interactive = None,
- domain = None,
- domain_guid = None,
- domain_sid = None,
- ntds_guid = None,
- invocationid = None,
- host_name = None,
- host_ip = None,
- host_ip6 = None,
- adminpass = None,
- krbtgtpass = None,
- machinepass = None,
- dns_backend = None,
- dns_forwarder = None,
- dnspass = None,
- ldapadminpass = None,
- root = None,
- nobody = None,
- wheel = None,
- users = None,
- quiet = None,
- blank = None,
- ldap_backend_type = None,
- server_role = None,
- function_level = None,
- next_rid = None,
- partitions_only = None,
- targetdir = None,
- ol_mmr_urls = None,
- use_xattrs = None,
- use_ntvfs = None,
- use_rfc2307 = None):
+ interactive=None,
+ domain=None,
+ domain_guid=None,
+ domain_sid=None,
+ ntds_guid=None,
+ invocationid=None,
+ host_name=None,
+ host_ip=None,
+ host_ip6=None,
+ adminpass=None,
+ krbtgtpass=None,
+ machinepass=None,
+ dns_backend=None,
+ dns_forwarder=None,
+ dnspass=None,
+ ldapadminpass=None,
+ root=None,
+ nobody=None,
+ wheel=None,
+ users=None,
+ quiet=None,
+ blank=None,
+ ldap_backend_type=None,
+ server_role=None,
+ function_level=None,
+ next_rid=None,
+ partitions_only=None,
+ targetdir=None,
+ ol_mmr_urls=None,
+ use_xattrs=None,
+ use_ntvfs=None,
+ use_rfc2307=None):
self.logger = self.get_logger("provision")
if quiet:
@@ -313,11 +312,11 @@ class cmd_domain_provision(Command):
while True:
adminpassplain = getpass("Administrator password: ")
if not adminpassplain:
- print >>sys.stderr, "Invalid administrator password."
+ self.errf.write("Invalid administrator password.\n")
else:
adminpassverify = getpass("Retype password: ")
if not adminpassplain == adminpassverify:
- print >>sys.stderr, "Sorry, passwords do not match."
+ self.errf.write("Sorry, passwords do not match.\n")
else:
adminpass = adminpassplain
break
@@ -422,7 +421,6 @@ class cmd_domain_provision(Command):
handle.close()
self.logger.warning("No nameserver found in %s" % RESOLV_CONF)
- return None
class cmd_domain_dcpromo(Command):
@@ -477,16 +475,15 @@ class cmd_domain_dcpromo(Command):
join_DC(server=server, creds=creds, lp=lp, domain=domain,
site=site, netbios_name=netbios_name, targetdir=targetdir,
domain_critical_only=domain_critical_only,
- machinepass=machinepass, use_ntvfs=use_ntvfs, dns_backend=dns_backend,
+ machinepass=machinepass, use_ntvfs=use_ntvfs,
+ dns_backend=dns_backend,
promote_existing=True)
- return
elif role == "RODC":
join_RODC(server=server, creds=creds, lp=lp, domain=domain,
site=site, netbios_name=netbios_name, targetdir=targetdir,
domain_critical_only=domain_critical_only,
machinepass=machinepass, use_ntvfs=use_ntvfs, dns_backend=dns_backend,
promote_existing=True)
- return
else:
raise CommandError("Invalid role '%s' (possible values: DC, RODC)" % role)
@@ -541,38 +538,35 @@ class cmd_domain_join(Command):
role = role.upper()
if role is None or role == "MEMBER":
- (join_password, sid, domain_name) = net.join_member(domain,
- netbios_name,
- LIBNET_JOIN_AUTOMATIC,
- machinepass=machinepass)
+ (join_password, sid, domain_name) = net.join_member(
+ domain, netbios_name, LIBNET_JOIN_AUTOMATIC,
+ machinepass=machinepass)
- self.outf.write("Joined domain %s (%s)\n" % (domain_name, sid))
- return
+ self.errf.write("Joined domain %s (%s)\n" % (domain_name, sid))
elif role == "DC":
join_DC(server=server, creds=creds, lp=lp, domain=domain,
site=site, netbios_name=netbios_name, targetdir=targetdir,
domain_critical_only=domain_critical_only,
machinepass=machinepass, use_ntvfs=use_ntvfs, dns_backend=dns_backend)
- return
elif role == "RODC":
join_RODC(server=server, creds=creds, lp=lp, domain=domain,
site=site, netbios_name=netbios_name, targetdir=targetdir,
domain_critical_only=domain_critical_only,
- machinepass=machinepass, use_ntvfs=use_ntvfs, dns_backend=dns_backend)
- return
+ machinepass=machinepass, use_ntvfs=use_ntvfs,
+ dns_backend=dns_backend)
elif role == "SUBDOMAIN":
netbios_domain = lp.get("workgroup")
if parent_domain is None:
parent_domain = ".".join(domain.split(".")[1:])
- join_subdomain(server=server, creds=creds, lp=lp, dnsdomain=domain, parent_domain=parent_domain,
- site=site, netbios_name=netbios_name, netbios_domain=netbios_domain, targetdir=targetdir,
- machinepass=machinepass, use_ntvfs=use_ntvfs, dns_backend=dns_backend)
- return
+ join_subdomain(server=server, creds=creds, lp=lp, dnsdomain=domain,
+ parent_domain=parent_domain, site=site,
+ netbios_name=netbios_name, netbios_domain=netbios_domain,
+ targetdir=targetdir, machinepass=machinepass,
+ use_ntvfs=use_ntvfs, dns_backend=dns_backend)
else:
raise CommandError("Invalid role '%s' (possible values: MEMBER, DC, RODC, SUBDOMAIN)" % role)
-
class cmd_domain_demote(Command):
"""Demote ourselves from the role of Domain Controller"""
@@ -612,9 +606,9 @@ class cmd_domain_demote(Command):
break
ntds_guid = samdb.get_ntds_GUID()
- msg = samdb.search(base=str(samdb.get_config_basedn()), scope=ldb.SCOPE_SUBTREE,
- expression="(objectGUID=%s)" % ntds_guid,
- attrs=['options'])
+ msg = samdb.search(base=str(samdb.get_config_basedn()),
+ scope=ldb.SCOPE_SUBTREE, expression="(objectGUID=%s)" % ntds_guid,
+ attrs=['options'])
if len(msg) == 0 or "options" not in msg[0]:
raise CommandError("Failed to find options on %s" % ntds_guid)
@@ -627,10 +621,11 @@ class cmd_domain_demote(Command):
if len(res) != 0:
raise CommandError("Current DC is still the owner of %d role(s), use the role command to transfer roles to another DC" % len(res))
- print "Using %s as partner server for the demotion" % server
+ self.errf.write("Using %s as partner server for the demotion\n" %
+ server)
(drsuapiBind, drsuapi_handle, supportedExtensions) = drsuapi_connect(server, lp, creds)
- print "Desactivating inbound replication"
+ self.errf.write("Desactivating inbound replication\n")
nmsg = ldb.Message()
nmsg.dn = msg[0].dn
@@ -641,14 +636,17 @@ class cmd_domain_demote(Command):
if not (dsa_options & DS_NTDSDSA_OPT_DISABLE_OUTBOUND_REPL) and not samdb.am_rodc():
- print "Asking partner server %s to synchronize from us" % server
+ self.errf.write("Asking partner server %s to synchronize from us\n"
+ % server)
for part in (samdb.get_schema_basedn(),
samdb.get_config_basedn(),
samdb.get_root_basedn()):
try:
sendDsReplicaSync(drsuapiBind, drsuapi_handle, ntds_guid, str(part), drsuapi.DRSUAPI_DRS_WRIT_REP)
except drsException, e:
- print "Error while demoting, re-enabling inbound replication"
+ self.errf.write(
+ "Error while demoting, "
+ "re-enabling inbound replication\n")
dsa_options ^= DS_NTDSDSA_OPT_DISABLE_INBOUND_REPL
nmsg["options"] = ldb.MessageElement(str(dsa_options), ldb.FLAG_MOD_REPLACE, "options")
samdb.modify(nmsg)
@@ -658,7 +656,7 @@ class cmd_domain_demote(Command):
session_info=system_session(),
credentials=creds, lp=lp)
- print "Changing userControl and container"
+ self.errf.write("Changing userControl and container\n")
res = remote_samdb.search(base=str(remote_samdb.get_root_basedn()),
expression="(&(objectClass=user)(sAMAccountName=%s$))" %
netbios_name.upper(),
@@ -667,14 +665,16 @@ class cmd_domain_demote(Command):
uac = int(str(res[0]["userAccountControl"]))
except Exception, e:
- print "Error while demoting, re-enabling inbound replication"
- dsa_options ^= DS_NTDSDSA_OPT_DISABLE_INBOUND_REPL
- nmsg["options"] = ldb.MessageElement(str(dsa_options), ldb.FLAG_MOD_REPLACE, "options")
- samdb.modify(nmsg)
- raise CommandError("Error while changing account control", e)
+ self.errf.write(
+ "Error while demoting, re-enabling inbound replication\n")
+ dsa_options ^= DS_NTDSDSA_OPT_DISABLE_INBOUND_REPL
+ nmsg["options"] = ldb.MessageElement(str(dsa_options), ldb.FLAG_MOD_REPLACE, "options")
+ samdb.modify(nmsg)
+ raise CommandError("Error while changing account control", e)
if (len(res) != 1):
- print "Error while demoting, re-enabling inbound replication"
+ self.errf.write(
+ "Error while demoting, re-enabling inbound replication")
dsa_options ^= DS_NTDSDSA_OPT_DISABLE_INBOUND_REPL
nmsg["options"] = ldb.MessageElement(str(dsa_options), ldb.FLAG_MOD_REPLACE, "options")
samdb.modify(nmsg)
@@ -695,7 +695,8 @@ class cmd_domain_demote(Command):
try:
remote_samdb.modify(msg)
except Exception, e:
- print "Error while demoting, re-enabling inbound replication"
+ self.errf.write(
+ "Error while demoting, re-enabling inbound replication")
dsa_options ^= DS_NTDSDSA_OPT_DISABLE_INBOUND_REPL
nmsg["options"] = ldb.MessageElement(str(dsa_options), ldb.FLAG_MOD_REPLACE, "options")
samdb.modify(nmsg)
@@ -721,7 +722,8 @@ class cmd_domain_demote(Command):
scope=ldb.SCOPE_ONELEVEL)
if i == 100:
- print "Error while demoting, re-enabling inbound replication"
+ self.errf.write(
+ "Error while demoting, re-enabling inbound replication\n")
dsa_options ^= DS_NTDSDSA_OPT_DISABLE_INBOUND_REPL
nmsg["options"] = ldb.MessageElement(str(dsa_options), ldb.FLAG_MOD_REPLACE, "options")
samdb.modify(nmsg)
@@ -745,7 +747,8 @@ class cmd_domain_demote(Command):
newdn = ldb.Dn(remote_samdb, "%s,%s" % (newrdn, str(computer_dn)))
remote_samdb.rename(dc_dn, newdn)
except Exception, e:
- print "Error while demoting, re-enabling inbound replication"
+ self.errf.write(
+ "Error while demoting, re-enabling inbound replication\n")
dsa_options ^= DS_NTDSDSA_OPT_DISABLE_INBOUND_REPL
nmsg["options"] = ldb.MessageElement(str(dsa_options), ldb.FLAG_MOD_REPLACE, "options")
samdb.modify(nmsg)
@@ -767,7 +770,8 @@ class cmd_domain_demote(Command):
try:
sendRemoveDsServer(drsuapiBind, drsuapi_handle, server_dsa_dn, domain)
except drsException, e:
- print "Error while demoting, re-enabling inbound replication"
+ self.errf.write(
+ "Error while demoting, re-enabling inbound replication\n")
dsa_options ^= DS_NTDSDSA_OPT_DISABLE_INBOUND_REPL
nmsg["options"] = ldb.MessageElement(str(dsa_options), ldb.FLAG_MOD_REPLACE, "options")
samdb.modify(nmsg)
@@ -802,7 +806,7 @@ class cmd_domain_demote(Command):
except ldb.LdbError, l:
pass
- self.outf.write("Demote successfull\n")
+ self.errf.write("Demote successfull\n")
class cmd_domain_level(Command):
diff --git a/source4/scripting/python/samba/netcmd/sites.py b/source4/scripting/python/samba/netcmd/sites.py
index 49a9f9d189..bf644f0551 100644
--- a/source4/scripting/python/samba/netcmd/sites.py
+++ b/source4/scripting/python/samba/netcmd/sites.py
@@ -16,8 +16,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-
-
import os
from samba import sites
from samba.samdb import SamDB
@@ -92,7 +90,8 @@ class cmd_sites_delete(Command):
samdb.transaction_commit()
except sites.SiteException, e:
samdb.transaction_cancel()
- raise CommandError("Error while removing site %s, error: %s" % (sitename, str(e)))
+ raise CommandError(
+ "Error while removing site %s, error: %s" % (sitename, str(e)))
self.outf.write("Site %s removed!\n" % sitename)
diff --git a/source4/scripting/python/samba/netcmd/spn.py b/source4/scripting/python/samba/netcmd/spn.py
index 29fc4cefcc..79fa69912e 100644
--- a/source4/scripting/python/samba/netcmd/spn.py
+++ b/source4/scripting/python/samba/netcmd/spn.py
@@ -53,9 +53,9 @@ class cmd_spn_list(Command):
# to the correct domain
(cleaneduser, realm, domain) = _get_user_realm_domain(user)
self.outf.write(cleaneduser+"\n")
- res = sam.search(expression="samaccountname=%s" % ldb.binary_encode(cleaneduser),
- scope=ldb.SCOPE_SUBTREE,
- attrs=["servicePrincipalName"])
+ res = sam.search(
+ expression="samaccountname=%s" % ldb.binary_encode(cleaneduser),
+ scope=ldb.SCOPE_SUBTREE, attrs=["servicePrincipalName"])
if len(res) >0:
spns = res[0].get("servicePrincipalName")
found = False
@@ -89,23 +89,24 @@ class cmd_spn_add(Command):
]
takes_args = ["name", "user"]
- def run(self, name, user, force=False, credopts=None, sambaopts=None, versionopts=None):
+ def run(self, name, user, force=False, credopts=None, sambaopts=None,
+ versionopts=None):
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp)
paths = provision.provision_paths_from_lp(lp, lp.get("realm"))
sam = SamDB(paths.samdb, session_info=system_session(),
credentials=creds, lp=lp)
- res = sam.search(expression="servicePrincipalName=%s" % ldb.binary_encode(name),
- scope=ldb.SCOPE_SUBTREE,
- )
+ res = sam.search(
+ expression="servicePrincipalName=%s" % ldb.binary_encode(name),
+ scope=ldb.SCOPE_SUBTREE)
if len(res) != 0 and not force:
raise CommandError("Service principal %s already"
" affected to another user" % name)
(cleaneduser, realm, domain) = _get_user_realm_domain(user)
- res = sam.search(expression="samaccountname=%s" % ldb.binary_encode(cleaneduser),
- scope=ldb.SCOPE_SUBTREE,
- attrs=["servicePrincipalName"])
+ res = sam.search(
+ expression="samaccountname=%s" % ldb.binary_encode(cleaneduser),
+ scope=ldb.SCOPE_SUBTREE, attrs=["servicePrincipalName"])
if len(res) >0:
res[0].dn
msg = ldb.Message()
@@ -145,15 +146,17 @@ class cmd_spn_delete(Command):
takes_args = ["name", "user?"]
- def run(self, name, user=None, credopts=None, sambaopts=None, versionopts=None):
+ def run(self, name, user=None, credopts=None, sambaopts=None,
+ versionopts=None):
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp)
paths = provision.provision_paths_from_lp(lp, lp.get("realm"))
sam = SamDB(paths.samdb, session_info=system_session(),
credentials=creds, lp=lp)
- res = sam.search(expression="servicePrincipalName=%s" % ldb.binary_encode(name),
- scope=ldb.SCOPE_SUBTREE,
- attrs=["servicePrincipalName", "samAccountName"])
+ res = sam.search(
+ expression="servicePrincipalName=%s" % ldb.binary_encode(name),
+ scope=ldb.SCOPE_SUBTREE,
+ attrs=["servicePrincipalName", "samAccountName"])
if len(res) >0:
result = None
if user is not None:
diff --git a/source4/scripting/python/samba/netcmd/testparm.py b/source4/scripting/python/samba/netcmd/testparm.py
index 5cb75e27ae..53357e4dff 100644
--- a/source4/scripting/python/samba/netcmd/testparm.py
+++ b/source4/scripting/python/samba/netcmd/testparm.py
@@ -70,11 +70,10 @@ class cmd_testparm(Command):
takes_args = []
- def run(self, sambaopts, versionopts,
- section_name=None, parameter_name=None,
- client_ip=None, client_name=None, verbose=False,
- suppress_prompt=None,
- show_all_parameters=False, server=None):
+ def run(self, sambaopts, versionopts, section_name=None,
+ parameter_name=None, client_ip=None, client_name=None,
+ verbose=False, suppress_prompt=None, show_all_parameters=False,
+ server=None):
if server:
raise NotImplementedError("--server not yet implemented")
if show_all_parameters:
@@ -100,7 +99,8 @@ class cmd_testparm(Command):
else:
if section_name is not None or parameter_name is not None:
if parameter_name is None:
- lp[section_name].dump(sys.stdout, lp.default_service, verbose)
+ lp[section_name].dump(sys.stdout, lp.default_service,
+ verbose)
else:
self.outf.write(lp.get(parameter_name, section_name)+"\n")
else:
@@ -148,8 +148,9 @@ class cmd_testparm(Command):
valid = False
if winbind_separator == '+':
- logger.error("'winbind separator = +' might cause problems with group "
- "membership.")
+ logger.error(
+ "'winbind separator = +' might cause problems with group "
+ "membership.")
valid = False
return valid
@@ -161,7 +162,8 @@ class cmd_testparm(Command):
valid = True
for s in lp.services():
if len(s) > 12:
- logger.warning("You have some share names that are longer than 12 "
+ logger.warning(
+ "You have some share names that are longer than 12 "
"characters. These may not be accessible to some older "
"clients. (Eg. Windows9x, WindowsMe, and not listed in "
"smbclient in Samba 3.0.)")
diff --git a/source4/scripting/python/samba/netcmd/time.py b/source4/scripting/python/samba/netcmd/time.py
index 92a7025fae..8f186bda99 100644
--- a/source4/scripting/python/samba/netcmd/time.py
+++ b/source4/scripting/python/samba/netcmd/time.py
@@ -49,7 +49,8 @@ Example2 return the date and time of the local server.
takes_args = ["server_name?"]
- def run(self, server_name=None, credopts=None, sambaopts=None, versionopts=None):
+ def run(self, server_name=None, credopts=None, sambaopts=None,
+ versionopts=None):
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp, fallback_machine=True)
net = Net(creds, lp, server=credopts.ipaddress)
diff --git a/source4/scripting/python/samba/netcmd/user.py b/source4/scripting/python/samba/netcmd/user.py
index 6ba6150004..1172f4efd3 100644
--- a/source4/scripting/python/samba/netcmd/user.py
+++ b/source4/scripting/python/samba/netcmd/user.py
@@ -107,11 +107,13 @@ Example3 shows how to create a new user in the OrgUnit organizational unit.
}
def run(self, username, password=None, credopts=None, sambaopts=None,
- versionopts=None, H=None, must_change_at_next_login=False, random_password=False,
- use_username_as_cn=False, userou=None, surname=None, given_name=None, initials=None,
- profile_path=None, script_path=None, home_drive=None, home_directory=None,
+ versionopts=None, H=None, must_change_at_next_login=False,
+ random_password=False, use_username_as_cn=False, userou=None,
+ surname=None, given_name=None, initials=None, profile_path=None,
+ script_path=None, home_drive=None, home_directory=None,
job_title=None, department=None, company=None, description=None,
- mail_address=None, internet_address=None, telephone_number=None, physical_delivery_office=None):
+ mail_address=None, internet_address=None, telephone_number=None,
+ physical_delivery_office=None):
if random_password:
password = generate_random_password(128, 255)
@@ -131,8 +133,7 @@ Example3 shows how to create a new user in the OrgUnit organizational unit.
try:
samdb = SamDB(url=H, session_info=system_session(),
credentials=creds, lp=lp)
- samdb.newuser(username, password,
- force_password_change_at_next_login_req=must_change_at_next_login,
+ samdb.newuser(username, password, force_password_change_at_next_login_req=must_change_at_next_login,
useusernameascn=use_username_as_cn, userou=userou, surname=surname, givenname=given_name, initials=initials,
profilepath=profile_path, homedrive=home_drive, scriptpath=script_path, homedirectory=home_directory,
jobtitle=job_title, department=department, company=company, description=description,
@@ -147,10 +148,13 @@ Example3 shows how to create a new user in the OrgUnit organizational unit.
class cmd_user_add(cmd_user_create):
__doc__ = cmd_user_create.__doc__
# take this print out after the add subcommand is removed.
- # the add subcommand is deprecated but left in for now to allow people to migrate to create
+ # the add subcommand is deprecated but left in for now to allow people to
+ # migrate to create
def run(self, *args, **kwargs):
- self.err.write("\nNote: samba-tool user add is deprecated. Please use samba-tool user create for the same function.\n")
+ self.err.write(
+ "Note: samba-tool user add is deprecated. "
+ "Please use samba-tool user create for the same function.\n")
return super(self, cmd_user_add).run(*args, **kwargs)
@@ -188,7 +192,8 @@ Example2 shows how to delete a user in the domain against the local server. su
"versionopts": options.VersionOptions,
}
- def run(self, username, credopts=None, sambaopts=None, versionopts=None, H=None):
+ def run(self, username, credopts=None, sambaopts=None, versionopts=None,
+ H=None):
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp, fallback_machine=True)