[LDAPsh-cvs] ldapsh ldapsh,1.57,1.58
Status: Beta
Brought to you by:
rcorvalan
From: <rco...@us...> - 2007-03-13 23:30:52
|
Update of /cvsroot/ldapsh/ldapsh In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv31753 Modified Files: ldapsh Log Message: Added Pages Results ("pagesize" command) Added "diff" command to compare 2 entries Added "-noheader" option to csv command Index: ldapsh =================================================================== RCS file: /cvsroot/ldapsh/ldapsh/ldapsh,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** ldapsh 3 Jun 2004 15:34:20 -0000 1.57 --- ldapsh 13 Mar 2007 23:30:44 -0000 1.58 *************** *** 301,305 **** use Term::ReadLine; use Data::Dumper qw(Dumper); ! #use Unicode::MapUTF8 qw(to_utf8 from_utf8); use subs qw(bind connect delete dump exit mkdir rename reset); --- 301,305 ---- use Term::ReadLine; use Data::Dumper qw(Dumper); ! use subs qw(bind connect delete dump exit mkdir rename reset); *************** *** 308,311 **** --- 308,312 ---- BEGIN { require Net::LDAP; + require Net::LDAP::Control::Paged; require Cwd; require Devel::Symdump; *************** *** 346,350 **** SSL => 0, BINDDN => '', ! LDAPVERSION => '3' }, RIGHTS => 'RWL' --- 347,352 ---- SSL => 0, BINDDN => '', ! LDAPVERSION => '3', ! PAGESIZE => 0 }, RIGHTS => 'RWL' *************** *** 588,593 **** sub _search { my %SearchParams = @_; ! ! my $result = _searchWEC( base => $SearchParams{BaseDN}, scope => $SearchParams{Scope}, --- 590,594 ---- sub _search { my %SearchParams = @_; ! my %SearchParams2 = ( base => $SearchParams{BaseDN}, scope => $SearchParams{Scope}, *************** *** 595,609 **** attrs => $SearchParams{Attrs} ); - return unless defined($result); ! if (_isReallyLDAPError($result->code)) { ! printf STDERR (qq(Error on LDAP search. Code='%s'. Message='%s'\n), $result->code, $result->error); ! return; ! } else { ! $Globals->{ENTRIES}{VALUE} = [] unless $Globals->{_APPENDRESULTS}{VALUE}; my @entries = $result->entries(); push @{$Globals->{ENTRIES}{VALUE}}, @entries; ! return \@entries; } } --- 596,641 ---- attrs => $SearchParams{Attrs} ); ! my $page; ! if ($Globals->{CONNPARAMS}{VALUE}{PAGESIZE}) { ! $page = Net::LDAP::Control::Paged->new( size => $Globals->{CONNPARAMS}{VALUE}{PAGESIZE} ); ! $SearchParams2{control} = [ $page ]; ! } ! ! my $isFirst = 1; ! my $isError = 0; ! my $cookie; ! while(1) { ! my $result = $isFirst ? _searchWEC(%SearchParams2) : $Globals->{LDAPCONN}{VALUE}->search(%SearchParams2); ! ! return unless defined($result); ! ! if (_isReallyLDAPError($result->code)) { ! printf STDERR (qq(Error on LDAP search. Code='%s'. Message='%s'\n), $result->code, $result->error); ! return; ! } ! ! if ($isFirst) { ! $Globals->{ENTRIES}{VALUE} = [] unless $Globals->{_APPENDRESULTS}{VALUE}; ! } my @entries = $result->entries(); push @{$Globals->{ENTRIES}{VALUE}}, @entries; ! ! $isFirst = 0; ! if ($Globals->{CONNPARAMS}{VALUE}{PAGESIZE}) { ! my ($result2) = $result->control(Net::LDAP::Constant::LDAP_CONTROL_PAGED()); ! unless ($result2) { ! $isError = 1; ! last; ! } ! last unless ($cookie = $result2->cookie); ! $page->cookie($cookie); ! } else { ! last; ! } } + + return undef if $isError; + return $Globals->{ENTRIES}{VALUE}; } *************** *** 1120,1125 **** $parser = new Pod::Text::Termcap; } if (defined($cmd) && $cmd eq "all") { ! $parser->parse_from_file($0, $Output->{FILEHANDLE}); } else { --- 1152,1159 ---- $parser = new Pod::Text::Termcap; } + $parser->output_fh($Output->{FILEHANDLE}); if (defined($cmd) && $cmd eq "all") { ! #$parser->parse_from_file($0, $Output->{FILEHANDLE}); ! $parser->parse_from_file($0); } else { *************** *** 1150,1154 **** if (-s $podfile) { print {$Output->{FILEHANDLE}} "\n------------------------------\n"; ! $parser->parse_from_file($podfile, $Output->{FILEHANDLE}); print {$Output->{FILEHANDLE}} "\n------------------------------\n"; $found = 1; --- 1184,1189 ---- if (-s $podfile) { print {$Output->{FILEHANDLE}} "\n------------------------------\n"; ! #$parser->parse_from_file($podfile, $Output->{FILEHANDLE}); ! $parser->parse_from_file($podfile); print {$Output->{FILEHANDLE}} "\n------------------------------\n"; $found = 1; *************** *** 1453,1470 **** =head3 diff ! TODO =cut sub diff($$) { ! my ($e1, $e2) = (shift, shift); my %attrs = (); ! map {$attrs{$_}=1} $e1->attributes; ! map {$attrs{$_}=1} $e2->attributes; my %diffs = (); ! foreach my $attr (keys(%attrs)) { ! my $values1 = $e1->get_value($attr, asref => 1); ! my $values2 = $e2->get_value($attr, asref => 1); } } --- 1488,1577 ---- =head3 diff ! B<Synopsis>: C<diff E<lt>entry1E<gt>, E<lt>entry1E<gt>> ! ! B<Synopsis>: C<diff E<lt>rdn1E<gt>, E<lt>rdn2E<gt>> ! ! Compare two objects and print on STDERR the differences: ! ! =over 8 ! ! =item * Attributes that are only on one side ! ! =item * Attribute values differences ! ! =back ! ! The arguments can either be ! ! =over 8 ! ! =item * Net::LDAP::Entry objects ! ! =item * RDN (relative distinguished names) that will be searched ! ! =back =cut sub diff($$) { ! my ($rdn1, $rdn2) = (shift, shift); ! my ($e1, $e2); ! if (ref($rdn1)) { ! $e1 = [$rdn1]; ! } else { ! $e1 = _entriesExpander(undef, $rdn1); ! return 0 unless defined($e1); ! unless (scalar(@$e1) == 1) { ! printf STDERR qq{The first argument ("%s") expanded to %d results\n}, $rdn1, scalar(@$e1); ! return 0; ! } ! } ! if (ref($rdn2)) { ! $e2 = [$rdn2]; ! } else { ! $e2 = _entriesExpander(undef, $rdn2); ! return 0 unless defined($e2); ! unless (scalar(@$e2) == 1) { ! printf STDERR qq{The second argument ("%s") expanded to %d results\n}, $rdn2, scalar(@$e2); ! return 0; ! } ! } ! my %attrs = (); ! map {$attrs{$_}=1} $e1->[0]->attributes; ! map {$attrs{$_}=1} $e2->[0]->attributes; my %diffs = (); ! my $nbNewlines = 1; ! foreach my $attr (sort keys(%attrs)) { ! my (%left, %right, %all, %onlyInLeft, %onlyInRight); ! foreach my $value (@{$e1->[0]->get_value($attr, asref => 1) || []}) { ! $left{$value} = 1; ! } ! foreach my $value (@{$e2->[0]->get_value($attr, asref => 1) || []}) { ! $right{$value} = 1; ! $onlyInRight{$value} = 1 unless exists $left{$value}; ! } ! foreach my $value (keys %left) { ! $onlyInLeft{$value} = 1 unless exists $right{$value}; ! } ! ! if (scalar(keys(%onlyInLeft)) > 0 or scalar(keys(%onlyInRight)) > 0) { ! printf {$Output->{FILEHANDLE}} "\n" x $nbNewlines; ! printf {$Output->{FILEHANDLE}} "[%s]\n", $attr; ! foreach my $value (sort keys(%onlyInLeft)) { ! printf {$Output->{FILEHANDLE}} " < %s\n", $value; ! } ! if (scalar(keys(%onlyInLeft)) > 0 and scalar(keys(%onlyInRight)) > 0) { ! print {$Output->{FILEHANDLE}} " -----------\n"; ! } ! foreach my $value (sort keys(%onlyInRight)) { ! printf {$Output->{FILEHANDLE}} " > %s\n", $value; ! } ! ! $nbNewlines = 2; ! } } + + return 0; } *************** *** 1940,1943 **** --- 2047,2052 ---- =item * C<-dn>: Output the DN of the entries. + =item * C<-noheader>: Don't print the file header. + =back *************** *** 1945,1950 **** sub csv { ! my $localArgs = {fs => ';', vs => '|', 'mv' => 1, 'dn' => 0}; ! my $entries = _entriesExpander [$localArgs, 'fs=s', 'vs=s', 'mv!', 'dn!'], @_; return 0 unless defined $entries; --- 2054,2059 ---- sub csv { ! my $localArgs = {fs => ';', vs => '|', 'mv' => 1, 'dn' => 0, 'header' => 1}; ! my $entries = _entriesExpander [$localArgs, 'fs=s', 'vs=s', 'mv!', 'dn!', 'header!'], @_; return 0 unless defined $entries; *************** *** 1958,1962 **** unshift @fields, 'DN' if $localArgs->{'dn'}; ! print {$Output->{FILEHANDLE}} join($localArgs->{'fs'}, @fields) . "\n"; foreach my $entry (@$entries) { print {$Output->{FILEHANDLE}} join( --- 2067,2072 ---- unshift @fields, 'DN' if $localArgs->{'dn'}; ! print {$Output->{FILEHANDLE}} (join($localArgs->{'fs'}, @fields) . "\n") ! if($localArgs->{'header'}); foreach my $entry (@$entries) { print {$Output->{FILEHANDLE}} join( *************** *** 1965,1969 **** my @vals = $_ eq 'DN' ? ($entry->dn()) : sort($entry->get_value($_)); if ($localArgs->{'mv'}) { ! join($localArgs->{'vs'}, @vals); } else { defined($vals[0]) ? $vals[0] : ''; --- 2075,2079 ---- my @vals = $_ eq 'DN' ? ($entry->dn()) : sort($entry->get_value($_)); if ($localArgs->{'mv'}) { ! join($localArgs->{'vs'}, map {utf8::decode($_); $_;} @vals); } else { defined($vals[0]) ? $vals[0] : ''; *************** *** 2957,2960 **** --- 3067,3090 ---- + =head3 pagesize + + B<Synopsis>: C<pagesize [E<lt>pagesizeE<gt>]> + + Set the PageSize for all future requests in the active connection. Setting this value using this command is equivalent to set L<$CONNPARAMS-E<gt>{PAGESIZE}|"_connparams__pagesize_"> + + Returns the previous value. + + If no parameter is given, do nothing but returning the current value. + + =cut + + sub pagesize { + my $newValue = shift; + my $oldValue = $Globals->{CONNPARAMS}{VALUE}{PAGESIZE}; + $Globals->{CONNPARAMS}{VALUE}{PAGESIZE} = $newValue if defined($newValue); + return $oldValue; + } + + =head3 append *************** *** 3091,3094 **** --- 3221,3228 ---- The protocol version to use (3 by default). + =head2 $CONNPARAMS-E<gt>{PAGESIZE} + + The PageSize for the searches, as described by RFC-2696. 0 means do not use paged searches. + =head2 $CONNPARAMS-E<gt>{SSL} *************** *** 3236,3240 **** } - package ldapsh; --- 3370,3373 ---- |