From a6fb69805c3999a85c064a96c93417bb1c284c5c Mon Sep 17 00:00:00 2001 From: Mark Hymers Date: Wed, 26 Dec 2007 20:49:42 +0000 Subject: [PATCH] * Remove use of deprecated functions from the string module --- debian/changelog | 3 ++- gpgwrapper | 12 ++++++------ sigcheck | 10 +++++----- ud-arbimport | 6 +++--- ud-echelon | 6 +++--- ud-emailmatcher | 26 +++++++++++++------------- ud-forwardlist | 8 ++++---- ud-generate | 36 ++++++++++++++++++------------------ ud-gpgimport | 12 ++++++------ ud-gpgsigfetch | 18 +++++++++--------- ud-groupadd | 2 +- ud-homecheck | 2 +- ud-host | 4 ++-- ud-info | 4 ++-- ud-ldapshow | 2 +- ud-mailgate | 26 +++++++++++++------------- ud-passchk | 4 ++-- ud-roleadd | 2 +- ud-sshlist | 6 +++--- ud-useradd | 2 +- ud-userimport | 15 +++++---------- ud-xearth | 2 +- userdir_gpg.py | 30 +++++++++++++++--------------- userdir_ldap.py | 24 ++++++++++++------------ 24 files changed, 129 insertions(+), 133 deletions(-) diff --git a/debian/changelog b/debian/changelog index b53129e..86b09e6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -18,8 +18,9 @@ userdir-ldap (0.3.15+xxx) XXunstable; urgency=low ud-{user,group,role}add and abstract them out into userdir_ldap.py * ud-useradd: Avoid a TypeError exception when constructing the template filename + * Remove use of deprecated functions from the string module - -- Mark Hymers Wed, 26 Dec 2007 18:00:08 +0000 + -- Mark Hymers Wed, 26 Dec 2007 20:49:18 +0000 userdir-ldap (0.3.15) unstable; urgency=low diff --git a/gpgwrapper b/gpgwrapper index 10f5d72..87ce632 100755 --- a/gpgwrapper +++ b/gpgwrapper @@ -41,7 +41,7 @@ # -e /etc/userdir-ldap/templtes/error-reply -- test.sh import sys, traceback, time, os; -import string, pwd, getopt; +import pwd, getopt; from userdir_gpg import *; EX_TEMPFAIL = 75; @@ -107,7 +107,7 @@ for (switch, val) in options: elif (switch == '-e'): ErrorTemplate = val; elif (switch == '-k'): - SetKeyrings(string.split(val,":")); + SetKeyrings(val.split(":")); elif (switch == '-a'): ReplyTo = val; elif (switch == '-d'): @@ -138,7 +138,7 @@ try: Msg = GetClearSig(Email); ErrMsg = "Message is not PGP signed:" - if string.find(Msg[0],"-----BEGIN PGP SIGNED MESSAGE-----") == -1: + if Msg[0].find("-----BEGIN PGP SIGNED MESSAGE-----") == -1: raise Error, "No PGP signature"; # Check the signature @@ -156,9 +156,9 @@ try: ErrMsg = "Problem stripping MIME headers from the decoded message" if Msg[1] == 1: try: - Index = string.index(Res[3],"\n\n") + 2; + Index = Res[3].index("\n\n") + 2; except ValueError: - Index = string.index(Res[3],"\n\r\n") + 3; + Index = Res[3].index("\n\r\n") + 3; PlainText = Res[3][Index:]; else: PlainText = Res[3]; @@ -193,7 +193,7 @@ try: os.environ["REPLYTO"] = Sender; # Invoke the child - Child = os.popen(string.join(arguments," "),"w"); + Child = os.popen(" ".join(arguments),"w"); Child.write(PlainText); if Child.close() != None: raise Error, "Child gave a non-zero return code"; diff --git a/sigcheck b/sigcheck index 95db708..57c4a90 100755 --- a/sigcheck +++ b/sigcheck @@ -25,7 +25,7 @@ # -e /etc/userdir-ldap/templtes/error-reply -- test.sh import sys, traceback, time, os; -import string, pwd, getopt; +import pwd, getopt; from userdir_gpg import *; EX_TEMPFAIL = 75; @@ -100,7 +100,7 @@ for (switch, val) in options: if (switch == '-r'): ReplayCacheFile = val; elif (switch == '-k'): - SetKeyrings(string.split(val,":")); + SetKeyrings(val.split(":")); elif (switch == '-d'): LDAPDn = val; elif (switch == '-l'): @@ -139,7 +139,7 @@ try: raise Error, "PGP/MIME disallowed"; ErrMsg = "Message is not PGP signed:" - if string.find(Msg[0],"-----BEGIN PGP SIGNED MESSAGE-----") == -1: + if Msg[0].find("-----BEGIN PGP SIGNED MESSAGE-----") == -1: raise Error, "No PGP signature"; # Check the signature @@ -171,8 +171,8 @@ try: while 1: Line = F.readline(); if Line == "": break; - if string.find(Res[3],string.strip(Line)) == -1: - raise Error,"Phrase '%s' was not found"%(string.strip(Line)); + if Res[3].find(Line.strip()) == -1: + raise Error,"Phrase '%s' was not found" % (Line.strip()) except: ErrMsg = "[%s] \"%s\" \"%s %s\"\n"%(Now,MsgID,ErrMsg,sys.exc_value); diff --git a/ud-arbimport b/ud-arbimport index ab3af80..5d5a37d 100755 --- a/ud-arbimport +++ b/ud-arbimport @@ -22,7 +22,7 @@ # the form of: # uid: -import string, re, time, ldap, getopt, sys; +import re, time, ldap, getopt, sys; from userdir_ldap import *; # Process options @@ -52,7 +52,7 @@ while(1): if User == None: User = Split[0]; if Split[0] == User: - Set.append(string.strip(Split[1])); + Set.append(Split[1].strip()); continue; else: if len(Set) == 0: @@ -74,4 +74,4 @@ while(1): if Line == "": break; User = Split[0]; - Set = [string.strip(Split[1])]; + Set = [Split[1].strip()]; diff --git a/ud-echelon b/ud-echelon index cdca2de..3632980 100755 --- a/ud-echelon +++ b/ud-echelon @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- mode: python -*- import userdir_gpg, userdir_ldap, sys, traceback, time, ldap, os, getopt; -import string, pwd +import pwd from userdir_gpg import *; from userdir_ldap import *; @@ -22,7 +22,7 @@ def TryGPG(Email): ErrLog.write(S); return None; - if string.find(Msg[0],"-----BEGIN PGP SIGNED MESSAGE-----") == -1: + if Msg[0].find("-----BEGIN PGP SIGNED MESSAGE-----") == -1: return None; Res = GPGCheckSig(Msg[0]); @@ -97,7 +97,7 @@ try: l = ldap.open(LDAPServer); if Debug == None: F = open(PassDir+"/pass-"+pwd.getpwuid(os.getuid())[0],"r"); - AccessPass = string.split(string.strip(F.readline())," "); + AccessPass = F.readline().strip().split(" ") l.simple_bind_s("uid="+AccessPass[0]+","+BaseDn,AccessPass[1]); F.close(); else: diff --git a/ud-emailmatcher b/ud-emailmatcher index daf76cd..bae8fd9 100755 --- a/ud-emailmatcher +++ b/ud-emailmatcher @@ -3,7 +3,7 @@ # This script tries to match a list of email addresses to the ldap database # uids. It makes use of the PGP key ring to determine matches -import string, re, time, ldap, getopt, sys; +import re, time, ldap, getopt, sys; from userdir_ldap import *; from userdir_gpg import *; @@ -13,14 +13,14 @@ AddressSplit = re.compile("(.*).*<([^@]*)@([^>]*)>"); def ImportForward(File,EmailMap): F = open(File,"r"); while(1): - Line = string.strip(F.readline()); + Line = F.readline().strip() if Line == "": break; - Split = string.split(Line,":"); + Split = Line.split(":") if len(Split) != 2: continue; - Addr = string.strip(Split[1]); + Addr = Split[1].strip() if EmailMap.has_key(Addr) and EmailMap[Addr] != Split[0]: print "Dup Over Emap",Line,Split else: @@ -34,12 +34,12 @@ def ImportOverride(File,OverMap): Line = F.readline(); if Line == "": break; - Line = string.strip(Line); + Line = Line.strip() - Split = string.split(Line,":"); + Split = Line.split(":") if len(Split) != 2: continue; - OverMap[Split[0]] = string.strip(Split[1]); + OverMap[Split[0]] = Split[1].strip() F.close(); (options, arguments) = getopt.getopt(sys.argv[1:], "o:f:") @@ -50,7 +50,7 @@ for x in arguments: Args.append("--keyring"); Args.append(x); Args = Args + GPGSearchOptions + [" 2> /dev/null"] -Keys = os.popen(string.join(Args," "),"r"); +Keys = os.popen(" ".join(Args),"r") l = ldap.open(LDAPServer); l.simple_bind_s("",""); @@ -80,7 +80,7 @@ while(1): if Line == "": break; - Split = string.split(Line,":"); + Split = Line.split(":") if len(Split) >= 8 and Split[0] == "pub": if FingerPrint != None and UID != None: for x in Emails: @@ -124,9 +124,9 @@ while(1): Line = sys.stdin.readline(); if Line == "": break; - Line = string.strip(Line); + Line = Line.strip() - Split = string.split(Line,"@"); + Split = Line.split("@") if len(Split) != 2: continue; @@ -134,7 +134,7 @@ while(1): if Split[1] == EmailAppend: if FinalMap.has_key(Line): print "Dup",Line - Split2 = string.split(Split[0],"-"); + Split2 = Split[0].split("-") FinalMap[Line] = Split2[0]; continue; @@ -146,7 +146,7 @@ while(1): continue; # Try again splitting off common address appendage modes - Split2 = string.split(Split[0],"-"); + Split2 = Split[0].split("-") Addr = Split2[0]+'@'+Split[1]; if EmailMap.has_key(Addr): if FinalMap.has_key(Addr): diff --git a/ud-forwardlist b/ud-forwardlist index 9e5e28a..727cfd9 100755 --- a/ud-forwardlist +++ b/ud-forwardlist @@ -12,12 +12,12 @@ # # It also understand .qmail type files -import string, re, time, getopt, os, sys, pwd, stat; +import re, time, getopt, os, sys, pwd, stat; AddressSplit = re.compile("<(.*)>"); while (1): - File = string.strip(sys.stdin.readline()); + File = sys.stdin.readline().strip() if File == "": break; @@ -32,7 +32,7 @@ while (1): Forward = open(File,"r"); Line = None; while (1): - Line2 = string.strip(Forward.readline()); + Line2 = Forward.readline().strip() if Line2 == "": break; if Line2[0] == '#' or Line2[0] == '\n': @@ -49,7 +49,7 @@ while (1): # Abort for funky things like pipes or directions to mailboxes if Line[0] == '/' or Line[0] == '|' or Line[0] == '.' or Line[-1] == '/' or \ - string.find(Line,'@') == -1: + Line.find('@') == -1: print "Invalid2", File; continue; diff --git a/ud-generate b/ud-generate index 3a9840b..2cc48aa 100755 --- a/ud-generate +++ b/ud-generate @@ -37,7 +37,7 @@ BSMTPCheck = re.compile(".*mx 0 (gluck)\.debian\.org\..*",re.DOTALL); DNSZone = ".debian.net" def Sanitize(Str): - return string.translate(Str,string.maketrans("\n\r\t","$$$")); + return Str.translate(string.maketrans("\n\r\t","$$$")) def DoLink(From,To,File): try: posix.remove(To+File); @@ -150,7 +150,7 @@ def GenShadow(l,File): # If the account is locked, mark it as such in shadow # See Debian Bug #308229 for why we set it to 1 instead of 0 - if (string.find(GetAttr(x,"userPassword"),"*LK*") != -1) \ + if (GetAttr(x,"userPassword").find("*LK*") != -1) \ or GetAttr(x,"userPassword").startswith("!"): ShadowExpire = '1' else: @@ -189,7 +189,7 @@ def GenSSHShadow(l,File): # If the account is locked, do not write it. # This is a partial stop-gap. The ssh also needs to change this # to ignore ~/.ssh/authorized* files. - if (string.find(GetAttr(x,"userPassword"),"*LK*") != -1) \ + if (GetAttr(x,"userPassword").find("*LK*") != -1) \ or GetAttr(x,"userPassword").startswith("!"): continue; @@ -374,7 +374,7 @@ def GenPrivate(l,File): continue; # If the account is locked, do not write it - if (string.find(GetAttr(x,"userPassword"),"*LK*") != -1) \ + if (GetAttr(x,"userPassword").find("*LK*") != -1) \ or GetAttr(x,"userPassword").startswith("!"): continue; @@ -419,7 +419,7 @@ def GenDisabledAccounts(l,File): Line = "" # *LK* is the reference value for a locked account # password starting with ! is also a locked account - if string.find(Pass,"*LK*") != -1 or Pass.startswith("!"): + if Pass.find("*LK*") != -1 or Pass.startswith("!"): # Format is : Line = "%s:%s" % (GetAttr(x,"uid"), "Account is locked") @@ -447,7 +447,7 @@ def GenMailDisable(l,File): Reason = None # If the account is locked, disable incoming mail - if (string.find(GetAttr(x,"userPassword"),"*LK*") != -1): + if (GetAttr(x,"userPassword").find("*LK*") != -1): if GetAttr(x,"uid") == "luther": continue else: @@ -586,12 +586,12 @@ def GenDNS(l,File,HomePrefix): try: F.write("; %s\n"%(EmailAddress(x))); for z in x[1]["dnsZoneEntry"]: - Split = string.split(string.lower(z)); - if string.lower(Split[1]) == 'in': + Split = z.lower().split() + if Split[1].lower() == 'in': for y in range(0,len(Split)): if Split[y] == "$": Split[y] = "\n\t"; - Line = string.join(Split," ") + "\n"; + Line = " ".join(Split) + "\n"; F.write(Line); Host = Split[0] + DNSZone; @@ -599,7 +599,7 @@ def GenDNS(l,File,HomePrefix): F.write("; Has BSMTP\n"); # Write some identification information - if string.lower(Split[2]) == "a": + if Split[2].lower() == "a": Line = "%s IN TXT \"%s\"\n"%(Split[0],EmailAddress(x)); for y in x[1]["keyFingerPrint"]: Line = Line + "%s IN TXT \"PGP %s\"\n"%(Split[0],FormatPGPKey(y)); @@ -637,7 +637,7 @@ def GenSSHFP(l,File,HomePrefix): Host = GetAttr(x,"hostname"); Algorithm = None for I in x[1]["sshRSAHostKey"]: - Split = string.split(I) + Split = I.split() if Split[0] == 'ssh-rsa': Algorithm = 1 if Split[0] == 'ssh-dss': @@ -675,12 +675,12 @@ def GenBSMTP(l,File,HomePrefix): continue; try: for z in x[1]["dnsZoneEntry"]: - Split = string.split(string.lower(z)); - if string.lower(Split[1]) == 'in': + Split = z.lower().split() + if Split[1].lower() == 'in': for y in range(0,len(Split)): if Split[y] == "$": Split[y] = "\n\t"; - Line = string.join(Split," ") + "\n"; + Line = " ".join(Split) + "\n"; Host = Split[0] + DNSZone; if BSMTPCheck.match(Line) != None: @@ -714,7 +714,7 @@ def GenSSHKnown(l,File): x[1].has_key("sshRSAHostKey") == 0: continue; Host = GetAttr(x,"hostname"); - SHost = string.find(Host,"."); + SHost = Host.find(".") for I in x[1]["sshRSAHostKey"]: if SHost == None: Line = "%s,%s %s" %(Host,socket.gethostbyname(Host),I); @@ -761,7 +761,7 @@ def GenHosts(l,File): # Connect to the ldap server l = ldap.open(LDAPServer); F = open(PassDir+"/pass-"+pwd.getpwuid(os.getuid())[0],"r"); -Pass = string.split(string.strip(F.readline())," "); +Pass = F.readline().strip().split(" ") F.close(); l.simple_bind_s("uid="+Pass[0]+","+BaseDn,Pass[1]); @@ -819,13 +819,13 @@ while(1): Line = F.readline(); if Line == "": break; - Line = string.strip(Line); + Line = Line.strip() if Line == "": continue; if Line[0] == '#': continue; - Split = string.split(Line," "); + Split = Line.split(" ") OutDir = GenerateDir + '/' + Split[0] + '/'; try: os.mkdir(OutDir); except: pass; diff --git a/ud-gpgimport b/ud-gpgimport index fd1a052..797aa5d 100755 --- a/ud-gpgimport +++ b/ud-gpgimport @@ -32,7 +32,7 @@ # in the directory but not in the key ring will be removed from the # directory. -import string, re, time, ldap, getopt, sys, pwd, os; +import re, time, ldap, getopt, sys, pwd, os; from userdir_ldap import *; from userdir_gpg import *; @@ -50,7 +50,7 @@ def LoadOverride(File): if Line == "": break; Split = re.split("[:\n]",Line); - UnknownMap[Split[0]] = string.strip(Split[1]); + UnknownMap[Split[0]] = Split[1].strip() # Process options AdminUser = pwd.getpwuid(os.getuid())[0]; @@ -108,12 +108,12 @@ print; Args = [GPGPath] + GPGBasicOptions; for x in arguments: Args.append("--keyring"); - if string.find(x,"/") == -1: + if x.find("/") == -1: Args.append("./"+x); else: Args.append(x); Args = Args + GPGSearchOptions + [" 2> /dev/null"] -Keys = os.popen(string.join(Args," "),"r"); +Keys = os.popen(" ".join(Args),"r"); # Loop over the GPG key file Outstanding = 0; @@ -124,7 +124,7 @@ while(1): if Line == "": break; - Split = string.split(Line,":"); + Split = Line.split(":") if len(Split) < 8 or Split[0] != "pub": continue; @@ -132,7 +132,7 @@ while(1): Line2 = Keys.readline(); if Line2 == "": break; - Split2 = string.split(Line2,":"); + Split2 = Line2.split(":"); if len(Split2) < 11 or Split2[0] != "fpr": continue; break; diff --git a/ud-gpgsigfetch b/ud-gpgsigfetch index 7e9ae13..4bca3cc 100755 --- a/ud-gpgsigfetch +++ b/ud-gpgsigfetch @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- mode: python -*- -import string, re, time, ldap, getopt, sys, pwd, os; +import re, time, ldap, getopt, sys, pwd, os; from userdir_gpg import *; Output = "extrakeys.gpg"; @@ -20,14 +20,14 @@ if len(arguments) == 0: Args = [GPGPath] + GPGBasicOptions; for x in arguments: Args.append("--keyring"); - if string.find(x,"/") == -1: + if x.find("/") == -1: Args.append("./"+x); else: Args.append(x); Args.append("--fast-list-mode"); Args.append("--list-sigs"); Args = Args + GPGSearchOptions + [" 2> /dev/null"] -Keys = os.popen(string.join(Args," "),"r"); +Keys = os.popen(" ".join(Args),"r"); # Loop over the GPG key file HaveKeys = {}; @@ -38,7 +38,7 @@ while(1): if Line == "": break; - Split = string.split(Line,":"); + Split = Line.split(":"); if len(Split) >= 8 and Split[0] == "pub": HaveKeys[Split[4]] = ""; continue; @@ -52,13 +52,13 @@ Keys.close(); Args = [GPGPath] + GPGBasicOptions; for x in [Output]: Args.append("--keyring"); - if string.find(x,"/") == -1: + if x.find("/") == -1: Args.append("./"+x); else: Args.append(x); OldArgs = Args; Args = Args + GPGSearchOptions + [" 2> /dev/null"] -Keys = os.popen(string.join(Args," "),"r"); +Keys = os.popen(" ".join(Args),"r"); print "Reading keys from output ring"; while(1): @@ -66,7 +66,7 @@ while(1): if Line == "": break; - Split = string.split(Line,":"); + Split = Line.split(":"); if len(Split) >= 8 and Split[0] == "pub": HaveKeys[Split[4]] = ""; continue; @@ -87,8 +87,8 @@ while (I > 0): OldI = I; I = I - 20; if I < 0: I = 0; - print string.join(Args+KeysToFetch[I:OldI]," ") - Fetcher = os.popen(string.join(Args+KeysToFetch[I:OldI]," "),"r"); + print " ".join(Args+KeysToFetch[I:OldI]) + Fetcher = os.popen(" ".join(Args+KeysToFetch[I:OldI]),"r"); while(1): Line = Fetcher.readline(); if Line == "": diff --git a/ud-groupadd b/ud-groupadd index b462b89..de074b9 100755 --- a/ud-groupadd +++ b/ud-groupadd @@ -19,7 +19,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -import string, re, time, ldap, getopt, sys, os, pwd; +import re, time, ldap, getopt, sys, os, pwd; from userdir_ldap import *; from userdir_gpg import *; diff --git a/ud-homecheck b/ud-homecheck index dda3410..ba463c1 100755 --- a/ud-homecheck +++ b/ud-homecheck @@ -3,7 +3,7 @@ # Checks a directory against the passwd file assuming it is the home # directory directory -import string, ldap, getopt, sys, os, pwd; +import ldap, getopt, sys, os, pwd; for x in os.listdir(sys.argv[1]): try: diff --git a/ud-host b/ud-host index ebcaa05..e186e9a 100755 --- a/ud-host +++ b/ud-host @@ -32,7 +32,7 @@ # -l list all hosts and their status # -f list all SSH fingerprints -import string, time, os, pwd, sys, getopt, ldap, crypt, readline, copy; +import time, os, pwd, sys, getopt, ldap, crypt, readline, copy; from tempfile import mktemp from os import O_CREAT, O_EXCL, O_WRONLY from userdir_ldap import *; @@ -170,7 +170,7 @@ def MultiChangeAttr(Attrs,Attr): Attrs[1][Attr].sort(); print "Old values: ",Attrs[1][Attr]; - Mode = string.upper(raw_input("[D]elete or [A]dd? ")); + Mode = raw_input("[D]elete or [A]dd? ").upper() if (Mode != 'D' and Mode != 'A'): return; diff --git a/ud-info b/ud-info index ac8f2af..8fde99a 100755 --- a/ud-info +++ b/ud-info @@ -17,7 +17,7 @@ # -r Enable 'root' functions, do this if your uid has access to # restricted variables. -import string, time, os, pwd, sys, getopt, ldap, crypt, readline, copy; +import time, os, pwd, sys, getopt, ldap, crypt, readline, copy; from userdir_ldap import *; RootMode = 0; @@ -229,7 +229,7 @@ def MultiChangeAttr(Attrs,Attr): Attrs[1][Attr].sort(); print "Old values: ",Attrs[1][Attr]; - Mode = string.upper(raw_input("[D]elete or [A]dd? ")); + Mode = raw_input("[D]elete or [A]dd? ").upper() if (Mode != 'D' and Mode != 'A'): return; diff --git a/ud-ldapshow b/ud-ldapshow index 0c54cb4..c397340 100755 --- a/ud-ldapshow +++ b/ud-ldapshow @@ -4,7 +4,7 @@ # Call with nokey to generate a missing key report # Call with noforward to generate a missing .forward report -import string, re, time, ldap, getopt, sys; +import re, time, ldap, getopt, sys; from userdir_ldap import *; def ShowDups(Attrs,Len): diff --git a/ud-mailgate b/ud-mailgate index 60baacd..cf82b56 100755 --- a/ud-mailgate +++ b/ud-mailgate @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- mode: python -*- import userdir_gpg, userdir_ldap, sys, traceback, time, ldap, os; -import string, pwd +import pwd from userdir_gpg import *; from userdir_ldap import *; @@ -195,7 +195,7 @@ def DoDel(Str,Attrs): # Handle a position change message, the line format is: # Lat: -12412.23 Long: +12341.2342 def DoPosition(Str,Attrs): - Match = re.match("^lat: ([+\-]?[\d:.ns]+(?: ?[ns])?) long: ([+\-]?[\d:.ew]+(?: ?[ew])?)$",string.lower(Str)); + Match = re.match("^lat: ([+\-]?[\d:.ns]+(?: ?[ns])?) long: ([+\-]?[\d:.ew]+(?: ?[ew])?)$", Str.lower()) if Match == None: return None; @@ -280,7 +280,7 @@ def DoDNS(Str,Attrs,DnRecord): # Handle an RBL list (mailRBL, mailRHSBL, mailWhitelist) def DoRBL(Str,Attrs): - Match = re.compile('^mail(rbl|rhsbl|whitelist) ([-a-z0-9.]+)$').match(string.lower(Str)) + Match = re.compile('^mail(rbl|rhsbl|whitelist) ([-a-z0-9.]+)$').match(Str.lower()) if Match == None: return None @@ -310,7 +310,7 @@ def HandleChange(Reply,DnRecord,Key): Attrs = []; Show = 0; for Line in Lines: - Line = string.strip(Line); + Line = Line.strip() if Line == "": continue; @@ -338,13 +338,13 @@ def HandleChange(Reply,DnRecord,Key): # Connect to the ldap server l = ldap.open(LDAPServer); F = open(PassDir+"/pass-"+pwd.getpwuid(os.getuid())[0],"r"); - AccessPass = string.split(string.strip(F.readline())," "); + AccessPass = F.readline().strip().split(" ") F.close(); # Modify the record l.simple_bind_s("uid="+AccessPass[0]+","+BaseDn,AccessPass[1]); oldAttrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid="+GetAttr(DnRecord,"uid")); - if ((string.find(GetAttr(oldAttrs[0],"userPassword"),"*LK*") != -1) + if ((GetAttr(oldAttrs[0],"userPassword").find("*LK*") != -1) or GetAttr(oldAttrs[0],"userPassword").startswith("!")): raise Error, "This account is locked"; Dn = "uid=" + GetAttr(DnRecord,"uid") + "," + BaseDn; @@ -409,13 +409,13 @@ def HandleChPass(Reply,DnRecord,Key): # Connect to the ldap server l = ldap.open(LDAPServer); F = open(PassDir+"/pass-"+pwd.getpwuid(os.getuid())[0],"r"); - AccessPass = string.split(string.strip(F.readline())," "); + AccessPass = F.readline().strip().split(" ") F.close(); l.simple_bind_s("uid="+AccessPass[0]+","+BaseDn,AccessPass[1]); # Check for a locked account Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid="+GetAttr(DnRecord,"uid")); - if (string.find(GetAttr(Attrs[0],"userPassword"),"*LK*") != -1) \ + if (GetAttr(Attrs[0],"userPassword").find("*LK*") != -1) \ or GetAttr(Attrs[0],"userPassword").startswith("!"): raise Error, "This account is locked"; @@ -448,8 +448,8 @@ try: Msg = GetClearSig(Email); ErrMsg = "Message is not PGP signed:" - if string.find(Msg[0],"-----BEGIN PGP SIGNED MESSAGE-----") == -1 and \ - string.find(Msg[0],"-----BEGIN PGP MESSAGE-----") == -1: + if Msg[0].find("-----BEGIN PGP SIGNED MESSAGE-----") == -1 and \ + Msg[0].find("-----BEGIN PGP MESSAGE-----") == -1: raise Error, "No PGP signature"; # Check the signature @@ -467,9 +467,9 @@ try: ErrMsg = "Problem stripping MIME headers from the decoded message" if Msg[1] == 1: try: - Index = string.index(Res[3],"\n\n") + 2; + Index = Res[3].index("\n\n") + 2; except ValueError: - Index = string.index(Res[3],"\n\r\n") + 3; + Index = Res[3].index("\n\r\n") + 3; PlainText = Res[3][Index:]; else: PlainText = Res[3]; @@ -514,7 +514,7 @@ try: if sys.argv[1] == "ping": Reply = HandlePing(Reply,Attrs[0],Res[2]); elif sys.argv[1] == "chpass": - if string.find(string.strip(PlainText),"Please change my Debian password") != 0: + if PlainText.strip().find("Please change my Debian password") != 0: raise Error,"Please send a signed message where the first line of text is the string 'Please change my Debian password'"; Reply = HandleChPass(Reply,Attrs[0],Res[2]); elif sys.argv[1] == "change": diff --git a/ud-passchk b/ud-passchk index e7c3cb7..6a7865a 100755 --- a/ud-passchk +++ b/ud-passchk @@ -2,7 +2,7 @@ # -*- mode: python -*- # Checks the passwd file to make sure all entries are in the directory -import string, ldap, getopt, sys, os; +import ldap, getopt, sys, os; from userdir_ldap import *; def PassCheck(l,File,HomePrefix): @@ -23,7 +23,7 @@ def PassCheck(l,File,HomePrefix): if Line == "": break; - Split = string.split(Line,":"); + Split = Line.split(":") if UIDMap.has_key(Split[0]) == 0: print Line, continue; diff --git a/ud-roleadd b/ud-roleadd index a3dc1b5..f6810f1 100755 --- a/ud-roleadd +++ b/ud-roleadd @@ -19,7 +19,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -import string, time, ldap, getopt, sys, os, pwd +import time, ldap, getopt, sys, os, pwd from userdir_ldap import * # This tries to search for a free UID. There are two possible ways to do diff --git a/ud-sshlist b/ud-sshlist index 279dc98..61f5f15 100755 --- a/ud-sshlist +++ b/ud-sshlist @@ -12,12 +12,12 @@ # # It also understand .qmail type files -import string, re, time, getopt, os, sys, pwd, stat; +import re, time, getopt, os, sys, pwd, stat; SSHAuthSplit = re.compile('^(.* )?(\d+) (\d+) (\d+) ?(.+)$'); while (1): - File = string.strip(sys.stdin.readline()); + File = sys.stdin.readline().strip() if File == "": break; @@ -32,7 +32,7 @@ while (1): Forward = open(File,"r"); Lines = []; while (1): - Line = string.strip(Forward.readline()); + Line = Forward.readline().strip() if Line == "": break; if Line[0] == '#' or Line[0] == '\n': diff --git a/ud-useradd b/ud-useradd index 8cc425b..494c348 100755 --- a/ud-useradd +++ b/ud-useradd @@ -19,7 +19,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -import string, re, time, ldap, getopt, sys, os, pwd; +import re, time, ldap, getopt, sys, os, pwd; from userdir_ldap import *; from userdir_gpg import *; diff --git a/ud-userimport b/ud-userimport index 4a21daf..3e926ec 100755 --- a/ud-userimport +++ b/ud-userimport @@ -37,7 +37,7 @@ # ldapimport -s /etc/shadow -g /etc/group # -import string, re, time, ldap, getopt, sys; +import re, time, ldap, getopt, sys; from userdir_ldap import *; DoAdd = 0; @@ -71,11 +71,6 @@ def ParseGecos(Field): Gecos[3] + "," + Gecos[4]; return (Field,cn,mn,sn); -# Check if a number string is really a number -def CheckNumber(Num): - for x in Num: - string.index(string.digits,x); - # Read the passwd file into the database def DoPasswd(l,Passwd): # Read the passwd file and import it @@ -88,8 +83,8 @@ def DoPasswd(l,Passwd): Split = re.split("[:\n]",Line); (Split[4],cn,mn,sn) = ParseGecos(Split[4]); - CheckNumber(Split[2]); - CheckNumber(Split[3]); + Split[2] = int(Split[2]) + Split[3] = int(Split[3]) Rec = [("uid",Split[0]), ("uidNumber",Split[2]), ("gidNumber",Split[3]), @@ -148,7 +143,7 @@ def DoShadow(l,Shadow): continue; for x in range(2,8): - CheckNumber(Split[x]); + Split[x] = int(Split[x]) Rec = [(ldap.MOD_REPLACE,"shadowLastChange",Split[2]), (ldap.MOD_REPLACE,"shadowMin",Split[3]), @@ -189,7 +184,7 @@ def DoGroup(l,Group): # Split up the group information Split = re.split("[:\n]",Line); Members = re.split("[, ]*",Split[3]); - CheckNumber(Split[2]); + Split[2] = int(Split[2]) # Iterate over the membership list and add the membership information # To the directory diff --git a/ud-xearth b/ud-xearth index 53f65bd..25e001a 100755 --- a/ud-xearth +++ b/ud-xearth @@ -14,7 +14,7 @@ # DGMS -> DD DDD + (MM + (SS.SSSSSS)/60)/60 # For Latitude + is North, for Longitude + is East -import string, re, time, ldap, getopt, sys, pwd, os, posix; +import re, time, ldap, getopt, sys, pwd, os, posix; from userdir_ldap import *; Anon = 0; diff --git a/userdir_gpg.py b/userdir_gpg.py index ab192c7..9b497b2 100644 --- a/userdir_gpg.py +++ b/userdir_gpg.py @@ -26,7 +26,7 @@ # packets so I can tell if a signature is made by pgp2 to enable the # pgp2 encrypting mode. -import string, mimetools, multifile, sys, StringIO, os, tempfile, re; +import mimetools, multifile, sys, StringIO, os, tempfile, re; import rfc822, time, fcntl, anydbm # General GPG options @@ -93,7 +93,7 @@ def GetClearSig(Msg,Paranoid = 0): while 1: x = mf.readline(); if not x: break; - if len(string.strip(x)) != 0: + if len(x.strip()) != 0: raise Error,"Unsigned text in message (at start)"; mf.seek(Pos); @@ -116,7 +116,7 @@ def GetClearSig(Msg,Paranoid = 0): InnerMsg = mimetools.Message(mf); if InnerMsg.gettype() != "application/pgp-signature": raise Error, "Invalid pgp/mime encoding [wrong signature type]"; - Signature = string.joinfields(mf.readlines(),''); + Signature = ''.join(mf.readlines()) # Check the last bit of the message.. if Paranoid != 0: @@ -125,7 +125,7 @@ def GetClearSig(Msg,Paranoid = 0): while 1: x = mf.readline(); if not x: break; - if len(string.strip(x)) != 0: + if len(x.strip()) != 0: raise Error,"Unsigned text in message (at end)"; mf.seek(Pos); @@ -134,20 +134,20 @@ def GetClearSig(Msg,Paranoid = 0): Output = "-----BEGIN PGP SIGNED MESSAGE-----\r\n"; # Semi-evil hack to get the proper hash type inserted in the message if Msg.getparam('micalg') != None: - Output = Output + "Hash: MD5,SHA1,%s\r\n"%(string.upper(Msg.getparam('micalg')[4:])); + Output = Output + "Hash: MD5,SHA1,%s\r\n"%(Msg.getparam('micalg')[4:].upper()) Output = Output + "\r\n"; - Output = Output + string.replace(Signed.getvalue(),"\n-","\n- -") + Signature; + Output = Output + Signed.getvalue().replace("\n-","\n- -") + Signature return (Output,1); else: if Paranoid == 0: # Just return the message body - return (string.joinfields(Msg.fp.readlines(),''),0); + return (''.join(Msg.fp.readlines()),0); Body = ""; State = 1; for x in Msg.fp.readlines(): Body = Body + x; - Tmp = string.strip(x); + Tmp = x.strip() if len(Tmp) == 0: continue; @@ -342,7 +342,7 @@ def GPGCheckSig(Message): if Why == None: GoodSig = 1; KeyID = Split[2]; - Owner = string.join(Split[3:],' '); + Owner = ' '.join(Split[3:]) # Bad signature response if Split[1] == "BADSIG": @@ -435,20 +435,20 @@ def GPGKeySearch(SearchCriteria): os.mkdir(dir, 0700) try: - Strm = os.popen(string.join(Args," "),"r"); + Strm = os.popen(" ".join(Args),"r") while(1): # Grab and split up line Line = Strm.readline(); if Line == "": break; - Split = string.split(Line,":"); - - # Store some of the key fields + Split = Line.split(":") + + # Store some of the key fields if Split[0] == 'pub': KeyID = Split[4]; Owner = Split[9]; - Length = int(Split[2]); + Length = int(Split[2]); # Output the key if Split[0] == 'fpr': @@ -471,7 +471,7 @@ def GPGPrintKeyInfo(Ident): # Perform a substition of template def TemplateSubst(Map,Template): for x in Map.keys(): - Template = string.replace(Template,x,Map[x]); + Template = Template.replace(x, Map[x]) return Template; # The replay class uses a python DB (BSD db if avail) to implement diff --git a/userdir_ldap.py b/userdir_ldap.py index 1b4299c..0ef1099 100644 --- a/userdir_ldap.py +++ b/userdir_ldap.py @@ -17,7 +17,7 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # Some routines and configuration that are used by the ldap progams -import termios, re, string, imp, ldap, sys, crypt, rfc822; +import termios, re, imp, ldap, sys, crypt, rfc822; import userdir_gpg try: @@ -42,7 +42,7 @@ Ech_ErrorLog = ConfModule.ech_errorlog; Ech_MainLog = ConfModule.ech_mainlog; # Break up the keyring list -userdir_gpg.SetKeyrings(string.split(ConfModule.keyrings,":")); +userdir_gpg.SetKeyrings(ConfModule.keyrings.split(":")) # This is a list of common last-name prefixes LastNamesPre = {"van": None, "von": None, "le": None, "de": None, "di": None}; @@ -146,7 +146,7 @@ def passwdAccessLDAP(LDAPServer, BaseDn, AdminUser): # Split up a name into multiple components. This tries to best guess how # to split up a name def NameSplit(Name): - Words = re.split(" ",string.strip(Name)); + Words = re.split(" ", Name.strip()) # Insert an empty middle name if (len(Words) == 2): @@ -176,7 +176,7 @@ def NameSplit(Name): Words.append(''); # Merge any of the last name prefixes into one big last name - while LastNamesPre.has_key(string.lower(Words[-2])): + while LastNamesPre.has_key(Words[-2].lower()): Words[-1] = Words[-2] + " " + Words[-1]; del Words[-2]; @@ -187,10 +187,10 @@ def NameSplit(Name): # If the name is multi-word then we glob them all into the last name and # do not worry about a middle name if (len(Words) > 3): - Words[2] = string.join(Words[1:]); + Words[2] = " ".join(Words[1:]) Words[1] = ""; - return (string.strip(Words[0]),string.strip(Words[1]),string.strip(Words[2])); + return (Words[0].strip(), Words[1].strip(), Words[2].strip()); # Compute a random password using /dev/urandom def GenPass(): @@ -247,7 +247,7 @@ def FlushOutstanding(l,Outstanding,Fast=0): # Convert a lat/long attribute into Decimal degrees def DecDegree(Posn,Anon=0): Parts = re.match('[-+]?(\d*)\\.?(\d*)',Posn).groups(); - Val = string.atof(Posn); + Val = float(Posn); if (abs(Val) >= 1806060.0): raise ValueError,"Too Big"; @@ -318,12 +318,12 @@ def FormatPGPKey(Str): I = I + 4; else: Res = Str; - return string.strip(Res); + return Res.strip() # Take an email address and split it into 3 parts, (Name,UID,Domain) def SplitEmail(Addr): # Is not an email address at all - if string.find(Addr,'@') == -1: + if Addr.find('@') == -1: return (Addr,"",""); Res1 = rfc822.AddrlistClass(Addr).getaddress(); @@ -335,7 +335,7 @@ def SplitEmail(Addr): # If there is no @ then the address was not parsed well. Try the alternate # Parsing scheme. This is particularly important when scanning PGP keys. - Res2 = string.split(Res1[1],"@"); + Res2 = Res1[1].split("@"); if len(Res2) != 2: Match = AddressSplit.match(Addr); if Match == None: @@ -396,8 +396,8 @@ def GetUID(l,Name,UnknownMap = {}): # deals with special purpose keys like 'James Troup (Alternate Debian key)' # Some people put their names backwards on their key too.. check that as well if len(Attrs) == 1 and \ - (string.find(string.lower(sn),string.lower(Attrs[0][1]["sn"][0])) != -1 or \ - string.find(string.lower(cn),string.lower(Attrs[0][1]["sn"][0])) != -1): + ( sn.lower().find(Attrs[0][1]["sn"][0].lower()) != -1 or \ + cn.lower().find(Attrs[0][1]["sn"][0].lower()) != -1 ): Stat = EmailAppend+" hit for "+str(Name); return (Name[1],[Stat]); -- 2.20.1