2002-04-30 04:24:29 +08:00
|
|
|
# This is a sample Perl module for the OpenLDAP server slapd.
|
|
|
|
# $OpenLDAP$
|
2003-12-07 03:25:01 +08:00
|
|
|
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
##
|
2004-01-02 03:15:16 +08:00
|
|
|
## Copyright 1998-2004 The OpenLDAP Foundation.
|
2003-12-07 03:25:01 +08:00
|
|
|
## Portions Copyright 1999 John C. Quillan.
|
|
|
|
## All rights reserved.
|
|
|
|
##
|
|
|
|
## Redistribution and use in source and binary forms, with or without
|
|
|
|
## modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
## Public License.
|
|
|
|
##
|
|
|
|
## A copy of this license is available in the file LICENSE in the
|
|
|
|
## top-level directory of the distribution or, alternatively, at
|
|
|
|
## <http://www.OpenLDAP.org/license.html>.
|
2002-04-30 04:24:29 +08:00
|
|
|
#
|
|
|
|
# Usage: Add something this to slapd.conf:
|
|
|
|
#
|
|
|
|
# database perl
|
|
|
|
# suffix "o=AnyOrg, c=US"
|
|
|
|
# perlModulePath /path/to/this/file
|
|
|
|
# perlModule SampleLDAP
|
1999-04-04 12:16:14 +08:00
|
|
|
|
|
|
|
package SampleLDAP;
|
|
|
|
|
1999-11-11 14:14:41 +08:00
|
|
|
use POSIX;
|
|
|
|
|
1999-04-04 12:16:14 +08:00
|
|
|
sub new
|
|
|
|
{
|
|
|
|
my $class = shift;
|
|
|
|
|
|
|
|
my $this = {};
|
|
|
|
bless $this, $class;
|
1999-11-11 14:14:41 +08:00
|
|
|
print STDERR "Here in new\n";
|
|
|
|
print STDERR "Posix Var " . BUFSIZ . " and " . FILENAME_MAX . "\n";
|
1999-04-04 12:16:14 +08:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2002-04-30 04:24:29 +08:00
|
|
|
sub init
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-04-04 12:16:14 +08:00
|
|
|
sub search
|
|
|
|
{
|
|
|
|
my $this = shift;
|
2002-04-16 11:47:39 +08:00
|
|
|
my($base, $scope, $deref, $sizeLim, $timeLim, $filterStr, $attrOnly, @attrs ) = @_;
|
1999-11-11 14:14:41 +08:00
|
|
|
print STDERR "====$filterStr====\n";
|
1999-04-04 12:16:14 +08:00
|
|
|
$filterStr =~ s/\(|\)//g;
|
|
|
|
$filterStr =~ s/=/: /;
|
|
|
|
|
|
|
|
my @match_dn = ();
|
|
|
|
foreach my $dn ( keys %$this ) {
|
|
|
|
if ( $this->{ $dn } =~ /$filterStr/im ) {
|
|
|
|
push @match_dn, $dn;
|
|
|
|
last if ( scalar @match_dn == $sizeLim );
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my @match_entries = ();
|
|
|
|
|
|
|
|
foreach my $dn ( @match_dn ) {
|
|
|
|
push @match_entries, $this->{ $dn };
|
|
|
|
}
|
|
|
|
|
|
|
|
return ( 0 , @match_entries );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sub compare
|
|
|
|
{
|
|
|
|
my $this = shift;
|
2002-02-02 18:37:25 +08:00
|
|
|
my ( $dn, $avaStr ) = @_;
|
2002-04-16 11:47:39 +08:00
|
|
|
my $rc = 5; # LDAP_COMPARE_FALSE
|
1999-04-04 12:16:14 +08:00
|
|
|
|
2002-02-02 18:37:25 +08:00
|
|
|
$avaStr =~ s/=/: /;
|
|
|
|
|
|
|
|
if ( $this->{ $dn } =~ /$avaStr/im ) {
|
2002-04-16 11:47:39 +08:00
|
|
|
$rc = 6; # LDAP_COMPARE_TRUE
|
2002-02-02 18:37:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return $rc;
|
1999-04-04 12:16:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sub modify
|
|
|
|
{
|
|
|
|
my $this = shift;
|
|
|
|
|
|
|
|
my ( $dn, @list ) = @_;
|
|
|
|
|
|
|
|
while ( @list > 0 ) {
|
|
|
|
my $action = shift @list;
|
|
|
|
my $key = shift @list;
|
|
|
|
my $value = shift @list;
|
|
|
|
|
|
|
|
if( $action eq "ADD" ) {
|
|
|
|
$this->{ $dn } .= "$key: $value\n";
|
|
|
|
|
|
|
|
}
|
|
|
|
elsif( $action eq "DELETE" ) {
|
|
|
|
$this->{ $dn } =~ s/^$key:\s*$value\n//mi ;
|
|
|
|
|
|
|
|
}
|
|
|
|
elsif( $action eq "REPLACE" ) {
|
|
|
|
$this->{ $dn } =~ s/$key: .*$/$key: $value/im ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub add
|
|
|
|
{
|
|
|
|
my $this = shift;
|
|
|
|
|
|
|
|
my ( $entryStr ) = @_;
|
|
|
|
|
|
|
|
my ( $dn ) = ( $entryStr =~ /dn:\s(.*)$/m );
|
|
|
|
|
|
|
|
#
|
2002-04-30 04:24:29 +08:00
|
|
|
# This needs to be here until a normalized dn is
|
1999-04-04 12:16:14 +08:00
|
|
|
# passed to this routine.
|
|
|
|
#
|
|
|
|
$dn = uc( $dn );
|
|
|
|
$dn =~ s/\s*//g;
|
|
|
|
|
|
|
|
|
|
|
|
$this->{$dn} = $entryStr;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub modrdn
|
|
|
|
{
|
|
|
|
my $this = shift;
|
|
|
|
|
|
|
|
my ( $dn, $newdn, $delFlag ) = @_;
|
|
|
|
|
|
|
|
$this->{ $newdn } = $this->{ $dn };
|
|
|
|
|
|
|
|
if( $delFlag ) {
|
|
|
|
delete $this->{ $dn };
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sub delete
|
|
|
|
{
|
|
|
|
my $this = shift;
|
|
|
|
|
|
|
|
my ( $dn ) = @_;
|
|
|
|
|
1999-11-11 14:14:41 +08:00
|
|
|
print STDERR "XXXXXX $dn XXXXXXX\n";
|
1999-04-04 12:16:14 +08:00
|
|
|
delete $this->{$dn};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub config
|
|
|
|
{
|
|
|
|
my $this = shift;
|
|
|
|
|
|
|
|
my ( @args ) = @_;
|
1999-11-11 14:14:41 +08:00
|
|
|
local $, = " - ";
|
|
|
|
print STDERR @args;
|
|
|
|
print STDERR "\n";
|
|
|
|
return 0;
|
1999-04-04 12:16:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|