3 # Generates passwd, shadow and group files from the ldap directory.
5 # Copyright (c) 2000-2001 Jason Gunthorpe <jgg@debian.org>
6 # Copyright (c) 2003-2004 James Troup <troup@debian.org>
7 # Copyright (c) 2004-2005,7 Joey Schulze <joey@infodrom.org>
8 # Copyright (c) 2001-2007 Ryan Murray <rmurray@debian.org>
9 # Copyright (c) 2008 Peter Palfrader <peter@palfrader.org>
10 # Copyright (c) 2008 Andreas Barth <aba@not.so.argh.org>
11 # Copyright (c) 2008 Mark Hymers <mhy@debian.org>
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 import string, re, time, ldap, getopt, sys, os, pwd, posix, socket, base64, sha, shutil, errno, tarfile, grp
28 from userdir_ldap import *;
38 EmailCheck = re.compile("^([^ <>@]+@[^ ,<>@]+)?$");
39 BSMTPCheck = re.compile(".*mx 0 (gluck)\.debian\.org\..*",re.DOTALL);
40 DNSZone = ".debian.net"
41 Keyrings = [ "/org/keyring.debian.org/keyrings/debian-keyring.gpg",
42 "/org/keyring.debian.org/keyrings/debian-keyring.pgp" ]
44 def safe_makedirs(dir):
48 if e.errno == errno.EEXIST:
57 if e.errno == errno.ENOENT:
63 return Str.translate(string.maketrans("\n\r\t","$$$"))
65 def DoLink(From,To,File):
66 try: posix.remove(To+File);
68 posix.link(From+File,To+File);
70 # See if this user is in the group list
71 def IsInGroup(DnRecord):
75 # See if the primary group is in the list
76 if Allowed.has_key(GetAttr(DnRecord,"gidNumber")) != 0:
79 # Check the host based ACL
80 if DnRecord[1].has_key("allowedHost") != 0:
81 for I in DnRecord[1]["allowedHost"]:
85 # See if there are supplementary groups
86 if DnRecord[1].has_key("supplementaryGid") == 0:
89 # Check the supplementary groups
90 for I in DnRecord[1]["supplementaryGid"]:
91 if Allowed.has_key(I):
100 try: os.remove(File + ".tmp");
102 try: os.remove(File + ".tdb.tmp");
105 def Done(File,F,Fdb):
108 os.rename(File + ".tmp",File);
111 os.rename(File + ".tdb.tmp",File+".tdb");
113 # Generate the password list
114 def GenPasswd(l,File,HomePrefix,PwdMarker):
117 F = open(File + ".tdb.tmp","w");
120 # Fetch all the users
122 if PasswdAttrs == None:
126 for x in PasswdAttrs:
127 if x[1].has_key("uidNumber") == 0 or IsInGroup(x) == 0:
130 # Do not let people try to buffer overflow some busted passwd parser.
131 if len(GetAttr(x,"gecos")) > 100 or len(GetAttr(x,"loginShell")) > 50:
134 userlist[GetAttr(x, "uid")] = int(GetAttr(x, "gidNumber"))
135 Line = "%s:%s:%s:%s:%s:%s%s:%s" % (GetAttr(x,"uid"),\
137 GetAttr(x,"uidNumber"),GetAttr(x,"gidNumber"),\
138 GetAttr(x,"gecos"),HomePrefix,GetAttr(x,"uid"),\
139 GetAttr(x,"loginShell"));
141 Line = Sanitize(Line) + "\n";
142 F.write("0%u %s" % (I,Line));
143 F.write(".%s %s" % (GetAttr(x,"uid"),Line));
144 F.write("=%s %s" % (GetAttr(x,"uidNumber"),Line));
147 # Oops, something unspeakable happened.
153 # Return the list of users so we know which keys to export
156 # Generate the shadow list
157 def GenShadow(l,File):
160 OldMask = os.umask(0077);
161 F = open(File + ".tdb.tmp","w",0600);
164 # Fetch all the users
166 if PasswdAttrs == None:
170 for x in PasswdAttrs:
171 if x[1].has_key("uidNumber") == 0 or IsInGroup(x) == 0:
174 Pass = GetAttr(x,"userPassword");
175 if Pass[0:7] != "{crypt}" or len(Pass) > 50:
180 # If the account is locked, mark it as such in shadow
181 # See Debian Bug #308229 for why we set it to 1 instead of 0
182 if (GetAttr(x,"userPassword").find("*LK*") != -1) \
183 or GetAttr(x,"userPassword").startswith("!"):
186 ShadowExpire = GetAttr(x,"shadowexpire")
188 Line = "%s:%s:%s:%s:%s:%s:%s:%s:" % (GetAttr(x,"uid"),\
189 Pass,GetAttr(x,"shadowLastChange"),\
190 GetAttr(x,"shadowMin"),GetAttr(x,"shadowMax"),\
191 GetAttr(x,"shadowWarning"),GetAttr(x,"shadowinactive"),\
193 Line = Sanitize(Line) + "\n";
194 F.write("0%u %s" % (I,Line));
195 F.write(".%s %s" % (GetAttr(x,"uid"),Line));
198 # Oops, something unspeakable happened.
204 # Generate the shadow list
205 def GenSSHShadow(l,masterFileName):
206 # Fetch all the users
209 # Depending on config, we write out either a single file,
210 # multiple files, or both
213 OldMask = os.umask(0077);
214 masterFile = open(masterFileName + ".tmp","w",0600);
217 Die(masterFileName,masterFile,None)
221 if PasswdAttrs == None:
224 # If we're going to be dealing with multiple keys, empty the
225 # directory before we start to avoid old keys hanging around
227 safe_rmtree(os.path.join(GlobalDir, 'userkeys'))
228 safe_makedirs(os.path.join(GlobalDir, 'userkeys'))
230 for x in PasswdAttrs:
231 # If the account is locked, do not write it.
232 # This is a partial stop-gap. The ssh also needs to change this
233 # to ignore ~/.ssh/authorized* files.
234 if (GetAttr(x,"userPassword").find("*LK*") != -1) \
235 or GetAttr(x,"userPassword").startswith("!"):
238 if x[1].has_key("uidNumber") == 0 or \
239 x[1].has_key("sshRSAAuthKey") == 0:
241 User = GetAttr(x,"uid");
246 OldMask = os.umask(0077);
247 File = os.path.join(GlobalDir, 'userkeys', User)
248 F = open(File + ".tmp","w",0600);
251 for I in x[1]["sshRSAAuthKey"]:
253 MultipleLine = "%s" % I
254 MultipleLine = Sanitize(MultipleLine) + "\n"
255 F.write(MultipleLine)
257 SingleLine = "%s: %s" % (User, I)
258 SingleLine = Sanitize(SingleLine) + "\n"
259 masterFile.write(SingleLine)
263 userfiles.append(os.path.basename(File))
265 # Oops, something unspeakable happened.
268 Die(masterFileName,masterFile,None)
272 Done(masterFileName,masterFile,None)
273 singlefile = os.path.basename(masterFileName)
275 return singlefile, userfiles
277 # Generate the group list
278 def GenGroup(l,File):
282 F = open(File + ".tdb.tmp","w");
284 # Generate the GroupMap
286 for x in GroupIDMap.keys():
289 # Fetch all the users
291 if PasswdAttrs == None:
294 # Sort them into a list of groups having a set of users
295 for x in PasswdAttrs:
296 if x[1].has_key("uidNumber") == 0 or IsInGroup(x) == 0:
298 if x[1].has_key("supplementaryGid") == 0:
301 for I in x[1]["supplementaryGid"]:
302 if GroupMap.has_key(I):
303 GroupMap[I].append(GetAttr(x,"uid"));
305 print "Group does not exist ",I,"but",GetAttr(x,"uid"),"is in it";
307 # Output the group file.
309 for x in GroupMap.keys():
310 grouprevmap[GroupIDMap[x]] = x
311 if GroupIDMap.has_key(x) == 0:
313 Line = "%s:x:%u:" % (x,GroupIDMap[x]);
315 for I in GroupMap[x]:
316 Line = Line + ("%s%s" % (Comma,I));
318 Line = Sanitize(Line) + "\n";
319 F.write("0%u %s" % (J,Line));
320 F.write(".%s %s" % (x,Line));
321 F.write("=%u %s" % (GroupIDMap[x],Line));
324 # Oops, something unspeakable happened.
332 # Generate the email forwarding list
333 def GenForward(l,File):
336 OldMask = os.umask(0022);
337 F = open(File + ".tmp","w",0644);
340 # Fetch all the users
342 if PasswdAttrs == None:
345 # Write out the email address for each user
346 for x in PasswdAttrs:
347 if x[1].has_key("emailForward") == 0 or IsInGroup(x) == 0:
350 # Do not allow people to try to buffer overflow busted parsers
351 if len(GetAttr(x,"emailForward")) > 200:
354 # Check the forwarding address
355 if EmailCheck.match(GetAttr(x,"emailForward")) == None:
357 Line = "%s: %s" % (GetAttr(x,"uid"),GetAttr(x,"emailForward"));
358 Line = Sanitize(Line) + "\n";
361 # Oops, something unspeakable happened.
367 def GenAllForward(l,File):
370 OldMask = os.umask(0022);
371 Fdb = os.popen("cdbmake %s %s.tmp"%(File,File),"w");
374 # Fetch all the users
376 if PasswdAttrs == None:
379 # Write out the email address for each user
380 for x in PasswdAttrs:
381 if x[1].has_key("emailForward") == 0:
384 # Do not allow people to try to buffer overflow busted parsers
385 Forward = GetAttr(x,"emailForward");
386 if len(Forward) > 200:
389 # Check the forwarding address
390 if EmailCheck.match(Forward) == None:
393 User = GetAttr(x,"uid");
394 Fdb.write("+%d,%d:%s->%s\n"%(len(User),len(Forward),User,Forward));
396 # Oops, something unspeakable happened.
400 if Fdb.close() != None:
401 raise "cdbmake gave an error";
403 # Generate the anon XEarth marker file
404 def GenMarkers(l,File):
407 F = open(File + ".tmp","w");
409 # Fetch all the users
411 if PasswdAttrs == None:
414 # Write out the position for each user
415 for x in PasswdAttrs:
416 if x[1].has_key("latitude") == 0 or x[1].has_key("longitude") == 0:
419 Line = "%8s %8s \"\""%(DecDegree(GetAttr(x,"latitude"),1),DecDegree(GetAttr(x,"longitude"),1));
420 Line = Sanitize(Line) + "\n";
425 # Oops, something unspeakable happened.
431 # Generate the debian-private subscription list
432 def GenPrivate(l,File):
435 F = open(File + ".tmp","w");
437 # Fetch all the users
439 if PasswdAttrs == None:
442 # Write out the position for each user
443 for x in PasswdAttrs:
444 if x[1].has_key("privateSub") == 0:
447 # If the account is locked, do not write it
448 if (GetAttr(x,"userPassword").find("*LK*") != -1) \
449 or GetAttr(x,"userPassword").startswith("!"):
452 # If the account has no PGP key, do not write it
453 if x[1].has_key("keyFingerPrint") == 0:
456 # Must be in the Debian group (yuk, hard coded for now)
457 if GetAttr(x,"gidNumber") != "800":
461 Line = "%s"%(GetAttr(x,"privateSub"));
462 Line = Sanitize(Line) + "\n";
467 # Oops, something unspeakable happened.
473 # Generate a list of locked accounts
474 def GenDisabledAccounts(l,File):
477 F = open(File + ".tmp","w");
479 # Fetch all the users
481 if PasswdAttrs == None:
485 for x in PasswdAttrs:
486 if x[1].has_key("uidNumber") == 0:
489 Pass = GetAttr(x,"userPassword");
491 # *LK* is the reference value for a locked account
492 # password starting with ! is also a locked account
493 if Pass.find("*LK*") != -1 or Pass.startswith("!"):
494 # Format is <login>:<reason>
495 Line = "%s:%s" % (GetAttr(x,"uid"), "Account is locked")
498 F.write(Sanitize(Line) + "\n")
500 # Oops, something unspeakable happened.
506 # Generate the list of local addresses that refuse all mail
507 def GenMailDisable(l,File):
510 F = open(File + ".tmp","w");
512 # Fetch all the users
514 if PasswdAttrs == None:
517 for x in PasswdAttrs:
520 if x[1].has_key("mailDisableMessage"):
521 Reason = GetAttr(x,"mailDisableMessage")
525 # Must be in the Debian group (yuk, hard coded for now)
526 if GetAttr(x,"gidNumber") != "800":
530 Line = "%s: %s"%(GetAttr(x,"uid"),Reason);
531 Line = Sanitize(Line) + "\n";
536 # Oops, something unspeakable happened.
542 # Generate a list of uids that should have boolean affects applied
543 def GenMailBool(l,File,Key):
546 F = open(File + ".tmp","w");
548 # Fetch all the users
550 if PasswdAttrs == None:
553 for x in PasswdAttrs:
556 if x[1].has_key(Key) == 0:
559 # Must be in the Debian group (yuk, hard coded for now)
560 if GetAttr(x,"gidNumber") != "800":
563 if GetAttr(x,Key) != "TRUE":
567 Line = "%s"%(GetAttr(x,"uid"));
568 Line = Sanitize(Line) + "\n";
573 # Oops, something unspeakable happened.
579 # Generate a list of hosts for RBL or whitelist purposes.
580 def GenMailList(l,File,Key):
583 F = open(File + ".tmp","w");
585 # Fetch all the users
587 if PasswdAttrs == None:
590 for x in PasswdAttrs:
593 if x[1].has_key(Key) == 0:
596 # Must be in the Debian group (yuk, hard coded for now)
597 if GetAttr(x,"gidNumber") != "800":
604 if Key == "mailWhitelist":
605 if re.match('^[-\w.]+(/[\d]+)?$',z) == None:
608 if re.match('^[-\w.]+$',z) == None:
612 Line = GetAttr(x,"uid")
616 if Key == "mailRHSBL":
617 Line += "/$sender_address_domain"
620 Line = Sanitize(Line) + "\n";
625 # Oops, something unspeakable happened.
631 # Generate the DNS Zone file
632 def GenDNS(l,File,HomePrefix):
635 F = open(File + ".tmp","w");
637 # Fetch all the users
639 if PasswdAttrs == None:
642 # Write out the zone file entry for each user
643 for x in PasswdAttrs:
644 if x[1].has_key("dnsZoneEntry") == 0:
647 # If the account has no PGP key, do not write it
648 if x[1].has_key("keyFingerPrint") == 0:
651 F.write("; %s\n"%(EmailAddress(x)));
652 for z in x[1]["dnsZoneEntry"]:
653 Split = z.lower().split()
654 if Split[1].lower() == 'in':
655 for y in range(0,len(Split)):
658 Line = " ".join(Split) + "\n";
661 Host = Split[0] + DNSZone;
662 if BSMTPCheck.match(Line) != None:
663 F.write("; Has BSMTP\n");
665 # Write some identification information
666 if Split[2].lower() == "a":
667 Line = "%s IN TXT \"%s\"\n"%(Split[0],EmailAddress(x));
668 for y in x[1]["keyFingerPrint"]:
669 Line = Line + "%s IN TXT \"PGP %s\"\n"%(Split[0],FormatPGPKey(y));
672 Line = "; Err %s"%(str(Split));
677 F.write("; Errors\n");
680 # Oops, something unspeakable happened.
686 # Generate the DNS SSHFP records
687 def GenSSHFP(l,File,HomePrefix):
690 F = open(File + ".tmp","w")
692 # Fetch all the hosts
694 if HostAttrs == None:
698 if x[1].has_key("hostname") == 0 or \
699 x[1].has_key("sshRSAHostKey") == 0:
701 Host = GetAttr(x,"hostname");
703 for I in x[1]["sshRSAHostKey"]:
705 if Split[0] == 'ssh-rsa':
707 if Split[0] == 'ssh-dss':
709 if Algorithm == None:
711 Fingerprint = sha.new(base64.decodestring(Split[1])).hexdigest()
712 Line = "%s. IN SSHFP %u 1 %s" % (Host,Algorithm,Fingerprint)
713 Line = Sanitize(Line) + "\n"
715 # Oops, something unspeakable happened.
721 # Generate the BSMTP file
722 def GenBSMTP(l,File,HomePrefix):
725 F = open(File + ".tmp","w");
727 # Fetch all the users
729 if PasswdAttrs == None:
732 # Write out the zone file entry for each user
733 for x in PasswdAttrs:
734 if x[1].has_key("dnsZoneEntry") == 0:
737 # If the account has no PGP key, do not write it
738 if x[1].has_key("keyFingerPrint") == 0:
741 for z in x[1]["dnsZoneEntry"]:
742 Split = z.lower().split()
743 if Split[1].lower() == 'in':
744 for y in range(0,len(Split)):
747 Line = " ".join(Split) + "\n";
749 Host = Split[0] + DNSZone;
750 if BSMTPCheck.match(Line) != None:
751 F.write("%s: user=%s group=Debian file=%s%s/bsmtp/%s\n"%(Host,
752 GetAttr(x,"uid"),HomePrefix,GetAttr(x,"uid"),Host));
755 F.write("; Errors\n");
758 # Oops, something unspeakable happened.
768 if not Host in HostToIPCache:
771 IPAdressesT = list(set([ (a[0],a[4][0]) for a in socket.getaddrinfo(Host, None)]))
772 except socket.gaierror, (code):
773 if code[0] != -2: raise
775 for addr in IPAdressesT:
776 if addr[0] == socket.AF_INET: IPAdresses += [addr[1], "::ffff:"+addr[1]]
777 else: IPAdresses += [addr[1]]
778 HostToIPCache[Host] = IPAdresses
779 return HostToIPCache[Host]
782 # Generate the ssh known hosts file
783 def GenSSHKnown(l,File,mode=None):
786 OldMask = os.umask(0022);
787 F = open(File + ".tmp","w",0644);
791 if HostAttrs == None:
795 if x[1].has_key("hostname") == 0 or \
796 x[1].has_key("sshRSAHostKey") == 0:
798 Host = GetAttr(x,"hostname");
800 SHost = Host.find(".")
801 if SHost != None: HostNames += [Host[0:SHost]]
803 for I in x[1]["sshRSAHostKey"]:
804 if mode and mode == 'authorized_keys':
805 #Line = 'command="rsync --server --sender -pr . /var/cache/userdir-ldap/hosts/%s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,from="%s" %s' % (Host, ",".join(HNames + HostToIP(Host)), I)
806 Line = 'command="rsync --server --sender -pr . /var/cache/userdir-ldap/hosts/%s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding %s' % (Host,I)
808 Line = "%s %s" %(",".join(HostNames + HostToIP(Host)), I);
809 Line = Sanitize(Line) + "\n";
811 # Oops, something unspeakable happened.
817 # Generate the debianhosts file (list of all IP addresses)
818 def GenHosts(l,File):
821 OldMask = os.umask(0022);
822 F = open(File + ".tmp","w",0644);
825 # Fetch all the hosts
826 HostNames = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"hostname=*",\
829 if HostNames == None:
833 if x[1].has_key("hostname") == 0:
835 Host = GetAttr(x,"hostname");
837 Addr = socket.gethostbyname(Host);
838 F.write(Addr + "\n");
841 # Oops, something unspeakable happened.
847 def GenKeyrings(l,OutDir):
849 shutil.copy(k, OutDir)
851 # Connect to the ldap server
852 l = ldap.open(LDAPServer);
853 F = open(PassDir+"/pass-"+pwd.getpwuid(os.getuid())[0],"r");
854 Pass = F.readline().strip().split(" ")
856 l.simple_bind_s("uid="+Pass[0]+","+BaseDn,Pass[1]);
858 # Fetch all the groups
860 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"gid=*",\
861 ["gid","gidNumber"]);
863 # Generate the GroupMap and GroupIDMap
865 if x[1].has_key("gidNumber") == 0:
867 GroupIDMap[x[1]["gid"][0]] = int(x[1]["gidNumber"][0]);
869 # Fetch all the users
870 PasswdAttrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid=*",\
871 ["uid","uidNumber","gidNumber","supplementaryGid",\
872 "gecos","loginShell","userPassword","shadowLastChange",\
873 "shadowMin","shadowMax","shadowWarning","shadowinactive",
874 "shadowexpire","emailForward","latitude","longitude",\
875 "allowedHost","sshRSAAuthKey","dnsZoneEntry","cn","sn",\
876 "keyFingerPrint","privateSub","mailDisableMessage",\
877 "mailGreylisting","mailCallout","mailRBL","mailRHSBL",\
879 # Fetch all the hosts
880 HostAttrs = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"sshRSAHostKey=*",\
881 ["hostname","sshRSAHostKey"]);
883 # Open the control file
884 if len(sys.argv) == 1:
885 F = open(GenerateConf,"r");
887 F = open(sys.argv[1],"r")
889 # Generate global things
890 GlobalDir = GenerateDir+"/";
891 SSHGlobal, SSHFiles = GenSSHShadow(l,GlobalDir+"ssh-rsa-shadow");
892 GenAllForward(l,GlobalDir+"mail-forward.cdb");
893 GenMarkers(l,GlobalDir+"markers");
894 GenPrivate(l,GlobalDir+"debian-private");
895 GenDisabledAccounts(l,GlobalDir+"disabled-accounts");
896 GenSSHKnown(l,GlobalDir+"ssh_known_hosts");
897 #GenSSHKnown(l,GlobalDir+"authorized_keys", 'authorized_keys');
898 GenHosts(l,GlobalDir+"debianhosts");
899 GenMailDisable(l,GlobalDir+"mail-disable");
900 GenMailBool(l,GlobalDir+"mail-greylist","mailGreylisting");
901 GenMailBool(l,GlobalDir+"mail-callout","mailCallout");
902 GenMailList(l,GlobalDir+"mail-rbl","mailRBL");
903 GenMailList(l,GlobalDir+"mail-rhsbl","mailRHSBL");
904 GenMailList(l,GlobalDir+"mail-whitelist","mailWhitelist");
905 GenKeyrings(l,GlobalDir);
908 GenForward(l,GlobalDir+"forward-alias");
920 Split = Line.split(" ")
921 OutDir = GenerateDir + '/' + Split[0] + '/';
922 try: os.mkdir(OutDir);
925 # Get the group list and convert any named groups to numerics
933 if GroupIDMap.has_key(I):
934 GroupList[str(GroupIDMap[I])] = None;
939 CurrentHost = Split[0];
941 # If we're using a single SSH file, deal with it
942 if SSHGlobal is not None:
943 DoLink(GlobalDir, OutDir, SSHGlobal)
945 DoLink(GlobalDir,OutDir,"debianhosts");
946 DoLink(GlobalDir,OutDir,"ssh_known_hosts");
947 DoLink(GlobalDir,OutDir,"disabled-accounts")
950 if ExtraList.has_key("[NOPASSWD]"):
951 userlist = GenPasswd(l,OutDir+"passwd",Split[1], "*");
953 userlist = GenPasswd(l,OutDir+"passwd",Split[1], "x");
955 grouprevmap = GenGroup(l,OutDir+"group");
957 # Now we know who we're allowing on the machine, export
958 # the relevant ssh keys
960 OldMask = os.umask(0077);
961 tf = tarfile.open(name=os.path.join(GlobalDir, 'ssh-keys-%s.tar.gz' % CurrentHost), mode='w:gz')
963 for f in userlist.keys():
964 if f not in SSHFiles:
966 # If we're not exporting their primary group, don't export
969 if userlist[f] in grouprevmap.keys():
970 grname = grouprevmap[userlist[f]]
973 if int(userlist[f]) <= 100:
974 # In these cases, look it up in the normal way so we
975 # deal with cases where, for instance, users are in group
976 # users as their primary group.
977 grname = grp.getgrgid(userlist[f])[0]
982 print "User %s is supposed to have their key exported to host %s but their primary group (gid: %d) isn't in LDAP" % (f, CurrentHost, userlist[f])
985 to = tf.gettarinfo(os.path.join(GlobalDir, 'userkeys', f), f)
986 # These will only be used where the username doesn't
987 # exist on the target system for some reason; hence,
988 # in those cases, the safest thing is for the file to
989 # be owned by root but group nobody. This deals with
990 # the bloody obscure case where the group fails to exist
991 # whilst the user does (in which case we want to avoid
992 # ending up with a file which is owned user:root to avoid
993 # a fairly obvious attack vector)
996 # Using the username / groupname fields avoids any need
997 # to give a shit^W^W^Wcare about the UIDoffset stuff.
1001 tf.addfile(to, file(os.path.join(GlobalDir, 'userkeys', f)))
1004 os.rename(os.path.join(GlobalDir, 'ssh-keys-%s.tar.gz' % CurrentHost),
1005 os.path.join(OutDir, 'ssh-keys.tar.gz'))
1007 if ExtraList.has_key("[UNTRUSTED]"):
1009 if not ExtraList.has_key("[NOPASSWD]"):
1010 GenShadow(l,OutDir+"shadow");
1012 # Link in global things
1013 DoLink(GlobalDir,OutDir,"markers");
1014 DoLink(GlobalDir,OutDir,"mail-forward.cdb");
1015 DoLink(GlobalDir,OutDir,"mail-disable");
1016 DoLink(GlobalDir,OutDir,"mail-greylist");
1017 DoLink(GlobalDir,OutDir,"mail-callout");
1018 DoLink(GlobalDir,OutDir,"mail-rbl");
1019 DoLink(GlobalDir,OutDir,"mail-rhsbl");
1020 DoLink(GlobalDir,OutDir,"mail-whitelist");
1023 DoLink(GlobalDir,OutDir,"forward-alias");
1025 if ExtraList.has_key("[DNS]"):
1026 GenDNS(l,OutDir+"dns-zone",Split[1]);
1027 GenSSHFP(l,OutDir+"dns-sshfp",Split[1])
1029 if ExtraList.has_key("[BSMTP]"):
1030 GenBSMTP(l,OutDir+"bsmtp",Split[1])
1032 if ExtraList.has_key("[PRIVATE]"):
1033 DoLink(GlobalDir,OutDir,"debian-private")
1035 if ExtraList.has_key("[KEYRING]"):
1037 DoLink(GlobalDir,OutDir,os.path.basename(k))
1040 try: posix.remove(OutDir+os.path.basename(k));