4 # Copyright (c) 2000 Jason Gunthorpe <jgg@debian.org>
5 # Copyright (c) 2001-2003 James Troup <troup@debian.org>
6 # Copyright (c) 2004 Joey Schulze <joey@debian.org>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 import string, re, time, ldap, getopt, sys, os, pwd;
23 from userdir_ldap import *;
24 from userdir_gpg import *;
26 # This tries to search for a free UID. There are two possible ways to do
27 # this, one is to fetch all the entires and pick the highest, the other
28 # is to randomly guess uids until one is free. This uses the former.
29 # Regrettably ldap doesn't have an integer attribute comparision function
30 # so we can only cut the search down slightly
32 # [JT] This is broken with Woody LDAP and the Schema; for now just
33 # search through all GIDs.
35 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,
36 "gidNumber=*",["gidNumber"]);
39 ID = int(GetAttr(I,"gidNumber","0"));
40 if ID > HighestUID and ID < 60000:
42 return HighestUID + 1;
45 AdminUser = pwd.getpwuid(os.getuid())[0];
49 OldGPGKeyRings = GPGKeyRings;
50 userdir_gpg.GPGKeyRings = [];
51 (options, arguments) = getopt.getopt(sys.argv[1:], "u:")
52 for (switch, val) in options:
56 l = passwdAccessLDAP(LDAPServer, BaseDn, AdminUser)
59 Group = raw_input("Group name? ");
63 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"gid=" + Group);
66 print "Group already exists";
69 print "Create group %s ID = %d"%(Group,Id);
71 # Submit the add request
72 Dn = "gid=" + Group + "," + BaseDn;
73 print "Updating LDAP directory..",
75 l.add_s(Dn,[("gid",Group),
76 ("gidNumber",str(Id)),
77 ("objectClass", GroupObjectClasses)])