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>
13 # Copyright (c) 2008 Thomas Viehmann <tv@beamnet.de>
14 # Copyright (c) 2009 Stephen Gran <steve@lobefin.net>
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 import string, re, time, ldap, getopt, sys, os, pwd, posix, socket, base64, sha, shutil, errno, tarfile, grp
31 from userdir_ldap import *
32 from userdir_exceptions import *
45 UUID_FORMAT = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
47 EmailCheck = re.compile("^([^ <>@]+@[^ ,<>@]+)?$")
48 BSMTPCheck = re.compile(".*mx 0 (gluck)\.debian\.org\..*",re.DOTALL)
49 PurposeHostField = re.compile(r".*\[\[([\*\-]?[a-z0-9.\-]*)(?:\|.*)?\]\]")
50 DNSZone = ".debian.net"
51 Keyrings = ConfModule.sync_keyrings.split(":")
53 def safe_makedirs(dir):
57 if e.errno == errno.EEXIST:
66 if e.errno == errno.ENOENT:
72 return Str.translate(string.maketrans("\n\r\t", "$$$"))
74 def DoLink(From, To, File):
76 posix.remove(To + File)
79 posix.link(From + File, To + File)
81 def IsRetired(DnRecord):
83 Looks for accountStatus in the LDAP record and tries to
84 match it against one of the known retired statuses
87 status = GetAttr(DnRecord, "accountStatus", None)
94 if status == "inactive":
97 elif status == "memorial":
100 elif status == "retiring":
101 # We'll give them a few extra days over what we said
102 age = 6 * 31 * 24 * 60 * 60
104 return (time.time() - time.mktime(time.strptime(line[1], "%Y-%m-%d"))) > age
114 return int(GetAttr(x, "gidNumber", 0)) == 800
118 # See if this user is in the group list
119 def IsInGroup(DnRecord):
123 # See if the primary group is in the list
124 if Allowed.has_key(GetAttr(DnRecord, "gidNumber")) != 0:
127 # Check the host based ACL
128 if DnRecord[1].has_key("allowedHost") != 0:
129 if CurrentHost in DnRecord[1]["allowedHost"]:
132 # See if there are supplementary groups
133 if DnRecord[1].has_key("supplementaryGid") == 0:
137 addGroups(supgroups, DnRecord[1]["supplementaryGid"], GetAttr(DnRecord, "uid"))
139 if Allowed.has_key(g):
143 def Die(File, F, Fdb):
149 os.remove(File + ".tmp")
153 os.remove(File + ".tdb.tmp")
157 def Done(File, F, Fdb):
160 os.rename(File + ".tmp", File)
163 os.rename(File + ".tdb.tmp", File + ".tdb")
165 # Generate the password list
166 def GenPasswd(File, HomePrefix, PwdMarker):
169 F = open(File + ".tdb.tmp", "w")
172 # Fetch all the users
176 for x in PasswdAttrs:
177 if x[1].has_key("uidNumber") == 0 or not IsInGroup(x):
180 # Do not let people try to buffer overflow some busted passwd parser.
181 if len(GetAttr(x, "gecos")) > 100 or len(GetAttr(x, "loginShell")) > 50:
184 userlist[GetAttr(x, "uid")] = int(GetAttr(x, "gidNumber"))
185 Line = "%s:%s:%s:%s:%s:%s%s:%s" % (GetAttr(x, "uid"),\
187 GetAttr(x, "uidNumber"), GetAttr(x, "gidNumber"),\
188 GetAttr(x, "gecos"), HomePrefix, GetAttr(x, "uid"),\
189 GetAttr(x, "loginShell"))
191 Line = Sanitize(Line) + "\n"
192 F.write("0%u %s" % (I, Line))
193 F.write(".%s %s" % (GetAttr(x, "uid"), Line))
194 F.write("=%s %s" % (GetAttr(x, "uidNumber"), Line))
197 # Oops, something unspeakable happened.
203 # Return the list of users so we know which keys to export
206 # Generate the shadow list
210 OldMask = os.umask(0077)
211 F = open(File + ".tdb.tmp", "w", 0600)
214 # Fetch all the users
218 for x in PasswdAttrs:
219 if x[1].has_key("uidNumber") == 0 or not IsInGroup(x):
222 Pass = GetAttr(x, "userPassword")
223 if Pass[0:7] != "{crypt}" or len(Pass) > 50:
228 # If the account is locked, mark it as such in shadow
229 # See Debian Bug #308229 for why we set it to 1 instead of 0
230 if (GetAttr(x, "userPassword").find("*LK*") != -1) \
231 or GetAttr(x, "userPassword").startswith("!"):
234 ShadowExpire = GetAttr(x, "shadowExpire")
236 Line = "%s:%s:%s:%s:%s:%s:%s:%s:" % (GetAttr(x, "uid"),\
237 Pass, GetAttr(x, "shadowLastChange"),\
238 GetAttr(x, "shadowMin"), GetAttr(x, "shadowMax"),\
239 GetAttr(x, "shadowWarning"), GetAttr(x, "shadowInactive"),\
241 Line = Sanitize(Line) + "\n"
242 F.write("0%u %s" % (I, Line))
243 F.write(".%s %s" % (GetAttr(x, "uid"), Line))
246 # Oops, something unspeakable happened.
252 # Generate the sudo passwd file
253 def GenShadowSudo(File, untrusted):
256 OldMask = os.umask(0077)
257 F = open(File + ".tmp", "w", 0600)
260 # Fetch all the users
263 for x in PasswdAttrs:
265 if x[1].has_key("uidNumber") == 0 or not IsInGroup(x):
268 if x[1].has_key('sudoPassword'):
269 for entry in x[1]['sudoPassword']:
270 Match = re.compile('^('+UUID_FORMAT+') (confirmed:[0-9a-f]{40}|unconfirmed) ([a-z0-9.,*]+) ([^ ]+)$').match(entry)
273 uuid = Match.group(1)
274 status = Match.group(2)
275 hosts = Match.group(3)
276 cryptedpass = Match.group(4)
278 if status != 'confirmed:'+make_passwd_hmac('password-is-confirmed', 'sudo', x[1]['uid'][0], uuid, hosts, cryptedpass):
280 for_all = hosts == "*"
281 for_this_host = CurrentHost in hosts.split(',')
282 if not (for_all or for_this_host):
284 # ignore * passwords for untrusted hosts, but copy host specific passwords
285 if for_all and untrusted:
288 if for_this_host: # this makes sure we take a per-host entry over the for-all entry
293 Line = "%s:%s" % (GetAttr(x, "uid"), Pass)
294 Line = Sanitize(Line) + "\n"
295 F.write("%s" % (Line))
297 # Oops, something unspeakable happened.
303 # Generate the shadow list
305 # Fetch all the users
310 safe_rmtree(os.path.join(GlobalDir, 'userkeys'))
311 safe_makedirs(os.path.join(GlobalDir, 'userkeys'))
313 for x in PasswdAttrs:
315 if x[1].has_key("uidNumber") == 0 or \
316 x[1].has_key("sshRSAAuthKey") == 0:
319 User = GetAttr(x, "uid")
323 OldMask = os.umask(0077)
324 File = os.path.join(GlobalDir, 'userkeys', User)
325 F = open(File + ".tmp", "w", 0600)
328 for I in x[1]["sshRSAAuthKey"]:
329 MultipleLine = "%s" % I
330 MultipleLine = Sanitize(MultipleLine) + "\n"
331 F.write(MultipleLine)
334 userfiles.append(os.path.basename(File))
336 # Oops, something unspeakable happened.
339 Die(masterFileName, masterFile, None)
344 def GenSSHtarballs(userlist, SSHFiles, grouprevmap, target):
345 OldMask = os.umask(0077)
346 tf = tarfile.open(name=os.path.join(GlobalDir, 'ssh-keys-%s.tar.gz' % CurrentHost), mode='w:gz')
348 for f in userlist.keys():
349 if f not in SSHFiles:
351 # If we're not exporting their primary group, don't export
354 if userlist[f] in grouprevmap.keys():
355 grname = grouprevmap[userlist[f]]
358 if int(userlist[f]) <= 100:
359 # In these cases, look it up in the normal way so we
360 # deal with cases where, for instance, users are in group
361 # users as their primary group.
362 grname = grp.getgrgid(userlist[f])[0]
367 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])
370 to = tf.gettarinfo(os.path.join(GlobalDir, 'userkeys', f), f)
371 # These will only be used where the username doesn't
372 # exist on the target system for some reason; hence,
373 # in those cases, the safest thing is for the file to
374 # be owned by root but group nobody. This deals with
375 # the bloody obscure case where the group fails to exist
376 # whilst the user does (in which case we want to avoid
377 # ending up with a file which is owned user:root to avoid
378 # a fairly obvious attack vector)
381 # Using the username / groupname fields avoids any need
382 # to give a shit^W^W^Wcare about the UIDoffset stuff.
386 tf.addfile(to, file(os.path.join(GlobalDir, 'userkeys', f)))
389 os.rename(os.path.join(GlobalDir, 'ssh-keys-%s.tar.gz' % CurrentHost), target)
391 # add a list of groups to existing groups,
392 # including all subgroups thereof, recursively.
393 # basically this proceduces the transitive hull of the groups in
395 def addGroups(existingGroups, newGroups, uid):
396 for group in newGroups:
397 # if it's a <group>@host, split it and verify it's on the current host.
398 s = group.split('@', 1)
399 if len(s) == 2 and s[1] != CurrentHost:
403 # let's see if we handled this group already
404 if group in existingGroups:
407 if not GroupIDMap.has_key(group):
408 print "Group", group, "does not exist but", uid, "is in it"
411 existingGroups.append(group)
413 if SubGroupMap.has_key(group):
414 addGroups(existingGroups, SubGroupMap[group], uid)
416 # Generate the group list
421 F = open(File + ".tdb.tmp", "w")
423 # Generate the GroupMap
425 for x in GroupIDMap.keys():
428 # Fetch all the users
431 # Sort them into a list of groups having a set of users
432 for x in PasswdAttrs:
433 uid = GetAttr(x, "uid")
434 if x[1].has_key("uidNumber") == 0 or not IsInGroup(x):
436 if x[1].has_key("supplementaryGid") == 0:
440 addGroups(supgroups, x[1]["supplementaryGid"], uid)
442 GroupMap[g].append(uid)
444 # Output the group file.
446 for x in GroupMap.keys():
447 grouprevmap[GroupIDMap[x]] = x
448 if GroupIDMap.has_key(x) == 0:
450 Line = "%s:x:%u:" % (x, GroupIDMap[x])
452 for I in GroupMap[x]:
453 Line = Line + ("%s%s" % (Comma, I))
455 Line = Sanitize(Line) + "\n"
456 F.write("0%u %s" % (J, Line))
457 F.write(".%s %s" % (x, Line))
458 F.write("=%u %s" % (GroupIDMap[x], Line))
461 # Oops, something unspeakable happened.
471 for x in DebianUsers:
472 if x[1].has_key("emailForward") == 0:
476 x[1].pop("emailForward")
479 # Do not allow people to try to buffer overflow busted parsers
480 if len(GetAttr(x, "emailForward")) > 200:
481 x[1].pop("emailForward")
484 # Check the forwarding address
485 if EmailCheck.match(GetAttr(x, "emailForward")) == None:
486 x[1].pop("emailForward")
488 # Generate the email forwarding list
489 def GenForward(File):
492 OldMask = os.umask(0022)
493 F = open(File + ".tmp", "w", 0644)
496 # Fetch all the users
499 # Write out the email address for each user
500 for x in DebianUsers:
501 if x[1].has_key("emailForward") == 0:
504 Line = "%s: %s" % (GetAttr(x, "uid"), GetAttr(x, "emailForward"))
505 Line = Sanitize(Line) + "\n"
508 # Oops, something unspeakable happened.
514 def GenAllForward(File):
517 OldMask = os.umask(0022)
518 Fdb = os.popen("cdbmake %s %s.tmp"%(File, File), "w")
521 # Fetch all the users
524 # Write out the email address for each user
525 for x in DebianUsers:
526 if x[1].has_key("emailForward") == 0:
529 # Do not allow people to try to buffer overflow busted parsers
530 Forward = GetAttr(x, "emailForward")
532 User = GetAttr(x, "uid")
533 Fdb.write("+%d,%d:%s->%s\n" % (len(User), len(Forward), User, Forward))
536 # Oops, something unspeakable happened.
540 if Fdb.close() != None:
541 raise "cdbmake gave an error"
543 # Generate the anon XEarth marker file
544 def GenMarkers(File):
547 F = open(File + ".tmp", "w")
549 # Fetch all the users
552 # Write out the position for each user
553 for x in DebianUsers:
554 if x[1].has_key("latitude") == 0 or x[1].has_key("longitude") == 0:
557 Line = "%8s %8s \"\""%(DecDegree(GetAttr(x, "latitude"), 1), DecDegree(GetAttr(x, "longitude"), 1))
558 Line = Sanitize(Line) + "\n"
563 # Oops, something unspeakable happened.
569 # Generate the debian-private subscription list
570 def GenPrivate(File):
573 F = open(File + ".tmp", "w")
575 # Fetch all the users
578 # Write out the position for each user
579 for x in DebianUsers:
580 if x[1].has_key("privateSub") == 0:
583 # If the account has no PGP key, do not write it
584 if x[1].has_key("keyFingerPrint") == 0:
588 Line = "%s"%(GetAttr(x, "privateSub"))
589 Line = Sanitize(Line) + "\n"
594 # Oops, something unspeakable happened.
600 # Generate a list of locked accounts
601 def GenDisabledAccounts(File):
604 F = open(File + ".tmp", "w")
606 # Fetch all the users
611 for x in PasswdAttrs:
612 if x[1].has_key("uidNumber") == 0:
615 Pass = GetAttr(x, "userPassword")
617 # *LK* is the reference value for a locked account
618 # password starting with ! is also a locked account
619 if Pass.find("*LK*") != -1 or Pass.startswith("!"):
620 # Format is <login>:<reason>
621 Line = "%s:%s" % (GetAttr(x, "uid"), "Account is locked")
622 DisabledUsers.append(x)
625 F.write(Sanitize(Line) + "\n")
628 # Oops, something unspeakable happened.
634 # Generate the list of local addresses that refuse all mail
635 def GenMailDisable(File):
638 F = open(File + ".tmp", "w")
640 # Fetch all the users
643 for x in DebianUsers:
646 if x[1].has_key("mailDisableMessage"):
647 Reason = GetAttr(x, "mailDisableMessage")
652 Line = "%s: %s"%(GetAttr(x, "uid"), Reason)
653 Line = Sanitize(Line) + "\n"
658 # Oops, something unspeakable happened.
664 # Generate a list of uids that should have boolean affects applied
665 def GenMailBool(File, Key):
668 F = open(File + ".tmp", "w")
670 # Fetch all the users
673 for x in DebianUsers:
676 if x[1].has_key(Key) == 0:
679 if GetAttr(x, Key) != "TRUE":
683 Line = "%s"%(GetAttr(x, "uid"))
684 Line = Sanitize(Line) + "\n"
689 # Oops, something unspeakable happened.
695 # Generate a list of hosts for RBL or whitelist purposes.
696 def GenMailList(File, Key):
699 F = open(File + ".tmp", "w")
701 # Fetch all the users
704 for x in DebianUsers:
707 if x[1].has_key(Key) == 0:
714 if Key == "mailWhitelist":
715 if re.match('^[-\w.]+(/[\d]+)?$', z) == None:
718 if re.match('^[-\w.]+$', z) == None:
722 Line = GetAttr(x, "uid")
726 if Key == "mailRHSBL":
727 Line += "/$sender_address_domain"
730 Line = Sanitize(Line) + "\n"
735 # Oops, something unspeakable happened.
741 def isRoleAccount(pwEntry):
742 if not pwEntry.has_key("objectClass"):
743 raise "pwEntry has no objectClass"
744 oc = pwEntry['objectClass']
746 i = oc.index('debianRoleAccount')
751 # Generate the DNS Zone file
752 def GenDNS(File, HomePrefix):
755 F = open(File + ".tmp", "w")
757 # Fetch all the users
760 # Write out the zone file entry for each user
761 for x in PasswdAttrs:
762 if x[1].has_key("dnsZoneEntry") == 0:
765 # If the account has no PGP key, do not write it
766 if x[1].has_key("keyFingerPrint") == 0 and not isRoleAccount(x[1]):
769 F.write("; %s\n"%(EmailAddress(x)))
770 for z in x[1]["dnsZoneEntry"]:
771 Split = z.lower().split()
772 if Split[1].lower() == 'in':
773 for y in range(0, len(Split)):
776 Line = " ".join(Split) + "\n"
779 Host = Split[0] + DNSZone
780 if BSMTPCheck.match(Line) != None:
781 F.write("; Has BSMTP\n")
783 # Write some identification information
784 if Split[2].lower() == "a":
785 Line = "%s IN TXT \"%s\"\n"%(Split[0], EmailAddress(x))
786 for y in x[1]["keyFingerPrint"]:
787 Line = Line + "%s IN TXT \"PGP %s\"\n"%(Split[0], FormatPGPKey(y))
790 Line = "; Err %s"%(str(Split))
795 F.write("; Errors\n")
798 # Oops, something unspeakable happened.
804 # Generate the DNS SSHFP records
805 def GenSSHFP(File, HomePrefix):
808 F = open(File + ".tmp", "w")
810 # Fetch all the hosts
812 if HostAttrs == None:
813 raise UDEmptyList, "No Hosts"
816 if x[1].has_key("hostname") == 0 or \
817 x[1].has_key("sshRSAHostKey") == 0:
819 Host = GetAttr(x, "hostname")
821 for I in x[1]["sshRSAHostKey"]:
823 if Split[0] == 'ssh-rsa':
825 if Split[0] == 'ssh-dss':
827 if Algorithm == None:
829 Fingerprint = sha.new(base64.decodestring(Split[1])).hexdigest()
830 Line = "%s. IN SSHFP %u 1 %s" % (Host, Algorithm, Fingerprint)
831 Line = Sanitize(Line) + "\n"
833 # Oops, something unspeakable happened.
839 # Generate the BSMTP file
840 def GenBSMTP(File, HomePrefix):
843 F = open(File + ".tmp", "w")
845 # Fetch all the users
848 # Write out the zone file entry for each user
849 for x in DebianUsers:
850 if x[1].has_key("dnsZoneEntry") == 0:
853 # If the account has no PGP key, do not write it
854 if x[1].has_key("keyFingerPrint") == 0:
857 for z in x[1]["dnsZoneEntry"]:
858 Split = z.lower().split()
859 if Split[1].lower() == 'in':
860 for y in range(0, len(Split)):
863 Line = " ".join(Split) + "\n"
865 Host = Split[0] + DNSZone
866 if BSMTPCheck.match(Line) != None:
867 F.write("%s: user=%s group=Debian file=%s%s/bsmtp/%s\n"%(Host,
868 GetAttr(x, "uid"), HomePrefix, GetAttr(x, "uid"), Host))
871 F.write("; Errors\n")
874 # Oops, something unspeakable happened.
884 if not Host in HostToIPCache:
887 IPAdressesT = list(set([ (a[0], a[4][0]) for a in socket.getaddrinfo(Host, None)]))
888 except socket.gaierror, (code):
892 if not IPAdressesT is None:
893 for addr in IPAdressesT:
894 if addr[0] == socket.AF_INET:
895 IPAdresses += [addr[1], "::ffff:"+addr[1]]
897 IPAdresses += [addr[1]]
898 HostToIPCache[Host] = IPAdresses
899 return HostToIPCache[Host]
901 # Generate the ssh known hosts file
902 def GenSSHKnown(File, mode=None):
905 OldMask = os.umask(0022)
906 F = open(File + ".tmp", "w", 0644)
910 if HostAttrs is None:
911 raise UDEmptyList, "No Hosts"
914 if x[1].has_key("hostname") == 0 or \
915 x[1].has_key("sshRSAHostKey") == 0:
917 Host = GetAttr(x, "hostname")
919 if Host.endswith(HostDomain):
920 HostNames.append(Host[:-(len(HostDomain) + 1)])
922 # in the purpose field [[host|some other text]] (where some other text is optional)
923 # makes a hyperlink on the web thing. we now also add these hosts to the ssh known_hosts
924 # file. But so that we don't have to add everything we link we can add an asterisk
925 # and say [[*... to ignore it. In order to be able to add stuff to ssh without
926 # http linking it we also support [[-hostname]] entries.
927 for i in x[1].get("purpose", []):
928 m = PurposeHostField.match(i)
931 # we ignore [[*..]] entries
932 if m.startswith('*'):
934 if m.startswith('-'):
938 if m.endswith(HostDomain):
939 HostNames.append(m[:-(len(HostDomain) + 1)])
941 for I in x[1]["sshRSAHostKey"]:
942 if mode and mode == 'authorized_keys':
943 #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)
944 Line = 'command="rsync --server --sender -pr . /var/cache/userdir-ldap/hosts/%s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding %s' % (Host,I)
946 Line = "%s %s" %(",".join(HostNames + HostToIP(Host)), I)
947 Line = Sanitize(Line) + "\n"
949 # Oops, something unspeakable happened.
955 # Generate the debianhosts file (list of all IP addresses)
956 def GenHosts(l, File):
959 OldMask = os.umask(0022)
960 F = open(File + ".tmp", "w", 0644)
963 # Fetch all the hosts
964 hostnames = l.search_s(HostBaseDn, ldap.SCOPE_ONELEVEL, "hostname=*",
967 if hostnames is None:
968 raise UDEmptyList, "No Hosts"
972 host = GetAttr(x, "hostname", None)
976 addrs += socket.getaddrinfo(host, None, socket.AF_INET)
980 addrs += socket.getaddrinfo(host, None, socket.AF_INET6)
984 for addrinfo in addrs:
985 if addrinfo[0] in (socket.AF_INET, socket.AF_INET6):
986 addr = addrinfo[4][0]
988 print >> F, addrinfo[4][0]
990 # Oops, something unspeakable happened.
996 def GenKeyrings(OutDir):
998 shutil.copy(k, OutDir)
1000 # Connect to the ldap server
1002 F = open(PassDir + "/pass-" + pwd.getpwuid(os.getuid())[0], "r")
1003 Pass = F.readline().strip().split(" ")
1005 l.simple_bind_s("uid=" + Pass[0] + "," + BaseDn, Pass[1])
1007 # Fetch all the groups
1009 Attrs = l.search_s(BaseDn, ldap.SCOPE_ONELEVEL, "gid=*",\
1010 ["gid", "gidNumber", "subGroup"])
1012 # Generate the SubGroupMap and GroupIDMap
1014 if x[1].has_key("gidNumber") == 0:
1016 GroupIDMap[x[1]["gid"][0]] = int(x[1]["gidNumber"][0])
1017 if x[1].has_key("subGroup") != 0:
1018 SubGroupMap.setdefault(x[1]["gid"][0], []).extend(x[1]["subGroup"])
1020 # Fetch all the users
1021 PasswdAttrs = l.search_s(BaseDn, ldap.SCOPE_ONELEVEL, "uid=*",\
1022 ["uid", "uidNumber", "gidNumber", "supplementaryGid",\
1023 "gecos", "loginShell", "userPassword", "shadowLastChange",\
1024 "shadowMin", "shadowMax", "shadowWarning", "shadowInactive",
1025 "shadowExpire", "emailForward", "latitude", "longitude",\
1026 "allowedHost", "sshRSAAuthKey", "dnsZoneEntry", "cn", "sn",\
1027 "keyFingerPrint", "privateSub", "mailDisableMessage",\
1028 "mailGreylisting", "mailCallout", "mailRBL", "mailRHSBL",\
1029 "mailWhitelist", "sudoPassword", "objectClass", "accountStatus"])
1031 if PasswdAttrs is None:
1032 raise UDEmptyList, "No Users"
1034 # Fetch all the hosts
1035 HostAttrs = l.search_s(HostBaseDn, ldap.SCOPE_ONELEVEL, "sshRSAHostKey=*",\
1036 ["hostname", "sshRSAHostKey", "purpose"])
1038 # Open the control file
1039 if len(sys.argv) == 1:
1040 F = open(GenerateConf, "r")
1042 F = open(sys.argv[1], "r")
1044 # Generate global things
1045 GlobalDir = GenerateDir + "/"
1046 GenDisabledAccounts(GlobalDir + "disabled-accounts")
1048 PasswdAttrs = filter(lambda x: not IsRetired(x), PasswdAttrs)
1049 #DebianUsers = filter(lambda x: IsGidDebian(x), PasswdAttrs)
1050 DebianUsers = PasswdAttrs
1054 GenMailDisable(GlobalDir + "mail-disable")
1055 GenAllForward(GlobalDir + "mail-forward.cdb")
1056 GenPrivate(GlobalDir + "debian-private")
1057 #GenSSHKnown(l,GlobalDir+"authorized_keys", 'authorized_keys')
1058 GenMailBool(GlobalDir + "mail-greylist", "mailGreylisting")
1059 GenMailBool(GlobalDir + "mail-callout", "mailCallout")
1060 GenMailList(GlobalDir + "mail-rbl", "mailRBL")
1061 GenMailList(GlobalDir + "mail-rhsbl", "mailRHSBL")
1062 GenMailList(GlobalDir + "mail-whitelist", "mailWhitelist")
1063 GenKeyrings(GlobalDir)
1066 GenForward(GlobalDir + "forward-alias")
1068 PasswdAttrs = filter(lambda x: not x in DisabledUsers, PasswdAttrs)
1070 SSHFiles = GenSSHShadow()
1071 GenMarkers(GlobalDir + "markers")
1072 GenSSHKnown(GlobalDir + "ssh_known_hosts")
1073 GenHosts(l, GlobalDir + "debianhosts")
1085 Split = Line.split(" ")
1086 OutDir = GenerateDir + '/' + Split[0] + '/'
1092 # Get the group list and convert any named groups to numerics
1100 if GroupIDMap.has_key(I):
1101 GroupList[str(GroupIDMap[I])] = None
1106 CurrentHost = Split[0]
1108 DoLink(GlobalDir, OutDir, "debianhosts")
1109 DoLink(GlobalDir, OutDir, "ssh_known_hosts")
1110 DoLink(GlobalDir, OutDir, "disabled-accounts")
1113 if ExtraList.has_key("[NOPASSWD]"):
1114 userlist = GenPasswd(OutDir + "passwd", Split[1], "*")
1116 userlist = GenPasswd(OutDir + "passwd", Split[1], "x")
1118 grouprevmap = GenGroup(OutDir + "group")
1119 GenShadowSudo(OutDir + "sudo-passwd", ExtraList.has_key("[UNTRUSTED]") or ExtraList.has_key("[NOPASSWD]"))
1121 # Now we know who we're allowing on the machine, export
1122 # the relevant ssh keys
1123 GenSSHtarballs(userlist, SSHFiles, grouprevmap, os.path.join(OutDir, 'ssh-keys.tar.gz'))
1125 if ExtraList.has_key("[UNTRUSTED]"):
1126 print "[UNTRUSTED] tag is obsolete and may be removed in the future."
1128 if not ExtraList.has_key("[NOPASSWD]"):
1129 GenShadow(OutDir + "shadow")
1131 # Link in global things
1132 if not ExtraList.has_key("[NOMARKERS]"):
1133 DoLink(GlobalDir, OutDir, "markers")
1134 DoLink(GlobalDir, OutDir, "mail-forward.cdb")
1135 DoLink(GlobalDir, OutDir, "mail-disable")
1136 DoLink(GlobalDir, OutDir, "mail-greylist")
1137 DoLink(GlobalDir, OutDir, "mail-callout")
1138 DoLink(GlobalDir, OutDir, "mail-rbl")
1139 DoLink(GlobalDir, OutDir, "mail-rhsbl")
1140 DoLink(GlobalDir, OutDir, "mail-whitelist")
1143 DoLink(GlobalDir, OutDir, "forward-alias")
1145 if ExtraList.has_key("[DNS]"):
1146 GenDNS(OutDir + "dns-zone", Split[1])
1147 GenSSHFP(OutDir + "dns-sshfp", Split[1])
1149 if ExtraList.has_key("[BSMTP]"):
1150 GenBSMTP(OutDir + "bsmtp", Split[1])
1152 if ExtraList.has_key("[PRIVATE]"):
1153 DoLink(GlobalDir, OutDir, "debian-private")
1155 if ExtraList.has_key("[KEYRING]"):
1157 DoLink(GlobalDir, OutDir, os.path.basename(k))
1161 posix.remove(OutDir + os.path.basename(k))
1167 # vim:set shiftwidth=3: