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>
12 # Copyright (c) 2008 Luk Claes <luk@debian.org>
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 import string, re, time, ldap, getopt, sys, os, pwd, posix, socket, base64, sha, shutil, errno, tarfile, grp
29 from userdir_ldap import *;
40 UUID_FORMAT = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
42 EmailCheck = re.compile("^([^ <>@]+@[^ ,<>@]+)?$");
43 BSMTPCheck = re.compile(".*mx 0 (gluck)\.debian\.org\..*",re.DOTALL);
44 DNSZone = ".debian.net"
45 Keyrings = ConfModule.sync_keyrings.split(":")
47 def safe_makedirs(dir):
51 if e.errno == errno.EEXIST:
60 if e.errno == errno.ENOENT:
66 return Str.translate(string.maketrans("\n\r\t","$$$"))
68 def DoLink(From,To,File):
69 try: posix.remove(To+File);
71 posix.link(From+File,To+File);
73 # See if this user is in the group list
74 def IsInGroup(DnRecord):
78 # See if the primary group is in the list
79 if Allowed.has_key(GetAttr(DnRecord,"gidNumber")) != 0:
82 # Check the host based ACL
83 if DnRecord[1].has_key("allowedHost") != 0:
84 for I in DnRecord[1]["allowedHost"]:
88 # See if there are supplementary groups
89 if DnRecord[1].has_key("supplementaryGid") == 0:
92 # Check the supplementary groups
93 for I in DnRecord[1]["supplementaryGid"]:
96 if len(s) == 2 and s[1] != CurrentHost:
98 if Allowed.has_key(group):
107 try: os.remove(File + ".tmp");
109 try: os.remove(File + ".tdb.tmp");
112 def Done(File,F,Fdb):
115 os.rename(File + ".tmp",File);
118 os.rename(File + ".tdb.tmp",File+".tdb");
120 # Generate the password list
121 def GenPasswd(l,File,HomePrefix,PwdMarker):
124 F = open(File + ".tdb.tmp","w");
127 # Fetch all the users
129 if PasswdAttrs == None:
133 for x in PasswdAttrs:
134 if x[1].has_key("uidNumber") == 0 or IsInGroup(x) == 0:
137 # Do not let people try to buffer overflow some busted passwd parser.
138 if len(GetAttr(x,"gecos")) > 100 or len(GetAttr(x,"loginShell")) > 50:
141 userlist[GetAttr(x, "uid")] = int(GetAttr(x, "gidNumber"))
142 Line = "%s:%s:%s:%s:%s:%s%s:%s" % (GetAttr(x,"uid"),\
144 GetAttr(x,"uidNumber"),GetAttr(x,"gidNumber"),\
145 GetAttr(x,"gecos"),HomePrefix,GetAttr(x,"uid"),\
146 GetAttr(x,"loginShell"));
148 Line = Sanitize(Line) + "\n";
149 F.write("0%u %s" % (I,Line));
150 F.write(".%s %s" % (GetAttr(x,"uid"),Line));
151 F.write("=%s %s" % (GetAttr(x,"uidNumber"),Line));
154 # Oops, something unspeakable happened.
160 # Return the list of users so we know which keys to export
163 # Generate the shadow list
164 def GenShadow(l,File):
167 OldMask = os.umask(0077);
168 F = open(File + ".tdb.tmp","w",0600);
171 # Fetch all the users
173 if PasswdAttrs == None:
177 for x in PasswdAttrs:
178 if x[1].has_key("uidNumber") == 0 or IsInGroup(x) == 0:
181 Pass = GetAttr(x,"userPassword");
182 if Pass[0:7] != "{crypt}" or len(Pass) > 50:
187 # If the account is locked, mark it as such in shadow
188 # See Debian Bug #308229 for why we set it to 1 instead of 0
189 if (GetAttr(x,"userPassword").find("*LK*") != -1) \
190 or GetAttr(x,"userPassword").startswith("!"):
193 ShadowExpire = GetAttr(x,"shadowExpire")
195 Line = "%s:%s:%s:%s:%s:%s:%s:%s:" % (GetAttr(x,"uid"),\
196 Pass,GetAttr(x,"shadowLastChange"),\
197 GetAttr(x,"shadowMin"),GetAttr(x,"shadowMax"),\
198 GetAttr(x,"shadowWarning"),GetAttr(x,"shadowInactive"),\
200 Line = Sanitize(Line) + "\n";
201 F.write("0%u %s" % (I,Line));
202 F.write(".%s %s" % (GetAttr(x,"uid"),Line));
205 # Oops, something unspeakable happened.
211 # Generate the sudo passwd file
212 def GenShadowSudo(l,File, untrusted):
215 OldMask = os.umask(0077);
216 F = open(File + ".tmp","w",0600);
219 # Fetch all the users
221 if PasswdAttrs == None:
224 for x in PasswdAttrs:
226 if x[1].has_key("uidNumber") == 0 or IsInGroup(x) == 0:
229 if x[1].has_key('sudoPassword'):
230 for entry in x[1]['sudoPassword']:
231 Match = re.compile('^('+UUID_FORMAT+') (confirmed:[0-9a-f]{40}|unconfirmed) ([a-z0-9.,*]+) ([^ ]+)$').match(entry)
234 uuid = Match.group(1)
235 status = Match.group(2)
236 hosts = Match.group(3)
237 cryptedpass = Match.group(4)
239 if status != 'confirmed:'+make_passwd_hmac('password-is-confirmed', 'sudo', x[1]['uid'][0], uuid, hosts, cryptedpass):
241 for_all = hosts == "*"
242 for_this_host = CurrentHost in hosts.split(',')
243 if not (for_all or for_this_host):
245 # ignore * passwords for untrusted hosts, but copy host specific passwords
246 if for_all and untrusted:
249 if for_this_host: # this makes sure we take a per-host entry over the for-all entry
254 Line = "%s:%s" % (GetAttr(x,"uid"), Pass)
255 Line = Sanitize(Line) + "\n";
256 F.write("%s" % (Line));
258 # Oops, something unspeakable happened.
264 # Generate the shadow list
266 # Fetch all the users
271 if PasswdAttrs == None:
274 safe_rmtree(os.path.join(GlobalDir, 'userkeys'))
275 safe_makedirs(os.path.join(GlobalDir, 'userkeys'))
277 for x in PasswdAttrs:
278 # If the account is locked, do not write it.
279 # This is a partial stop-gap. The ssh also needs to change this
280 # to ignore ~/.ssh/authorized* files.
281 if (GetAttr(x,"userPassword").find("*LK*") != -1) \
282 or GetAttr(x,"userPassword").startswith("!"):
285 if x[1].has_key("uidNumber") == 0 or \
286 x[1].has_key("sshRSAAuthKey") == 0:
288 User = GetAttr(x,"uid");
292 OldMask = os.umask(0077);
293 File = os.path.join(GlobalDir, 'userkeys', User)
294 F = open(File + ".tmp","w",0600);
297 for I in x[1]["sshRSAAuthKey"]:
298 MultipleLine = "%s" % I
299 MultipleLine = Sanitize(MultipleLine) + "\n"
300 F.write(MultipleLine)
303 userfiles.append(os.path.basename(File))
305 # Oops, something unspeakable happened.
308 Die(masterFileName,masterFile,None)
313 def GenSSHtarballs(userlist, SSHFiles, grouprevmap, target):
314 OldMask = os.umask(0077);
315 tf = tarfile.open(name=os.path.join(GlobalDir, 'ssh-keys-%s.tar.gz' % CurrentHost), mode='w:gz')
317 for f in userlist.keys():
318 if f not in SSHFiles:
320 # If we're not exporting their primary group, don't export
323 if userlist[f] in grouprevmap.keys():
324 grname = grouprevmap[userlist[f]]
327 if int(userlist[f]) <= 100:
328 # In these cases, look it up in the normal way so we
329 # deal with cases where, for instance, users are in group
330 # users as their primary group.
331 grname = grp.getgrgid(userlist[f])[0]
336 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])
339 to = tf.gettarinfo(os.path.join(GlobalDir, 'userkeys', f), f)
340 # These will only be used where the username doesn't
341 # exist on the target system for some reason; hence,
342 # in those cases, the safest thing is for the file to
343 # be owned by root but group nobody. This deals with
344 # the bloody obscure case where the group fails to exist
345 # whilst the user does (in which case we want to avoid
346 # ending up with a file which is owned user:root to avoid
347 # a fairly obvious attack vector)
350 # Using the username / groupname fields avoids any need
351 # to give a shit^W^W^Wcare about the UIDoffset stuff.
355 tf.addfile(to, file(os.path.join(GlobalDir, 'userkeys', f)))
358 os.rename(os.path.join(GlobalDir, 'ssh-keys-%s.tar.gz' % CurrentHost), target)
360 # add a list of groups to existing groups,
361 # including all subgroups thereof, recursively.
362 # basically this proceduces the transitive hull of the groups in
364 def addGroups(existingGroups, newGroups, uid):
365 for group in newGroups:
366 # if it's a <group>@host, split it and verify it's on the current host.
367 s = group.split('@', 1)
368 if len(s) == 2 and s[1] != CurrentHost:
372 # let's see if we handled this group already
373 if group in existingGroups:
376 if not GroupIDMap.has_key(group):
377 print "Group does not exist ",group,"but",uid,"is in it"
380 existingGroups.append(group)
382 if SubGroupMap.has_key(group):
383 addGroups(existingGroups, SubGroupMap[group])
385 # Generate the group list
386 def GenGroup(l,File):
390 F = open(File + ".tdb.tmp","w");
392 # Generate the GroupMap
394 for x in GroupIDMap.keys():
397 # Fetch all the users
399 if PasswdAttrs == None:
402 # Sort them into a list of groups having a set of users
403 for x in PasswdAttrs:
404 uid = GetAttr(x,"uid")
405 if x[1].has_key("uidNumber") == 0 or IsInGroup(x) == 0:
407 if x[1].has_key("supplementaryGid") == 0:
411 addGroups(supgroups, x[1]["supplementaryGid"], uid)
413 GroupMap[g].append(uid);
415 # Output the group file.
417 for x in GroupMap.keys():
418 grouprevmap[GroupIDMap[x]] = x
419 if GroupIDMap.has_key(x) == 0:
421 Line = "%s:x:%u:" % (x,GroupIDMap[x]);
423 for I in GroupMap[x]:
424 Line = Line + ("%s%s" % (Comma,I));
426 Line = Sanitize(Line) + "\n";
427 F.write("0%u %s" % (J,Line));
428 F.write(".%s %s" % (x,Line));
429 F.write("=%u %s" % (GroupIDMap[x],Line));
432 # Oops, something unspeakable happened.
440 # Generate the email forwarding list
441 def GenForward(l,File):
444 OldMask = os.umask(0022);
445 F = open(File + ".tmp","w",0644);
448 # Fetch all the users
450 if PasswdAttrs == None:
453 # Write out the email address for each user
454 for x in PasswdAttrs:
455 if x[1].has_key("emailForward") == 0 or IsInGroup(x) == 0:
458 # Do not allow people to try to buffer overflow busted parsers
459 if len(GetAttr(x,"emailForward")) > 200:
462 # Check the forwarding address
463 if EmailCheck.match(GetAttr(x,"emailForward")) == None:
465 Line = "%s: %s" % (GetAttr(x,"uid"),GetAttr(x,"emailForward"));
466 Line = Sanitize(Line) + "\n";
469 # Oops, something unspeakable happened.
475 def GenAllForward(l,File):
478 OldMask = os.umask(0022);
479 Fdb = os.popen("cdbmake %s %s.tmp"%(File,File),"w");
482 # Fetch all the users
484 if PasswdAttrs == None:
487 # Write out the email address for each user
488 for x in PasswdAttrs:
489 if x[1].has_key("emailForward") == 0:
492 # Do not allow people to try to buffer overflow busted parsers
493 Forward = GetAttr(x,"emailForward");
494 if len(Forward) > 200:
497 # Check the forwarding address
498 if EmailCheck.match(Forward) == None:
501 User = GetAttr(x,"uid");
502 Fdb.write("+%d,%d:%s->%s\n"%(len(User),len(Forward),User,Forward));
504 # Oops, something unspeakable happened.
508 if Fdb.close() != None:
509 raise "cdbmake gave an error";
511 # Generate the anon XEarth marker file
512 def GenMarkers(l,File):
515 F = open(File + ".tmp","w");
517 # Fetch all the users
519 if PasswdAttrs == None:
522 # Write out the position for each user
523 for x in PasswdAttrs:
524 if x[1].has_key("latitude") == 0 or x[1].has_key("longitude") == 0:
527 Line = "%8s %8s \"\""%(DecDegree(GetAttr(x,"latitude"),1),DecDegree(GetAttr(x,"longitude"),1));
528 Line = Sanitize(Line) + "\n";
533 # Oops, something unspeakable happened.
539 # Generate the debian-private subscription list
540 def GenPrivate(l,File):
543 F = open(File + ".tmp","w");
545 # Fetch all the users
547 if PasswdAttrs == None:
550 # Write out the position for each user
551 for x in PasswdAttrs:
552 if x[1].has_key("privateSub") == 0:
555 # If the account is locked, do not write it
556 if (GetAttr(x,"userPassword").find("*LK*") != -1) \
557 or GetAttr(x,"userPassword").startswith("!"):
560 # If the account has no PGP key, do not write it
561 if x[1].has_key("keyFingerPrint") == 0:
564 # Must be in the Debian group (yuk, hard coded for now)
565 if GetAttr(x,"gidNumber") != "800":
569 Line = "%s"%(GetAttr(x,"privateSub"));
570 Line = Sanitize(Line) + "\n";
575 # Oops, something unspeakable happened.
581 # Generate a list of locked accounts
582 def GenDisabledAccounts(l,File):
585 F = open(File + ".tmp","w");
587 # Fetch all the users
589 if PasswdAttrs == None:
593 for x in PasswdAttrs:
594 if x[1].has_key("uidNumber") == 0:
597 Pass = GetAttr(x,"userPassword");
599 # *LK* is the reference value for a locked account
600 # password starting with ! is also a locked account
601 if Pass.find("*LK*") != -1 or Pass.startswith("!"):
602 # Format is <login>:<reason>
603 Line = "%s:%s" % (GetAttr(x,"uid"), "Account is locked")
606 F.write(Sanitize(Line) + "\n")
608 # Oops, something unspeakable happened.
614 # Generate the list of local addresses that refuse all mail
615 def GenMailDisable(l,File):
618 F = open(File + ".tmp","w");
620 # Fetch all the users
622 if PasswdAttrs == None:
625 for x in PasswdAttrs:
628 if x[1].has_key("mailDisableMessage"):
629 Reason = GetAttr(x,"mailDisableMessage")
633 # Must be in the Debian group (yuk, hard coded for now)
634 if GetAttr(x,"gidNumber") != "800":
638 Line = "%s: %s"%(GetAttr(x,"uid"),Reason);
639 Line = Sanitize(Line) + "\n";
644 # Oops, something unspeakable happened.
650 # Generate a list of uids that should have boolean affects applied
651 def GenMailBool(l,File,Key):
654 F = open(File + ".tmp","w");
656 # Fetch all the users
658 if PasswdAttrs == None:
661 for x in PasswdAttrs:
664 if x[1].has_key(Key) == 0:
667 # Must be in the Debian group (yuk, hard coded for now)
668 if GetAttr(x,"gidNumber") != "800":
671 if GetAttr(x,Key) != "TRUE":
675 Line = "%s"%(GetAttr(x,"uid"));
676 Line = Sanitize(Line) + "\n";
681 # Oops, something unspeakable happened.
687 # Generate a list of hosts for RBL or whitelist purposes.
688 def GenMailList(l,File,Key):
691 F = open(File + ".tmp","w");
693 # Fetch all the users
695 if PasswdAttrs == None:
698 for x in PasswdAttrs:
701 if x[1].has_key(Key) == 0:
704 # Must be in the Debian group (yuk, hard coded for now)
705 if GetAttr(x,"gidNumber") != "800":
712 if Key == "mailWhitelist":
713 if re.match('^[-\w.]+(/[\d]+)?$',z) == None:
716 if re.match('^[-\w.]+$',z) == None:
720 Line = GetAttr(x,"uid")
724 if Key == "mailRHSBL":
725 Line += "/$sender_address_domain"
728 Line = Sanitize(Line) + "\n";
733 # Oops, something unspeakable happened.
739 # Generate the DNS Zone file
740 def GenDNS(l,File,HomePrefix):
743 F = open(File + ".tmp","w");
745 # Fetch all the users
747 if PasswdAttrs == None:
750 # Write out the zone file entry for each user
751 for x in PasswdAttrs:
752 if x[1].has_key("dnsZoneEntry") == 0:
755 # If the account has no PGP key, do not write it
756 if x[1].has_key("keyFingerPrint") == 0:
759 F.write("; %s\n"%(EmailAddress(x)));
760 for z in x[1]["dnsZoneEntry"]:
761 Split = z.lower().split()
762 if Split[1].lower() == 'in':
763 for y in range(0,len(Split)):
766 Line = " ".join(Split) + "\n";
769 Host = Split[0] + DNSZone;
770 if BSMTPCheck.match(Line) != None:
771 F.write("; Has BSMTP\n");
773 # Write some identification information
774 if Split[2].lower() == "a":
775 Line = "%s IN TXT \"%s\"\n"%(Split[0],EmailAddress(x));
776 for y in x[1]["keyFingerPrint"]:
777 Line = Line + "%s IN TXT \"PGP %s\"\n"%(Split[0],FormatPGPKey(y));
780 Line = "; Err %s"%(str(Split));
785 F.write("; Errors\n");
788 # Oops, something unspeakable happened.
794 # Generate the DNS SSHFP records
795 def GenSSHFP(l,File,HomePrefix):
798 F = open(File + ".tmp","w")
800 # Fetch all the hosts
802 if HostAttrs == None:
806 if x[1].has_key("hostname") == 0 or \
807 x[1].has_key("sshRSAHostKey") == 0:
809 Host = GetAttr(x,"hostname");
811 for I in x[1]["sshRSAHostKey"]:
813 if Split[0] == 'ssh-rsa':
815 if Split[0] == 'ssh-dss':
817 if Algorithm == None:
819 Fingerprint = sha.new(base64.decodestring(Split[1])).hexdigest()
820 Line = "%s. IN SSHFP %u 1 %s" % (Host,Algorithm,Fingerprint)
821 Line = Sanitize(Line) + "\n"
823 # Oops, something unspeakable happened.
829 # Generate the BSMTP file
830 def GenBSMTP(l,File,HomePrefix):
833 F = open(File + ".tmp","w");
835 # Fetch all the users
837 if PasswdAttrs == None:
840 # Write out the zone file entry for each user
841 for x in PasswdAttrs:
842 if x[1].has_key("dnsZoneEntry") == 0:
845 # If the account has no PGP key, do not write it
846 if x[1].has_key("keyFingerPrint") == 0:
849 for z in x[1]["dnsZoneEntry"]:
850 Split = z.lower().split()
851 if Split[1].lower() == 'in':
852 for y in range(0,len(Split)):
855 Line = " ".join(Split) + "\n";
857 Host = Split[0] + DNSZone;
858 if BSMTPCheck.match(Line) != None:
859 F.write("%s: user=%s group=Debian file=%s%s/bsmtp/%s\n"%(Host,
860 GetAttr(x,"uid"),HomePrefix,GetAttr(x,"uid"),Host));
863 F.write("; Errors\n");
866 # Oops, something unspeakable happened.
876 if not Host in HostToIPCache:
879 IPAdressesT = list(set([ (a[0],a[4][0]) for a in socket.getaddrinfo(Host, None)]))
880 except socket.gaierror, (code):
881 if code[0] != -2: raise
883 for addr in IPAdressesT:
884 if addr[0] == socket.AF_INET: IPAdresses += [addr[1], "::ffff:"+addr[1]]
885 else: IPAdresses += [addr[1]]
886 HostToIPCache[Host] = IPAdresses
887 return HostToIPCache[Host]
890 # Generate the ssh known hosts file
891 def GenSSHKnown(l,File,mode=None):
894 OldMask = os.umask(0022);
895 F = open(File + ".tmp","w",0644);
899 if HostAttrs == None:
903 if x[1].has_key("hostname") == 0 or \
904 x[1].has_key("sshRSAHostKey") == 0:
906 Host = GetAttr(x,"hostname");
908 SHost = Host.find(".")
909 if SHost != None: HostNames += [Host[0:SHost]]
911 for I in x[1]["sshRSAHostKey"]:
912 if mode and mode == 'authorized_keys':
913 #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)
914 Line = 'command="rsync --server --sender -pr . /var/cache/userdir-ldap/hosts/%s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding %s' % (Host,I)
916 Line = "%s %s" %(",".join(HostNames + HostToIP(Host)), I);
917 Line = Sanitize(Line) + "\n";
919 # Oops, something unspeakable happened.
925 # Generate the debianhosts file (list of all IP addresses)
926 def GenHosts(l,File):
929 OldMask = os.umask(0022);
930 F = open(File + ".tmp","w",0644);
933 # Fetch all the hosts
934 HostNames = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"hostname=*",\
937 if HostNames == None:
941 if x[1].has_key("hostname") == 0:
943 Host = GetAttr(x,"hostname");
945 Addr = socket.gethostbyname(Host);
946 F.write(Addr + "\n");
949 # Oops, something unspeakable happened.
955 def GenKeyrings(l,OutDir):
957 shutil.copy(k, OutDir)
960 # Connect to the ldap server
962 F = open(PassDir+"/pass-"+pwd.getpwuid(os.getuid())[0],"r");
963 Pass = F.readline().strip().split(" ")
965 l.simple_bind_s("uid="+Pass[0]+","+BaseDn,Pass[1]);
967 # Fetch all the groups
969 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"gid=*",\
970 ["gid","gidNumber","subGroup"]);
972 # Generate the SubGroupMap and GroupIDMap
974 if x[1].has_key("gidNumber") == 0:
976 GroupIDMap[x[1]["gid"][0]] = int(x[1]["gidNumber"][0]);
977 if x[1].has_key("subGroup") != 0:
978 SubGroupMap.setdefault(x[1]["gid"][0], []).extend(x[1]["subGroup"]);
980 # Fetch all the users
981 PasswdAttrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid=*",\
982 ["uid","uidNumber","gidNumber","supplementaryGid",\
983 "gecos","loginShell","userPassword","shadowLastChange",\
984 "shadowMin","shadowMax","shadowWarning","shadowInactive",
985 "shadowExpire","emailForward","latitude","longitude",\
986 "allowedHost","sshRSAAuthKey","dnsZoneEntry","cn","sn",\
987 "keyFingerPrint","privateSub","mailDisableMessage",\
988 "mailGreylisting","mailCallout","mailRBL","mailRHSBL",\
989 "mailWhitelist", "sudoPassword"]);
990 # Fetch all the hosts
991 HostAttrs = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"sshRSAHostKey=*",\
992 ["hostname","sshRSAHostKey"]);
994 # Open the control file
995 if len(sys.argv) == 1:
996 F = open(GenerateConf,"r");
998 F = open(sys.argv[1],"r")
1000 # Generate global things
1001 GlobalDir = GenerateDir+"/";
1002 SSHFiles = GenSSHShadow(l);
1003 GenAllForward(l,GlobalDir+"mail-forward.cdb");
1004 GenMarkers(l,GlobalDir+"markers");
1005 GenPrivate(l,GlobalDir+"debian-private");
1006 GenDisabledAccounts(l,GlobalDir+"disabled-accounts");
1007 GenSSHKnown(l,GlobalDir+"ssh_known_hosts");
1008 #GenSSHKnown(l,GlobalDir+"authorized_keys", 'authorized_keys');
1009 GenHosts(l,GlobalDir+"debianhosts");
1010 GenMailDisable(l,GlobalDir+"mail-disable");
1011 GenMailBool(l,GlobalDir+"mail-greylist","mailGreylisting");
1012 GenMailBool(l,GlobalDir+"mail-callout","mailCallout");
1013 GenMailList(l,GlobalDir+"mail-rbl","mailRBL");
1014 GenMailList(l,GlobalDir+"mail-rhsbl","mailRHSBL");
1015 GenMailList(l,GlobalDir+"mail-whitelist","mailWhitelist");
1016 GenKeyrings(l,GlobalDir);
1019 GenForward(l,GlobalDir+"forward-alias");
1022 Line = F.readline();
1031 Split = Line.split(" ")
1032 OutDir = GenerateDir + '/' + Split[0] + '/';
1033 try: os.mkdir(OutDir);
1036 # Get the group list and convert any named groups to numerics
1041 ExtraList[I] = None;
1043 GroupList[I] = None;
1044 if GroupIDMap.has_key(I):
1045 GroupList[str(GroupIDMap[I])] = None;
1047 Allowed = GroupList;
1050 CurrentHost = Split[0];
1052 DoLink(GlobalDir,OutDir,"debianhosts");
1053 DoLink(GlobalDir,OutDir,"ssh_known_hosts");
1054 DoLink(GlobalDir,OutDir,"disabled-accounts")
1057 if ExtraList.has_key("[NOPASSWD]"):
1058 userlist = GenPasswd(l,OutDir+"passwd",Split[1], "*");
1060 userlist = GenPasswd(l,OutDir+"passwd",Split[1], "x");
1062 grouprevmap = GenGroup(l,OutDir+"group");
1063 GenShadowSudo(l, OutDir+"sudo-passwd", ExtraList.has_key("[UNTRUSTED]") or ExtraList.has_key("[NOPASSWD]"))
1065 # Now we know who we're allowing on the machine, export
1066 # the relevant ssh keys
1067 GenSSHtarballs(userlist, SSHFiles, grouprevmap, os.path.join(OutDir, 'ssh-keys.tar.gz'))
1069 if ExtraList.has_key("[UNTRUSTED]"):
1070 print "[UNTRUSTED] tag is obsolete and may be removed in the future."
1072 if not ExtraList.has_key("[NOPASSWD]"):
1073 GenShadow(l,OutDir+"shadow");
1075 # Link in global things
1076 if not ExtraList.has_key("[NOMARKERS]"):
1077 DoLink(GlobalDir,OutDir,"markers");
1078 DoLink(GlobalDir,OutDir,"mail-forward.cdb");
1079 DoLink(GlobalDir,OutDir,"mail-disable");
1080 DoLink(GlobalDir,OutDir,"mail-greylist");
1081 DoLink(GlobalDir,OutDir,"mail-callout");
1082 DoLink(GlobalDir,OutDir,"mail-rbl");
1083 DoLink(GlobalDir,OutDir,"mail-rhsbl");
1084 DoLink(GlobalDir,OutDir,"mail-whitelist");
1087 DoLink(GlobalDir,OutDir,"forward-alias");
1089 if ExtraList.has_key("[DNS]"):
1090 GenDNS(l,OutDir+"dns-zone",Split[1]);
1091 GenSSHFP(l,OutDir+"dns-sshfp",Split[1])
1093 if ExtraList.has_key("[BSMTP]"):
1094 GenBSMTP(l,OutDir+"bsmtp",Split[1])
1096 if ExtraList.has_key("[PRIVATE]"):
1097 DoLink(GlobalDir,OutDir,"debian-private")
1099 if ExtraList.has_key("[KEYRING]"):
1101 DoLink(GlobalDir,OutDir,os.path.basename(k))
1104 try: posix.remove(OutDir+os.path.basename(k));
1109 # vim:set shiftwidth=3: