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