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 the account is locked, disable incoming mail
521 if (GetAttr(x,"userPassword").find("*LK*") != -1):
522 if GetAttr(x,"uid") == "luther":
525 Reason = "user account locked"
527 if x[1].has_key("mailDisableMessage"):
528 Reason = GetAttr(x,"mailDisableMessage")
532 # Must be in the Debian group (yuk, hard coded for now)
533 if GetAttr(x,"gidNumber") != "800":
537 Line = "%s: %s"%(GetAttr(x,"uid"),Reason);
538 Line = Sanitize(Line) + "\n";
543 # Oops, something unspeakable happened.
549 # Generate a list of uids that should have boolean affects applied
550 def GenMailBool(l,File,Key):
553 F = open(File + ".tmp","w");
555 # Fetch all the users
557 if PasswdAttrs == None:
560 for x in PasswdAttrs:
563 if x[1].has_key(Key) == 0:
566 # Must be in the Debian group (yuk, hard coded for now)
567 if GetAttr(x,"gidNumber") != "800":
570 if GetAttr(x,Key) != "TRUE":
574 Line = "%s"%(GetAttr(x,"uid"));
575 Line = Sanitize(Line) + "\n";
580 # Oops, something unspeakable happened.
586 # Generate a list of hosts for RBL or whitelist purposes.
587 def GenMailList(l,File,Key):
590 F = open(File + ".tmp","w");
592 # Fetch all the users
594 if PasswdAttrs == None:
597 for x in PasswdAttrs:
600 if x[1].has_key(Key) == 0:
603 # Must be in the Debian group (yuk, hard coded for now)
604 if GetAttr(x,"gidNumber") != "800":
611 if Key == "mailWhitelist":
612 if re.match('^[-\w.]+(/[\d]+)?$',z) == None:
615 if re.match('^[-\w.]+$',z) == None:
619 Line = GetAttr(x,"uid")
623 if Key == "mailRHSBL":
624 Line += "/$sender_address_domain"
627 Line = Sanitize(Line) + "\n";
632 # Oops, something unspeakable happened.
638 # Generate the DNS Zone file
639 def GenDNS(l,File,HomePrefix):
642 F = open(File + ".tmp","w");
644 # Fetch all the users
646 if PasswdAttrs == None:
649 # Write out the zone file entry for each user
650 for x in PasswdAttrs:
651 if x[1].has_key("dnsZoneEntry") == 0:
654 # If the account has no PGP key, do not write it
655 if x[1].has_key("keyFingerPrint") == 0:
658 F.write("; %s\n"%(EmailAddress(x)));
659 for z in x[1]["dnsZoneEntry"]:
660 Split = z.lower().split()
661 if Split[1].lower() == 'in':
662 for y in range(0,len(Split)):
665 Line = " ".join(Split) + "\n";
668 Host = Split[0] + DNSZone;
669 if BSMTPCheck.match(Line) != None:
670 F.write("; Has BSMTP\n");
672 # Write some identification information
673 if Split[2].lower() == "a":
674 Line = "%s IN TXT \"%s\"\n"%(Split[0],EmailAddress(x));
675 for y in x[1]["keyFingerPrint"]:
676 Line = Line + "%s IN TXT \"PGP %s\"\n"%(Split[0],FormatPGPKey(y));
679 Line = "; Err %s"%(str(Split));
684 F.write("; Errors\n");
687 # Oops, something unspeakable happened.
693 # Generate the DNS SSHFP records
694 def GenSSHFP(l,File,HomePrefix):
697 F = open(File + ".tmp","w")
699 # Fetch all the hosts
701 if HostAttrs == None:
705 if x[1].has_key("hostname") == 0 or \
706 x[1].has_key("sshRSAHostKey") == 0:
708 Host = GetAttr(x,"hostname");
710 for I in x[1]["sshRSAHostKey"]:
712 if Split[0] == 'ssh-rsa':
714 if Split[0] == 'ssh-dss':
716 if Algorithm == None:
718 Fingerprint = sha.new(base64.decodestring(Split[1])).hexdigest()
719 Line = "%s. IN SSHFP %u 1 %s" % (Host,Algorithm,Fingerprint)
720 Line = Sanitize(Line) + "\n"
722 # Oops, something unspeakable happened.
728 # Generate the BSMTP file
729 def GenBSMTP(l,File,HomePrefix):
732 F = open(File + ".tmp","w");
734 # Fetch all the users
736 if PasswdAttrs == None:
739 # Write out the zone file entry for each user
740 for x in PasswdAttrs:
741 if x[1].has_key("dnsZoneEntry") == 0:
744 # If the account has no PGP key, do not write it
745 if x[1].has_key("keyFingerPrint") == 0:
748 for z in x[1]["dnsZoneEntry"]:
749 Split = z.lower().split()
750 if Split[1].lower() == 'in':
751 for y in range(0,len(Split)):
754 Line = " ".join(Split) + "\n";
756 Host = Split[0] + DNSZone;
757 if BSMTPCheck.match(Line) != None:
758 F.write("%s: user=%s group=Debian file=%s%s/bsmtp/%s\n"%(Host,
759 GetAttr(x,"uid"),HomePrefix,GetAttr(x,"uid"),Host));
762 F.write("; Errors\n");
765 # Oops, something unspeakable happened.
775 if not Host in HostToIPCache:
778 IPAdressesT = list(set([ (a[0],a[4][0]) for a in socket.getaddrinfo(Host, None)]))
779 except socket.gaierror, (code):
780 if code[0] != -2: raise
782 for addr in IPAdressesT:
783 if addr[0] == socket.AF_INET: IPAdresses += [addr[1], "::ffff:"+addr[1]]
784 else: IPAdresses += [addr[1]]
785 HostToIPCache[Host] = IPAdresses
786 return HostToIPCache[Host]
789 # Generate the ssh known hosts file
790 def GenSSHKnown(l,File,mode=None):
793 OldMask = os.umask(0022);
794 F = open(File + ".tmp","w",0644);
798 if HostAttrs == None:
802 if x[1].has_key("hostname") == 0 or \
803 x[1].has_key("sshRSAHostKey") == 0:
805 Host = GetAttr(x,"hostname");
807 SHost = Host.find(".")
808 if SHost != None: HostNames += [Host[0:SHost]]
810 for I in x[1]["sshRSAHostKey"]:
811 if mode and mode == 'authorized_keys':
812 #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)
813 Line = 'command="rsync --server --sender -pr . /var/cache/userdir-ldap/hosts/%s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding %s' % (Host,I)
815 Line = "%s %s" %(",".join(HostNames + HostToIP(Host)), I);
816 Line = Sanitize(Line) + "\n";
818 # Oops, something unspeakable happened.
824 # Generate the debianhosts file (list of all IP addresses)
825 def GenHosts(l,File):
828 OldMask = os.umask(0022);
829 F = open(File + ".tmp","w",0644);
832 # Fetch all the hosts
833 HostNames = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"hostname=*",\
836 if HostNames == None:
840 if x[1].has_key("hostname") == 0:
842 Host = GetAttr(x,"hostname");
844 Addr = socket.gethostbyname(Host);
845 F.write(Addr + "\n");
848 # Oops, something unspeakable happened.
854 def GenKeyrings(l,OutDir):
856 shutil.copy(k, OutDir)
858 # Connect to the ldap server
859 l = ldap.open(LDAPServer);
860 F = open(PassDir+"/pass-"+pwd.getpwuid(os.getuid())[0],"r");
861 Pass = F.readline().strip().split(" ")
863 l.simple_bind_s("uid="+Pass[0]+","+BaseDn,Pass[1]);
865 # Fetch all the groups
867 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"gid=*",\
868 ["gid","gidNumber"]);
870 # Generate the GroupMap and GroupIDMap
872 if x[1].has_key("gidNumber") == 0:
874 GroupIDMap[x[1]["gid"][0]] = int(x[1]["gidNumber"][0]);
876 # Fetch all the users
877 PasswdAttrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid=*",\
878 ["uid","uidNumber","gidNumber","supplementaryGid",\
879 "gecos","loginShell","userPassword","shadowLastChange",\
880 "shadowMin","shadowMax","shadowWarning","shadowinactive",
881 "shadowexpire","emailForward","latitude","longitude",\
882 "allowedHost","sshRSAAuthKey","dnsZoneEntry","cn","sn",\
883 "keyFingerPrint","privateSub","mailDisableMessage",\
884 "mailGreylisting","mailCallout","mailRBL","mailRHSBL",\
886 # Fetch all the hosts
887 HostAttrs = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"sshRSAHostKey=*",\
888 ["hostname","sshRSAHostKey"]);
890 # Open the control file
891 if len(sys.argv) == 1:
892 F = open(GenerateConf,"r");
894 F = open(sys.argv[1],"r")
896 # Generate global things
897 GlobalDir = GenerateDir+"/";
898 SSHGlobal, SSHFiles = GenSSHShadow(l,GlobalDir+"ssh-rsa-shadow");
899 GenAllForward(l,GlobalDir+"mail-forward.cdb");
900 GenMarkers(l,GlobalDir+"markers");
901 GenPrivate(l,GlobalDir+"debian-private");
902 GenDisabledAccounts(l,GlobalDir+"disabled-accounts");
903 GenSSHKnown(l,GlobalDir+"ssh_known_hosts");
904 #GenSSHKnown(l,GlobalDir+"authorized_keys", 'authorized_keys');
905 GenHosts(l,GlobalDir+"debianhosts");
906 GenMailDisable(l,GlobalDir+"mail-disable");
907 GenMailBool(l,GlobalDir+"mail-greylist","mailGreylisting");
908 GenMailBool(l,GlobalDir+"mail-callout","mailCallout");
909 GenMailList(l,GlobalDir+"mail-rbl","mailRBL");
910 GenMailList(l,GlobalDir+"mail-rhsbl","mailRHSBL");
911 GenMailList(l,GlobalDir+"mail-whitelist","mailWhitelist");
912 GenKeyrings(l,GlobalDir);
915 GenForward(l,GlobalDir+"forward-alias");
927 Split = Line.split(" ")
928 OutDir = GenerateDir + '/' + Split[0] + '/';
929 try: os.mkdir(OutDir);
932 # Get the group list and convert any named groups to numerics
940 if GroupIDMap.has_key(I):
941 GroupList[str(GroupIDMap[I])] = None;
946 CurrentHost = Split[0];
948 # If we're using a single SSH file, deal with it
949 if SSHGlobal is not None:
950 DoLink(GlobalDir, OutDir, SSHGlobal)
952 DoLink(GlobalDir,OutDir,"debianhosts");
953 DoLink(GlobalDir,OutDir,"ssh_known_hosts");
954 DoLink(GlobalDir,OutDir,"disabled-accounts")
957 if ExtraList.has_key("[NOPASSWD]"):
958 userlist = GenPasswd(l,OutDir+"passwd",Split[1], "*");
960 userlist = GenPasswd(l,OutDir+"passwd",Split[1], "x");
962 grouprevmap = GenGroup(l,OutDir+"group");
963 if ExtraList.has_key("[UNTRUSTED]"):
965 if not ExtraList.has_key("[NOPASSWD]"):
966 GenShadow(l,OutDir+"shadow");
968 # Now we know who we're allowing on the machine, export
969 # the relevant ssh keys
971 tf = tarfile.open(name=os.path.join(GlobalDir, 'ssh-keys-%s.tar.gz' % CurrentHost), mode='w:gz')
972 for f in userlist.keys():
973 if f not in SSHFiles:
975 # If we're not exporting their primary group, don't export
978 if userlist[f] in grouprevmap.keys():
979 grname = grouprevmap[userlist[f]]
982 if int(userlist[f]) <= 100:
983 # In these cases, look it up in the normal way so we
984 # deal with cases where, for instance, users are in group
985 # users as their primary group.
986 grname = grp.getgrgid(userlist[f])[0]
991 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])
994 to = tf.gettarinfo(os.path.join(GlobalDir, 'userkeys', f), f)
995 # These will only be used where the username doesn't
996 # exist on the target system for some reason; hence,
997 # in those cases, the safest thing is for the file to
998 # be owned by root but group nobody. This deals with
999 # the bloody obscure case where the group fails to exist
1000 # whilst the user does (in which case we want to avoid
1001 # ending up with a file which is owned user:root to avoid
1002 # a fairly obvious attack vector)
1005 # Using the username / groupname fields avoids any need
1006 # to give a shit^W^W^Wcare about the UIDoffset stuff.
1010 tf.addfile(to, file(os.path.join(GlobalDir, 'userkeys', f)))
1013 os.rename(os.path.join(GlobalDir, 'ssh-keys-%s.tar.gz' % CurrentHost),
1014 os.path.join(OutDir, 'ssh-keys.tar.gz'))
1016 # Link in global things
1017 DoLink(GlobalDir,OutDir,"markers");
1018 DoLink(GlobalDir,OutDir,"mail-forward.cdb");
1019 DoLink(GlobalDir,OutDir,"mail-disable");
1020 DoLink(GlobalDir,OutDir,"mail-greylist");
1021 DoLink(GlobalDir,OutDir,"mail-callout");
1022 DoLink(GlobalDir,OutDir,"mail-rbl");
1023 DoLink(GlobalDir,OutDir,"mail-rhsbl");
1024 DoLink(GlobalDir,OutDir,"mail-whitelist");
1027 DoLink(GlobalDir,OutDir,"forward-alias");
1029 if ExtraList.has_key("[DNS]"):
1030 GenDNS(l,OutDir+"dns-zone",Split[1]);
1031 GenSSHFP(l,OutDir+"dns-sshfp",Split[1])
1033 if ExtraList.has_key("[BSMTP]"):
1034 GenBSMTP(l,OutDir+"bsmtp",Split[1])
1036 if ExtraList.has_key("[PRIVATE]"):
1037 DoLink(GlobalDir,OutDir,"debian-private")
1039 if ExtraList.has_key("[KEYRING]"):
1041 DoLink(GlobalDir,OutDir,os.path.basename(k))
1044 try: posix.remove(OutDir+os.path.basename(k));