]> git.sur5r.net Git - openldap/blob - servers/slapd/back-perl/search.c
Add a safety check to bvcasechr
[openldap] / servers / slapd / back-perl / search.c
1 /* $OpenLDAP$ */
2 /*
3  *       Copyright 1999, John C. Quillan, All rights reserved.
4  *
5  *       Redistribution and use in source and binary forms are permitted only
6  *       as authorized by the OpenLDAP Public License.  A copy of this
7  *       license is available at http://www.OpenLDAP.org/license.html or
8  *       in file LICENSE in the top-level directory of the distribution.
9  */
10
11 #include "portable.h"
12
13 #include <stdio.h>
14 /*      #include <ac/types.h>
15         #include <ac/socket.h>
16 */
17
18 #include <EXTERN.h>
19 #include <perl.h>
20
21 #include "slap.h"
22 #include "perl_back.h"
23
24 /**********************************************************
25  *
26  * Search
27  *
28  **********************************************************/
29 int
30 perl_back_search(
31         Backend *be,
32         Connection *conn,
33         Operation *op,
34         const char *base,
35         const char *nbase,
36         int scope,
37         int deref,
38         int sizelimit,
39         int timelimit,
40         Filter *filter,
41         const char *filterstr,
42         AttributeName *attrs,
43         int attrsonly
44         )
45 {
46         char test[500];
47         int count ;
48         int err = 0;
49         char *matched = NULL, *info = NULL;
50         PerlBackend *perl_back = (PerlBackend *)be->be_private;
51         AttributeName *an;
52         Entry   *e;
53         char *buf;
54         int i;
55         int return_code;
56
57         ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex );  
58
59         {
60                 dSP; ENTER; SAVETMPS;
61
62                 PUSHMARK(sp) ;
63                 XPUSHs( perl_back->pb_obj_ref );
64                 XPUSHs(sv_2mortal(newSVpv( filterstr , 0)));
65                 XPUSHs(sv_2mortal(newSViv( sizelimit )));
66                 XPUSHs(sv_2mortal(newSViv( timelimit )));
67                 XPUSHs(sv_2mortal(newSViv( attrsonly )));
68
69                 for ( an = attrs; an && an->an_name.bv_val; an++ ) {
70                         XPUSHs(sv_2mortal(newSVpv( an->an_name.bv_val , 0)));
71                 }
72                 PUTBACK;
73
74                 count = perl_call_method("search", G_ARRAY );
75
76                 SPAGAIN;
77
78                 if (count < 1) {
79                         croak("Big trouble in back_search\n") ;
80                 }
81
82                 if ( count > 1 ) {
83                                                          
84                         for ( i = 1; i < count; i++ ) {
85
86                                 buf = POPp;
87
88                                 if ( (e = str2entry( buf )) == NULL ) {
89                                         Debug( LDAP_DEBUG_ANY, "str2entry(%s) failed\n", buf, 0, 0 );
90
91                                 } else {
92                                         send_search_entry( be, conn, op,
93                                                 e, attrs, attrsonly, NULL );
94                                                          
95                                         entry_free( e );
96                                 }
97                         }
98                 }
99
100                 /*
101                  * We grab the return code last because the stack comes
102                  * from perl in reverse order. 
103                  *
104                  * ex perl: return ( 0, $res_1, $res_2 );
105                  *
106                  * ex stack: <$res_2> <$res_1> <0>
107                  */
108
109                 return_code = POPi;
110
111
112
113                 PUTBACK; FREETMPS; LEAVE;
114         }
115
116         ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex );        
117
118         if( return_code != 0 ) {
119                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
120                         NULL, NULL, NULL, NULL );
121
122         } else {
123                 send_ldap_result( conn, op, LDAP_SUCCESS,
124                         NULL, NULL, NULL, NULL );
125         }
126 }
127