Project

General

Profile

Download (673 Bytes) Statistics
| Branch: | Revision:
865f4ff4 Marc Dequènes (Duck)
#!/usr/bin/perl

# example parameter: /operations/add/monitorOpCompleted

use warnings;
use strict;
use File::Basename;
use IO::File;
use Data::Dumper;

my $param = $ARGV[0];
unless ($param =~ m#^(/[a-zA-Z0-9 ]+)+$#)
{
exit 1;
}

my $location = 'cn=' . join(',cn=', reverse(split(qr(/), dirname($param)))) . "monitor";
my $attr = basename($param);

my $fh = IO::File->new;
# shell escapes are not possible, $param was check earlier using regex
$fh->open('ldapsearch -Q -Y EXTERNAL -H ldapi:/// -b "' . $location . '" -s base -LLL "' . $attr . '" 2>/dev/null |');
while (my $line = $fh->getline)
{
if ($line =~ m/^$attr: (.*)$/)
{
print "$1\n";
exit 0;
}
}

exit 2;