4 This is a sample Perl module for the OpenLDAP server slapd.
5 It also contains the documentation that you will need to
8 WARNING: the interfaces of this backen to the perl module
9 MAY change. Any suggestions would greatly be appreciated.
14 The Perl back end works by embedding a Perl interpreter into
15 the slapd backend. Then when the configuration file indicates
16 that we are going to be using a Perl backend it will get an
17 option that tells it what module to use. It then creates a
18 new Perl object that handles all the request for that particular
19 instance of the back end.
24 You will need to create a method for each one of the
25 following actions that you wish to handle.
27 * new # Creates a new object.
28 * search # Performs the ldap search
29 * compare # does a compare
30 * modify # modify's and entry
31 * add # adds an entry to back end
32 * modrdn # modifies a an entries rdn
33 * delete # deletes an ldap entry
34 * config # process unknown config file lines
35 * init # called after backend is initialized
39 This method is called when the config file encounters a
40 B<perlmod> line. The module in that line is then effectively
41 used into the perl interpreter, then the new method is called
42 to create a new object. Note that multiple instances of that
43 object may be instantiated, as with any perl object.
45 The new method doesn't receive any arguments other than the
52 This method is called when a search request comes from a client.
53 It arguments are as follow.
58 * alias deferencing policy
62 * attributes only flag ( 1 for yes )
63 * list of attributes that are to be returned. (could be empty)
69 This method is called when a compare request comes from a client.
70 Its arguments are as follows.
74 * attribute assertion string
80 This method is called when a modify request comes from a client.
81 Its arguments are as follows.
85 * lists formatted as follows
86 { ADD | DELETE | REPLACE }, key, value
92 This method is called when a add request comes from a client.
93 Its arguments are as follows.
96 * entry in string format.
102 This method is called when a modrdn request comes from a client.
103 Its arguments are as follows.
108 * delete old dn flage ( 1 means yes )
114 This method is called when a delete request comes from a client.
115 Its arguments are as follows.
125 * arrray of arguments on line
127 RETURN: non zero value if this is not a valid option.
133 RETURN: non zero value if initialization failed.
137 The perl section of the config file recognizes the following
138 options. It should also be noted that any option not recoginized
139 will be sent to the B<config> method of the perl module as noted
142 database perl # startn section for the perl database
144 suffix "o=AnyOrg, c=US"
146 perlModulePath /path/to/libs # addes the path to @INC variable same
147 # as "use lib '/path/to/libs'"
149 perlModule ModName # use the module name ModName from ModName.pm
151 filterSearchResults # search results are candidates that need to be
152 # filtered, rather than search results to be
153 # returned directly to the client
167 print STDERR "Here in new\n";
168 print STDERR "Posix Var " . BUFSIZ . " and " . FILENAME_MAX . "\n";
175 my($base, $scope, $deref, $sizeLim, $timeLim, $filterStr, $attrOnly, @attrs ) = @_;
176 print STDERR "====$filterStr====\n";
177 $filterStr =~ s/\(|\)//g;
178 $filterStr =~ s/=/: /;
181 foreach my $dn ( keys %$this ) {
182 if ( $this->{ $dn } =~ /$filterStr/im ) {
184 last if ( scalar @match_dn == $sizeLim );
189 my @match_entries = ();
191 foreach my $dn ( @match_dn ) {
192 push @match_entries, $this->{ $dn };
195 return ( 0 , @match_entries );
202 my ( $dn, $avaStr ) = @_;
203 my $rc = 5; # LDAP_COMPARE_FALSE
207 if ( $this->{ $dn } =~ /$avaStr/im ) {
208 $rc = 6; # LDAP_COMPARE_TRUE
218 my ( $dn, @list ) = @_;
220 while ( @list > 0 ) {
221 my $action = shift @list;
222 my $key = shift @list;
223 my $value = shift @list;
225 if( $action eq "ADD" ) {
226 $this->{ $dn } .= "$key: $value\n";
229 elsif( $action eq "DELETE" ) {
230 $this->{ $dn } =~ s/^$key:\s*$value\n//mi ;
233 elsif( $action eq "REPLACE" ) {
234 $this->{ $dn } =~ s/$key: .*$/$key: $value/im ;
245 my ( $entryStr ) = @_;
247 my ( $dn ) = ( $entryStr =~ /dn:\s(.*)$/m );
250 # This needs to be here untill a normalize dn is
251 # passed to this routine.
257 $this->{$dn} = $entryStr;
266 my ( $dn, $newdn, $delFlag ) = @_;
268 $this->{ $newdn } = $this->{ $dn };
271 delete $this->{ $dn };
283 print STDERR "XXXXXX $dn XXXXXXX\n";