]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/init.c
03ab2d18011c49b48b908b2d9c3e6fcaceae87a7
[openldap] / servers / slapd / back-shell / init.c
1 /* init.c - initialize shell backend */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/socket.h>
13 #include <ac/unistd.h>
14
15 #include "slap.h"
16 #include "shell.h"
17
18 #ifdef SLAPD_SHELL_DYNAMIC
19
20 int back_shell_LTX_init_module(int argc, char *argv[]) {
21     BackendInfo bi;
22
23     memset( &bi, '\0', sizeof(bi) );
24     bi.bi_type = "shell";
25     bi.bi_init = shell_back_initialize;
26
27     backend_add(&bi);
28     return 0;
29 }
30
31 #endif /* SLAPD_SHELL_DYNAMIC */
32
33 int
34 shell_back_initialize(
35     BackendInfo *bi
36 )
37 {
38         bi->bi_open = 0;
39         bi->bi_config = 0;
40         bi->bi_close = 0;
41         bi->bi_destroy = shell_back_destroy;
42
43         bi->bi_db_init = shell_back_db_init;
44         bi->bi_db_config = shell_back_db_config;
45         bi->bi_db_open = 0;
46         bi->bi_db_close = 0;
47         bi->bi_db_destroy = shell_back_db_destroy;
48
49         bi->bi_op_bind = shell_back_bind;
50         bi->bi_op_unbind = shell_back_unbind;
51         bi->bi_op_search = shell_back_search;
52         bi->bi_op_compare = shell_back_compare;
53         bi->bi_op_modify = shell_back_modify;
54         bi->bi_op_modrdn = shell_back_modrdn;
55         bi->bi_op_add = shell_back_add;
56         bi->bi_op_delete = shell_back_delete;
57         bi->bi_op_abandon = shell_back_abandon;
58
59         bi->bi_extended = 0;
60
61         bi->bi_acl_group = 0;
62         bi->bi_acl_attribute = 0;
63         bi->bi_chk_referrals = 0;
64
65         bi->bi_connection_init = 0;
66         bi->bi_connection_destroy = 0;
67
68 #ifdef SHELL_SURROGATE_PARENT
69         ldap_pvt_thread_mutex_init( &shell_surrogate_index_mutex );
70         ldap_pvt_thread_mutex_init( &shell_surrogate_fd_mutex[0] );
71         ldap_pvt_thread_mutex_init( &shell_surrogate_fd_mutex[1] );
72 #endif
73
74         return 0;
75 }
76
77 int
78 shell_back_destroy(
79         BackendInfo *bi
80 )
81 {
82 #ifdef SHELL_SURROGATE_PARENT
83         ldap_pvt_thread_mutex_destroy( &shell_surrogate_index_mutex );
84         ldap_pvt_thread_mutex_destroy( &shell_surrogate_fd_mutex[0] );
85         ldap_pvt_thread_mutex_destroy( &shell_surrogate_fd_mutex[1] );
86         if ( shell_surrogate_fd[0] >= 0 ) {
87                 close( shell_surrogate_fd[0] );
88                 close( shell_surrogate_fd[1] );
89         }
90         if ( shell_surrogate_pid >= 0 )
91                 kill( shell_surrogate_pid, SIGTERM );
92 #endif
93
94         return 0;
95 }
96
97 int
98 shell_back_db_init(
99     Backend     *be
100 )
101 {
102         struct shellinfo        *si;
103
104 #ifdef SHELL_SURROGATE_PARENT
105         if ( shell_surrogate_fd[0] < 0 )
106                 make_surrogate_parent();
107 #endif
108
109         si = (struct shellinfo *) ch_calloc( 1, sizeof(struct shellinfo) );
110
111         be->be_private = si;
112
113         return si == NULL;
114 }
115
116 int
117 shell_back_db_destroy(
118     Backend     *be
119 )
120 {
121         free( be->be_private );
122         return 0;
123 }