diff options
author | Gerald Carter <jerry@samba.org> | 2003-09-23 20:39:22 +0000 |
---|---|---|
committer | Gerald Carter <jerry@samba.org> | 2003-09-23 20:39:22 +0000 |
commit | 79cb5593a8a99647426d3deb70babc64f43473f8 (patch) | |
tree | 873077306a41ff8e5941c5503d97409b3f74ab63 /examples/LDAP/smbldap-tools/smbldap-groupmod.pl | |
parent | 0675d21aa83c41bca315d434923b83af762d9d2b (diff) | |
download | samba-79cb5593a8a99647426d3deb70babc64f43473f8.tar.gz samba-79cb5593a8a99647426d3deb70babc64f43473f8.tar.bz2 samba-79cb5593a8a99647426d3deb70babc64f43473f8.zip |
update smbldap-tool sscripts from Jérôme Tournier
(This used to be commit c1546a5311a4e9ad2d6566e71e11c6d5f8f120a9)
Diffstat (limited to 'examples/LDAP/smbldap-tools/smbldap-groupmod.pl')
-rwxr-xr-x | examples/LDAP/smbldap-tools/smbldap-groupmod.pl | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/examples/LDAP/smbldap-tools/smbldap-groupmod.pl b/examples/LDAP/smbldap-tools/smbldap-groupmod.pl index 4a891a2772..f897101602 100755 --- a/examples/LDAP/smbldap-tools/smbldap-groupmod.pl +++ b/examples/LDAP/smbldap-tools/smbldap-groupmod.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w # This code was developped by IDEALX (http://IDEALX.org/) and # contributors (their names can be found in the CONTRIBUTORS file). # @@ -23,6 +23,9 @@ use strict; +use FindBin; +use FindBin qw($RealBin); +use lib "$RealBin/"; use smbldap_tools; use smbldap_conf; @@ -70,45 +73,30 @@ if (defined($tmp = $Options{'g'}) and $tmp =~ /\d+/) { } } if (!($gid == $tmp)) { - my $tmpldif = -"dn: cn=$groupName,$groupsdn -changetype: modify -replace: gidNumber -gidNumber: $tmp - -"; - die "$0: error while modifying group $groupName\n" - unless (do_ldapmodify($tmpldif) == 0); - undef $tmpldif; - + my $ldap_master=connect_ldap_master(); + my $modify = $ldap_master->modify ( "cn=$groupName,$groupsdn", + changes => [ + replace => [gidNumber => $tmp] + ] + ); + $modify->code && die "failed to modify entry: ", $modify->error ; + # take down session + $ldap_master->unbind } } -if (defined($newname)) { - my $FILE="|$ldapmodrdn >/dev/null"; - open (FILE, $FILE) || die "$!\n"; - print FILE <<EOF; -cn=$groupName,$groupsdn -cn=$newname - -EOF - ; - close FILE; - die "$0: error while modifying group $groupName\n" if ($?); - - my $tmpldif = -"dn: cn=$newname,$groupsdn -changetype: modify -delete: cn -- -add: cn -cn: $newname - -"; - die "$0: error while modifying group $groupName\n" - unless (do_ldapmodify($tmpldif) == 0); - undef $tmpldif; +if (defined($newname)) { + my $ldap_master=connect_ldap_master(); + my $modify = $ldap_master->moddn ( + "cn=$groupName,$groupsdn", + newrdn => "cn=$newname", + deleteoldrdn => "1", + newsuperior => "$groupsdn" + ); + $modify->code && die "failed to modify entry: ", $modify->error ; + # take down session + $ldap_master->unbind } # Add members @@ -117,16 +105,24 @@ if (defined($Options{'m'})) { my @members = split( /,/, $members ); my $member; foreach $member ( @members ) { - my $tmpldif = -"dn: cn=$groupName,$groupsdn -changetype: modify -add: memberUid -memberUid: $member - -"; - die "$0: error while modifying group $groupName\n" - unless (do_ldapmodify($tmpldif) == 0); - undef $tmpldif; + if (is_unix_user($member)) { + if (is_group_member("cn=$groupName,$groupsdn",$member)) { + print "User $member already in the group\n"; + } else { + print "adding user $member to group $groupName\n"; + my $ldap_master=connect_ldap_master(); + my $modify = $ldap_master->modify ( "cn=$groupName,$groupsdn", + changes => [ + add => [memberUid => $member] + ] + ); + $modify->code && warn "failed to add entry: ", $modify->error ; + # take down session + $ldap_master->unbind + } + } else { + print "User $member does not exist: create it first !\n"; + } } } @@ -136,16 +132,20 @@ if (defined($Options{'x'})) { my @members = split( /,/, $members ); my $member; foreach $member ( @members ) { - my $tmpldif = -"dn: cn=$groupName,$groupsdn -changetype: modify -delete: memberUid -memberUid: $member - -"; - die "$0: error while modifying group $groupName\n" - unless (do_ldapmodify($tmpldif) == 0); - undef $tmpldif; + if (is_group_member("cn=$groupName,$groupsdn",$member)) { + print "deleting user $member from group $groupName\n"; + my $ldap_master=connect_ldap_master(); + my $modify = $ldap_master->modify ( "cn=$groupName,$groupsdn", + changes => [ + delete => [memberUid => $member] + ] + ); + $modify->code && warn "failed to delete entry: ", $modify->error ; + # take down session + $ldap_master->unbind + } else { + print "User $member is not in the group $groupName!\n"; + } } } |