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