summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2012-12-24 09:12:04 +1100
committerStefan Metzmacher <metze@samba.org>2013-09-04 07:06:05 +0200
commitd19c437a36b26e71c24bc25e672d714e21ba50bd (patch)
treefd2a8dcc0c68afa64670eb10d8c41ec7d5d80ec9 /source4
parentb106d9090e8f8f44f02059d2ced3d10066787060 (diff)
downloadsamba-d19c437a36b26e71c24bc25e672d714e21ba50bd.tar.gz
samba-d19c437a36b26e71c24bc25e672d714e21ba50bd.tar.bz2
samba-d19c437a36b26e71c24bc25e672d714e21ba50bd.zip
scripting/samba_upgradedns: Tighten up exception and attribute list handling
This avoids asking for attributes that will not be used, and looks only for the expected exceptions, rather than all exceptions. Andrew Bartlett Reviewed-by: Stefan Metzmacher <metze@samba.org> Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source4')
-rwxr-xr-xsource4/scripting/bin/samba_upgradedns19
1 files changed, 10 insertions, 9 deletions
diff --git a/source4/scripting/bin/samba_upgradedns b/source4/scripting/bin/samba_upgradedns
index 9c1a6b4d5a..6b208c927f 100755
--- a/source4/scripting/bin/samba_upgradedns
+++ b/source4/scripting/bin/samba_upgradedns
@@ -284,7 +284,7 @@ if __name__ == '__main__':
expression='(sAMAccountName=DnsAdmins)',
attrs=['objectSid'])
dnsadmins_sid = ndr_unpack(security.dom_sid, msg[0]['objectSid'][0])
- except Exception, e:
+ except IndexError:
logger.info("Adding DNS accounts")
add_dns_accounts(ldbs.sam, domaindn)
dnsadmins_sid = get_dnsadmins_sid(ldbs.sam, domaindn)
@@ -314,7 +314,7 @@ if __name__ == '__main__':
msg = ldbs.sam.search(base=names.configdn, scope=ldb.SCOPE_DEFAULT,
expression=expression, attrs=['nCName'])
ncname = msg[0]['nCName'][0]
- except Exception, e:
+ except IndexError:
logger.info("Creating DNS partitions")
logger.info("Looking up IPv4 addresses")
@@ -415,16 +415,17 @@ if __name__ == '__main__':
dn = 'samAccountName=dns-%s,CN=Principals' % hostname
msg = ldbs.secrets.search(expression='(dn=%s)' % dn, attrs=['secret'])
dnssecret = msg[0]['secret'][0]
- except Exception:
+ except IndexError:
+
logger.info("Adding dns-%s account" % hostname)
try:
msg = ldbs.sam.search(base=domaindn, scope=ldb.SCOPE_DEFAULT,
expression='(sAMAccountName=dns-%s)' % (hostname),
- attrs=['clearTextPassword'])
+ attrs=[])
dn = msg[0].dn
ldbs.sam.delete(dn)
- except Exception:
+ except IndexError:
pass
dnspass = samba.generate_random_password(128, 255)
@@ -472,9 +473,9 @@ if __name__ == '__main__':
# Check if dns-HOSTNAME account exists and delete it if required
try:
dn_str = 'samAccountName=dns-%s,CN=Principals' % hostname
- msg = ldbs.secrets.search(expression='(dn=%s)' % dn_str, attrs=['secret'])
+ msg = ldbs.secrets.search(expression='(dn=%s)' % dn_str, attrs=[])
dn = msg[0].dn
- except Exception:
+ except IndexError:
dn = None
if dn is not None:
@@ -486,9 +487,9 @@ if __name__ == '__main__':
try:
msg = ldbs.sam.search(base=domaindn, scope=ldb.SCOPE_DEFAULT,
expression='(sAMAccountName=dns-%s)' % (hostname),
- attrs=['clearTextPassword'])
+ attrs=[])
dn = msg[0].dn
- except Exception:
+ except IndexError:
dn = None
if dn is not None: