]> git.sur5r.net Git - openldap/blob - servers/slapd/back-perl/SampleLDAP.pm
Removed unnecessary definition that is already in core.schema.
[openldap] / servers / slapd / back-perl / SampleLDAP.pm
1 =head1 Introduction
2
3 This is a sample Perl module for the OpenLDAP server slapd.
4 It also contains the documentation that you will need to
5 get up and going.
6
7 WARNING: the interfaces of this backen to the perl module
8 MAY change.  Any suggestions would greatly be appreciated.
9
10
11 =head1 Overview
12
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.
19
20
21 =head1 Interface
22
23 You will need to create a method for each one of the
24 following actions that you wish to handle.
25
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
34
35 =head2 new
36
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.
42
43 The new method doesn't receive any arguments other than the
44 class name.
45
46 RETURN: 
47
48 =head2 search
49
50 This method is called when a search request comes from a client.
51 It arguments are as follow.
52
53   * obj reference
54   * filter string
55   * size limit
56   * time limit
57   * attributes only flag ( 1 for yes )
58   * list of attributes that are to be returned. (could be empty)
59
60 RETURN:
61
62 =head2 compare
63
64 This method is called when a compare request comes from a client.
65 Its arguments are as follows.
66
67   * obj reference
68   * dn
69
70 RETURN:
71
72 =head2 modify
73
74 This method is called when a modify request comes from a client.
75 Its arguments are as follows.
76
77   * obj reference
78   * dn
79   * lists formatted as follows
80    { ADD | DELETE | REPLACE }, key, value
81
82 RETURN:
83
84 =head2 add
85
86 This method is called when a add request comes from a client.
87 Its arguments are as follows.
88
89   * obj reference
90   * entry in string format.
91
92 RETURN:
93
94 =head2 modrdn
95
96 This method is called when a modrdn request comes from a client.
97 Its arguments are as follows.
98
99   * obj reference
100   * dn
101   * new rdn
102   * delete old dn flage ( 1 means yes )
103
104 RETURN:
105
106 =head2 delete
107
108 This method is called when a delete request comes from a client.
109 Its arguments are as follows.
110
111   * obj reference
112   * dn
113
114 RETURN:
115
116 =head2 config
117
118   * obj reference
119   * arrray of arguments on line
120
121 RETURN: non zero value if this is not a valid option.
122
123 =head1 Configuration
124
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
128 above.
129
130   database perl         # startn section for the perl database
131
132   suffix          "o=AnyOrg, c=US"
133
134   perlModulePath /path/to/libs  # addes the path to @INC variable same
135                              # as "use lib '/path/to/libs'"
136
137   perlModule ModName       # use the module name ModName from ModName.pm
138
139
140
141 =cut
142
143 package SampleLDAP;
144
145 sub new
146 {
147         my $class = shift;
148
149         my $this = {};
150         bless $this, $class;
151
152         return $this;
153 }
154
155 sub search
156 {
157         my $this = shift;
158         my( $filterStr, $sizeLim, $timeLim, $attrOnly, @attrs ) = @_;
159
160         $filterStr =~ s/\(|\)//g;
161         $filterStr =~ s/=/: /;
162
163         my @match_dn = ();
164         foreach my $dn ( keys %$this ) {
165                 if ( $this->{ $dn } =~ /$filterStr/im ) {
166                         push @match_dn, $dn;
167                         last if ( scalar @match_dn == $sizeLim );
168
169                 }
170         }
171
172         my @match_entries = ();
173         
174         foreach my $dn ( @match_dn )  {
175                 push @match_entries, $this->{ $dn };
176         }
177
178         return ( 0 , @match_entries );
179
180 }
181
182 sub compare
183 {
184         my $this = shift;
185         my ( $dn ) = @_;
186
187         return 1;
188 }
189
190 sub modify
191 {
192         my $this = shift;
193
194         my ( $dn, @list ) = @_;
195
196         while ( @list > 0 ) {
197                 my $action = shift @list;
198                 my $key    = shift @list;
199                 my $value  = shift @list;
200
201                 if( $action eq "ADD" ) {
202                         $this->{ $dn } .= "$key: $value\n";
203
204                 }
205                 elsif( $action eq "DELETE" ) {
206                         $this->{ $dn } =~ s/^$key:\s*$value\n//mi ;
207
208                 }
209                 elsif( $action eq "REPLACE" ) {
210                         $this->{ $dn } =~ s/$key: .*$/$key: $value/im ;
211                 }
212         }
213
214         return 0;
215 }
216
217 sub add
218 {
219         my $this = shift;
220
221         my ( $entryStr ) = @_;
222
223         my ( $dn ) = ( $entryStr =~ /dn:\s(.*)$/m );
224
225         #
226         # This needs to be here untill a normalize dn is
227         # passed to this routine.
228         #
229         $dn = uc( $dn );
230         $dn =~ s/\s*//g;
231
232
233         $this->{$dn} = $entryStr;
234
235         return 0;
236 }
237
238 sub modrdn
239 {
240         my $this = shift;
241
242         my ( $dn, $newdn, $delFlag ) = @_;
243
244         $this->{ $newdn } = $this->{ $dn };
245
246         if( $delFlag ) {
247                 delete $this->{ $dn };
248         }
249         return 0;
250
251 }
252
253 sub delete
254 {
255         my $this = shift;
256
257         my ( $dn ) = @_;
258         
259         delete $this->{$dn};
260 }
261
262 sub config
263 {
264         my $this = shift;
265
266         my ( @args ) = @_;
267                         
268         return 1;
269 }
270
271 1;
272
273