Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / back-perl / SampleLDAP.pm
blob832cf43c1810312fd0484fbb90b75228e882b7e7
1 # This is a sample Perl module for the OpenLDAP server slapd.
2 # $OpenLDAP: pkg/ldap/servers/slapd/back-perl/SampleLDAP.pm,v 1.10.2.3 2008/02/11 23:26:47 kurt Exp $
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2008 The OpenLDAP Foundation.
6 ## Portions Copyright 1999 John C. Quillan.
7 ## All rights reserved.
8 ##
9 ## Redistribution and use in source and binary forms, with or without
10 ## modification, are permitted only as authorized by the OpenLDAP
11 ## Public License.
13 ## A copy of this license is available in the file LICENSE in the
14 ## top-level directory of the distribution or, alternatively, at
15 ## <http://www.OpenLDAP.org/license.html>.
17 # Usage: Add something like this to slapd.conf:
19 # database perl
20 # suffix "o=AnyOrg,c=US"
21 # perlModulePath /directory/containing/this/module
22 # perlModule SampleLDAP
24 # See the slapd-perl(5) manual page for details.
26 package SampleLDAP;
27 use strict;
28 use warnings;
29 use POSIX;
31 $SampleLDAP::VERSION = '1.01';
33 sub new {
34 my $class = shift;
36 my $this = {};
37 bless $this, $class;
38 print {*STDERR} "Here in new\n";
39 print {*STDERR} 'Posix Var ' . BUFSIZ . ' and ' . FILENAME_MAX . "\n";
40 return $this;
43 sub init {
44 return 0;
47 sub search {
48 my $this = shift;
49 my ( $base, $scope, $deref, $sizeLim, $timeLim, $filterStr, $attrOnly,
50 @attrs )
51 = @_;
52 print {*STDERR}, "====$filterStr====\n";
53 $filterStr =~ s/\(|\)//gm;
54 $filterStr =~ s/=/: /m;
56 my @match_dn = ();
57 for my $dn ( keys %{$this} ) {
58 if ( $this->{$dn} =~ /$filterStr/imx ) {
59 push @match_dn, $dn;
60 last if ( scalar @match_dn == $sizeLim );
65 my @match_entries = ();
67 for my $dn (@match_dn) {
68 push @match_entries, $this->{$dn};
71 return ( 0, @match_entries );
75 sub compare {
76 my $this = shift;
77 my ( $dn, $avaStr ) = @_;
78 my $rc = 5; # LDAP_COMPARE_FALSE
80 $avaStr =~ s/=/: /m;
82 if ( $this->{$dn} =~ /$avaStr/im ) {
83 $rc = 6; # LDAP_COMPARE_TRUE
86 return $rc;
89 sub modify {
90 my $this = shift;
92 my ( $dn, @list ) = @_;
94 while ( @list > 0 ) {
95 my $action = shift @list;
96 my $key = shift @list;
97 my $value = shift @list;
99 if ( $action eq 'ADD' ) {
100 $this->{$dn} .= "$key: $value\n";
103 elsif ( $action eq 'DELETE' ) {
104 $this->{$dn} =~ s/^$key:\s*$value\n//im;
107 elsif ( $action eq 'REPLACE' ) {
108 $this->{$dn} =~ s/$key: .*$/$key: $value/im;
112 return 0;
115 sub add {
116 my $this = shift;
118 my ($entryStr) = @_;
120 my ($dn) = ( $entryStr =~ /dn:\s(.*)$/m );
123 # This needs to be here until a normalized dn is
124 # passed to this routine.
126 $dn = uc $dn;
127 $dn =~ s/\s*//gm;
129 $this->{$dn} = $entryStr;
131 return 0;
134 sub modrdn {
135 my $this = shift;
137 my ( $dn, $newdn, $delFlag ) = @_;
139 $this->{$newdn} = $this->{$dn};
141 if ($delFlag) {
142 delete $this->{$dn};
144 return 0;
148 sub delete {
149 my $this = shift;
151 my ($dn) = @_;
153 print {*STDERR} "XXXXXX $dn XXXXXXX\n";
154 delete $this->{$dn};
155 return 0;
158 sub config {
159 my $this = shift;
161 my (@args) = @_;
162 local $, = ' - ';
163 print {*STDERR} @args;
164 print {*STDERR} "\n";
165 return 0;