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 = ConfModule.sync_keyrings.split(":")
43 def safe_makedirs(dir):
47 if e.errno == errno.EEXIST:
56 if e.errno == errno.ENOENT:
62 return Str.translate(string.maketrans("\n\r\t","$$$"))
64 def DoLink(From,To,File):
65 try: posix.remove(To+File);
67 posix.link(From+File,To+File);
69 # See if this user is in the group list
70 def IsInGroup(DnRecord):
74 # See if the primary group is in the list
75 if Allowed.has_key(GetAttr(DnRecord,"gidNumber")) != 0:
78 # Check the host based ACL
79 if DnRecord[1].has_key("allowedHost") != 0:
80 for I in DnRecord[1]["allowedHost"]:
84 # See if there are supplementary groups
85 if DnRecord[1].has_key("supplementaryGid") == 0:
88 # Check the supplementary groups
89 for I in DnRecord[1]["supplementaryGid"]:
90 if Allowed.has_key(I):
99 try: os.remove(File + ".tmp");
101 try: os.remove(File + ".tdb.tmp");
104 def Done(File,F,Fdb):
107 os.rename(File + ".tmp",File);
110 os.rename(File + ".tdb.tmp",File+".tdb");
112 # Generate the password list
113 def GenPasswd(l,File,HomePrefix,PwdMarker):
116 F = open(File + ".tdb.tmp","w");
119 # Fetch all the users
121 if PasswdAttrs == None:
125 for x in PasswdAttrs:
126 if x[1].has_key("uidNumber") == 0 or IsInGroup(x) == 0:
129 # Do not let people try to buffer overflow some busted passwd parser.
130 if len(GetAttr(x,"gecos")) > 100 or len(GetAttr(x,"loginShell")) > 50:
133 userlist[GetAttr(x, "uid")] = int(GetAttr(x, "gidNumber"))
134 Line = "%s:%s:%s:%s:%s:%s%s:%s" % (GetAttr(x,"uid"),\
136 GetAttr(x,"uidNumber"),GetAttr(x,"gidNumber"),\
137 GetAttr(x,"gecos"),HomePrefix,GetAttr(x,"uid"),\
138 GetAttr(x,"loginShell"));
140 Line = Sanitize(Line) + "\n";
141 F.write("0%u %s" % (I,Line));
142 F.write(".%s %s" % (GetAttr(x,"uid"),Line));
143 F.write("=%s %s" % (GetAttr(x,"uidNumber"),Line));
146 # Oops, something unspeakable happened.
152 # Return the list of users so we know which keys to export
155 # Generate the shadow list
156 def GenShadow(l,File):
159 OldMask = os.umask(0077);
160 F = open(File + ".tdb.tmp","w",0600);
163 # Fetch all the users
165 if PasswdAttrs == None:
169 for x in PasswdAttrs:
170 if x[1].has_key("uidNumber") == 0 or IsInGroup(x) == 0:
173 Pass = GetAttr(x,"userPassword");
174 if Pass[0:7] != "{crypt}" or len(Pass) > 50:
179 # If the account is locked, mark it as such in shadow
180 # See Debian Bug #308229 for why we set it to 1 instead of 0
181 if (GetAttr(x,"userPassword").find("*LK*") != -1) \
182 or GetAttr(x,"userPassword").startswith("!"):
185 ShadowExpire = GetAttr(x,"shadowExpire")
187 Line = "%s:%s:%s:%s:%s:%s:%s:%s:" % (GetAttr(x,"uid"),\
188 Pass,GetAttr(x,"shadowLastChange"),\
189 GetAttr(x,"shadowMin"),GetAttr(x,"shadowMax"),\
190 GetAttr(x,"shadowWarning"),GetAttr(x,"shadowInactive"),\
192 Line = Sanitize(Line) + "\n";
193 F.write("0%u %s" % (I,Line));
194 F.write(".%s %s" % (GetAttr(x,"uid"),Line));
197 # Oops, something unspeakable happened.
203 # Generate the shadow list
204 def GenSSHShadow(l,masterFileName):
205 # Fetch all the users
208 # Depending on config, we write out either a single file,
209 # multiple files, or both
212 OldMask = os.umask(0077);
213 masterFile = open(masterFileName + ".tmp","w",0600);
216 Die(masterFileName,masterFile,None)
220 if PasswdAttrs == None:
223 # If we're going to be dealing with multiple keys, empty the
224 # directory before we start to avoid old keys hanging around
226 safe_rmtree(os.path.join(GlobalDir, 'userkeys'))
227 safe_makedirs(os.path.join(GlobalDir, 'userkeys'))
229 for x in PasswdAttrs:
230 # If the account is locked, do not write it.
231 # This is a partial stop-gap. The ssh also needs to change this
232 # to ignore ~/.ssh/authorized* files.
233 if (GetAttr(x,"userPassword").find("*LK*") != -1) \
234 or GetAttr(x,"userPassword").startswith("!"):
237 if x[1].has_key("uidNumber") == 0 or \
238 x[1].has_key("sshRSAAuthKey") == 0:
240 User = GetAttr(x,"uid");
245 OldMask = os.umask(0077);
246 File = os.path.join(GlobalDir, 'userkeys', User)
247 F = open(File + ".tmp","w",0600);
250 for I in x[1]["sshRSAAuthKey"]:
252 MultipleLine = "%s" % I
253 MultipleLine = Sanitize(MultipleLine) + "\n"
254 F.write(MultipleLine)
256 SingleLine = "%s: %s" % (User, I)
257 SingleLine = Sanitize(SingleLine) + "\n"
258 masterFile.write(SingleLine)
262 userfiles.append(os.path.basename(File))
264 # Oops, something unspeakable happened.
267 Die(masterFileName,masterFile,None)
271 Done(masterFileName,masterFile,None)
272 singlefile = os.path.basename(masterFileName)
274 return singlefile, userfiles
276 # Generate the group list
277 def GenGroup(l,File):
281 F = open(File + ".tdb.tmp","w");
283 # Generate the GroupMap
285 for x in GroupIDMap.keys():
288 # Fetch all the users
290 if PasswdAttrs == None:
293 # Sort them into a list of groups having a set of users
294 for x in PasswdAttrs:
295 if x[1].has_key("uidNumber") == 0 or IsInGroup(x) == 0:
297 if x[1].has_key("supplementaryGid") == 0:
300 for I in x[1]["supplementaryGid"]:
301 if GroupMap.has_key(I):
302 GroupMap[I].append(GetAttr(x,"uid"));
304 print "Group does not exist ",I,"but",GetAttr(x,"uid"),"is in it";
306 # Output the group file.
308 for x in GroupMap.keys():
309 grouprevmap[GroupIDMap[x]] = x
310 if GroupIDMap.has_key(x) == 0:
312 Line = "%s:x:%u:" % (x,GroupIDMap[x]);
314 for I in GroupMap[x]:
315 Line = Line + ("%s%s" % (Comma,I));
317 Line = Sanitize(Line) + "\n";
318 F.write("0%u %s" % (J,Line));
319 F.write(".%s %s" % (x,Line));
320 F.write("=%u %s" % (GroupIDMap[x],Line));
323 # Oops, something unspeakable happened.
331 # Generate the email forwarding list
332 def GenForward(l,File):
335 OldMask = os.umask(0022);
336 F = open(File + ".tmp","w",0644);
339 # Fetch all the users
341 if PasswdAttrs == None:
344 # Write out the email address for each user
345 for x in PasswdAttrs:
346 if x[1].has_key("emailForward") == 0 or IsInGroup(x) == 0:
349 # Do not allow people to try to buffer overflow busted parsers
350 if len(GetAttr(x,"emailForward")) > 200:
353 # Check the forwarding address
354 if EmailCheck.match(GetAttr(x,"emailForward")) == None:
356 Line = "%s: %s" % (GetAttr(x,"uid"),GetAttr(x,"emailForward"));
357 Line = Sanitize(Line) + "\n";
360 # Oops, something unspeakable happened.
366 def GenAllForward(l,File):
369 OldMask = os.umask(0022);
370 Fdb = os.popen("cdbmake %s %s.tmp"%(File,File),"w");
373 # Fetch all the users
375 if PasswdAttrs == None:
378 # Write out the email address for each user
379 for x in PasswdAttrs:
380 if x[1].has_key("emailForward") == 0:
383 # Do not allow people to try to buffer overflow busted parsers
384 Forward = GetAttr(x,"emailForward");
385 if len(Forward) > 200:
388 # Check the forwarding address
389 if EmailCheck.match(Forward) == None:
392 User = GetAttr(x,"uid");
393 Fdb.write("+%d,%d:%s->%s\n"%(len(User),len(Forward),User,Forward));
395 # Oops, something unspeakable happened.
399 if Fdb.close() != None:
400 raise "cdbmake gave an error";
402 # Generate the anon XEarth marker file
403 def GenMarkers(l,File):
406 F = open(File + ".tmp","w");
408 # Fetch all the users
410 if PasswdAttrs == None:
413 # Write out the position for each user
414 for x in PasswdAttrs:
415 if x[1].has_key("latitude") == 0 or x[1].has_key("longitude") == 0:
418 Line = "%8s %8s \"\""%(DecDegree(GetAttr(x,"latitude"),1),DecDegree(GetAttr(x,"longitude"),1));
419 Line = Sanitize(Line) + "\n";
424 # Oops, something unspeakable happened.
430 # Generate the debian-private subscription list
431 def GenPrivate(l,File):
434 F = open(File + ".tmp","w");
436 # Fetch all the users
438 if PasswdAttrs == None:
441 # Write out the position for each user
442 for x in PasswdAttrs:
443 if x[1].has_key("privateSub") == 0:
446 # If the account is locked, do not write it
447 if (GetAttr(x,"userPassword").find("*LK*") != -1) \
448 or GetAttr(x,"userPassword").startswith("!"):
451 # If the account has no PGP key, do not write it
452 if x[1].has_key("keyFingerPrint") == 0:
455 # Must be in the Debian group (yuk, hard coded for now)
456 if GetAttr(x,"gidNumber") != "800":
460 Line = "%s"%(GetAttr(x,"privateSub"));
461 Line = Sanitize(Line) + "\n";
466 # Oops, something unspeakable happened.
472 # Generate a list of locked accounts
473 def GenDisabledAccounts(l,File):
476 F = open(File + ".tmp","w");
478 # Fetch all the users
480 if PasswdAttrs == None:
484 for x in PasswdAttrs:
485 if x[1].has_key("uidNumber") == 0:
488 Pass = GetAttr(x,"userPassword");
490 # *LK* is the reference value for a locked account
491 # password starting with ! is also a locked account
492 if Pass.find("*LK*") != -1 or Pass.startswith("!"):
493 # Format is <login>:<reason>
494 Line = "%s:%s" % (GetAttr(x,"uid"), "Account is locked")
497 F.write(Sanitize(Line) + "\n")
499 # Oops, something unspeakable happened.
505 # Generate the list of local addresses that refuse all mail
506 def GenMailDisable(l,File):
509 F = open(File + ".tmp","w");
511 # Fetch all the users
513 if PasswdAttrs == None:
516 for x in PasswdAttrs:
519 if x[1].has_key("mailDisableMessage"):
520 Reason = GetAttr(x,"mailDisableMessage")
524 # Must be in the Debian group (yuk, hard coded for now)
525 if GetAttr(x,"gidNumber") != "800":
529 Line = "%s: %s"%(GetAttr(x,"uid"),Reason);
530 Line = Sanitize(Line) + "\n";
535 # Oops, something unspeakable happened.
541 # Generate a list of uids that should have boolean affects applied
542 def GenMailBool(l,File,Key):
545 F = open(File + ".tmp","w");
547 # Fetch all the users
549 if PasswdAttrs == None:
552 for x in PasswdAttrs:
555 if x[1].has_key(Key) == 0:
558 # Must be in the Debian group (yuk, hard coded for now)
559 if GetAttr(x,"gidNumber") != "800":
562 if GetAttr(x,Key) != "TRUE":
566 Line = "%s"%(GetAttr(x,"uid"));
567 Line = Sanitize(Line) + "\n";
572 # Oops, something unspeakable happened.
578 # Generate a list of hosts for RBL or whitelist purposes.
579 def GenMailList(l,File,Key):
582 F = open(File + ".tmp","w");
584 # Fetch all the users
586 if PasswdAttrs == None:
589 for x in PasswdAttrs:
592 if x[1].has_key(Key) == 0:
595 # Must be in the Debian group (yuk, hard coded for now)
596 if GetAttr(x,"gidNumber") != "800":
603 if Key == "mailWhitelist":
604 if re.match('^[-\w.]+(/[\d]+)?$',z) == None:
607 if re.match('^[-\w.]+$',z) == None:
611 Line = GetAttr(x,"uid")
615 if Key == "mailRHSBL":
616 Line += "/$sender_address_domain"
619 Line = Sanitize(Line) + "\n";
624 # Oops, something unspeakable happened.
630 # Generate the DNS Zone file
631 def GenDNS(l,File,HomePrefix):
634 F = open(File + ".tmp","w");
636 # Fetch all the users
638 if PasswdAttrs == None:
641 # Write out the zone file entry for each user
642 for x in PasswdAttrs:
643 if x[1].has_key("dnsZoneEntry") == 0:
646 # If the account has no PGP key, do not write it
647 if x[1].has_key("keyFingerPrint") == 0:
650 F.write("; %s\n"%(EmailAddress(x)));
651 for z in x[1]["dnsZoneEntry"]:
652 Split = z.lower().split()
653 if Split[1].lower() == 'in':
654 for y in range(0,len(Split)):
657 Line = " ".join(Split) + "\n";
660 Host = Split[0] + DNSZone;
661 if BSMTPCheck.match(Line) != None:
662 F.write("; Has BSMTP\n");
664 # Write some identification information
665 if Split[2].lower() == "a":
666 Line = "%s IN TXT \"%s\"\n"%(Split[0],EmailAddress(x));
667 for y in x[1]["keyFingerPrint"]:
668 Line = Line + "%s IN TXT \"PGP %s\"\n"%(Split[0],FormatPGPKey(y));
671 Line = "; Err %s"%(str(Split));
676 F.write("; Errors\n");
679 # Oops, something unspeakable happened.
685 # Generate the DNS SSHFP records
686 def GenSSHFP(l,File,HomePrefix):
689 F = open(File + ".tmp","w")
691 # Fetch all the hosts
693 if HostAttrs == None:
697 if x[1].has_key("hostname") == 0 or \
698 x[1].has_key("sshRSAHostKey") == 0:
700 Host = GetAttr(x,"hostname");
702 for I in x[1]["sshRSAHostKey"]:
704 if Split[0] == 'ssh-rsa':
706 if Split[0] == 'ssh-dss':
708 if Algorithm == None:
710 Fingerprint = sha.new(base64.decodestring(Split[1])).hexdigest()
711 Line = "%s. IN SSHFP %u 1 %s" % (Host,Algorithm,Fingerprint)
712 Line = Sanitize(Line) + "\n"
714 # Oops, something unspeakable happened.
720 # Generate the BSMTP file
721 def GenBSMTP(l,File,HomePrefix):
724 F = open(File + ".tmp","w");
726 # Fetch all the users
728 if PasswdAttrs == None:
731 # Write out the zone file entry for each user
732 for x in PasswdAttrs:
733 if x[1].has_key("dnsZoneEntry") == 0:
736 # If the account has no PGP key, do not write it
737 if x[1].has_key("keyFingerPrint") == 0:
740 for z in x[1]["dnsZoneEntry"]:
741 Split = z.lower().split()
742 if Split[1].lower() == 'in':
743 for y in range(0,len(Split)):
746 Line = " ".join(Split) + "\n";
748 Host = Split[0] + DNSZone;
749 if BSMTPCheck.match(Line) != None:
750 F.write("%s: user=%s group=Debian file=%s%s/bsmtp/%s\n"%(Host,
751 GetAttr(x,"uid"),HomePrefix,GetAttr(x,"uid"),Host));
754 F.write("; Errors\n");
757 # Oops, something unspeakable happened.
767 if not Host in HostToIPCache:
770 IPAdressesT = list(set([ (a[0],a[4][0]) for a in socket.getaddrinfo(Host, None)]))
771 except socket.gaierror, (code):
772 if code[0] != -2: raise
774 for addr in IPAdressesT:
775 if addr[0] == socket.AF_INET: IPAdresses += [addr[1], "::ffff:"+addr[1]]
776 else: IPAdresses += [addr[1]]
777 HostToIPCache[Host] = IPAdresses
778 return HostToIPCache[Host]
781 # Generate the ssh known hosts file
782 def GenSSHKnown(l,File,mode=None):
785 OldMask = os.umask(0022);
786 F = open(File + ".tmp","w",0644);
790 if HostAttrs == None:
794 if x[1].has_key("hostname") == 0 or \
795 x[1].has_key("sshRSAHostKey") == 0:
797 Host = GetAttr(x,"hostname");
799 SHost = Host.find(".")
800 if SHost != None: HostNames += [Host[0:SHost]]
802 for I in x[1]["sshRSAHostKey"]:
803 if mode and mode == 'authorized_keys':
804 #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)
805 Line = 'command="rsync --server --sender -pr . /var/cache/userdir-ldap/hosts/%s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding %s' % (Host,I)
807 Line = "%s %s" %(",".join(HostNames + HostToIP(Host)), I);
808 Line = Sanitize(Line) + "\n";
810 # Oops, something unspeakable happened.
816 # Generate the debianhosts file (list of all IP addresses)
817 def GenHosts(l,File):
820 OldMask = os.umask(0022);
821 F = open(File + ".tmp","w",0644);
824 # Fetch all the hosts
825 HostNames = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"hostname=*",\
828 if HostNames == None:
832 if x[1].has_key("hostname") == 0:
834 Host = GetAttr(x,"hostname");
836 Addr = socket.gethostbyname(Host);
837 F.write(Addr + "\n");
840 # Oops, something unspeakable happened.
846 def GenKeyrings(l,OutDir):
848 shutil.copy(k, OutDir)
850 # Connect to the ldap server
851 l = ldap.open(LDAPServer);
852 F = open(PassDir+"/pass-"+pwd.getpwuid(os.getuid())[0],"r");
853 Pass = F.readline().strip().split(" ")
855 l.simple_bind_s("uid="+Pass[0]+","+BaseDn,Pass[1]);
857 # Fetch all the groups
859 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"gid=*",\
860 ["gid","gidNumber"]);
862 # Generate the GroupMap and GroupIDMap
864 if x[1].has_key("gidNumber") == 0:
866 GroupIDMap[x[1]["gid"][0]] = int(x[1]["gidNumber"][0]);
868 # Fetch all the users
869 PasswdAttrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid=*",\
870 ["uid","uidNumber","gidNumber","supplementaryGid",\
871 "gecos","loginShell","userPassword","shadowLastChange",\
872 "shadowMin","shadowMax","shadowWarning","shadowInactive",
873 "shadowExpire","emailForward","latitude","longitude",\
874 "allowedHost","sshRSAAuthKey","dnsZoneEntry","cn","sn",\
875 "keyFingerPrint","privateSub","mailDisableMessage",\
876 "mailGreylisting","mailCallout","mailRBL","mailRHSBL",\
878 # Fetch all the hosts
879 HostAttrs = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"sshRSAHostKey=*",\
880 ["hostname","sshRSAHostKey"]);
882 # Open the control file
883 if len(sys.argv) == 1:
884 F = open(GenerateConf,"r");
886 F = open(sys.argv[1],"r")
888 # Generate global things
889 GlobalDir = GenerateDir+"/";
890 SSHGlobal, SSHFiles = GenSSHShadow(l,GlobalDir+"ssh-rsa-shadow");
891 GenAllForward(l,GlobalDir+"mail-forward.cdb");
892 GenMarkers(l,GlobalDir+"markers");
893 GenPrivate(l,GlobalDir+"debian-private");
894 GenDisabledAccounts(l,GlobalDir+"disabled-accounts");
895 GenSSHKnown(l,GlobalDir+"ssh_known_hosts");
896 #GenSSHKnown(l,GlobalDir+"authorized_keys", 'authorized_keys');
897 GenHosts(l,GlobalDir+"debianhosts");
898 GenMailDisable(l,GlobalDir+"mail-disable");
899 GenMailBool(l,GlobalDir+"mail-greylist","mailGreylisting");
900 GenMailBool(l,GlobalDir+"mail-callout","mailCallout");
901 GenMailList(l,GlobalDir+"mail-rbl","mailRBL");
902 GenMailList(l,GlobalDir+"mail-rhsbl","mailRHSBL");
903 GenMailList(l,GlobalDir+"mail-whitelist","mailWhitelist");
904 GenKeyrings(l,GlobalDir);
907 GenForward(l,GlobalDir+"forward-alias");
919 Split = Line.split(" ")
920 OutDir = GenerateDir + '/' + Split[0] + '/';
921 try: os.mkdir(OutDir);
924 # Get the group list and convert any named groups to numerics
932 if GroupIDMap.has_key(I):
933 GroupList[str(GroupIDMap[I])] = None;
938 CurrentHost = Split[0];
940 # If we're using a single SSH file, deal with it
941 if SSHGlobal is not None:
942 DoLink(GlobalDir, OutDir, SSHGlobal)
944 DoLink(GlobalDir,OutDir,"debianhosts");
945 DoLink(GlobalDir,OutDir,"ssh_known_hosts");
946 DoLink(GlobalDir,OutDir,"disabled-accounts")
949 if ExtraList.has_key("[NOPASSWD]"):
950 userlist = GenPasswd(l,OutDir+"passwd",Split[1], "*");
952 userlist = GenPasswd(l,OutDir+"passwd",Split[1], "x");
954 grouprevmap = GenGroup(l,OutDir+"group");
956 # Now we know who we're allowing on the machine, export
957 # the relevant ssh keys
959 OldMask = os.umask(0077);
960 tf = tarfile.open(name=os.path.join(GlobalDir, 'ssh-keys-%s.tar.gz' % CurrentHost), mode='w:gz')
962 for f in userlist.keys():
963 if f not in SSHFiles:
965 # If we're not exporting their primary group, don't export
968 if userlist[f] in grouprevmap.keys():
969 grname = grouprevmap[userlist[f]]
972 if int(userlist[f]) <= 100:
973 # In these cases, look it up in the normal way so we
974 # deal with cases where, for instance, users are in group
975 # users as their primary group.
976 grname = grp.getgrgid(userlist[f])[0]
981 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])
984 to = tf.gettarinfo(os.path.join(GlobalDir, 'userkeys', f), f)
985 # These will only be used where the username doesn't
986 # exist on the target system for some reason; hence,
987 # in those cases, the safest thing is for the file to
988 # be owned by root but group nobody. This deals with
989 # the bloody obscure case where the group fails to exist
990 # whilst the user does (in which case we want to avoid
991 # ending up with a file which is owned user:root to avoid
992 # a fairly obvious attack vector)
995 # Using the username / groupname fields avoids any need
996 # to give a shit^W^W^Wcare about the UIDoffset stuff.
1000 tf.addfile(to, file(os.path.join(GlobalDir, 'userkeys', f)))
1003 os.rename(os.path.join(GlobalDir, 'ssh-keys-%s.tar.gz' % CurrentHost),
1004 os.path.join(OutDir, 'ssh-keys.tar.gz'))
1006 if ExtraList.has_key("[UNTRUSTED]"):
1008 if not ExtraList.has_key("[NOPASSWD]"):
1009 GenShadow(l,OutDir+"shadow");
1011 # Link in global things
1012 DoLink(GlobalDir,OutDir,"markers");
1013 DoLink(GlobalDir,OutDir,"mail-forward.cdb");
1014 DoLink(GlobalDir,OutDir,"mail-disable");
1015 DoLink(GlobalDir,OutDir,"mail-greylist");
1016 DoLink(GlobalDir,OutDir,"mail-callout");
1017 DoLink(GlobalDir,OutDir,"mail-rbl");
1018 DoLink(GlobalDir,OutDir,"mail-rhsbl");
1019 DoLink(GlobalDir,OutDir,"mail-whitelist");
1022 DoLink(GlobalDir,OutDir,"forward-alias");
1024 if ExtraList.has_key("[DNS]"):
1025 GenDNS(l,OutDir+"dns-zone",Split[1]);
1026 GenSSHFP(l,OutDir+"dns-sshfp",Split[1])
1028 if ExtraList.has_key("[BSMTP]"):
1029 GenBSMTP(l,OutDir+"bsmtp",Split[1])
1031 if ExtraList.has_key("[PRIVATE]"):
1032 DoLink(GlobalDir,OutDir,"debian-private")
1034 if ExtraList.has_key("[KEYRING]"):
1036 DoLink(GlobalDir,OutDir,os.path.basename(k))
1039 try: posix.remove(OutDir+os.path.basename(k));