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