Commit 16efeb47 authored by Julien Cristau's avatar Julien Cristau

Use "not in" operator in various places ("foo not in bar" instead of "not foo in bar").

parent d429d921
......@@ -14,6 +14,8 @@ userdir-ldap (0.3.97) UNRELEASED; urgency=medium
[ Julien Cristau ]
* ud-mailgate: don't let punycode through.
* ud-generate: use subprocess.Popen instead of os.popen in GenCDB.
* Use "not in" operator in various places ("foo not in bar" instead of "not
foo in bar").
-- Peter Palfrader <weasel@debian.org> Sat, 06 Apr 2019 22:04:34 +0200
......
......@@ -46,7 +46,7 @@ try:
import simplejson as json
except ImportError:
import json
if not '__author__' in json.__dict__:
if '__author__' not in json.__dict__:
sys.stderr.write("Warning: This is probably the wrong json module. We want python 2.6's json\n")
sys.stderr.write("module, or simplejson on pytyon 2.5. Let's see if/how stuff blows up.\n")
......@@ -174,7 +174,7 @@ def IsInGroup(account, allowed, current_host):
if account.is_allowed_by_hostacl(current_host): return True
# See if there are supplementary groups
if not 'supplementaryGid' in account: return False
if 'supplementaryGid' not in account: return False
supgroups=[]
addGroups(supgroups, account['supplementaryGid'], account['uid'], current_host)
......@@ -353,7 +353,7 @@ def GenSSHGitolite(accounts, hosts, File, sshcommand=None, current_host=None):
if not GitoliteSSHRestrictions is None and GitoliteSSHRestrictions != "":
for a in accounts:
if not 'sshRSAAuthKey' in a: continue
if 'sshRSAAuthKey' not in a: continue
User = a['uid']
prefix = GitoliteSSHRestrictions
......@@ -375,7 +375,7 @@ def GenSSHGitolite(accounts, hosts, File, sshcommand=None, current_host=None):
F.write(line)
for dn, attrs in hosts:
if not 'sshRSAHostKey' in attrs: continue
if 'sshRSAHostKey' not in attrs: continue
hostname = "host-" + attrs['hostname'][0]
prefix = GitoliteSSHRestrictions
prefix = prefix.replace('@@COMMAND@@', sshcommand)
......@@ -397,7 +397,7 @@ def GenSSHShadow(global_dir, accounts):
userkeys = {}
for a in accounts:
if not 'sshRSAAuthKey' in a: continue
if 'sshRSAAuthKey' not in a: continue
contents = []
for I in a['sshRSAAuthKey']:
......@@ -416,7 +416,7 @@ def GenWebPassword(accounts, File):
os.umask(OldMask)
for a in accounts:
if not 'webPassword' in a: continue
if 'webPassword' not in a: continue
if not a.pw_active(): continue
Pass = str(a['webPassword'])
......@@ -438,7 +438,7 @@ def GenRtcPassword(accounts, File):
for a in accounts:
if a.is_guest_account(): continue
if not 'rtcPassword' in a: continue
if 'rtcPassword' not in a: continue
if not a.pw_active(): continue
Line = "%s%s:%s:%s:AUTHORIZED" % (a['uid'], rtc_append, str(a['rtcPassword']), rtc_realm)
......@@ -460,7 +460,7 @@ def GenTOTPSeed(accounts, File):
F.write("# Option User Prefix Seed\n")
for a in accounts:
if a.is_guest_account(): continue
if not 'totpSeed' in a: continue
if 'totpSeed' not in a: continue
if not a.pw_active(): continue
Line = "HOTP/T30/6 %s - %s" % (a['uid'], a['totpSeed'])
......@@ -573,7 +573,7 @@ def GenGroup(accounts, File, current_host):
# Sort them into a list of groups having a set of users
for a in accounts:
GroupHasPrimaryMembers[ a['gidNumber'] ] = True
if not 'supplementaryGid' in a: continue
if 'supplementaryGid' not in a: continue
supgroups=[]
addGroups(supgroups, a['supplementaryGid'], a['uid'], current_host)
......@@ -583,7 +583,7 @@ def GenGroup(accounts, File, current_host):
# Output the group file.
J = 0
for x in GroupMap.keys():
if not x in GroupIDMap:
if x not in GroupIDMap:
continue
if len(GroupMap[x]) == 0 and GroupIDMap[x] not in GroupHasPrimaryMembers:
......@@ -612,7 +612,7 @@ def GenGroup(accounts, File, current_host):
def CheckForward(accounts):
for a in accounts:
if not 'emailForward' in a: continue
if 'emailForward' not in a: continue
delete = False
......@@ -633,7 +633,7 @@ def GenForward(accounts, File):
os.umask(OldMask)
for a in accounts:
if not 'emailForward' in a: continue
if 'emailForward' not in a: continue
Line = "%s: %s" % (a['uid'], a['emailForward'])
Line = Sanitize(Line) + "\n"
F.write(Line)
......@@ -653,7 +653,7 @@ def GenCDB(accounts, File, key):
try:
# Write out the email address for each user
for a in accounts:
if not key in a: continue
if key not in a: continue
value = a[key]
user = a['uid']
Fdb.stdin.write("+%d,%d:%s->%s\n" % (len(user), len(value), user, value))
......@@ -679,7 +679,7 @@ def GenDBM(accounts, File, key):
# Write out the email address for each user
for a in accounts:
if not key in a: continue
if key not in a: continue
value = a[key]
user = a['uid']
Fdb[user] = value
......@@ -724,7 +724,7 @@ def GenPrivate(accounts, File):
for a in accounts:
if not a.is_active_user(): continue
if a.is_guest_account(): continue
if not 'privateSub' in a: continue
if 'privateSub' not in a: continue
try:
Line = "%s"%(a['privateSub'])
Line = Sanitize(Line) + "\n"
......@@ -766,7 +766,7 @@ def GenMailDisable(accounts, File):
F = open(File + ".tmp", "w")
for a in accounts:
if not 'mailDisableMessage' in a: continue
if 'mailDisableMessage' not in a: continue
Line = "%s: %s"%(a['uid'], a['mailDisableMessage'])
Line = Sanitize(Line) + "\n"
F.write(Line)
......@@ -784,7 +784,7 @@ def GenMailBool(accounts, File, key):
F = open(File + ".tmp", "w")
for a in accounts:
if not key in a: continue
if key not in a: continue
if not a[key] == 'TRUE': continue
Line = "%s"%(a['uid'])
Line = Sanitize(Line) + "\n"
......@@ -806,7 +806,7 @@ def GenMailList(accounts, File, key):
else: validregex = re.compile('^[-\w.]+$')
for a in accounts:
if not key in a: continue
if key not in a: continue
filtered = filter(lambda z: validregex.match(z), a[key])
if len(filtered) == 0: continue
......@@ -835,7 +835,7 @@ def GenDNS(accounts, File):
# Write out the zone file entry for each user
for a in accounts:
if not 'dnsZoneEntry' in a: continue
if 'dnsZoneEntry' not in a: continue
if not a.is_active_user() and not isRoleAccount(a): continue
if a.is_guest_account(): continue
......@@ -976,7 +976,7 @@ def GenBSMTP(accounts, File, HomePrefix):
# Write out the zone file entry for each user
for a in accounts:
if not 'dnsZoneEntry' in a: continue
if 'dnsZoneEntry' not in a: continue
if not a.is_active_user(): continue
try:
......@@ -1084,7 +1084,7 @@ def GenHosts(host_attrs, File):
if IsDebianHost.match(GetAttr(x, "hostname")) is None:
continue
if not 'ipHostNumber' in x[1]:
if 'ipHostNumber' not in x[1]:
continue
addrs = x[1]["ipHostNumber"]
......@@ -1224,7 +1224,7 @@ def generate_all(global_dir, ldap_conn):
GenForward(accounts, global_dir + "forward-alias")
GenAllUsers(accounts, global_dir + 'all-accounts.json')
accounts = filter(lambda a: not a in accounts_disabled, accounts)
accounts = filter(lambda a: a not in accounts_disabled, accounts)
ssh_userkeys = GenSSHShadow(global_dir, accounts)
GenMarkers(accounts, global_dir + "markers")
......@@ -1237,7 +1237,7 @@ def generate_all(global_dir, ldap_conn):
setup_group_maps(ldap_conn)
for host in host_attrs:
if not "hostname" in host[1]:
if "hostname" not in host[1]:
continue
generate_host(host, global_dir, accounts, host_attrs, ssh_userkeys)
......@@ -1283,11 +1283,11 @@ def generate_host(host, global_dir, all_accounts, all_hosts, ssh_userkeys):
# the relevant ssh keys
GenSSHtarballs(global_dir, userlist, ssh_userkeys, grouprevmap, os.path.join(OutDir, 'ssh-keys.tar.gz'), current_host)
if not 'NOPASSWD' in ExtraList:
if 'NOPASSWD' not in ExtraList:
GenShadow(accounts, OutDir + "shadow")
# Link in global things
if not 'NOMARKERS' in ExtraList:
if 'NOMARKERS' not in ExtraList:
DoLink(global_dir, OutDir, "markers")
DoLink(global_dir, OutDir, "mail-forward.cdb")
DoLink(global_dir, OutDir, "mail-forward.db")
......@@ -1332,7 +1332,7 @@ def generate_host(host, global_dir, all_accounts, all_hosts, ssh_userkeys):
options = v[1].split(',')
group = options.pop(0);
gitolite_accounts = filter(lambda x: IsInGroup(x, [group], current_host), all_accounts)
if not 'nohosts' in options:
if 'nohosts' not in options:
gitolite_hosts = filter(lambda x: GitoliteExportHosts.match(x[1]["hostname"][0]), all_hosts)
else:
gitolite_hosts = []
......
......@@ -209,7 +209,7 @@ print Ignored,"keys already in the directory (ignored)";
# Look for unmatched keys
for x in KeyMap.keys():
if KeyMap[x][1] == 0 and not x in pgpkeys_extra:
if KeyMap[x][1] == 0 and x not in pgpkeys_extra:
print "key %s belonging to %s removed"%(x,KeyMap[x][0]);
if KeyCount.has_key(KeyMap[x][0]) :
KeyCount[KeyMap[x][0]] = KeyCount[KeyMap[x][0]] - 1
......
......@@ -162,7 +162,7 @@ def do_accounts():
want = load_expected()
have = load_existing()
if not options.user in have.by_name:
if options.user not in have.by_name:
print >> sys.stderr, "Cannot find our user, '%s', in pts listentries"%(options.user)
sys.exit(1)
me = have.by_name[options.user]
......
......@@ -249,7 +249,7 @@ if GuestAccount:
shadowExpire = int(time.time() / 3600 / 24) + exp
res = raw_input("Hosts to grant access to: ")
for h in res.split():
if not '.' in h: h = h + '.' + HostDomain
if '.' not in h: h = h + '.' + HostDomain
if exp > 0: h = h + " " + datetime.datetime.fromtimestamp( time.time() + exp * 24*3600 ).strftime("%Y%m%d")
hostacl.append(h)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment