only look for *LK*, and not base anything off the fingerprint when disabling mail...
[mirror/userdir-ldap.git] / ud-generate
1 #!/usr/bin/env python
2 # -*- mode: python -*-
3 # Generates passwd, shadow and group files from the ldap directory.
4
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  Joey Schulze <joey@infodrom.org>
8 #   Copyright (c) 2001-2007  Ryan Murray <rmurray@debian.org>
9 #
10 #   This program is free software; you can redistribute it and/or modify
11 #   it under the terms of the GNU General Public License as published by
12 #   the Free Software Foundation; either version 2 of the License, or
13 #   (at your option) any later version.
14 #
15 #   This program is distributed in the hope that it will be useful,
16 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 #   GNU General Public License for more details.
19 #
20 #   You should have received a copy of the GNU General Public License
21 #   along with this program; if not, write to the Free Software
22 #   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 import string, re, time, ldap, getopt, sys, os, pwd, posix, socket, base64, sha
25 from userdir_ldap import *;
26
27 global Allowed;
28 global CurrentHost;
29
30 PasswdAttrs = None;
31 GroupIDMap = {};
32 Allowed = None;
33 CurrentHost = "";
34
35 EmailCheck = re.compile("^([^ <>@]+@[^ ,<>@]+)?$");
36 BSMTPCheck = re.compile(".*mx 0 (gluck)\.debian\.org\..*",re.DOTALL);
37 DNSZone = ".debian.net"
38
39 def Sanitize(Str):
40   return string.translate(Str,string.maketrans("\n\r\t","$$$"));
41
42 def DoLink(From,To,File):
43    try: posix.remove(To+File);
44    except: pass;
45    posix.link(From+File,To+File);
46
47 # See if this user is in the group list
48 def IsInGroup(DnRecord):
49   if Allowed == None:
50      return 1;
51
52   # See if the primary group is in the list
53   if Allowed.has_key(GetAttr(DnRecord,"gidNumber")) != 0:
54      return 1;
55
56   # Check the host based ACL
57   if DnRecord[1].has_key("allowedHost") != 0:
58      for I in DnRecord[1]["allowedHost"]:
59         if CurrentHost == I:
60            return 1;
61
62   # See if there are supplementary groups
63   if DnRecord[1].has_key("supplementaryGid") == 0:
64      return 0;
65
66   # Check the supplementary groups
67   for I in DnRecord[1]["supplementaryGid"]:
68      if Allowed.has_key(I):
69         return 1;
70   return 0;
71
72 def Die(File,F,Fdb):
73    if F != None:
74       F.close();
75    if Fdb != None:
76       Fdb.close();
77    try: os.remove(File + ".tmp");
78    except: pass;
79    try: os.remove(File + ".tdb.tmp");
80    except: pass;
81
82 def Done(File,F,Fdb):
83   if F != None:
84     F.close();
85     os.rename(File + ".tmp",File);
86   if Fdb != None:
87     Fdb.close();
88     os.rename(File + ".tdb.tmp",File+".tdb");
89   
90 # Generate the password list
91 def GenPasswd(l,File,HomePrefix):
92   F = None;
93   try:
94    F = open(File + ".tdb.tmp","w");
95
96    # Fetch all the users
97    global PasswdAttrs;
98    if PasswdAttrs == None:
99       raise "No Users";
100
101    I = 0;
102    for x in PasswdAttrs:
103       if x[1].has_key("uidNumber") == 0 or IsInGroup(x) == 0:
104          continue;
105
106       # Do not let people try to buffer overflow some busted passwd parser.
107       if len(GetAttr(x,"gecos")) > 100 or len(GetAttr(x,"loginShell")) > 50:
108          continue;
109
110       Line = "%s:x:%s:%s:%s:%s%s:%s" % (GetAttr(x,"uid"),\
111               GetAttr(x,"uidNumber"),GetAttr(x,"gidNumber"),\
112               GetAttr(x,"gecos"),HomePrefix,GetAttr(x,"uid"),\
113               GetAttr(x,"loginShell"));
114
115       Line = Sanitize(Line) + "\n";
116       F.write("0%u %s" % (I,Line));
117       F.write(".%s %s" % (GetAttr(x,"uid"),Line));
118       F.write("=%s %s" % (GetAttr(x,"uidNumber"),Line));
119       I = I + 1;
120
121   # Oops, something unspeakable happened.
122   except:
123    Die(File,None,F);
124    raise;
125   Done(File,None,F);
126
127 # Generate the shadow list
128 def GenShadow(l,File):
129   F = None;
130   try:
131    OldMask = os.umask(0077);
132    F = open(File + ".tdb.tmp","w",0600);
133    os.umask(OldMask);
134
135    # Fetch all the users
136    global PasswdAttrs;
137    if PasswdAttrs == None:
138       raise "No Users";
139
140    I = 0;
141    for x in PasswdAttrs:
142       if x[1].has_key("uidNumber") == 0 or IsInGroup(x) == 0:
143          continue;
144          
145       Pass = GetAttr(x,"userPassword");
146       if Pass[0:7] != "{crypt}" or len(Pass) > 50:
147          Pass = '*';
148       else:
149          Pass = Pass[7:];
150       Line = "%s:%s:%s:%s:%s:%s:%s:%s:" % (GetAttr(x,"uid"),\
151               Pass,GetAttr(x,"shadowLastChange"),\
152               GetAttr(x,"shadowMin"),GetAttr(x,"shadowMax"),\
153               GetAttr(x,"shadowWarning"),GetAttr(x,"shadowinactive"),\
154               GetAttr(x,"shadowexpire"));
155       Line = Sanitize(Line) + "\n";
156       F.write("0%u %s" % (I,Line));
157       F.write(".%s %s" % (GetAttr(x,"uid"),Line));
158       I = I + 1;
159
160   # Oops, something unspeakable happened.
161   except:
162    Die(File,None,F);
163    raise;
164   Done(File,None,F);
165
166 # Generate the shadow list
167 def GenSSHShadow(l,File):
168   F = None;
169   try:
170    OldMask = os.umask(0077);
171    F = open(File + ".tmp","w",0600);
172    os.umask(OldMask);
173
174    # Fetch all the users
175    global PasswdAttrs;
176    if PasswdAttrs == None:
177       raise "No Users";
178
179    for x in PasswdAttrs:
180       # If the account is locked, do not write it.
181       # This is a partial stop-gap. The ssh also needs to change this
182       # to ignore ~/.ssh/authorized* files.
183       if (string.find(GetAttr(x,"userPassword"),"*LK*")  != -1):
184          continue;
185
186       if x[1].has_key("uidNumber") == 0 or \
187          x[1].has_key("sshRSAAuthKey") == 0:
188          continue;
189       for I in x[1]["sshRSAAuthKey"]:
190          User = GetAttr(x,"uid");
191          Line = "%s: %s" %(User,I);
192          Line = Sanitize(Line) + "\n";
193          F.write(Line);
194   # Oops, something unspeakable happened.
195   except:
196    Die(File,F,None);
197    raise;
198   Done(File,F,None);
199
200 # Generate the group list
201 def GenGroup(l,File):
202   F = None;
203   try:
204    F = open(File + ".tdb.tmp","w");
205
206    # Generate the GroupMap
207    GroupMap = {};
208    for x in GroupIDMap.keys():
209       GroupMap[x] = [];
210       
211    # Fetch all the users
212    global PasswdAttrs;
213    if PasswdAttrs == None:
214       raise "No Users";
215
216    # Sort them into a list of groups having a set of users
217    for x in PasswdAttrs:
218       if x[1].has_key("uidNumber") == 0 or IsInGroup(x) == 0:
219          continue;
220       if x[1].has_key("supplementaryGid") == 0:
221          continue;
222          
223       for I in x[1]["supplementaryGid"]:
224          if GroupMap.has_key(I):
225             GroupMap[I].append(GetAttr(x,"uid"));
226          else:
227             print "Group does not exist ",I,"but",GetAttr(x,"uid"),"is in it";
228             
229    # Output the group file.
230    J = 0;
231    for x in GroupMap.keys():
232       if GroupIDMap.has_key(x) == 0:
233          continue;
234       Line = "%s:x:%u:" % (x,GroupIDMap[x]);
235       Comma = '';
236       for I in GroupMap[x]:
237         Line = Line + ("%s%s" % (Comma,I));
238         Comma = ',';
239       Line = Sanitize(Line) + "\n";
240       F.write("0%u %s" % (J,Line));
241       F.write(".%s %s" % (x,Line));
242       F.write("=%u %s" % (GroupIDMap[x],Line));
243       J = J + 1;
244       
245   # Oops, something unspeakable happened.
246   except:
247    Die(File,None,F);
248    raise;
249   Done(File,None,F);
250
251 # Generate the email forwarding list
252 def GenForward(l,File):
253   F = None;
254   try:
255    OldMask = os.umask(0022);
256    F = open(File + ".tmp","w",0644);
257    os.umask(OldMask);
258
259    # Fetch all the users
260    global PasswdAttrs;
261    if PasswdAttrs == None:
262       raise "No Users";
263
264    # Write out the email address for each user
265    for x in PasswdAttrs:
266       if x[1].has_key("emailForward") == 0 or IsInGroup(x) == 0:
267          continue;
268       
269       # Do not allow people to try to buffer overflow busted parsers
270       if len(GetAttr(x,"emailForward")) > 200:
271          continue;
272
273       # Check the forwarding address
274       if EmailCheck.match(GetAttr(x,"emailForward")) == None:
275          continue;
276       Line = "%s: %s" % (GetAttr(x,"uid"),GetAttr(x,"emailForward"));
277       Line = Sanitize(Line) + "\n";
278       F.write(Line);
279       
280   # Oops, something unspeakable happened.
281   except:
282    Die(File,F,None);
283    raise;
284   Done(File,F,None);
285
286 def GenAllForward(l,File):
287   Fdb = None;
288   try:
289    OldMask = os.umask(0022);
290    Fdb = os.popen("cdbmake %s %s.tmp"%(File,File),"w");
291    os.umask(OldMask);
292
293    # Fetch all the users
294    global PasswdAttrs;
295    if PasswdAttrs == None:
296       raise "No Users";
297
298    # Write out the email address for each user
299    for x in PasswdAttrs:
300       if x[1].has_key("emailForward") == 0:
301          continue;
302       
303       # Do not allow people to try to buffer overflow busted parsers
304       Forward = GetAttr(x,"emailForward");
305       if len(Forward) > 200:
306          continue;
307
308       # Check the forwarding address
309       if EmailCheck.match(Forward) == None:
310          continue;
311          
312       User = GetAttr(x,"uid");
313       Fdb.write("+%d,%d:%s->%s\n"%(len(User),len(Forward),User,Forward));
314    Fdb.write("\n");
315   # Oops, something unspeakable happened.
316   except:
317     Fdb.close();
318     raise;
319   if Fdb.close() != None:
320     raise "cdbmake gave an error";
321
322 # Generate the anon XEarth marker file 
323 def GenMarkers(l,File):
324   F = None;
325   try:
326    F = open(File + ".tmp","w");
327
328    # Fetch all the users
329    global PasswdAttrs;
330    if PasswdAttrs == None:
331       raise "No Users";
332
333    # Write out the position for each user
334    for x in PasswdAttrs:
335       if x[1].has_key("latitude") == 0 or x[1].has_key("longitude") == 0:
336          continue;       
337       try:
338          Line = "%8s %8s \"\""%(DecDegree(GetAttr(x,"latitude"),1),DecDegree(GetAttr(x,"longitude"),1));
339          Line = Sanitize(Line) + "\n";
340          F.write(Line);
341       except:
342          pass;
343       
344   # Oops, something unspeakable happened.
345   except:
346    Die(File,F,None);
347    raise;
348   Done(File,F,None);
349
350 # Generate the debian-private subscription list
351 def GenPrivate(l,File):
352   F = None;
353   try:
354    F = open(File + ".tmp","w");
355
356    # Fetch all the users
357    global PasswdAttrs;
358    if PasswdAttrs == None:
359       raise "No Users";
360
361    # Write out the position for each user
362    for x in PasswdAttrs:
363       if x[1].has_key("privateSub") == 0:
364          continue;
365
366       # If the account is locked, do not write it
367       if (string.find(GetAttr(x,"userPassword"),"*LK*")  != -1):
368          continue;
369
370       # If the account has no PGP key, do not write it
371       if x[1].has_key("keyFingerPrint") == 0:
372          continue;
373
374       # Must be in the Debian group (yuk, hard coded for now)
375       if GetAttr(x,"gidNumber") != "800":
376          continue;
377
378       try:
379          Line = "%s"%(GetAttr(x,"privateSub"));
380          Line = Sanitize(Line) + "\n";
381          F.write(Line);
382       except:
383          pass;
384       
385   # Oops, something unspeakable happened.
386   except:
387    Die(File,F,None);
388    raise;
389   Done(File,F,None);
390
391 # Generate the list of local addresses that refuse all mail
392 def GenMailDisable(l,File):
393   F = None;
394   try:
395    F = open(File + ".tmp","w");
396
397    # Fetch all the users
398    global PasswdAttrs;
399    if PasswdAttrs == None:
400       raise "No Users";
401
402    for x in PasswdAttrs:
403       Reason = None
404       
405       # If the account is locked, disable incoming mail
406       if (string.find(GetAttr(x,"userPassword"),"*LK*")  != -1):
407          Reason = "user account locked"
408       else:
409          if x[1].has_key("mailDisableMessage"):
410             Reason = GetAttr(x,"mailDisableMessage")
411          else:
412             continue
413
414       # Must be in the Debian group (yuk, hard coded for now)
415       if GetAttr(x,"gidNumber") != "800":
416          continue;
417
418       try:
419          Line = "%s: %s"%(GetAttr(x,"uid"),Reason);
420          Line = Sanitize(Line) + "\n";
421          F.write(Line);
422       except:
423          pass;
424       
425   # Oops, something unspeakable happened.
426   except:
427    Die(File,F,None);
428    raise;
429   Done(File,F,None);
430
431 # Generate a list of uids that should have boolean affects applied
432 def GenMailBool(l,File,Key):
433   F = None;
434   try:
435    F = open(File + ".tmp","w");
436
437    # Fetch all the users
438    global PasswdAttrs;
439    if PasswdAttrs == None:
440       raise "No Users";
441
442    for x in PasswdAttrs:
443       Reason = None
444       
445       if x[1].has_key(Key) == 0:
446          continue
447
448       # Must be in the Debian group (yuk, hard coded for now)
449       if GetAttr(x,"gidNumber") != "800":
450          continue
451
452       if GetAttr(x,Key) != "TRUE":
453          continue
454
455       try:
456          Line = "%s"%(GetAttr(x,"uid"));
457          Line = Sanitize(Line) + "\n";
458          F.write(Line);
459       except:
460          pass;
461       
462   # Oops, something unspeakable happened.
463   except:
464    Die(File,F,None);
465    raise;
466   Done(File,F,None);
467
468 # Generate a list of hosts for RBL or whitelist purposes.
469 def GenMailList(l,File,Key):
470   F = None;
471   try:
472    F = open(File + ".tmp","w");
473
474    # Fetch all the users
475    global PasswdAttrs;
476    if PasswdAttrs == None:
477       raise "No Users";
478
479    for x in PasswdAttrs:
480       Reason = None
481       
482       if x[1].has_key(Key) == 0:
483          continue
484
485       # Must be in the Debian group (yuk, hard coded for now)
486       if GetAttr(x,"gidNumber") != "800":
487          continue
488
489       try:
490          found = 0
491          Line = None
492          for z in x[1][Key]:
493              if Key == "mailWhitelist":
494                  if re.match('^[-\w.]+(/[\d]+)?$',z) == None:
495                      continue
496              else:
497                  if re.match('^[-\w.]+$',z) == None:
498                      continue
499              if found == 0:
500                  found = 1
501                  Line = GetAttr(x,"uid")
502              else:
503                  Line += " "
504              Line += ": " + z
505              if Key == "mailRHSBL":
506                  Line += "/$sender_address_domain"
507
508          if Line != None:
509              Line = Sanitize(Line) + "\n";
510              F.write(Line);
511       except:
512          pass;
513       
514   # Oops, something unspeakable happened.
515   except:
516    Die(File,F,None);
517    raise;
518   Done(File,F,None);
519
520 # Generate the DNS Zone file
521 def GenDNS(l,File,HomePrefix):
522   F = None;
523   try:
524    F = open(File + ".tmp","w");
525    
526    # Fetch all the users
527    global PasswdAttrs;
528    if PasswdAttrs == None:
529       raise "No Users";
530
531    # Write out the zone file entry for each user
532    for x in PasswdAttrs:
533       if x[1].has_key("dnsZoneEntry") == 0:
534          continue;
535
536       # If the account has no PGP key, do not write it
537       if x[1].has_key("keyFingerPrint") == 0:
538          continue;
539       try:
540          F.write("; %s\n"%(EmailAddress(x)));
541          for z in x[1]["dnsZoneEntry"]:
542             Split = string.split(string.lower(z));
543             if string.lower(Split[1]) == 'in':
544                for y in range(0,len(Split)):
545                   if Split[y] == "$":
546                      Split[y] = "\n\t";
547                Line = string.join(Split," ") + "\n";
548                F.write(Line);
549                
550                Host = Split[0] + DNSZone;
551                if BSMTPCheck.match(Line) != None:
552                    F.write("; Has BSMTP\n");
553                                
554                # Write some identification information
555                if string.lower(Split[2]) == "a":
556                   Line = "%s IN TXT \"%s\"\n"%(Split[0],EmailAddress(x));
557                   for y in x[1]["keyFingerPrint"]:
558                      Line = Line + "%s IN TXT \"PGP %s\"\n"%(Split[0],FormatPGPKey(y));
559                   F.write(Line);
560             else:
561                Line = "; Err %s"%(str(Split));
562                F.write(Line);
563
564          F.write("\n");
565       except:
566          F.write("; Errors\n");
567          pass;
568       
569   # Oops, something unspeakable happened.
570   except:
571    Die(File,F,None);
572    raise;
573   Done(File,F,None);
574
575 # Generate the DNS SSHFP records
576 def GenSSHFP(l,File,HomePrefix):
577   F = None
578   try:
579    F = open(File + ".tmp","w")
580    
581    # Fetch all the hosts
582    global HostAttrs
583    if HostAttrs == None:
584       raise "No Hosts"
585
586    for x in HostAttrs:
587       if x[1].has_key("hostname") == 0 or \
588          x[1].has_key("sshRSAHostKey") == 0:
589          continue
590       Host = GetAttr(x,"hostname");
591       Algorithm = None
592       for I in x[1]["sshRSAHostKey"]:
593          Split = string.split(I)
594          if Split[0] == 'ssh-rsa':
595             Algorithm = 1
596          if Split[0] == 'ssh-dss':
597             Algorithm = 2
598          if Algorithm == None:
599             continue
600          Fingerprint = sha.new(base64.decodestring(Split[1])).hexdigest()
601          Line = "%s. IN SSHFP %u 1 %s" % (Host,Algorithm,Fingerprint)
602          Line = Sanitize(Line) + "\n"
603          F.write(Line)
604   # Oops, something unspeakable happened.
605   except:
606    Die(File,F,None)
607    raise;
608   Done(File,F,None)
609
610 # Generate the BSMTP file
611 def GenBSMTP(l,File,HomePrefix):
612   F = None;
613   try:
614    F = open(File + ".tmp","w");
615    
616    # Fetch all the users
617    global PasswdAttrs;
618    if PasswdAttrs == None:
619       raise "No Users";
620
621    # Write out the zone file entry for each user
622    for x in PasswdAttrs:
623       if x[1].has_key("dnsZoneEntry") == 0:
624          continue;
625
626       # If the account has no PGP key, do not write it
627       if x[1].has_key("keyFingerPrint") == 0:
628          continue;
629       try:
630          for z in x[1]["dnsZoneEntry"]:
631             Split = string.split(string.lower(z));
632             if string.lower(Split[1]) == 'in':
633                for y in range(0,len(Split)):
634                   if Split[y] == "$":
635                      Split[y] = "\n\t";
636                Line = string.join(Split," ") + "\n";
637                
638                Host = Split[0] + DNSZone;
639                if BSMTPCheck.match(Line) != None:
640                    F.write("%s: user=%s group=Debian file=%s%s/bsmtp/%s\n"%(Host,
641                                GetAttr(x,"uid"),HomePrefix,GetAttr(x,"uid"),Host));
642                                
643       except:
644          F.write("; Errors\n");
645          pass;
646       
647   # Oops, something unspeakable happened.
648   except:
649    Die(File,F,None);
650    raise;
651   Done(File,F,None);
652
653 # Generate the ssh known hosts file
654 def GenSSHKnown(l,File):
655   F = None;
656   try:
657    OldMask = os.umask(0022);
658    F = open(File + ".tmp","w",0644);
659    os.umask(OldMask);
660
661    global HostAttrs
662    if HostAttrs == None:
663       raise "No Hosts";
664    
665    for x in HostAttrs:
666       if x[1].has_key("hostname") == 0 or \
667          x[1].has_key("sshRSAHostKey") == 0:
668          continue;
669       Host = GetAttr(x,"hostname");
670       SHost = string.find(Host,".");
671       for I in x[1]["sshRSAHostKey"]:
672          if SHost == None:
673             Line = "%s,%s %s" %(Host,socket.gethostbyname(Host),I);
674          else:
675             Line = "%s,%s,%s %s" %(Host,Host[0:SHost],socket.gethostbyname(Host),I);
676          Line = Sanitize(Line) + "\n";
677          F.write(Line);
678   # Oops, something unspeakable happened.
679   except:
680    Die(File,F,None);
681    raise;
682   Done(File,F,None);
683
684 # Generate the debianhosts file (list of all IP addresses)
685 def GenHosts(l,File):
686   F = None;
687   try:
688    OldMask = os.umask(0022);
689    F = open(File + ".tmp","w",0644);
690    os.umask(OldMask);
691
692    # Fetch all the hosts
693    HostNames = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"hostname=*",\
694                 ["hostname"]);
695    
696    if HostNames == None:
697       raise "No Hosts";
698
699    for x in HostNames:
700       if x[1].has_key("hostname") == 0:
701          continue;
702       Host = GetAttr(x,"hostname");
703       try:
704         Addr = socket.gethostbyname(Host);
705         F.write(Addr + "\n");
706       except:
707         pass
708   # Oops, something unspeakable happened.
709   except:
710    Die(File,F,None);
711    raise;
712   Done(File,F,None);
713
714 # Connect to the ldap server
715 l = ldap.open(LDAPServer);
716 F = open(PassDir+"/pass-"+pwd.getpwuid(os.getuid())[0],"r");
717 Pass = string.split(string.strip(F.readline())," ");
718 F.close();
719 l.simple_bind_s("uid="+Pass[0]+","+BaseDn,Pass[1]);
720
721 # Fetch all the groups
722 GroupIDMap = {};
723 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"gid=*",\
724                   ["gid","gidNumber"]);
725
726 # Generate the GroupMap and GroupIDMap
727 for x in Attrs:
728    if x[1].has_key("gidNumber") == 0:
729       continue;
730    GroupIDMap[x[1]["gid"][0]] = int(x[1]["gidNumber"][0]);
731
732 # Fetch all the users
733 PasswdAttrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid=*",\
734                 ["uid","uidNumber","gidNumber","supplementaryGid",\
735                  "gecos","loginShell","userPassword","shadowLastChange",\
736                  "shadowMin","shadowMax","shadowWarning","shadowinactive",
737                  "shadowexpire","emailForward","latitude","longitude",\
738                  "allowedHost","sshRSAAuthKey","dnsZoneEntry","cn","sn",\
739                  "keyFingerPrint","privateSub","mailDisableMessage",\
740                  "mailGreylisting","mailCallout","mailRBL","mailRHSBL",\
741                  "mailWhitelist"]);
742 # Fetch all the hosts
743 HostAttrs    = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"sshRSAHostKey=*",\
744                 ["hostname","sshRSAHostKey"]);
745
746 # Open the control file
747 if len(sys.argv) == 1:
748    F = open(GenerateConf,"r");
749 else:
750    F = open(sys.argv[1],"r")
751
752 # Generate global things
753 GlobalDir = GenerateDir+"/";
754 GenSSHShadow(l,GlobalDir+"ssh-rsa-shadow");
755 GenAllForward(l,GlobalDir+"mail-forward.cdb");
756 GenMarkers(l,GlobalDir+"markers");
757 GenPrivate(l,GlobalDir+"debian-private");
758 GenSSHKnown(l,GlobalDir+"ssh_known_hosts");
759 GenHosts(l,GlobalDir+"debianhosts");
760 GenMailDisable(l,GlobalDir+"mail-disable");
761 GenMailBool(l,GlobalDir+"mail-greylist","mailGreylisting");
762 GenMailBool(l,GlobalDir+"mail-callout","mailCallout");
763 GenMailList(l,GlobalDir+"mail-rbl","mailRBL");
764 GenMailList(l,GlobalDir+"mail-rhsbl","mailRHSBL");
765 GenMailList(l,GlobalDir+"mail-whitelist","mailWhitelist");
766
767 # Compatibility.
768 GenForward(l,GlobalDir+"forward-alias");
769    
770 while(1):
771    Line = F.readline();
772    if Line == "":
773       break;
774    Line = string.strip(Line);
775    if Line == "":
776       continue;
777    if Line[0] == '#':
778       continue;
779
780    Split = string.split(Line," ");
781    OutDir = GenerateDir + '/' + Split[0] + '/';
782    try: os.mkdir(OutDir);
783    except: pass;
784
785    # Get the group list and convert any named groups to numerics
786    GroupList = {};
787    ExtraList = {};
788    for I in Split[2:]:
789       if I[0] == '[':
790          ExtraList[I] = None;
791          continue;
792       GroupList[I] = None;
793       if GroupIDMap.has_key(I):
794          GroupList[str(GroupIDMap[I])] = None;
795
796    Allowed = GroupList;
797    if Allowed == {}:
798      Allowed = None
799    CurrentHost = Split[0];
800
801    sys.stdout.flush();
802    GenPasswd(l,OutDir+"passwd",Split[1]);
803    sys.stdout.flush();
804    GenGroup(l,OutDir+"group");
805    if ExtraList.has_key("[UNTRUSTED]"):
806         continue;
807    GenShadow(l,OutDir+"shadow");
808         
809    # Link in global things   
810    DoLink(GlobalDir,OutDir,"ssh-rsa-shadow");
811    DoLink(GlobalDir,OutDir,"markers");
812    DoLink(GlobalDir,OutDir,"mail-forward.cdb");
813    DoLink(GlobalDir,OutDir,"debianhosts");
814    DoLink(GlobalDir,OutDir,"ssh_known_hosts");
815    DoLink(GlobalDir,OutDir,"mail-disable");
816    DoLink(GlobalDir,OutDir,"mail-greylist");
817    DoLink(GlobalDir,OutDir,"mail-callout");
818    DoLink(GlobalDir,OutDir,"mail-rbl");
819    DoLink(GlobalDir,OutDir,"mail-rhsbl");
820    DoLink(GlobalDir,OutDir,"mail-whitelist");
821
822    # Compatibility.
823    DoLink(GlobalDir,OutDir,"forward-alias");
824
825    if ExtraList.has_key("[DNS]"):
826       GenDNS(l,OutDir+"dns-zone",Split[1]);
827       GenSSHFP(l,OutDir+"dns-sshfp",Split[1])
828       
829    if ExtraList.has_key("[BSMTP]"):
830       GenBSMTP(l,OutDir+"bsmtp",Split[1])
831
832    if ExtraList.has_key("[PRIVATE]"):
833       DoLink(GlobalDir,OutDir,"debian-private")