#!/usr/bin/perl use strict; use warnings; use LATMOS::Accounts; use Getopt::Long; use Pod::Usage; =head1 NAME la-search - Perform object search in Latmos::Accounts base =head1 SYNOPSIS la-search [options] filter [filter2 [...]] =head1 OPTIONS =over 4 =item --config configdir Use this configuration directory instead default =item --base basename Perform search in this specific base instead default =item --with-unexp Take into account all objects (even non propagated ones, with attribute 'exported'=0) (default) =item --wo-unexp Take into account only propagated objects (attribute 'exported'=1) =item --fmt format (Only if NO obj_id is given) Specify a format of output. The "format" string may query tags in form: %{ATTRIBUTE:printflike} Where ATTRIBUTE is the name of an attribute and the optional C<:printflike> is a printf like string to print the attribute content (without the C<%>). Examples for users: --fmt "Name %{sn}, First Name %{givenName}\n" --fmt "Name %{sn:20s}, First Name %{givenName}\n" =item FILTER Filter are in form "[ATTRIBUTE][OPERATOR][VALUE]" where attribute is a supported attribute. OPERATOR can be: =over 4 =item C<=> Search object having attribute strictely equal to VALUE. If VALUE is C<*> match any non empty value. =item C<~> Search object having attribute containing VALUE. =back =back =cut GetOptions( 'c|config=s' => \my $config, 'b|base=s' => \my $base, 'o|object=s' => \my $otype, 'fmt=s' => \my $fmt, 'no-unexp|wo-unexp' => \my $nounexp, 'with-unexp' => \my $unexp, 'help' => sub { pod2usage(0) }, ) or pod2usage(); $otype ||= 'user'; my $LA = LATMOS::Accounts->new($config, noacl => 1); my $labase = $LA->base($base); $labase && $labase->load or die "Cannot load base"; $labase->unexported($nounexp ? 0 : 1); my @result = $labase->search_objects($otype, @ARGV); foreach (@result) { if ($fmt) { my $o = $labase->get_object($otype, $_); print $o->queryformat($fmt); } else { print "$_\n"; } } STDOUT->autoflush(1); warn "\n" . scalar(@result) . " results\n"; exit(0);