1 # This code was developped by IDEALX (http://IDEALX.org/) and
2 # contributors (their names can be found in the CONTRIBUTORS file).
4 # Copyright (C) 2001-2002 IDEALX
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 # Purpose of smbldap-groupmod : group (posix) modification
34 my $ok = getopts
('og:n:m:x:?', \
%Options);
35 if ( (!$ok) || (@ARGV < 1) || ($Options{'?'}) ) {
36 print "Usage: $0 [-g gid [-o]] [-n name] [-m members(,)] [-x members (,)] groupname\n";
37 print " -g new gid\n";
38 print " -o gid is not unique\n";
39 print " -n new group name\n";
40 print " -m add members (comma delimited)\n";
41 print " -x delete members (comma delimted)\n";
42 print " -? show this help message\n";
46 my $groupName = $ARGV[0];
48 if (!defined(get_group_dn
($groupName))) {
49 print "$0: group $groupName doesn't exist\n";
53 my $newname = $Options{'n'};
55 my $nscd_status = system "/etc/init.d/nscd status >/dev/null 2>&1";
57 if ($nscd_status == 0) {
58 system "/etc/init.d/nscd restart > /dev/null 2>&1";
61 my $gid = getgrnam($groupName);
64 if (defined($tmp = $Options{'g'}) and $tmp =~ /\d+/) {
65 if (!defined($Options{'o'})) {
66 if (defined(getgrgid($tmp))) {
67 print "$0: gid $tmp exists\n";
71 if (!($gid == $tmp)) {
73 "dn: cn=$groupName,$groupsdn
79 die "$0: error while modifying group $groupName\n"
80 unless (do_ldapmodify
($tmpldif) == 0);
86 if (defined($newname)) {
87 my $FILE="|$ldapmodrdn >/dev/null";
88 open (FILE
, $FILE) || die "$!\n";
90 cn=$groupName,$groupsdn
96 die "$0: error while modifying group $groupName\n" if ($?
);
99 "dn: cn=$newname,$groupsdn
107 die "$0: error while modifying group $groupName\n"
108 unless (do_ldapmodify
($tmpldif) == 0);
114 if (defined($Options{'m'})) {
115 my $members = $Options{'m'};
116 my @members = split( /,/, $members );
118 foreach $member ( @members ) {
120 "dn: cn=$groupName,$groupsdn
126 die "$0: error while modifying group $groupName\n"
127 unless (do_ldapmodify
($tmpldif) == 0);
133 if (defined($Options{'x'})) {
134 my $members = $Options{'x'};
135 my @members = split( /,/, $members );
137 foreach $member ( @members ) {
139 "dn: cn=$groupName,$groupsdn
145 die "$0: error while modifying group $groupName\n"
146 unless (do_ldapmodify
($tmpldif) == 0);
151 $nscd_status = system "/etc/init.d/nscd status >/dev/null 2>&1";
153 if ($nscd_status == 0) {
154 system "/etc/init.d/nscd restart > /dev/null 2>&1";
159 ############################################################
163 smbldap-groupmod.pl - Modify a group
167 smbldap-groupmod.pl [-g gid [-o]] [-n group_name ] group
171 The smbldap-groupmod.pl command modifies the system account files to
172 reflect the changes that are specified on the command line.
173 The options which apply to the smbldap-groupmod command are
175 -g gid The numerical value of the group's ID. This value must be
176 unique, unless the -o option is used. The value must be non-
177 negative. Any files which the old group ID is the file
178 group ID must have the file group ID changed manually.
181 The name of the group will be changed from group to group_name.
184 The members to be added to the group in comma-delimeted form.
187 The members to be removed from the group in comma-delimted form.
191 smbldap-groupmod.pl -g 253 development
192 This will change the GID of the 'development' group to '253'.
194 smbldap-groupmod.pl -n Idiots Managers
195 This will change the name of the 'Managers' group to 'Idiots'.
197 smbldap-groupmod.pl -m "jdoe,jsmith" "Domain Admins"
198 This will add 'jdoe' and 'jsmith' to the 'Domain Admins' group.
200 smbldap-groupmod.pl -x "jdoe,jsmith" "Domain Admins"
201 This will remove 'jdoe' and 'jsmith' from the 'Domain Admins' group.