| 1 |
/* $OpenLDAP$ */ |
| 2 |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
| 3 |
* |
| 4 |
* Copyright 1999-2024 The OpenLDAP Foundation. |
| 5 |
* Portions Copyright 1999 John C. Quillan. |
| 6 |
* Portions Copyright 2002 myinternet Limited. |
| 7 |
* All rights reserved. |
| 8 |
* |
| 9 |
* Redistribution and use in source and binary forms, with or without |
| 10 |
* modification, are permitted only as authorized by the OpenLDAP |
| 11 |
* Public License. |
| 12 |
* |
| 13 |
* A copy of this license is available in file LICENSE in the |
| 14 |
* top-level directory of the distribution or, alternatively, at |
| 15 |
* <http://www.OpenLDAP.org/license.html>. |
| 16 |
*/ |
| 17 |
|
| 18 |
#include "perl_back.h" |
| 19 |
#include "../slap-config.h" |
| 20 |
|
| 21 |
#ifdef PERL_SYS_INIT3 |
| 22 |
#include <ac/unistd.h> /* maybe get environ */ |
| 23 |
extern char **environ; |
| 24 |
#endif |
| 25 |
|
| 26 |
static void perl_back_xs_init LDAP_P((PERL_BACK_XS_INIT_PARAMS)); |
| 27 |
EXT void boot_DynaLoader LDAP_P((PERL_BACK_BOOT_DYNALOADER_PARAMS)); |
| 28 |
|
| 29 |
PerlInterpreter *PERL_INTERPRETER = NULL; |
| 30 |
ldap_pvt_thread_mutex_t perl_interpreter_mutex; |
| 31 |
|
| 32 |
|
| 33 |
/********************************************************** |
| 34 |
* |
| 35 |
* Init |
| 36 |
* |
| 37 |
**********************************************************/ |
| 38 |
|
| 39 |
int |
| 40 |
perl_back_initialize( |
| 41 |
BackendInfo *bi |
| 42 |
) |
| 43 |
{ |
| 44 |
char *embedding[] = { "", "-e", "0", NULL }, **argv = embedding; |
| 45 |
int argc = 3; |
| 46 |
#ifdef PERL_SYS_INIT3 |
| 47 |
char **env = environ; |
| 48 |
#else |
| 49 |
char **env = NULL; |
| 50 |
#endif |
| 51 |
|
| 52 |
bi->bi_open = NULL; |
| 53 |
bi->bi_config = 0; |
| 54 |
bi->bi_close = perl_back_close; |
| 55 |
bi->bi_destroy = 0; |
| 56 |
|
| 57 |
bi->bi_db_init = perl_back_db_init; |
| 58 |
bi->bi_db_config = perl_back_db_config; |
| 59 |
bi->bi_db_open = perl_back_db_open; |
| 60 |
bi->bi_db_close = 0; |
| 61 |
bi->bi_db_destroy = perl_back_db_destroy; |
| 62 |
|
| 63 |
bi->bi_op_bind = perl_back_bind; |
| 64 |
bi->bi_op_unbind = 0; |
| 65 |
bi->bi_op_search = perl_back_search; |
| 66 |
bi->bi_op_compare = perl_back_compare; |
| 67 |
bi->bi_op_modify = perl_back_modify; |
| 68 |
bi->bi_op_modrdn = perl_back_modrdn; |
| 69 |
bi->bi_op_add = perl_back_add; |
| 70 |
bi->bi_op_delete = perl_back_delete; |
| 71 |
bi->bi_op_abandon = 0; |
| 72 |
|
| 73 |
bi->bi_extended = 0; |
| 74 |
|
| 75 |
bi->bi_chk_referrals = 0; |
| 76 |
|
| 77 |
bi->bi_connection_init = 0; |
| 78 |
bi->bi_connection_destroy = 0; |
| 79 |
|
| 80 |
/* injecting code from perl_back_open, because using function reference (bi->bi_open) is not functional */ |
| 81 |
Debug( LDAP_DEBUG_TRACE, "perl backend open\n" ); |
| 82 |
|
| 83 |
if( PERL_INTERPRETER != NULL ) { |
| 84 |
Debug( LDAP_DEBUG_ANY, "perl backend open: already opened\n" ); |
| 85 |
return 1; |
| 86 |
} |
| 87 |
|
| 88 |
ldap_pvt_thread_mutex_init( &perl_interpreter_mutex ); |
| 89 |
|
| 90 |
#ifdef PERL_SYS_INIT3 |
| 91 |
PERL_SYS_INIT3(&argc, &argv, &env); |
| 92 |
#endif |
| 93 |
PERL_INTERPRETER = perl_alloc(); |
| 94 |
perl_construct(PERL_INTERPRETER); |
| 95 |
#ifdef PERL_EXIT_DESTRUCT_END |
| 96 |
PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
| 97 |
#endif |
| 98 |
perl_parse(PERL_INTERPRETER, perl_back_xs_init, argc, argv, env); |
| 99 |
perl_run(PERL_INTERPRETER); |
| 100 |
return perl_back_init_cf( bi ); |
| 101 |
} |
| 102 |
|
| 103 |
int |
| 104 |
perl_back_db_init( |
| 105 |
BackendDB *be, |
| 106 |
ConfigReply *cr |
| 107 |
) |
| 108 |
{ |
| 109 |
be->be_private = (PerlBackend *) ch_malloc( sizeof(PerlBackend) ); |
| 110 |
memset( be->be_private, '\0', sizeof(PerlBackend)); |
| 111 |
|
| 112 |
((PerlBackend *)be->be_private)->pb_filter_search_results = 0; |
| 113 |
|
| 114 |
Debug( LDAP_DEBUG_TRACE, "perl backend db init\n" ); |
| 115 |
|
| 116 |
be->be_cf_ocs = be->bd_info->bi_cf_ocs; |
| 117 |
|
| 118 |
return 0; |
| 119 |
} |
| 120 |
|
| 121 |
int |
| 122 |
perl_back_db_open( |
| 123 |
BackendDB *be, |
| 124 |
ConfigReply *cr |
| 125 |
) |
| 126 |
{ |
| 127 |
int count; |
| 128 |
int return_code; |
| 129 |
|
| 130 |
PerlBackend *perl_back = (PerlBackend *) be->be_private; |
| 131 |
|
| 132 |
ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex ); |
| 133 |
|
| 134 |
{ |
| 135 |
dSP; ENTER; SAVETMPS; |
| 136 |
|
| 137 |
PUSHMARK(sp); |
| 138 |
XPUSHs( perl_back->pb_obj_ref ); |
| 139 |
|
| 140 |
PUTBACK; |
| 141 |
|
| 142 |
count = call_method("init", G_SCALAR); |
| 143 |
|
| 144 |
SPAGAIN; |
| 145 |
|
| 146 |
if (count != 1) { |
| 147 |
croak("Big trouble in perl_back_db_open\n"); |
| 148 |
} |
| 149 |
|
| 150 |
return_code = POPi; |
| 151 |
|
| 152 |
PUTBACK; FREETMPS; LEAVE; |
| 153 |
} |
| 154 |
|
| 155 |
ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex ); |
| 156 |
|
| 157 |
return return_code; |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
static void |
| 162 |
perl_back_xs_init(PERL_BACK_XS_INIT_PARAMS) |
| 163 |
{ |
| 164 |
char *file = __FILE__; |
| 165 |
dXSUB_SYS; |
| 166 |
newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); |
| 167 |
} |
| 168 |
|
| 169 |
#if SLAPD_PERL == SLAPD_MOD_DYNAMIC |
| 170 |
|
| 171 |
/* conditionally define the init_module() function */ |
| 172 |
SLAP_BACKEND_INIT_MODULE( perl ) |
| 173 |
|
| 174 |
#endif /* SLAPD_PERL == SLAPD_MOD_DYNAMIC */ |
| 175 |
|
| 176 |
|