[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: Shell Filter Test Utility?



Here is a config and a perl version of a sample search that actually goes to our PH service.

config file
#
# See slapd.conf(5) for details on configuration options.
# This file should NOT be world readable.
#
include   /opt/local/etc/openldap/slapd.at.conf
include   /opt/local/etc/openldap/slapd.oc.conf
schemacheck off
# referral  ldap://ldap.nwu.edu

pidfile   /opt/local/var/slapd.pid
argsfile  /opt/local/var/slapd.args

#######################################################################
# ldbm database definitions
#######################################################################

database  shell
suffix    "o=at.nwu.edu"
suffix    "edu"
search    /var/db/ldap/search.pl
bind /var/db/ldap/bind.pl



#!/opt/local/bin/perl

# Simple script which acts as a shell back-end for slapd

open(LOG, ">>/var/db/ldap/log");
print LOG "======search========\n";

# This should be an associative array...
while( <STDIN> ) {
  chop;
  if( /base: (.*)/i ) {
    $base = $1;
    print LOG "$_\n";
  } elsif( /filter: (.*)/i ) {
    $filter = $1;
    print LOG "$_\n";
  } elsif( /attrs: (.*)/i ) {
    $attrs = $1;
  } else {
    print LOG "$_\n";
  }
}

  print LOG "now filter= $filter\n";

  $pr5=0;
  if($base =~ m/at.nwu.edu/i ) {
    print LOG "o is at.nwu.edu\n";
    if($filter =~ /\(cn=\*?([\w.]*)\*? \*?([\w.]*)\*?\)/ ) {
      $pr1=$1; $pr2 = $2; $pr5 = 16; }
    elsif($filter =~ /\(cn=\*?([\w .]]*)\*?\).*?\(cn=\*?([\w. ]*)\*?\)/ ) {
      $pr1= $1; $pr2 = $2; $pr5 = 15;
    }
    elsif($filter =~ /\(cn=\*?(\w*)\*?, ?\*?([\w. ]*)\*?/ ) {
      $pr2= $1; $pr1 = $2; $pr5 = 17;
    }
    elsif($filter =~ /\(cn=\*?([\w. ]*)\*?\)/ ) {
      $pr1=$1; $pr5 = 11;
    }
    elsif($filter =~ /\(sn=\*?([\w. ]*)\*?\)/
      && ($pr1 = $1)
      && $filter =~ /\(givenname=\*?([\w. ]*)\*?\)/ ) {
      $pr2 = $1; $pr5=13; }
    elsif($filter =~ /\(sn=\*?([\w ]*)\*?\)/ ) {
      $pr1 = $1; $pr5= 12; if($filter =~ /\(givenname=\*?([\w ]*)\*?\)/i ) {
        $pr5=13; $pr2 = $1;
      }
    }
    elsif($filter =~ /\([csg]n=\*?(\w*)\*?\)\([csg]n=\*?(\w*)\*?\)\([csg]n=\*?(\
w*)\*?\)/ ) {
      $pr1 = $1; $pr2 = $2; $pr3 = $3; $pr5=5; }
    elsif($filter =~ /\([csg]n=([*\w]*)\)\([csg]n=([*\w]*)\)\([csg]n=([*\w]*)\)/
 ) {
      $pr1 = $1; $pr2 = $2; $pr3 = $3; $pr5=3; }
    elsif($filter =~ /\([csg]n=\*?(\w*)\*?\)\([csg]n=\*?(\w*)\*?\)/ ) {
      $pr1 = $1; $pr2 = $2; $pr5 = 2; }
    elsif($filter =~ /\([csg]n=\*?(\w*)\*?\)/ ) {
      $pr1 = $1; $pr5 = 1;  }
    elsif($filter =~ /(\([csg]n=([^ \)]*)\))*/) {
      $pr0=$0; $pr1=$1; $pr2=$2; $pr3=$3; $pr5 = 7;
    }
  } else {
    if($filter =~ /x(\([csg]n=\*?(\w*)\*?\))*/ ) {
      $pr0=$0; $pra=$1; $pr1=$2; $pr2=$3; $pr3=$4; $pr5 = 6;
    }
    elsif($filter =~ /\([csg]n=\*?(\w*\*?)\)\([csg]n=\*?(\w*\*?)\)\([csg]n=\*?(\
w*\*?)\)/ ) {
      $pr1 = $1; $pr2 = $2; $pr3 = $3; $pr5=33; }
    elsif($filter =~ /\([csg]n=([\*\w]*)\)\([csg]n=([\*\w]*)\)\([csg]n=([\*\w]*)
\)/ ) {
      $pr1 = $1; $pr2 = $2; $pr3 = $3; $pr5=3; }
    elsif($filter =~ /[csg]n=([\w\*]*)\)\([csg]n=([\w\*]*)\)/ ) {
      $pr1 = $1; $pr2 = $2; $pr5 = 2; }
    elsif($filter =~ /[csg]n=([\w\*]*)/ ) {
      $pr1 = $1; $pr5 = 1;  }
  }

print LOG "Using base $base, filter $filter\n";

# Do the real lookup here...
  print LOG "filter: $filter;\n";
  print LOG "filtered = $pr0, $pra, $pr1, $pr2, $pr3, $pr4, $pr5;\n";
  if($pr1) { $pr1 = $pr1 . "*"; }
  if($pr2) { $pr2 = $pr2 . "*";}
  if($pr3) { $pr3 = $pr3 . "*"; }
  print LOG "phreq=$pr1 $pr2 $pr3";
  if( $pr1 . $pr2 . $pr3 . $pr4 ) {
  print LOG "base=$base\n\n";

  open(RESULT,"/opt/local/bin/ph -m $pr1 $pr2 $pr3 $pr4  |");
  $rescnt=0;
  $inaddr=0;
  while (<RESULT>) {
    print LOG "PH res: ", $_;
    chop;
    if(/nickname: (.*)/ ) {
      print LOG "nickname: $1\n";
      print "nickname: $1\n";
    } elsif( /--------/ ) {
      print LOG "<result-----> ";
      if($rescnt) {
        print LOG "    blank line   ";
        print "\n"; }
      $rescnt++;
    } elsif(/name: ([^, ]*), ?(.*)/) {
      $name = $_;
      print LOG "dn: \"cn=$2 $1,o=at.nwu.edu\"\n";
      print "dn: \"cn=$2 $1,o=at.nwu.edu\"\n";
      print LOG "cn: $2 $1\n";
      print "cn: $2 $1\n";
      if( $attrs =~ / sn/ ) {
      print LOG "sn: $1\n";
      print "sn: $1\n";
      }
      if( $attrs =~ / givenname/ ) {
      print LOG "givenname: $2\n";
      print "givenname: $2\n";
      print LOG "name: $2 $1\n";
      print "name: $2 $1\n";
      }
    } elsif( /name: (.*)$/ ) {
      print LOG "dn: \"cn=$1, o=at.nwu.edu\"\n";
      print "dn: \"cn=$1, o=at.nwu.edu\"\n";
      print "name: $1\n";
    } elsif( /email: (.*)/i ) {
      $email = $_;
      print LOG "Email: $1\n";
      print "mail: $1\n";
    } elsif(/department: (.*)/) {
      print LOG "ou: $1\n";
      print "ou: $1\n";
      print LOG "c: us\n";
      print "c: us\n";
      print LOG "o: at.nwu.edu\n";
      print "o: at.nwu.edu\n";
    } elsif( /title: (.*)/) {
      print LOG "title: $1\n";
      print "title: $1\n";
    } elsif( /netid: (.*)/ ) {
      print LOG "uid: $1\n";
      print "uid: $1\n";
    } elsif( /office_phone: (.*)/) {
      if($inaddr) {
        print LOG "\n";
        print "\n";
      }
      $inaddr=0;
      print LOG "telephonenumber: $1\n";
      print "telephonenumber: $1\n";
    } elsif( /office_address: (.*)/) {
      $inaddr=1;
      print LOG "postalAddress: $1";
      print "postalAddress: $1";
    } elsif( /\S+:/ ) {
      if($inaddr) {
        print LOG ":endaddr:\n";
        print "\n";
      }
      $inaddr=0;
    } elsif($inaddr && /  : (.*)/) {
      print LOG 'inaddr:$'," $1";
      print '$'," $1";
    } elsif(/evanston/i) {
        print LOG "City: Evanston, IL\n";
        print "l: Evanston, IL\n";
    } elsif( /chicago/i) {
        print LOG "city: Chicago, IL\n";
        print "city: Chicago, IL\n";
    }
  }
  }

# print "dn: \"cn=John Smith, o=at.nwu.edu\"\n";
# print "cn: John Smith\n";
# print "sn: Smith\n";
print LOG "\nRESULT\n";
print "\nRESULT\n";
print LOG "code: 0\n";
print "code: 0\n";
close(LOG);
exit 0;



Albert Steiner

At 05:45 AM 6/16/00 +1000, Tim Burgess wrote:
>Gday All,
>
>Am trying to write a shell backend and it seems to me that the hardest
>obstacle to overcome is the search function.  What would be *really* nice
>is a utility that will:
>
>a) accept an ldif file (from stdin, say)
>b) test it for a match to the rfc xxxx (i can't remember :] ) filter spec
>passed on the commans line.
>c) either output something or return status depending on the result
>
>Does anyone know of such a utility or something similar?
>
>Cheers,
>
>Tim Burgess :)
> 
--------------
Albert Steiner  Coordinator Distributed Computing
Technology Support Services
N O R T H W E S T E R N   U N I V E R S I T Y
1603 Orrington Suite #1400, Evanston, IL 60201-5064
a-steiner@northwestern.edu  Phone 847-491-4056 FAX 847-467-7732