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 UUID_FORMAT = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
40 EmailCheck = re.compile("^([^ <>@]+@[^ ,<>@]+)?$");
41 BSMTPCheck = re.compile(".*mx 0 (gluck)\.debian\.org\..*",re.DOTALL);
42 DNSZone = ".debian.net"
43 Keyrings = ConfModule.sync_keyrings.split(":")
45 def safe_makedirs(dir):
49 if e.errno == errno.EEXIST:
58 if e.errno == errno.ENOENT:
64 return Str.translate(string.maketrans("\n\r\t","$$$"))
66 def DoLink(From,To,File):
67 try: posix.remove(To+File);
69 posix.link(From+File,To+File);
71 # See if this user is in the group list
72 def IsInGroup(DnRecord):
76 # See if the primary group is in the list
77 if Allowed.has_key(GetAttr(DnRecord,"gidNumber")) != 0:
80 # Check the host based ACL
81 if DnRecord[1].has_key("allowedHost") != 0:
82 for I in DnRecord[1]["allowedHost"]:
86 # See if there are supplementary groups
87 if DnRecord[1].has_key("supplementaryGid") == 0:
90 # Check the supplementary groups
91 for I in DnRecord[1]["supplementaryGid"]:
92 if Allowed.has_key(I):
101 try: os.remove(File + ".tmp");
103 try: os.remove(File + ".tdb.tmp");
106 def Done(File,F,Fdb):
109 os.rename(File + ".tmp",File);
112 os.rename(File + ".tdb.tmp",File+".tdb");
114 # Generate the password list
115 def GenPasswd(l,File,HomePrefix,PwdMarker):
118 F = open(File + ".tdb.tmp","w");
121 # Fetch all the users
123 if PasswdAttrs == None:
127 for x in PasswdAttrs:
128 if x[1].has_key("uidNumber") == 0 or IsInGroup(x) == 0:
131 # Do not let people try to buffer overflow some busted passwd parser.
132 if len(GetAttr(x,"gecos")) > 100 or len(GetAttr(x,"loginShell")) > 50:
135 userlist[GetAttr(x, "uid")] = int(GetAttr(x, "gidNumber"))
136 Line = "%s:%s:%s:%s:%s:%s%s:%s" % (GetAttr(x,"uid"),\
138 GetAttr(x,"uidNumber"),GetAttr(x,"gidNumber"),\
139 GetAttr(x,"gecos"),HomePrefix,GetAttr(x,"uid"),\
140 GetAttr(x,"loginShell"));
142 Line = Sanitize(Line) + "\n";
143 F.write("0%u %s" % (I,Line));
144 F.write(".%s %s" % (GetAttr(x,"uid"),Line));
145 F.write("=%s %s" % (GetAttr(x,"uidNumber"),Line));
148 # Oops, something unspeakable happened.
154 # Return the list of users so we know which keys to export
157 # Generate the shadow list
158 def GenShadow(l,File):
161 OldMask = os.umask(0077);
162 F = open(File + ".tdb.tmp","w",0600);
165 # Fetch all the users
167 if PasswdAttrs == None:
171 for x in PasswdAttrs:
172 if x[1].has_key("uidNumber") == 0 or IsInGroup(x) == 0:
175 Pass = GetAttr(x,"userPassword");
176 if Pass[0:7] != "{crypt}" or len(Pass) > 50:
181 # If the account is locked, mark it as such in shadow
182 # See Debian Bug #308229 for why we set it to 1 instead of 0
183 if (GetAttr(x,"userPassword").find("*LK*") != -1) \
184 or GetAttr(x,"userPassword").startswith("!"):
187 ShadowExpire = GetAttr(x,"shadowExpire")
189 Line = "%s:%s:%s:%s:%s:%s:%s:%s:" % (GetAttr(x,"uid"),\
190 Pass,GetAttr(x,"shadowLastChange"),\
191 GetAttr(x,"shadowMin"),GetAttr(x,"shadowMax"),\
192 GetAttr(x,"shadowWarning"),GetAttr(x,"shadowInactive"),\
194 Line = Sanitize(Line) + "\n";
195 F.write("0%u %s" % (I,Line));
196 F.write(".%s %s" % (GetAttr(x,"uid"),Line));
199 # Oops, something unspeakable happened.
205 # Generate the sudo passwd file
206 def GenShadowSudo(l,File):
209 OldMask = os.umask(0077);
210 F = open(File + ".tmp","w",0600);
213 # Fetch all the users
215 if PasswdAttrs == None:
218 for x in PasswdAttrs:
220 if x[1].has_key("uidNumber") == 0 or IsInGroup(x) == 0:
223 if x[1].has_key('sudoPassword'):
224 for entry in x[1]['sudoPassword']:
225 Match = re.compile('^('+UUID_FORMAT+') (confirmed:[0-9a-f]{40}|unconfirmed) ([a-z0-9.,*]+) ([^ ]+)$').match(entry)
228 uuid = Match.group(1)
229 status = Match.group(2)
230 hosts = Match.group(3)
231 cryptedpass = Match.group(4)
233 if status != 'confirmed:'+make_sudopasswd_hmac('password-is-confirmed', uuid, hosts, cryptedpass):
235 for_all = hosts == "*"
236 for_this_host = CurrentHost in hosts.split(',')
237 if not (for_all or for_this_host):
240 if for_this_host: # this makes sure we take a per-host entry over the for-all entry
245 Line = "%s:%s" % (GetAttr(x,"uid"), Pass)
246 Line = Sanitize(Line) + "\n";
247 F.write("%s" % (Line));
249 # Oops, something unspeakable happened.
255 # Generate the shadow list
256 def GenSSHShadow(l,masterFileName):
257 # Fetch all the users
260 # Depending on config, we write out either a single file,
261 # multiple files, or both
264 OldMask = os.umask(0077);
265 masterFile = open(masterFileName + ".tmp","w",0600);
268 Die(masterFileName,masterFile,None)
272 if PasswdAttrs == None:
275 # If we're going to be dealing with multiple keys, empty the
276 # directory before we start to avoid old keys hanging around
278 safe_rmtree(os.path.join(GlobalDir, 'userkeys'))
279 safe_makedirs(os.path.join(GlobalDir, 'userkeys'))
281 for x in PasswdAttrs:
282 # If the account is locked, do not write it.
283 # This is a partial stop-gap. The ssh also needs to change this
284 # to ignore ~/.ssh/authorized* files.
285 if (GetAttr(x,"userPassword").find("*LK*") != -1) \
286 or GetAttr(x,"userPassword").startswith("!"):
289 if x[1].has_key("uidNumber") == 0 or \
290 x[1].has_key("sshRSAAuthKey") == 0:
292 User = GetAttr(x,"uid");
297 OldMask = os.umask(0077);
298 File = os.path.join(GlobalDir, 'userkeys', User)
299 F = open(File + ".tmp","w",0600);
302 for I in x[1]["sshRSAAuthKey"]:
304 MultipleLine = "%s" % I
305 MultipleLine = Sanitize(MultipleLine) + "\n"
306 F.write(MultipleLine)
308 SingleLine = "%s: %s" % (User, I)
309 SingleLine = Sanitize(SingleLine) + "\n"
310 masterFile.write(SingleLine)
314 userfiles.append(os.path.basename(File))
316 # Oops, something unspeakable happened.
319 Die(masterFileName,masterFile,None)
323 Done(masterFileName,masterFile,None)
324 singlefile = os.path.basename(masterFileName)
326 return singlefile, userfiles
328 # Generate the group list
329 def GenGroup(l,File):
333 F = open(File + ".tdb.tmp","w");
335 # Generate the GroupMap
337 for x in GroupIDMap.keys():
340 # Fetch all the users
342 if PasswdAttrs == None:
345 # Sort them into a list of groups having a set of users
346 for x in PasswdAttrs:
347 if x[1].has_key("uidNumber") == 0 or IsInGroup(x) == 0:
349 if x[1].has_key("supplementaryGid") == 0:
352 for I in x[1]["supplementaryGid"]:
353 if GroupMap.has_key(I):
354 GroupMap[I].append(GetAttr(x,"uid"));
356 print "Group does not exist ",I,"but",GetAttr(x,"uid"),"is in it";
358 # Output the group file.
360 for x in GroupMap.keys():
361 grouprevmap[GroupIDMap[x]] = x
362 if GroupIDMap.has_key(x) == 0:
364 Line = "%s:x:%u:" % (x,GroupIDMap[x]);
366 for I in GroupMap[x]:
367 Line = Line + ("%s%s" % (Comma,I));
369 Line = Sanitize(Line) + "\n";
370 F.write("0%u %s" % (J,Line));
371 F.write(".%s %s" % (x,Line));
372 F.write("=%u %s" % (GroupIDMap[x],Line));
375 # Oops, something unspeakable happened.
383 # Generate the email forwarding list
384 def GenForward(l,File):
387 OldMask = os.umask(0022);
388 F = open(File + ".tmp","w",0644);
391 # Fetch all the users
393 if PasswdAttrs == None:
396 # Write out the email address for each user
397 for x in PasswdAttrs:
398 if x[1].has_key("emailForward") == 0 or IsInGroup(x) == 0:
401 # Do not allow people to try to buffer overflow busted parsers
402 if len(GetAttr(x,"emailForward")) > 200:
405 # Check the forwarding address
406 if EmailCheck.match(GetAttr(x,"emailForward")) == None:
408 Line = "%s: %s" % (GetAttr(x,"uid"),GetAttr(x,"emailForward"));
409 Line = Sanitize(Line) + "\n";
412 # Oops, something unspeakable happened.
418 def GenAllForward(l,File):
421 OldMask = os.umask(0022);
422 Fdb = os.popen("cdbmake %s %s.tmp"%(File,File),"w");
425 # Fetch all the users
427 if PasswdAttrs == None:
430 # Write out the email address for each user
431 for x in PasswdAttrs:
432 if x[1].has_key("emailForward") == 0:
435 # Do not allow people to try to buffer overflow busted parsers
436 Forward = GetAttr(x,"emailForward");
437 if len(Forward) > 200:
440 # Check the forwarding address
441 if EmailCheck.match(Forward) == None:
444 User = GetAttr(x,"uid");
445 Fdb.write("+%d,%d:%s->%s\n"%(len(User),len(Forward),User,Forward));
447 # Oops, something unspeakable happened.
451 if Fdb.close() != None:
452 raise "cdbmake gave an error";
454 # Generate the anon XEarth marker file
455 def GenMarkers(l,File):
458 F = open(File + ".tmp","w");
460 # Fetch all the users
462 if PasswdAttrs == None:
465 # Write out the position for each user
466 for x in PasswdAttrs:
467 if x[1].has_key("latitude") == 0 or x[1].has_key("longitude") == 0:
470 Line = "%8s %8s \"\""%(DecDegree(GetAttr(x,"latitude"),1),DecDegree(GetAttr(x,"longitude"),1));
471 Line = Sanitize(Line) + "\n";
476 # Oops, something unspeakable happened.
482 # Generate the debian-private subscription list
483 def GenPrivate(l,File):
486 F = open(File + ".tmp","w");
488 # Fetch all the users
490 if PasswdAttrs == None:
493 # Write out the position for each user
494 for x in PasswdAttrs:
495 if x[1].has_key("privateSub") == 0:
498 # If the account is locked, do not write it
499 if (GetAttr(x,"userPassword").find("*LK*") != -1) \
500 or GetAttr(x,"userPassword").startswith("!"):
503 # If the account has no PGP key, do not write it
504 if x[1].has_key("keyFingerPrint") == 0:
507 # Must be in the Debian group (yuk, hard coded for now)
508 if GetAttr(x,"gidNumber") != "800":
512 Line = "%s"%(GetAttr(x,"privateSub"));
513 Line = Sanitize(Line) + "\n";
518 # Oops, something unspeakable happened.
524 # Generate a list of locked accounts
525 def GenDisabledAccounts(l,File):
528 F = open(File + ".tmp","w");
530 # Fetch all the users
532 if PasswdAttrs == None:
536 for x in PasswdAttrs:
537 if x[1].has_key("uidNumber") == 0:
540 Pass = GetAttr(x,"userPassword");
542 # *LK* is the reference value for a locked account
543 # password starting with ! is also a locked account
544 if Pass.find("*LK*") != -1 or Pass.startswith("!"):
545 # Format is <login>:<reason>
546 Line = "%s:%s" % (GetAttr(x,"uid"), "Account is locked")
549 F.write(Sanitize(Line) + "\n")
551 # Oops, something unspeakable happened.
557 # Generate the list of local addresses that refuse all mail
558 def GenMailDisable(l,File):
561 F = open(File + ".tmp","w");
563 # Fetch all the users
565 if PasswdAttrs == None:
568 for x in PasswdAttrs:
571 if x[1].has_key("mailDisableMessage"):
572 Reason = GetAttr(x,"mailDisableMessage")
576 # Must be in the Debian group (yuk, hard coded for now)
577 if GetAttr(x,"gidNumber") != "800":
581 Line = "%s: %s"%(GetAttr(x,"uid"),Reason);
582 Line = Sanitize(Line) + "\n";
587 # Oops, something unspeakable happened.
593 # Generate a list of uids that should have boolean affects applied
594 def GenMailBool(l,File,Key):
597 F = open(File + ".tmp","w");
599 # Fetch all the users
601 if PasswdAttrs == None:
604 for x in PasswdAttrs:
607 if x[1].has_key(Key) == 0:
610 # Must be in the Debian group (yuk, hard coded for now)
611 if GetAttr(x,"gidNumber") != "800":
614 if GetAttr(x,Key) != "TRUE":
618 Line = "%s"%(GetAttr(x,"uid"));
619 Line = Sanitize(Line) + "\n";
624 # Oops, something unspeakable happened.
630 # Generate a list of hosts for RBL or whitelist purposes.
631 def GenMailList(l,File,Key):
634 F = open(File + ".tmp","w");
636 # Fetch all the users
638 if PasswdAttrs == None:
641 for x in PasswdAttrs:
644 if x[1].has_key(Key) == 0:
647 # Must be in the Debian group (yuk, hard coded for now)
648 if GetAttr(x,"gidNumber") != "800":
655 if Key == "mailWhitelist":
656 if re.match('^[-\w.]+(/[\d]+)?$',z) == None:
659 if re.match('^[-\w.]+$',z) == None:
663 Line = GetAttr(x,"uid")
667 if Key == "mailRHSBL":
668 Line += "/$sender_address_domain"
671 Line = Sanitize(Line) + "\n";
676 # Oops, something unspeakable happened.
682 # Generate the DNS Zone file
683 def GenDNS(l,File,HomePrefix):
686 F = open(File + ".tmp","w");
688 # Fetch all the users
690 if PasswdAttrs == None:
693 # Write out the zone file entry for each user
694 for x in PasswdAttrs:
695 if x[1].has_key("dnsZoneEntry") == 0:
698 # If the account has no PGP key, do not write it
699 if x[1].has_key("keyFingerPrint") == 0:
702 F.write("; %s\n"%(EmailAddress(x)));
703 for z in x[1]["dnsZoneEntry"]:
704 Split = z.lower().split()
705 if Split[1].lower() == 'in':
706 for y in range(0,len(Split)):
709 Line = " ".join(Split) + "\n";
712 Host = Split[0] + DNSZone;
713 if BSMTPCheck.match(Line) != None:
714 F.write("; Has BSMTP\n");
716 # Write some identification information
717 if Split[2].lower() == "a":
718 Line = "%s IN TXT \"%s\"\n"%(Split[0],EmailAddress(x));
719 for y in x[1]["keyFingerPrint"]:
720 Line = Line + "%s IN TXT \"PGP %s\"\n"%(Split[0],FormatPGPKey(y));
723 Line = "; Err %s"%(str(Split));
728 F.write("; Errors\n");
731 # Oops, something unspeakable happened.
737 # Generate the DNS SSHFP records
738 def GenSSHFP(l,File,HomePrefix):
741 F = open(File + ".tmp","w")
743 # Fetch all the hosts
745 if HostAttrs == None:
749 if x[1].has_key("hostname") == 0 or \
750 x[1].has_key("sshRSAHostKey") == 0:
752 Host = GetAttr(x,"hostname");
754 for I in x[1]["sshRSAHostKey"]:
756 if Split[0] == 'ssh-rsa':
758 if Split[0] == 'ssh-dss':
760 if Algorithm == None:
762 Fingerprint = sha.new(base64.decodestring(Split[1])).hexdigest()
763 Line = "%s. IN SSHFP %u 1 %s" % (Host,Algorithm,Fingerprint)
764 Line = Sanitize(Line) + "\n"
766 # Oops, something unspeakable happened.
772 # Generate the BSMTP file
773 def GenBSMTP(l,File,HomePrefix):
776 F = open(File + ".tmp","w");
778 # Fetch all the users
780 if PasswdAttrs == None:
783 # Write out the zone file entry for each user
784 for x in PasswdAttrs:
785 if x[1].has_key("dnsZoneEntry") == 0:
788 # If the account has no PGP key, do not write it
789 if x[1].has_key("keyFingerPrint") == 0:
792 for z in x[1]["dnsZoneEntry"]:
793 Split = z.lower().split()
794 if Split[1].lower() == 'in':
795 for y in range(0,len(Split)):
798 Line = " ".join(Split) + "\n";
800 Host = Split[0] + DNSZone;
801 if BSMTPCheck.match(Line) != None:
802 F.write("%s: user=%s group=Debian file=%s%s/bsmtp/%s\n"%(Host,
803 GetAttr(x,"uid"),HomePrefix,GetAttr(x,"uid"),Host));
806 F.write("; Errors\n");
809 # Oops, something unspeakable happened.
819 if not Host in HostToIPCache:
822 IPAdressesT = list(set([ (a[0],a[4][0]) for a in socket.getaddrinfo(Host, None)]))
823 except socket.gaierror, (code):
824 if code[0] != -2: raise
826 for addr in IPAdressesT:
827 if addr[0] == socket.AF_INET: IPAdresses += [addr[1], "::ffff:"+addr[1]]
828 else: IPAdresses += [addr[1]]
829 HostToIPCache[Host] = IPAdresses
830 return HostToIPCache[Host]
833 # Generate the ssh known hosts file
834 def GenSSHKnown(l,File,mode=None):
837 OldMask = os.umask(0022);
838 F = open(File + ".tmp","w",0644);
842 if HostAttrs == None:
846 if x[1].has_key("hostname") == 0 or \
847 x[1].has_key("sshRSAHostKey") == 0:
849 Host = GetAttr(x,"hostname");
851 SHost = Host.find(".")
852 if SHost != None: HostNames += [Host[0:SHost]]
854 for I in x[1]["sshRSAHostKey"]:
855 if mode and mode == 'authorized_keys':
856 #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)
857 Line = 'command="rsync --server --sender -pr . /var/cache/userdir-ldap/hosts/%s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding %s' % (Host,I)
859 Line = "%s %s" %(",".join(HostNames + HostToIP(Host)), I);
860 Line = Sanitize(Line) + "\n";
862 # Oops, something unspeakable happened.
868 # Generate the debianhosts file (list of all IP addresses)
869 def GenHosts(l,File):
872 OldMask = os.umask(0022);
873 F = open(File + ".tmp","w",0644);
876 # Fetch all the hosts
877 HostNames = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"hostname=*",\
880 if HostNames == None:
884 if x[1].has_key("hostname") == 0:
886 Host = GetAttr(x,"hostname");
888 Addr = socket.gethostbyname(Host);
889 F.write(Addr + "\n");
892 # Oops, something unspeakable happened.
898 def GenKeyrings(l,OutDir):
900 shutil.copy(k, OutDir)
902 # Connect to the ldap server
904 F = open(PassDir+"/pass-"+pwd.getpwuid(os.getuid())[0],"r");
905 Pass = F.readline().strip().split(" ")
907 l.simple_bind_s("uid="+Pass[0]+","+BaseDn,Pass[1]);
909 # Fetch all the groups
911 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"gid=*",\
912 ["gid","gidNumber"]);
914 # Generate the GroupMap and GroupIDMap
916 if x[1].has_key("gidNumber") == 0:
918 GroupIDMap[x[1]["gid"][0]] = int(x[1]["gidNumber"][0]);
920 # Fetch all the users
921 PasswdAttrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid=*",\
922 ["uid","uidNumber","gidNumber","supplementaryGid",\
923 "gecos","loginShell","userPassword","shadowLastChange",\
924 "shadowMin","shadowMax","shadowWarning","shadowInactive",
925 "shadowExpire","emailForward","latitude","longitude",\
926 "allowedHost","sshRSAAuthKey","dnsZoneEntry","cn","sn",\
927 "keyFingerPrint","privateSub","mailDisableMessage",\
928 "mailGreylisting","mailCallout","mailRBL","mailRHSBL",\
929 "mailWhitelist", "sudoPassword"]);
930 # Fetch all the hosts
931 HostAttrs = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"sshRSAHostKey=*",\
932 ["hostname","sshRSAHostKey"]);
934 # Open the control file
935 if len(sys.argv) == 1:
936 F = open(GenerateConf,"r");
938 F = open(sys.argv[1],"r")
940 # Generate global things
941 GlobalDir = GenerateDir+"/";
942 SSHGlobal, SSHFiles = GenSSHShadow(l,GlobalDir+"ssh-rsa-shadow");
943 GenAllForward(l,GlobalDir+"mail-forward.cdb");
944 GenMarkers(l,GlobalDir+"markers");
945 GenPrivate(l,GlobalDir+"debian-private");
946 GenDisabledAccounts(l,GlobalDir+"disabled-accounts");
947 GenSSHKnown(l,GlobalDir+"ssh_known_hosts");
948 #GenSSHKnown(l,GlobalDir+"authorized_keys", 'authorized_keys');
949 GenHosts(l,GlobalDir+"debianhosts");
950 GenMailDisable(l,GlobalDir+"mail-disable");
951 GenMailBool(l,GlobalDir+"mail-greylist","mailGreylisting");
952 GenMailBool(l,GlobalDir+"mail-callout","mailCallout");
953 GenMailList(l,GlobalDir+"mail-rbl","mailRBL");
954 GenMailList(l,GlobalDir+"mail-rhsbl","mailRHSBL");
955 GenMailList(l,GlobalDir+"mail-whitelist","mailWhitelist");
956 GenKeyrings(l,GlobalDir);
959 GenForward(l,GlobalDir+"forward-alias");
971 Split = Line.split(" ")
972 OutDir = GenerateDir + '/' + Split[0] + '/';
973 try: os.mkdir(OutDir);
976 # Get the group list and convert any named groups to numerics
984 if GroupIDMap.has_key(I):
985 GroupList[str(GroupIDMap[I])] = None;
990 CurrentHost = Split[0];
992 # If we're using a single SSH file, deal with it
993 if SSHGlobal is not None:
994 DoLink(GlobalDir, OutDir, SSHGlobal)
996 DoLink(GlobalDir,OutDir,"debianhosts");
997 DoLink(GlobalDir,OutDir,"ssh_known_hosts");
998 DoLink(GlobalDir,OutDir,"disabled-accounts")
1001 if ExtraList.has_key("[NOPASSWD]"):
1002 userlist = GenPasswd(l,OutDir+"passwd",Split[1], "*");
1004 userlist = GenPasswd(l,OutDir+"passwd",Split[1], "x");
1006 grouprevmap = GenGroup(l,OutDir+"group");
1007 GenShadowSudo(l, OutDir+"sudo-passwd")
1009 # Now we know who we're allowing on the machine, export
1010 # the relevant ssh keys
1011 if MultipleSSHFiles:
1012 OldMask = os.umask(0077);
1013 tf = tarfile.open(name=os.path.join(GlobalDir, 'ssh-keys-%s.tar.gz' % CurrentHost), mode='w:gz')
1015 for f in userlist.keys():
1016 if f not in SSHFiles:
1018 # If we're not exporting their primary group, don't export
1021 if userlist[f] in grouprevmap.keys():
1022 grname = grouprevmap[userlist[f]]
1025 if int(userlist[f]) <= 100:
1026 # In these cases, look it up in the normal way so we
1027 # deal with cases where, for instance, users are in group
1028 # users as their primary group.
1029 grname = grp.getgrgid(userlist[f])[0]
1030 except Exception, e:
1034 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])
1037 to = tf.gettarinfo(os.path.join(GlobalDir, 'userkeys', f), f)
1038 # These will only be used where the username doesn't
1039 # exist on the target system for some reason; hence,
1040 # in those cases, the safest thing is for the file to
1041 # be owned by root but group nobody. This deals with
1042 # the bloody obscure case where the group fails to exist
1043 # whilst the user does (in which case we want to avoid
1044 # ending up with a file which is owned user:root to avoid
1045 # a fairly obvious attack vector)
1048 # Using the username / groupname fields avoids any need
1049 # to give a shit^W^W^Wcare about the UIDoffset stuff.
1053 tf.addfile(to, file(os.path.join(GlobalDir, 'userkeys', f)))
1056 os.rename(os.path.join(GlobalDir, 'ssh-keys-%s.tar.gz' % CurrentHost),
1057 os.path.join(OutDir, 'ssh-keys.tar.gz'))
1059 if ExtraList.has_key("[UNTRUSTED]"):
1061 if not ExtraList.has_key("[NOPASSWD]"):
1062 GenShadow(l,OutDir+"shadow");
1064 # Link in global things
1065 DoLink(GlobalDir,OutDir,"markers");
1066 DoLink(GlobalDir,OutDir,"mail-forward.cdb");
1067 DoLink(GlobalDir,OutDir,"mail-disable");
1068 DoLink(GlobalDir,OutDir,"mail-greylist");
1069 DoLink(GlobalDir,OutDir,"mail-callout");
1070 DoLink(GlobalDir,OutDir,"mail-rbl");
1071 DoLink(GlobalDir,OutDir,"mail-rhsbl");
1072 DoLink(GlobalDir,OutDir,"mail-whitelist");
1075 DoLink(GlobalDir,OutDir,"forward-alias");
1077 if ExtraList.has_key("[DNS]"):
1078 GenDNS(l,OutDir+"dns-zone",Split[1]);
1079 GenSSHFP(l,OutDir+"dns-sshfp",Split[1])
1081 if ExtraList.has_key("[BSMTP]"):
1082 GenBSMTP(l,OutDir+"bsmtp",Split[1])
1084 if ExtraList.has_key("[PRIVATE]"):
1085 DoLink(GlobalDir,OutDir,"debian-private")
1087 if ExtraList.has_key("[KEYRING]"):
1089 DoLink(GlobalDir,OutDir,os.path.basename(k))
1092 try: posix.remove(OutDir+os.path.basename(k));