3 This is a sample Perl module for the OpenLDAP server slapd.
4 It also contains the documentation that you will need to
7 WARNING: the interfaces of this backen to the perl module
8 MAY change. Any suggestions would greatly be appreciated.
13 The Perl back end works by embedding a Perl interpreter into
14 the slapd backend. Then when the configuration file indicates
15 that we are going to be using a Perl backend it will get an
16 option that tells it what module to use. It then creates a
17 new Perl object that handles all the request for that particular
18 instance of the back end.
23 You will need to create a method for each one of the
24 following actions that you wish to handle.
26 * new # Creates a new object.
27 * search # Performs the ldap search
28 * compare # does a compare
29 * modify # modify's and entry
30 * add # adds an entry to back end
31 * modrdn # modifies a an entries rdn
32 * delete # deletes an ldap entry
33 * config # process unknow config file lines
37 This method is called when the config file encounters a
38 B<perlmod> line. The module in that line is then effectively
39 used into the perl interpreter, then the new method is called
40 to create a new object. Note that multiple instances of that
41 object may be instantiated, as with any perl object.
43 The new method doesn't receive any arguments other than the
50 This method is called when a search request comes from a client.
51 It arguments are as follow.
57 * attributes only flag ( 1 for yes )
58 * list of attributes that are to be returned. (could be empty)
64 This method is called when a compare request comes from a client.
65 Its arguments are as follows.
74 This method is called when a modify request comes from a client.
75 Its arguments are as follows.
79 * lists formatted as follows
80 { ADD | DELETE | REPLACE }, key, value
86 This method is called when a add request comes from a client.
87 Its arguments are as follows.
90 * entry in string format.
96 This method is called when a modrdn request comes from a client.
97 Its arguments are as follows.
102 * delete old dn flage ( 1 means yes )
108 This method is called when a delete request comes from a client.
109 Its arguments are as follows.
119 * arrray of arguments on line
121 RETURN: non zero value if this is not a valid option.
125 The perl section of the config file recognizes the following
126 options. It should also be noted that any option not recoginized
127 will be sent to the B<config> method of the perl module as noted
130 database perl # startn section for the perl database
132 suffix "o=AnyOrg, c=US"
134 perlModulePath /path/to/libs # addes the path to @INC variable same
135 # as "use lib '/path/to/libs'"
137 perlModule ModName # use the module name ModName from ModName.pm
158 my( $filterStr, $sizeLim, $timeLim, $attrOnly, @attrs ) = @_;
160 $filterStr =~ s/\(|\)//g;
161 $filterStr =~ s/=/: /;
164 foreach my $dn ( keys %$this ) {
165 if ( $this->{ $dn } =~ /$filterStr/im ) {
167 last if ( scalar @match_dn == $sizeLim );
172 my @match_entries = ();
174 foreach my $dn ( @match_dn ) {
175 push @match_entries, $this->{ $dn };
178 return ( 0 , @match_entries );
194 my ( $dn, @list ) = @_;
196 while ( @list > 0 ) {
197 my $action = shift @list;
198 my $key = shift @list;
199 my $value = shift @list;
201 if( $action eq "ADD" ) {
202 $this->{ $dn } .= "$key: $value\n";
205 elsif( $action eq "DELETE" ) {
206 $this->{ $dn } =~ s/^$key:\s*$value\n//mi ;
209 elsif( $action eq "REPLACE" ) {
210 $this->{ $dn } =~ s/$key: .*$/$key: $value/im ;
221 my ( $entryStr ) = @_;
223 my ( $dn ) = ( $entryStr =~ /dn:\s(.*)$/m );
226 # This needs to be here untill a normalize dn is
227 # passed to this routine.
233 $this->{$dn} = $entryStr;
242 my ( $dn, $newdn, $delFlag ) = @_;
244 $this->{ $newdn } = $this->{ $dn };
247 delete $this->{ $dn };