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, untrusted):
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_passwd_hmac('password-is-confirmed', 'sudo', x[1]['uid'][0], uuid, hosts, cryptedpass):
235 for_all = hosts == "*"
236 for_this_host = CurrentHost in hosts.split(',')
237 if not (for_all or for_this_host):
239 # ignore * passwords for untrusted hosts, but copy host specific passwords
240 if for_all and untrusted:
243 if for_this_host: # this makes sure we take a per-host entry over the for-all entry
248 Line = "%s:%s" % (GetAttr(x,"uid"), Pass)
249 Line = Sanitize(Line) + "\n";
250 F.write("%s" % (Line));
252 # Oops, something unspeakable happened.
258 # Generate the shadow list
260 # Fetch all the users
265 if PasswdAttrs == None:
268 safe_rmtree(os.path.join(GlobalDir, 'userkeys'))
269 safe_makedirs(os.path.join(GlobalDir, 'userkeys'))
271 for x in PasswdAttrs:
272 # If the account is locked, do not write it.
273 # This is a partial stop-gap. The ssh also needs to change this
274 # to ignore ~/.ssh/authorized* files.
275 if (GetAttr(x,"userPassword").find("*LK*") != -1) \
276 or GetAttr(x,"userPassword").startswith("!"):
279 if x[1].has_key("uidNumber") == 0 or \
280 x[1].has_key("sshRSAAuthKey") == 0:
282 User = GetAttr(x,"uid");
286 OldMask = os.umask(0077);
287 File = os.path.join(GlobalDir, 'userkeys', User)
288 F = open(File + ".tmp","w",0600);
291 for I in x[1]["sshRSAAuthKey"]:
292 MultipleLine = "%s" % I
293 MultipleLine = Sanitize(MultipleLine) + "\n"
294 F.write(MultipleLine)
297 userfiles.append(os.path.basename(File))
299 # Oops, something unspeakable happened.
302 Die(masterFileName,masterFile,None)
307 def GenSSHtarballs(userlist, SSHFiles, grouprevmap, target):
308 OldMask = os.umask(0077);
309 tf = tarfile.open(name=os.path.join(GlobalDir, 'ssh-keys-%s.tar.gz' % CurrentHost), mode='w:gz')
311 for f in userlist.keys():
312 if f not in SSHFiles:
314 # If we're not exporting their primary group, don't export
317 if userlist[f] in grouprevmap.keys():
318 grname = grouprevmap[userlist[f]]
321 if int(userlist[f]) <= 100:
322 # In these cases, look it up in the normal way so we
323 # deal with cases where, for instance, users are in group
324 # users as their primary group.
325 grname = grp.getgrgid(userlist[f])[0]
330 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])
333 to = tf.gettarinfo(os.path.join(GlobalDir, 'userkeys', f), f)
334 # These will only be used where the username doesn't
335 # exist on the target system for some reason; hence,
336 # in those cases, the safest thing is for the file to
337 # be owned by root but group nobody. This deals with
338 # the bloody obscure case where the group fails to exist
339 # whilst the user does (in which case we want to avoid
340 # ending up with a file which is owned user:root to avoid
341 # a fairly obvious attack vector)
344 # Using the username / groupname fields avoids any need
345 # to give a shit^W^W^Wcare about the UIDoffset stuff.
349 tf.addfile(to, file(os.path.join(GlobalDir, 'userkeys', f)))
352 os.rename(os.path.join(GlobalDir, 'ssh-keys-%s.tar.gz' % CurrentHost), target)
354 # Generate the group list
355 def GenGroup(l,File):
359 F = open(File + ".tdb.tmp","w");
361 # Generate the GroupMap
363 for x in GroupIDMap.keys():
366 # Fetch all the users
368 if PasswdAttrs == None:
371 # Sort them into a list of groups having a set of users
372 for x in PasswdAttrs:
373 if x[1].has_key("uidNumber") == 0 or IsInGroup(x) == 0:
375 if x[1].has_key("supplementaryGid") == 0:
378 for I in x[1]["supplementaryGid"]:
379 if GroupMap.has_key(I):
380 GroupMap[I].append(GetAttr(x,"uid"));
382 print "Group does not exist ",I,"but",GetAttr(x,"uid"),"is in it";
384 # Output the group file.
386 for x in GroupMap.keys():
387 grouprevmap[GroupIDMap[x]] = x
388 if GroupIDMap.has_key(x) == 0:
390 Line = "%s:x:%u:" % (x,GroupIDMap[x]);
392 for I in GroupMap[x]:
393 Line = Line + ("%s%s" % (Comma,I));
395 Line = Sanitize(Line) + "\n";
396 F.write("0%u %s" % (J,Line));
397 F.write(".%s %s" % (x,Line));
398 F.write("=%u %s" % (GroupIDMap[x],Line));
401 # Oops, something unspeakable happened.
409 # Generate the email forwarding list
410 def GenForward(l,File):
413 OldMask = os.umask(0022);
414 F = open(File + ".tmp","w",0644);
417 # Fetch all the users
419 if PasswdAttrs == None:
422 # Write out the email address for each user
423 for x in PasswdAttrs:
424 if x[1].has_key("emailForward") == 0 or IsInGroup(x) == 0:
427 # Do not allow people to try to buffer overflow busted parsers
428 if len(GetAttr(x,"emailForward")) > 200:
431 # Check the forwarding address
432 if EmailCheck.match(GetAttr(x,"emailForward")) == None:
434 Line = "%s: %s" % (GetAttr(x,"uid"),GetAttr(x,"emailForward"));
435 Line = Sanitize(Line) + "\n";
438 # Oops, something unspeakable happened.
444 def GenAllForward(l,File):
447 OldMask = os.umask(0022);
448 Fdb = os.popen("cdbmake %s %s.tmp"%(File,File),"w");
451 # Fetch all the users
453 if PasswdAttrs == None:
456 # Write out the email address for each user
457 for x in PasswdAttrs:
458 if x[1].has_key("emailForward") == 0:
461 # Do not allow people to try to buffer overflow busted parsers
462 Forward = GetAttr(x,"emailForward");
463 if len(Forward) > 200:
466 # Check the forwarding address
467 if EmailCheck.match(Forward) == None:
470 User = GetAttr(x,"uid");
471 Fdb.write("+%d,%d:%s->%s\n"%(len(User),len(Forward),User,Forward));
473 # Oops, something unspeakable happened.
477 if Fdb.close() != None:
478 raise "cdbmake gave an error";
480 # Generate the anon XEarth marker file
481 def GenMarkers(l,File):
484 F = open(File + ".tmp","w");
486 # Fetch all the users
488 if PasswdAttrs == None:
491 # Write out the position for each user
492 for x in PasswdAttrs:
493 if x[1].has_key("latitude") == 0 or x[1].has_key("longitude") == 0:
496 Line = "%8s %8s \"\""%(DecDegree(GetAttr(x,"latitude"),1),DecDegree(GetAttr(x,"longitude"),1));
497 Line = Sanitize(Line) + "\n";
502 # Oops, something unspeakable happened.
508 # Generate the debian-private subscription list
509 def GenPrivate(l,File):
512 F = open(File + ".tmp","w");
514 # Fetch all the users
516 if PasswdAttrs == None:
519 # Write out the position for each user
520 for x in PasswdAttrs:
521 if x[1].has_key("privateSub") == 0:
524 # If the account is locked, do not write it
525 if (GetAttr(x,"userPassword").find("*LK*") != -1) \
526 or GetAttr(x,"userPassword").startswith("!"):
529 # If the account has no PGP key, do not write it
530 if x[1].has_key("keyFingerPrint") == 0:
533 # Must be in the Debian group (yuk, hard coded for now)
534 if GetAttr(x,"gidNumber") != "800":
538 Line = "%s"%(GetAttr(x,"privateSub"));
539 Line = Sanitize(Line) + "\n";
544 # Oops, something unspeakable happened.
550 # Generate a list of locked accounts
551 def GenDisabledAccounts(l,File):
554 F = open(File + ".tmp","w");
556 # Fetch all the users
558 if PasswdAttrs == None:
562 for x in PasswdAttrs:
563 if x[1].has_key("uidNumber") == 0:
566 Pass = GetAttr(x,"userPassword");
568 # *LK* is the reference value for a locked account
569 # password starting with ! is also a locked account
570 if Pass.find("*LK*") != -1 or Pass.startswith("!"):
571 # Format is <login>:<reason>
572 Line = "%s:%s" % (GetAttr(x,"uid"), "Account is locked")
575 F.write(Sanitize(Line) + "\n")
577 # Oops, something unspeakable happened.
583 # Generate the list of local addresses that refuse all mail
584 def GenMailDisable(l,File):
587 F = open(File + ".tmp","w");
589 # Fetch all the users
591 if PasswdAttrs == None:
594 for x in PasswdAttrs:
597 if x[1].has_key("mailDisableMessage"):
598 Reason = GetAttr(x,"mailDisableMessage")
602 # Must be in the Debian group (yuk, hard coded for now)
603 if GetAttr(x,"gidNumber") != "800":
607 Line = "%s: %s"%(GetAttr(x,"uid"),Reason);
608 Line = Sanitize(Line) + "\n";
613 # Oops, something unspeakable happened.
619 # Generate a list of uids that should have boolean affects applied
620 def GenMailBool(l,File,Key):
623 F = open(File + ".tmp","w");
625 # Fetch all the users
627 if PasswdAttrs == None:
630 for x in PasswdAttrs:
633 if x[1].has_key(Key) == 0:
636 # Must be in the Debian group (yuk, hard coded for now)
637 if GetAttr(x,"gidNumber") != "800":
640 if GetAttr(x,Key) != "TRUE":
644 Line = "%s"%(GetAttr(x,"uid"));
645 Line = Sanitize(Line) + "\n";
650 # Oops, something unspeakable happened.
656 # Generate a list of hosts for RBL or whitelist purposes.
657 def GenMailList(l,File,Key):
660 F = open(File + ".tmp","w");
662 # Fetch all the users
664 if PasswdAttrs == None:
667 for x in PasswdAttrs:
670 if x[1].has_key(Key) == 0:
673 # Must be in the Debian group (yuk, hard coded for now)
674 if GetAttr(x,"gidNumber") != "800":
681 if Key == "mailWhitelist":
682 if re.match('^[-\w.]+(/[\d]+)?$',z) == None:
685 if re.match('^[-\w.]+$',z) == None:
689 Line = GetAttr(x,"uid")
693 if Key == "mailRHSBL":
694 Line += "/$sender_address_domain"
697 Line = Sanitize(Line) + "\n";
702 # Oops, something unspeakable happened.
708 # Generate the DNS Zone file
709 def GenDNS(l,File,HomePrefix):
712 F = open(File + ".tmp","w");
714 # Fetch all the users
716 if PasswdAttrs == None:
719 # Write out the zone file entry for each user
720 for x in PasswdAttrs:
721 if x[1].has_key("dnsZoneEntry") == 0:
724 # If the account has no PGP key, do not write it
725 if x[1].has_key("keyFingerPrint") == 0:
728 F.write("; %s\n"%(EmailAddress(x)));
729 for z in x[1]["dnsZoneEntry"]:
730 Split = z.lower().split()
731 if Split[1].lower() == 'in':
732 for y in range(0,len(Split)):
735 Line = " ".join(Split) + "\n";
738 Host = Split[0] + DNSZone;
739 if BSMTPCheck.match(Line) != None:
740 F.write("; Has BSMTP\n");
742 # Write some identification information
743 if Split[2].lower() == "a":
744 Line = "%s IN TXT \"%s\"\n"%(Split[0],EmailAddress(x));
745 for y in x[1]["keyFingerPrint"]:
746 Line = Line + "%s IN TXT \"PGP %s\"\n"%(Split[0],FormatPGPKey(y));
749 Line = "; Err %s"%(str(Split));
754 F.write("; Errors\n");
757 # Oops, something unspeakable happened.
763 # Generate the DNS SSHFP records
764 def GenSSHFP(l,File,HomePrefix):
767 F = open(File + ".tmp","w")
769 # Fetch all the hosts
771 if HostAttrs == None:
775 if x[1].has_key("hostname") == 0 or \
776 x[1].has_key("sshRSAHostKey") == 0:
778 Host = GetAttr(x,"hostname");
780 for I in x[1]["sshRSAHostKey"]:
782 if Split[0] == 'ssh-rsa':
784 if Split[0] == 'ssh-dss':
786 if Algorithm == None:
788 Fingerprint = sha.new(base64.decodestring(Split[1])).hexdigest()
789 Line = "%s. IN SSHFP %u 1 %s" % (Host,Algorithm,Fingerprint)
790 Line = Sanitize(Line) + "\n"
792 # Oops, something unspeakable happened.
798 # Generate the BSMTP file
799 def GenBSMTP(l,File,HomePrefix):
802 F = open(File + ".tmp","w");
804 # Fetch all the users
806 if PasswdAttrs == None:
809 # Write out the zone file entry for each user
810 for x in PasswdAttrs:
811 if x[1].has_key("dnsZoneEntry") == 0:
814 # If the account has no PGP key, do not write it
815 if x[1].has_key("keyFingerPrint") == 0:
818 for z in x[1]["dnsZoneEntry"]:
819 Split = z.lower().split()
820 if Split[1].lower() == 'in':
821 for y in range(0,len(Split)):
824 Line = " ".join(Split) + "\n";
826 Host = Split[0] + DNSZone;
827 if BSMTPCheck.match(Line) != None:
828 F.write("%s: user=%s group=Debian file=%s%s/bsmtp/%s\n"%(Host,
829 GetAttr(x,"uid"),HomePrefix,GetAttr(x,"uid"),Host));
832 F.write("; Errors\n");
835 # Oops, something unspeakable happened.
845 if not Host in HostToIPCache:
848 IPAdressesT = list(set([ (a[0],a[4][0]) for a in socket.getaddrinfo(Host, None)]))
849 except socket.gaierror, (code):
850 if code[0] != -2: raise
852 for addr in IPAdressesT:
853 if addr[0] == socket.AF_INET: IPAdresses += [addr[1], "::ffff:"+addr[1]]
854 else: IPAdresses += [addr[1]]
855 HostToIPCache[Host] = IPAdresses
856 return HostToIPCache[Host]
859 # Generate the ssh known hosts file
860 def GenSSHKnown(l,File,mode=None):
863 OldMask = os.umask(0022);
864 F = open(File + ".tmp","w",0644);
868 if HostAttrs == None:
872 if x[1].has_key("hostname") == 0 or \
873 x[1].has_key("sshRSAHostKey") == 0:
875 Host = GetAttr(x,"hostname");
877 SHost = Host.find(".")
878 if SHost != None: HostNames += [Host[0:SHost]]
880 for I in x[1]["sshRSAHostKey"]:
881 if mode and mode == 'authorized_keys':
882 #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)
883 Line = 'command="rsync --server --sender -pr . /var/cache/userdir-ldap/hosts/%s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding %s' % (Host,I)
885 Line = "%s %s" %(",".join(HostNames + HostToIP(Host)), I);
886 Line = Sanitize(Line) + "\n";
888 # Oops, something unspeakable happened.
894 # Generate the debianhosts file (list of all IP addresses)
895 def GenHosts(l,File):
898 OldMask = os.umask(0022);
899 F = open(File + ".tmp","w",0644);
902 # Fetch all the hosts
903 HostNames = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"hostname=*",\
906 if HostNames == None:
910 if x[1].has_key("hostname") == 0:
912 Host = GetAttr(x,"hostname");
914 Addr = socket.gethostbyname(Host);
915 F.write(Addr + "\n");
918 # Oops, something unspeakable happened.
924 def GenKeyrings(l,OutDir):
926 shutil.copy(k, OutDir)
929 # Connect to the ldap server
931 F = open(PassDir+"/pass-"+pwd.getpwuid(os.getuid())[0],"r");
932 Pass = F.readline().strip().split(" ")
934 l.simple_bind_s("uid="+Pass[0]+","+BaseDn,Pass[1]);
936 # Fetch all the groups
938 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"gid=*",\
939 ["gid","gidNumber"]);
941 # Generate the GroupMap and GroupIDMap
943 if x[1].has_key("gidNumber") == 0:
945 GroupIDMap[x[1]["gid"][0]] = int(x[1]["gidNumber"][0]);
947 # Fetch all the users
948 PasswdAttrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid=*",\
949 ["uid","uidNumber","gidNumber","supplementaryGid",\
950 "gecos","loginShell","userPassword","shadowLastChange",\
951 "shadowMin","shadowMax","shadowWarning","shadowInactive",
952 "shadowExpire","emailForward","latitude","longitude",\
953 "allowedHost","sshRSAAuthKey","dnsZoneEntry","cn","sn",\
954 "keyFingerPrint","privateSub","mailDisableMessage",\
955 "mailGreylisting","mailCallout","mailRBL","mailRHSBL",\
956 "mailWhitelist", "sudoPassword"]);
957 # Fetch all the hosts
958 HostAttrs = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"sshRSAHostKey=*",\
959 ["hostname","sshRSAHostKey"]);
961 # Open the control file
962 if len(sys.argv) == 1:
963 F = open(GenerateConf,"r");
965 F = open(sys.argv[1],"r")
967 # Generate global things
968 GlobalDir = GenerateDir+"/";
969 SSHFiles = GenSSHShadow(l);
970 GenAllForward(l,GlobalDir+"mail-forward.cdb");
971 GenMarkers(l,GlobalDir+"markers");
972 GenPrivate(l,GlobalDir+"debian-private");
973 GenDisabledAccounts(l,GlobalDir+"disabled-accounts");
974 GenSSHKnown(l,GlobalDir+"ssh_known_hosts");
975 #GenSSHKnown(l,GlobalDir+"authorized_keys", 'authorized_keys');
976 GenHosts(l,GlobalDir+"debianhosts");
977 GenMailDisable(l,GlobalDir+"mail-disable");
978 GenMailBool(l,GlobalDir+"mail-greylist","mailGreylisting");
979 GenMailBool(l,GlobalDir+"mail-callout","mailCallout");
980 GenMailList(l,GlobalDir+"mail-rbl","mailRBL");
981 GenMailList(l,GlobalDir+"mail-rhsbl","mailRHSBL");
982 GenMailList(l,GlobalDir+"mail-whitelist","mailWhitelist");
983 GenKeyrings(l,GlobalDir);
986 GenForward(l,GlobalDir+"forward-alias");
998 Split = Line.split(" ")
999 OutDir = GenerateDir + '/' + Split[0] + '/';
1000 try: os.mkdir(OutDir);
1003 # Get the group list and convert any named groups to numerics
1008 ExtraList[I] = None;
1010 GroupList[I] = None;
1011 if GroupIDMap.has_key(I):
1012 GroupList[str(GroupIDMap[I])] = None;
1014 Allowed = GroupList;
1017 CurrentHost = Split[0];
1019 DoLink(GlobalDir,OutDir,"debianhosts");
1020 DoLink(GlobalDir,OutDir,"ssh_known_hosts");
1021 DoLink(GlobalDir,OutDir,"disabled-accounts")
1024 if ExtraList.has_key("[NOPASSWD]"):
1025 userlist = GenPasswd(l,OutDir+"passwd",Split[1], "*");
1027 userlist = GenPasswd(l,OutDir+"passwd",Split[1], "x");
1029 grouprevmap = GenGroup(l,OutDir+"group");
1030 GenShadowSudo(l, OutDir+"sudo-passwd", ExtraList.has_key("[UNTRUSTED]") or ExtraList.has_key("[NOPASSWD]"))
1032 # Now we know who we're allowing on the machine, export
1033 # the relevant ssh keys
1034 GenSSHtarballs(userlist, SSHFiles, grouprevmap, os.path.join(OutDir, 'ssh-keys.tar.gz'))
1036 if ExtraList.has_key("[UNTRUSTED]"):
1037 print "[UNTRUSTED] tag is obsolete and may be removed in the future."
1039 if not ExtraList.has_key("[NOPASSWD]"):
1040 GenShadow(l,OutDir+"shadow");
1042 # Link in global things
1043 if not ExtraList.has_key("[NOMARKERS]"):
1044 DoLink(GlobalDir,OutDir,"markers");
1045 DoLink(GlobalDir,OutDir,"mail-forward.cdb");
1046 DoLink(GlobalDir,OutDir,"mail-disable");
1047 DoLink(GlobalDir,OutDir,"mail-greylist");
1048 DoLink(GlobalDir,OutDir,"mail-callout");
1049 DoLink(GlobalDir,OutDir,"mail-rbl");
1050 DoLink(GlobalDir,OutDir,"mail-rhsbl");
1051 DoLink(GlobalDir,OutDir,"mail-whitelist");
1054 DoLink(GlobalDir,OutDir,"forward-alias");
1056 if ExtraList.has_key("[DNS]"):
1057 GenDNS(l,OutDir+"dns-zone",Split[1]);
1058 GenSSHFP(l,OutDir+"dns-sshfp",Split[1])
1060 if ExtraList.has_key("[BSMTP]"):
1061 GenBSMTP(l,OutDir+"bsmtp",Split[1])
1063 if ExtraList.has_key("[PRIVATE]"):
1064 DoLink(GlobalDir,OutDir,"debian-private")
1066 if ExtraList.has_key("[KEYRING]"):
1068 DoLink(GlobalDir,OutDir,os.path.basename(k))
1071 try: posix.remove(OutDir+os.path.basename(k));
1076 # vim:set shiftwidth=3: