X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-perl%2FSampleLDAP.pm;h=9a8cf8ced6ff2cfd9629f46cfe4d8ab0590d661e;hb=76b7a8302611b0a62e32b4b35f8f1988f986f9e5;hp=c6a8f9ea5dd0fcbcf571c01ce299e2421ff00bb3;hpb=d019bff7b89d1710f55e608be75d5a1b754cd257;p=openldap
diff --git a/servers/slapd/back-perl/SampleLDAP.pm b/servers/slapd/back-perl/SampleLDAP.pm
index c6a8f9ea5d..9a8cf8ced6 100644
--- a/servers/slapd/back-perl/SampleLDAP.pm
+++ b/servers/slapd/back-perl/SampleLDAP.pm
@@ -1,158 +1,171 @@
# This is a sample Perl module for the OpenLDAP server slapd.
-#
# $OpenLDAP$
-#
-# Usage: Add something this to slapd.conf:
+## This work is part of OpenLDAP Software .
+##
+## Copyright 1998-2011 The OpenLDAP Foundation.
+## 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
+## .
+
+# Usage: Add something like this to slapd.conf:
#
# database perl
-# suffix "o=AnyOrg, c=US"
-# perlModulePath /path/to/this/file
+# suffix "o=AnyOrg,c=US"
+# perlModulePath /directory/containing/this/module
# perlModule SampleLDAP
+#
+# See the slapd-perl(5) manual page for details.
+#
+# This demo module keeps an in-memory hash {"DN" => "LDIF entry", ...}
+# built in sub add{} & co. The data is lost when slapd shuts down.
package SampleLDAP;
-
+use strict;
+use warnings;
use POSIX;
-sub new
-{
- my $class = shift;
+$SampleLDAP::VERSION = '1.01';
- my $this = {};
- bless $this, $class;
- print STDERR "Here in new\n";
- print STDERR "Posix Var " . BUFSIZ . " and " . FILENAME_MAX . "\n";
- return $this;
+sub new {
+ my $class = shift;
+
+ my $this = {};
+ bless $this, $class;
+ print {*STDERR} "Here in new\n";
+ print {*STDERR} 'Posix Var ' . BUFSIZ . ' and ' . FILENAME_MAX . "\n";
+ return $this;
}
-sub init
-{
- return 0;
+sub init {
+ return 0;
}
-sub search
-{
- my $this = shift;
- my($base, $scope, $deref, $sizeLim, $timeLim, $filterStr, $attrOnly, @attrs ) = @_;
- print STDERR "====$filterStr====\n";
- $filterStr =~ s/\(|\)//g;
- $filterStr =~ s/=/: /;
+sub search {
+ my $this = shift;
+ my ( $base, $scope, $deref, $sizeLim, $timeLim, $filterStr, $attrOnly,
+ @attrs )
+ = @_;
+ print {*STDERR} "====$filterStr====\n";
+ $filterStr =~ s/\(|\)//gm;
+ $filterStr =~ s/=/: /m;
+
+ my @match_dn = ();
+ for my $dn ( keys %{$this} ) {
+ if ( $this->{$dn} =~ /$filterStr/imx ) {
+ push @match_dn, $dn;
+ last if ( scalar @match_dn == $sizeLim );
- 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 = ();
- my @match_entries = ();
-
- foreach my $dn ( @match_dn ) {
- push @match_entries, $this->{ $dn };
- }
+ for my $dn (@match_dn) {
+ push @match_entries, $this->{$dn};
+ }
- return ( 0 , @match_entries );
+ return ( 0, @match_entries );
}
-sub compare
-{
- my $this = shift;
- my ( $dn, $avaStr ) = @_;
- my $rc = 5; # LDAP_COMPARE_FALSE
+sub compare {
+ my $this = shift;
+ my ( $dn, $avaStr ) = @_;
+ my $rc = 5; # LDAP_COMPARE_FALSE
- $avaStr =~ s/=/: /;
+ $avaStr =~ s/=/: /m;
- if ( $this->{ $dn } =~ /$avaStr/im ) {
- $rc = 6; # LDAP_COMPARE_TRUE
- }
+ if ( $this->{$dn} =~ /$avaStr/im ) {
+ $rc = 6; # LDAP_COMPARE_TRUE
+ }
- return $rc;
+ return $rc;
}
-sub modify
-{
- my $this = shift;
+sub modify {
+ my $this = shift;
- my ( $dn, @list ) = @_;
+ my ( $dn, @list ) = @_;
- while ( @list > 0 ) {
- my $action = shift @list;
- my $key = shift @list;
- my $value = shift @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";
+ if ( $action eq 'ADD' ) {
+ $this->{$dn} .= "$key: $value\n";
- }
- elsif( $action eq "DELETE" ) {
- $this->{ $dn } =~ s/^$key:\s*$value\n//mi ;
+ }
+ elsif ( $action eq 'DELETE' ) {
+ $this->{$dn} =~ s/^$key:\s*$value\n//im;
- }
- elsif( $action eq "REPLACE" ) {
- $this->{ $dn } =~ s/$key: .*$/$key: $value/im ;
- }
- }
+ }
+ elsif ( $action eq 'REPLACE' ) {
+ $this->{$dn} =~ s/$key: .*$/$key: $value/im;
+ }
+ }
- return 0;
+ return 0;
}
-sub add
-{
- my $this = shift;
+sub add {
+ my $this = shift;
- my ( $entryStr ) = @_;
+ my ($entryStr) = @_;
- my ( $dn ) = ( $entryStr =~ /dn:\s(.*)$/m );
+ my ($dn) = ( $entryStr =~ /dn:\s(.*)$/m );
- #
- # This needs to be here until a normalized dn is
- # passed to this routine.
- #
- $dn = uc( $dn );
- $dn =~ s/\s*//g;
+ #
+ # This needs to be here until a normalized dn is
+ # passed to this routine.
+ #
+ $dn = uc $dn;
+ $dn =~ s/\s*//gm;
+ $this->{$dn} = $entryStr;
- $this->{$dn} = $entryStr;
-
- return 0;
+ return 0;
}
-sub modrdn
-{
- my $this = shift;
+sub modrdn {
+ my $this = shift;
- my ( $dn, $newdn, $delFlag ) = @_;
+ my ( $dn, $newdn, $delFlag ) = @_;
- $this->{ $newdn } = $this->{ $dn };
+ $this->{$newdn} = $this->{$dn};
- if( $delFlag ) {
- delete $this->{ $dn };
- }
- return 0;
+ if ($delFlag) {
+ delete $this->{$dn};
+ }
+ return 0;
}
-sub delete
-{
- my $this = shift;
+sub delete {
+ my $this = shift;
+
+ my ($dn) = @_;
- my ( $dn ) = @_;
-
- print STDERR "XXXXXX $dn XXXXXXX\n";
- delete $this->{$dn};
+ print {*STDERR} "XXXXXX $dn XXXXXXX\n";
+ delete $this->{$dn};
+ return 0;
}
-sub config
-{
- my $this = shift;
+sub config {
+ my $this = shift;
- my ( @args ) = @_;
- local $, = " - ";
- print STDERR @args;
- print STDERR "\n";
- return 0;
+ my (@args) = @_;
+ local $, = ' - ';
+ print {*STDERR} @args;
+ print {*STDERR} "\n";
+ return 0;
}
1;