[LDAPsh-cvs] ldapsh ldapsh,1.13,1.14
Status: Beta
Brought to you by:
rcorvalan
From: <po...@us...> - 2003-05-27 12:06:34
|
Update of /cvsroot/ldapsh/ldapsh In directory sc8-pr-cvs1:/tmp/cvs-serv21409 Modified Files: ldapsh Log Message: Extend cp operation to copy multiple entries between subtrees (patch 606653) Index: ldapsh =================================================================== RCS file: /cvsroot/ldapsh/ldapsh/ldapsh,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** ldapsh 27 May 2003 12:04:19 -0000 1.13 --- ldapsh 27 May 2003 12:06:32 -0000 1.14 *************** *** 506,510 **** $line2 =~ s/^\s+//; my ($cmd, $rest) = split(/\s+/, $line2, 2); ! if ($cmd =~ /^(cd|acd|setdn|pushd|cat|vi|ls|list|dump|ldif|search)$/) { return _cdCommandCompletion(@_); } else { --- 506,510 ---- $line2 =~ s/^\s+//; my ($cmd, $rest) = split(/\s+/, $line2, 2); ! if ($cmd =~ /^(cd|acd|setdn|pushd|cat|vi|ls|list|dump|ldif|search|cp)$/) { return _cdCommandCompletion(@_); } else { *************** *** 1624,1631 **** =head3 cp ! B<Synopsis>: C<cp E<lt>from-rdnE<gt> E<lt>to-rdnE<gt>> ! Copy an entry to a new dn. Only 1:1 within same level in the LDAP ! tree. From and to must be RDNs. =cut --- 1624,1646 ---- =head3 cp ! B<Synopsis>: C<cp E<lt>from-expansion|*E<gt> E<lt>toE<gt>> ! Copy an entry to a new dn or copy a set of entries to new locations in the ! LDAP tree. ! ! "from-expansion" will be expanded in the usual way ! (see L<Expansion|expansion>), with the addition that "*" corresponds to ! the filter "(objectclass=*)". ! ! If "to" is an B<RDN>, a single object will be copied to a new B<RDN> within ! the same level of the LDAP tree, and you will get an error if "from-expansion" ! expands to more than one object. ! ! If "to" is a B<DN>, all the objects from "from-expansion" will be be copied to ! the new location, using "to" as a base-dn and retaining their old B<RDN>s. ! This makes it convenient to copy many objects. ! ! B<TODO>: With "to" a B<DN>, we may want to copy entire subtrees. Currently we ! only copy objects as leaves. =cut *************** *** 1633,1653 **** sub cp($$) { my ($from, $to) = @_; my $entries = _entriesExpander undef, $from; ! if (scalar(@$entries) != 1) { print STDERR "$from does not exist or is ambiguous.\n"; return undef; } - my $entry = @$entries[0]; my ($oldrdn, $oldpath) = splitdn($entry->dn, 2); my ($old_rdn_attr, $old_rdn_attr_val) = split("=", $oldrdn, 2); ! my ($new_rdn_attr, $new_rdn_attr_val) = split("=", $to, 2); ! if ($entry->exists($old_rdn_attr)) { ! $entry->delete($old_rdn_attr) } - my $newdn = "$to,$oldpath"; $entry->dn($newdn); $entry->add($new_rdn_attr => $new_rdn_attr_val); my $result = $Globals->{LDAPCONN}{VALUE}->add($entry); --- 1648,1681 ---- 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; ! if (scalar(@$entries) != 1 && ! $localcopy) { print STDERR "$from does not exist or is ambiguous.\n"; return undef; } + foreach my $entry (@$entries) { my ($oldrdn, $oldpath) = splitdn($entry->dn, 2); + my ($newrdn) = splitdn($to, 2); my ($old_rdn_attr, $old_rdn_attr_val) = split("=", $oldrdn, 2); ! my ($new_rdn_attr, $new_rdn_attr_val) = split("=", $newrdn, 2); ! ! my $newdn; ! if ($localcopy) { ! $newdn = "$newrdn,$oldpath"; ! } else { ! $newdn = "$oldrdn,$to"; } $entry->dn($newdn); + + if ($localcopy) { + if ($entry->exists($old_rdn_attr)) { + $entry->delete($old_rdn_attr) + } $entry->add($new_rdn_attr => $new_rdn_attr_val); + } my $result = $Globals->{LDAPCONN}{VALUE}->add($entry); *************** *** 1658,1661 **** --- 1686,1690 ---- } $Globals->{ENTRIES}{VALUE} = []; + } } |