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>
7 # Copyright (c) 2008 Peter Palfrader <peter@palfrader.org>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 import re, time, ldap, getopt, sys, os, pwd;
24 from userdir_ldap import *;
25 from userdir_gpg import *;
27 # This tries to search for a free UID. There are two possible ways to do
28 # this, one is to fetch all the entires and pick the highest, the other
29 # is to randomly guess uids until one is free. This uses the former.
30 # Regrettably ldap doesn't have an integer attribute comparision function
31 # so we can only cut the search down slightly
33 # [JT] This is broken with Woody LDAP and the Schema; for now just
34 # search through all GIDs.
36 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,
37 "gidNumber=*",["gidNumber"]);
40 ID = int(GetAttr(I,"gidNumber","0"));
41 if ID > HighestUID and ID < 60000:
43 return HighestUID + 1;
46 AdminUser = pwd.getpwuid(os.getuid())[0];
50 OldGPGKeyRings = GPGKeyRings;
51 userdir_gpg.GPGKeyRings = [];
52 (options, arguments) = getopt.getopt(sys.argv[1:], "u:")
53 for (switch, val) in options:
57 l = passwdAccessLDAP(BaseDn, AdminUser)
60 Group = raw_input("Group name? ");
64 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"gid=" + Group);
67 print "Group already exists";
70 print "Create group %s ID = %d"%(Group,Id);
72 # Submit the add request
73 Dn = "gid=" + Group + "," + BaseDn;
74 print "Updating LDAP directory..",
76 l.add_s(Dn,[("gid",Group),
77 ("gidNumber",str(Id)),
78 ("objectClass", GroupObjectClasses)])