3 # $Id: smbldap-migrate-groups.pl,v 1.1.2.1 2002/06/04 22:25:39 jerry Exp $
5 # This code was developped by IDEALX (http://IDEALX.org/) and
6 # contributors (their names can be found in the CONTRIBUTORS file).
8 # Copyright (C) 2002 IDEALX
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License
12 # as published by the Free Software Foundation; either version 2
13 # of the License, or (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25 # Purpose of smbldap-migrate-groups : to parse a Windows
26 # group dump and populate Unix groups
27 # Reads group dump on stdin
39 my ($group, $mb) = @_;
42 if (!(@members = group_get_members
($group))) {
46 foreach my $m (@members) {
47 if ( !($m =~ m/^\*/) ) {
52 if (!process_rec_group
($gname, $mb)) {
53 print "recursive group not added : $gname\n";
60 # given a group dn and a list of members, update the group
63 my ($group, $dn_line, @members, $recgroup) = @_;
67 foreach $m (@members) {
68 if ( ($m =~ m/^\*/) ) {
72 print "recursive group not added : $gname\n";
74 if (!process_rec_group
($gname, \
@new_mb)) {
75 print "recursive group not added : $gname\n";
83 # new_mb contains flat members from group dump
84 # now append them to existing members
85 push @new_mb, group_get_members
($group);
91 my $nmb = $#new_mb + 1;
92 print STDERR
"Group $group now has $nmb member(s)\n";
95 foreach $m (@new_mb) {
96 $mbs .= "memberUid: $m\n";
110 die "$0: error while modifying group $group\n"
111 unless (do_ldapmodify
($tmpldif) == 0);
117 my ($group, @members) = @_;
119 print "Group name $group\n";
123 foreach $m (@members) {
134 my ($group, @members, $nocreate, $noupdate, $recgroup) = @_;
137 if (!defined($dn_line = get_group_dn
($group))) {
138 # group not found, create it ?
140 system "/usr/local/sbin/smbldap-groupadd.pl \"$group\"; sleep 5";
141 if (!defined($dn_line = get_group_dn
($group))) {
144 modify_group
($group, $dn_line, @members, $recgroup);
147 print "not created:\n";
148 display_group
($group, @members);
151 # group found, update it ?
153 modify_group
($group, $dn_line, @members, $recgroup);
156 print "not updated:\n";
157 display_group
($group, @members);
162 ###################################################
166 my $ok = getopts
('CUr?', \
%Options);
167 if ( (!$ok) || ($Options{'?'}) ) {
168 print "Usage: $0 [-CUr?] < group_dump\n";
169 print " -C don't create group if it doesn't exist\n";
170 print " -U don't update group if it exists\n";
171 print " -r recursively process groups\n";
184 next if ( $line =~ m/^\s*$/ );
186 if ($group_name eq "") {
187 if ( $line =~ m/^Group name\s+(.+).$/ ) {
192 if ($group_desc eq "") {
193 if ( $line =~ m/^Comment\s+(.*)$/ ) {
198 next if ( $line =~ m/^-+.$/ );
200 if ( $line =~ m/^Members/ ) {
205 if ( $line =~ m/^The command completed successfully/ ) {
208 push(@members, split(/\s+/, $line));
216 if ( $#members > -1) {
217 process_group
($group_name, @members, $Options{'C'}, $Options{'U'}, $Options{'r'});
220 #print "gn=$group_name\n";
221 #print "gd=$group_desc\n";
223 #foreach $m (@members)