]> git.sur5r.net Git - openldap/blob - servers/slapd/back-perl/init.c
Per ITS#419, don't require SLAPD_RLOOKUPS when HAVE_TCPD
[openldap] / servers / slapd / back-perl / init.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  /* init.c - initialize shell backend */
13         
14 #include <stdio.h>
15 /* #include <ac/types.h>
16         #include <ac/socket.h>
17 */
18
19
20
21 #include <EXTERN.h>
22 #include <perl.h>
23
24 #include "slap.h"
25 #include "perl_back.h"
26
27
28 LDAP_F( void )
29 perl_back_xs_init LDAP_P((void));
30 LDAP_F( void )
31 boot_DynaLoader LDAP_P((CV* cv));
32
33 PerlInterpreter *perl_interpreter = NULL;
34 ldap_pvt_thread_mutex_t perl_interpreter_mutex;
35
36 #ifdef SLAPD_PERL_DYNAMIC
37
38 int back_perl_LTX_init_module(int argc, char *argv[]) {
39     BackendInfo bi;
40
41     memset( &bi, 0, sizeof(bi) );
42     bi.bi_type = "perl";
43     bi.bi_init = perl_back_initialize;
44
45     backend_add(&bi);
46     return 0;
47 }
48
49 #endif /* SLAPD_PERL_DYNAMIC */
50
51
52 /**********************************************************
53  *
54  * Init
55  *
56  **********************************************************/
57
58 int
59 perl_back_initialize(
60         BackendInfo     *bi
61 )
62 {
63         char *embedding[] = { "", "-e", "0" };
64
65         Debug( LDAP_DEBUG_TRACE, "perl backend open\n", 0, 0, 0 );
66
67         if( perl_interpreter != NULL ) {
68                 Debug( LDAP_DEBUG_ANY, "perl backend open: already opened\n",
69                         0, 0, 0 );
70                 return 1;
71         }
72         
73         perl_interpreter = perl_alloc();
74         perl_construct(perl_interpreter);
75         perl_parse(perl_interpreter, perl_back_xs_init, 3, embedding, (char **)NULL);
76         perl_run(perl_interpreter);
77
78         bi->bi_open = perl_back_open;
79         bi->bi_config = 0;
80         bi->bi_close = perl_back_close;
81         bi->bi_destroy = perl_back_destroy;
82
83         bi->bi_db_init = perl_back_db_init;
84         bi->bi_db_config = perl_back_db_config;
85         bi->bi_db_open = 0;
86         bi->bi_db_close = 0;
87         bi->bi_db_destroy = perl_back_db_destroy;
88
89         bi->bi_op_bind = perl_back_bind;
90         bi->bi_op_unbind = perl_back_unbind;
91         bi->bi_op_search = perl_back_search;
92         bi->bi_op_compare = perl_back_compare;
93         bi->bi_op_modify = perl_back_modify;
94         bi->bi_op_modrdn = perl_back_modrdn;
95         bi->bi_op_add = perl_back_add;
96         bi->bi_op_delete = perl_back_delete;
97         bi->bi_op_abandon = 0;
98
99         bi->bi_extended = 0;
100
101         bi->bi_acl_group = 0;
102
103 #ifdef HAVE_CYRUS_SASL
104         bi->bi_sasl_authorize = 0;
105         bi->bi_sasl_getsecret = 0;
106         bi->bi_sasl_putsecret = 0;
107 #endif /* HAVE_CYRUS_SASL */
108
109         bi->bi_connection_init = 0;
110         bi->bi_connection_destroy = 0;
111
112         return 0;
113 }
114                 
115 int
116 perl_back_open(
117         BackendInfo     *bi
118 )
119 {
120         ldap_pvt_thread_mutex_init( &perl_interpreter_mutex );
121         return 0;
122 }
123
124 int
125 perl_back_db_init(
126         Backend *be
127 )
128 {
129         be->be_private = (PerlBackend *) ch_malloc( sizeof(PerlBackend) );
130         memset( be->be_private, 0, sizeof(PerlBackend));
131
132         Debug( LDAP_DEBUG_TRACE, "perl backend db init\n", 0, 0, 0 );
133
134         return 0;
135 }
136
137
138 static void
139 perl_back_xs_init()
140 {
141     char *file = __FILE__;
142     dXSUB_SYS;
143         newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
144 }