]> git.sur5r.net Git - openldap/blob - servers/slapd/frontend.c
ITS#5322 don't try to free a NULL locker
[openldap] / servers / slapd / frontend.c
1 /* frontend.c - routines for dealing with frontend */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2008 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
11  * A copy of this license is available in the file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms are permitted
19  * provided that this notice is preserved and that due credit is given
20  * to the University of Michigan at Ann Arbor. The name of the University
21  * may not be used to endorse or promote products derived from this
22  * software without specific prior written permission. This software
23  * is provided ``as is'' without express or implied warranty.
24  */
25
26
27 #include "portable.h"
28
29 #include <stdio.h>
30
31 #include <ac/string.h>
32 #include <ac/socket.h>
33 #include <sys/stat.h>
34
35 #include "slap.h"
36 #include "lutil.h"
37 #include "lber_pvt.h"
38
39 #include "ldap_rq.h"
40
41 static BackendInfo      slap_frontendInfo;
42 static BackendDB        slap_frontendDB;
43 BackendDB       *frontendDB;
44
45 static int
46 fe_entry_get_rw(
47         Operation *op,
48         struct berval *ndn,
49         ObjectClass *oc,
50         AttributeDescription *at,
51         int rw,
52         Entry **e )
53 {
54         BackendDB       *bd;
55         int             rc = LDAP_NO_SUCH_OBJECT;
56
57         bd = op->o_bd;
58         op->o_bd = select_backend( ndn, 0 );
59         if ( op->o_bd != NULL ) {
60                 if ( op->o_bd->be_fetch ) {
61                         rc = op->o_bd->be_fetch( op, ndn, oc, at, rw, e );
62                 }
63         }
64         op->o_bd = bd;
65
66         return rc;
67 }
68
69 static int
70 fe_entry_release_rw(
71         Operation *op,
72         Entry *e,
73         int rw )
74 {
75         BackendDB       *bd;
76         int             rc = LDAP_NO_SUCH_OBJECT;
77
78         bd = op->o_bd;
79         op->o_bd = select_backend( &e->e_nname, 0 );
80         if ( op->o_bd != NULL ) {
81                 if ( op->o_bd->be_release ) {
82                         rc = op->o_bd->be_release( op, e, rw );
83                 }
84         }
85         op->o_bd = bd;
86
87         return rc;
88 }
89
90 int
91 frontend_init( void )
92 {
93         /* data */
94         frontendDB = &slap_frontendDB;
95
96         /* ACLs */
97         frontendDB->be_dfltaccess = ACL_READ;
98
99         /* limits */
100         frontendDB->be_def_limit.lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;  /* backward compatible limits */
101         frontendDB->be_def_limit.lms_t_hard = 0;
102         frontendDB->be_def_limit.lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;  /* backward compatible limits */
103         frontendDB->be_def_limit.lms_s_hard = 0;
104         frontendDB->be_def_limit.lms_s_unchecked = -1;                  /* no limit on unchecked size */
105         frontendDB->be_def_limit.lms_s_pr = 0;                          /* page limit */
106         frontendDB->be_def_limit.lms_s_pr_hide = 0;                     /* don't hide number of entries left */
107         frontendDB->be_def_limit.lms_s_pr_total = 0;                    /* number of total entries returned by pagedResults equal to hard limit */
108
109 #if 0
110         /* FIXME: do we need this? */
111         frontendDB->be_pcl_mutexp = &frontendDB->be_pcl_mutex;
112         ldap_pvt_thread_mutex_init( frontendDB->be_pcl_mutexp );
113 #endif
114
115         /* suffix */
116         frontendDB->be_suffix = ch_calloc( 2, sizeof( struct berval ) );
117         ber_str2bv( "", 0, 1, &frontendDB->be_suffix[0] );
118         BER_BVZERO( &frontendDB->be_suffix[1] );
119         frontendDB->be_nsuffix = ch_calloc( 2, sizeof( struct berval ) );
120         ber_str2bv( "", 0, 1, &frontendDB->be_nsuffix[0] );
121         BER_BVZERO( &frontendDB->be_nsuffix[1] );
122
123         /* info */
124         frontendDB->bd_info = &slap_frontendInfo;
125
126         SLAP_BFLAGS(frontendDB) |= SLAP_BFLAG_FRONTEND;
127
128         /* name */
129         frontendDB->bd_info->bi_type = "frontend";
130
131         /* known controls */
132         if ( slap_known_controls ) {
133                 int     i;
134
135                 frontendDB->bd_info->bi_controls = slap_known_controls;
136
137                 for ( i = 0; slap_known_controls[ i ]; i++ ) {
138                         int     cid;
139
140                         if ( slap_find_control_id( slap_known_controls[ i ], &cid )
141                                         == LDAP_CONTROL_NOT_FOUND )
142                         {
143                                 assert( 0 );
144                                 return -1;
145                         }
146
147                         frontendDB->bd_info->bi_ctrls[ cid ] = 1;
148                         frontendDB->be_ctrls[ cid ] = 1;
149                 }
150         }
151
152         /* calls */
153         frontendDB->bd_info->bi_op_abandon = fe_op_abandon;
154         frontendDB->bd_info->bi_op_add = fe_op_add;
155         frontendDB->bd_info->bi_op_bind = fe_op_bind;
156         frontendDB->bd_info->bi_op_compare = fe_op_compare;
157         frontendDB->bd_info->bi_op_delete = fe_op_delete;
158         frontendDB->bd_info->bi_op_modify = fe_op_modify;
159         frontendDB->bd_info->bi_op_modrdn = fe_op_modrdn;
160         frontendDB->bd_info->bi_op_search = fe_op_search;
161         frontendDB->bd_info->bi_extended = fe_extended;
162         frontendDB->bd_info->bi_operational = fe_aux_operational;
163         frontendDB->bd_info->bi_entry_get_rw = fe_entry_get_rw;
164         frontendDB->bd_info->bi_entry_release_rw = fe_entry_release_rw;
165         frontendDB->bd_info->bi_access_allowed = fe_access_allowed;
166         frontendDB->bd_info->bi_acl_group = fe_acl_group;
167         frontendDB->bd_info->bi_acl_attribute = fe_acl_attribute;
168
169 #if 0
170         /* FIXME: is this too early? */
171         return backend_startup_one( frontendDB );
172 #endif
173
174         return 0;
175 }
176