[LDAPsh-cvs] ldapsh ldapsh,1.35,1.36
Status: Beta
Brought to you by:
rcorvalan
From: <j-d...@us...> - 2003-12-14 08:48:09
|
Update of /cvsroot/ldapsh/ldapsh In directory sc8-pr-cvs1:/tmp/cvs-serv10064 Modified Files: ldapsh Log Message: * Added 'rename' and 'mv'. * Touch-ups for 'cp'. Index: ldapsh =================================================================== RCS file: /cvsroot/ldapsh/ldapsh/ldapsh,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** ldapsh 13 Dec 2003 12:39:44 -0000 1.35 --- ldapsh 14 Dec 2003 02:51:59 -0000 1.36 *************** *** 220,224 **** use Data::Dumper qw(Dumper); use Unicode::MapUTF8 qw(to_utf8 from_utf8); ! use subs qw(bind connect delete dump exit mkdir reset); BEGIN { --- 220,224 ---- use Data::Dumper qw(Dumper); use Unicode::MapUTF8 qw(to_utf8 from_utf8); ! use subs qw(bind connect delete dump exit mkdir rename reset); BEGIN { *************** *** 628,632 **** # DN Completion return _cdCommandCompletion(@_); ! } elsif ($cmd =~ /^(cat|vi|ls|list|csv|dump|ldif|search|cp)$/) { # Filter Completion return _filterCommandCompletion(@_); --- 628,632 ---- # DN Completion return _cdCommandCompletion(@_); ! } elsif ($cmd =~ /^(cat|vi|ls|list|csv|dump|ldif|search|cp|mv|rename|remove|rm)$/) { # Filter Completion return _filterCommandCompletion(@_); *************** *** 2094,2098 **** L<Expansion|expansion>). If C<-a> is specified, an attempt will be made to delete leaf entries before their parent entries. Thus, to delete an entire ! subdirectory hierarchy, you might try this: cd 'cn=Old Directory Subtree' --- 2094,2098 ---- L<Expansion|expansion>). If C<-a> is specified, an attempt will be made to delete leaf entries before their parent entries. Thus, to delete an entire ! subtree, you might try this: cd 'cn=Old Directory Subtree' *************** *** 2159,2163 **** the filter C<(objectclass=*)>. ! If C<to> parameter is an RDN, a single object will be copied to a new RDN within the same level of the LDAP tree, and you will get an error if C<from-expansion> expands to more than one object. --- 2159,2163 ---- the filter C<(objectclass=*)>. ! If the C<to> parameter is an RDN, a single object will be copied to a new RDN within the same level of the LDAP tree, and you will get an error if C<from-expansion> expands to more than one object. *************** *** 2174,2178 **** sub cp($$) { my ($from, $to) = @_; ! $from = undef if ($from eq "*"); my $localcopy = (scalar(_splitdn($to,2)) == 1); #I.e $to is an RDN. my $entries = _entriesExpander undef, $from; --- 2174,2178 ---- sub cp($$) { my ($from, $to) = @_; ! $from = "objectclass=*" if ($from eq "*"); my $localcopy = (scalar(_splitdn($to,2)) == 1); #I.e $to is an RDN. my $entries = _entriesExpander undef, $from; *************** *** 2212,2215 **** --- 2212,2284 ---- $Globals->{ENTRIES}{VALUE} = []; } + } + + =head3 rename + + B<Synopsis>: C<rename 'E<lt>from-expansionE<gt>'|'*' 'E<lt>toE<gt>'> + + Rename an entry with a new RDN or move a set of entries to new locations in the + LDAP tree. + + C<from-expansion> will be expanded in the usual way + (see L<Expansion|expansion>), with the addition that C<*> corresponds to + the filter C<(objectclass=*)>. + + If your directory server does not allow subtrees to be moved, you may have to + copy entries to a new location and then remove the old subtree (see L<cp|cp> + and L<remove|remove>). + + =cut + + sub rename($$) { + my ($from, $to) = @_; + $from = "objectclass=*" if ($from eq "*"); + my $entries = _entriesExpander undef, $from; + if (scalar(@$entries) > 1) { + foreach my $entry (@$entries) { + my $rdn = rdn($entry->dn); + my $result = $Globals->{LDAPCONN}{VALUE}->moddn($entry, newrdn => $rdn, newsuperior => $to); + if ($result->is_error) { + printf STDERR qq{LDAP error moving '%s'. Code:%s. Message:%s\n}, + $entry->dn, $result->code, $result->error; + return 0; + } + } + } + elsif (scalar(@$entries) == 1 ) { + my $entry = @$entries[0]; + if (scalar(_splitdn($to, 2)) > 1) { + my $rdn = rdn($entry->dn); + my $result = $Globals->{LDAPCONN}{VALUE}->moddn($entry, newrdn => $rdn, newsuperior => $to); + if ($result->is_error) { + printf STDERR qq{LDAP error moving '%s'. Code:%s. Message:%s\n}, + $entry->dn, $result->code, $result->error; + return 0; + } + } + else { + my $result = $Globals->{LDAPCONN}{VALUE}->moddn($entry, newrdn => $to, deleteoldrdn => 1); + if ($result->is_error) { + printf STDERR qq{LDAP error renaming '%s'. Code:%s. Message:%s\n}, + $entry->dn, $result->code, $result->error; + return 0; + } + } + } + else { + printf STDERR "No entries were renamed or moved.\n"; + return 0; + } + return 1; + } + + =head3 mv + + A synonym for L<rename|rename>. + + =cut + + sub mv($$) { + rename(shift, shift); } |