ud-mailgate: remove exception for münchen.debian.net
[mirror/userdir-ldap.git] / ud-sshlist
1 #!/usr/bin/env python
2 # -*- mode: python -*-
3 # This script takes a list of .forward files and generates a list of colon
4 # delimited fields for import into a ldap directory. The fields represent
5 # the user and their email forwarding.
6 #
7 # A sample invokation..
8 #   cd /home
9 #   find -name ".foward" -maxdepth 2 | mkforwardlist | sort | less
10 # Then correct any invalid forward files if possible. After that stash the
11 # output in a file, remove the invalid lines and import it.
12 #
13 # It also understand .qmail type files
14
15 import re, time, getopt, os, sys, pwd, stat;
16
17 SSHAuthSplit = re.compile('^(.* )?(\d+) (\d+) (\d+) ?(.+)$');
18
19 while (1):
20    File = sys.stdin.readline().strip()
21    if File == "":
22       break;
23
24    # Attempt to determine the UID   
25    try:
26       User = pwd.getpwuid(os.stat(File)[stat.ST_UID])[0];
27    except KeyError:
28       print "Invalid0", File;
29       continue;
30
31    # Read the first two non comment non empty lines
32    Forward = open(File,"r");
33    Lines = [];
34    while (1):
35       Line = Forward.readline().strip()
36       if Line == "":
37          break;
38       if Line[0] == '#' or Line[0] == '\n':
39          continue;
40       if SSHAuthSplit.match(Line) == None:
41          print "Bad line", File;
42       else:
43          Lines.append(Line);
44
45    for x in Lines:
46       print User + ":",x;