Thread: [LDAPsh-cvs] ldapsh ldapsh,1.9,1.10
Status: Beta
Brought to you by:
rcorvalan
From: <rco...@us...> - 2002-09-13 11:54:00
|
Update of /cvsroot/ldapsh/ldapsh In directory usw-pr-cvs1:/tmp/cvs-serv5496 Modified Files: ldapsh Log Message: 1) Now loads to_utf8() and from_utf8() functions from Unicode::MapUFT8 when start, so these functions can be used by the user 2) Added a few words in some in-line documentation (such as what is returned by a function) 3) The ldif() and vi() functions now return $entries instead of 1. 4) Now vi() uses the $EDITOR variable instead of using "vi". By default this variable is set to "vi" 5) Now, the redir() function returns a handler to the old file descriptor 6) Added a cp() function. Many thanks to Peder O. Klingenberg 7) Now simple pipes and file redirections can be done without having to use redir(). Example: ls | grep external Example: ls > entries.list Warning: The parsing is very very simple, to avoig going into troubles and have to recognize if a pipe is or not inside a filter, for example. Only | and > are implemented, and Cafter them you can put only spaces, alphanumeric, ".", "_" or "-" Index: ldapsh =================================================================== RCS file: /cvsroot/ldapsh/ldapsh/ldapsh,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ldapsh 31 Jul 2002 09:54:33 -0000 1.9 --- ldapsh 13 Sep 2002 11:53:54 -0000 1.10 *************** *** 136,139 **** --- 136,140 ---- use Term::ReadLine; use Data::Dumper qw(Dumper); + use Unicode::MapUTF8 qw(to_utf8 from_utf8); use subs qw(connect bind dump exit reset); *************** *** 1180,1183 **** --- 1181,1186 ---- The result entries go to the L<$ENTRIES|"$ENTRIES"> array reference. + Returns a reference to an array containing the Net::LDAP::Entry objects found. + =cut *************** *** 1213,1218 **** B<Synopsis>: C<search E<lt>expansionE<gt>> ! Search the entries returned by the expansion (see L<Expansion|expansion>). Does not dump the entries themselves, only a summary ! of the search results. =cut --- 1216,1223 ---- B<Synopsis>: C<search E<lt>expansionE<gt>> ! Search the entries returned by the expansion (see L<Expansion|expansion>). ! Does not dump the entries themselves, only a summary of the search results. ! ! Returns a reference to an array containing the Net::LDAP::Entry objects found. =cut *************** *** 1240,1243 **** --- 1245,1250 ---- Print the entries returned by the expansion (see L<Expansion|expansion>) in an LDIF format. + Returns a reference to an array containing the Net::LDAP::Entry objects found. + =cut *************** *** 1248,1252 **** require Net::LDAP::LDIF; Net::LDAP::LDIF->new(\*STDOUT,"w")->write(@$entries); ! return 1; } --- 1255,1259 ---- require Net::LDAP::LDIF; Net::LDAP::LDIF->new(\*STDOUT,"w")->write(@$entries); ! return $entries; } *************** *** 1281,1287 **** my (undef, $tempfile) = File::Temp::tempfile('LDAPShell_vi_XXXXXXXXXX', SUFFIX => '.ldif'); Net::LDAP::LDIF->new($tempfile,"w")->write(@$entries); ! system("vi $tempfile"); ! unlink "$tempfile"; ! return 1; } --- 1288,1294 ---- my (undef, $tempfile) = File::Temp::tempfile('LDAPShell_vi_XXXXXXXXXX', SUFFIX => '.ldif'); Net::LDAP::LDIF->new($tempfile,"w")->write(@$entries); ! system($Globals->{EDITOR}{VALUE}, $tempfile); ! unlink $tempfile; ! return $entries; } *************** *** 1443,1448 **** --- 1450,1457 ---- sub redir { my $out = shift || ">&STDOUTBCK"; + open(tmpSTDOUTBCK, '>&STDOUT'); open STDOUT, $out || return 0; select STDOUT; $|=1; + return(\*tmpSTDOUTBCK); } *************** *** 1574,1579 **** } - - =head3 commit --- 1583,1586 ---- *************** *** 1613,1616 **** --- 1620,1662 ---- + =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 + + 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); + if ($result->is_error) { + printf STDERR qq{LDAP Error updating entry '%s'. Code:%s. Message:%s\n}, + $entry->dn, $result->code, $result->error; + return undef; + } + $Globals->{ENTRIES}{VALUE} = []; + } + + =head2 $ENTRIES manipulation *************** *** 1901,1909 **** s/^(cd|acd|setdn|pushd|lcd|help)\s+((?:[^'"].*)?[^'"])$/$1 "$2"/; ! # The line below will quote some barewords like "-l", "-a" etc... # It's not perfect, but simple while (s/([\s,])(-\w)([\s,]|$)/$1'$2'$3/g) {}; eval() || print STDERR $@; } --- 1947,1961 ---- s/^(cd|acd|setdn|pushd|lcd|help)\s+((?:[^'"].*)?[^'"])$/$1 "$2"/; ! # The line below will quote some barewords such as "-l", "-a" etc... # It's not perfect, but simple while (s/([\s,])(-\w)([\s,]|$)/$1'$2'$3/g) {}; + my $redir; + if ($redir = s/([|>][\s\w\d_\/.-]+)//) { + redir($1); + } + eval() || print STDERR $@; + redir if ($redir); } |