ud-mailgate: remove exception for münchen.debian.net
[mirror/userdir-ldap.git] / ud-arbimport
1 #!/usr/bin/env python
2 # -*- mode: python -*-
3
4 #   Copyright (c) 1999       Jason Gunthorpe <jgg@debian.org>
5 #   Copyright (c) 2004       Joey Schulze <joey@debian.org>
6 #
7 #   This program is free software; you can redistribute it and/or modify
8 #   it under the terms of the GNU General Public License as published by
9 #   the Free Software Foundation; either version 2 of the License, or
10 #   (at your option) any later version.
11 #
12 #   This program is distributed in the hope that it will be useful,
13 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #   GNU General Public License for more details.
16 #
17 #   You should have received a copy of the GNU General Public License
18 #   along with this program; if not, write to the Free Software
19 #   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 # This script imports arbitary lists of data. The input is a file with 
22 # the form of:
23 #  uid: <data>
24
25 import re, time, ldap, getopt, sys;
26 from userdir_ldap import *;
27
28 # Process options
29 (options, arguments) = getopt.getopt(sys.argv[1:], "u:m:n")
30 for (switch, val) in options:
31    if (switch == '-u'):
32       AdminUser = val
33    elif (switch == '-m'):
34        LoadOverride(val);
35    elif (switch == '-n'):
36        NoAct = 1;
37 if len(arguments) == 0:
38    print "Give the key to assignt to then the file to import";
39    sys.exit(0)
40
41 # Main program starts here
42 l = passwdAccessLDAP(BaseDn, AdminUser)
43
44 List = open(arguments[1],"r");
45 Set = [];
46 User = None;
47 while(1):
48    Line = List.readline();
49    if Line != "":
50       # Glob similar lines
51       Split = re.split("[:\n]",Line);
52       if User == None:
53          User = Split[0];
54       if Split[0] == User:
55          Set.append(Split[1].strip());
56          continue;
57    else:
58       if len(Set) == 0:
59          break;
60    
61    # Generate the command..
62    Rec = [(ldap.MOD_REPLACE,arguments[0],Set[0])];
63    for x in Set[1:]:
64       Rec.append((ldap.MOD_ADD,arguments[0],x))
65
66    Dn = "uid=" + User + "," + BaseDn;
67    try:
68       print Dn,Rec;
69       l.modify_s(Dn,Rec);
70    except:
71       print "Failed",Dn;
72    
73    # Out of data..
74    if Line == "":
75       break;   
76    User = Split[0];
77    Set = [Split[1].strip()];