1/*	$NetBSD: frontend.c,v 1.1.1.3 2010/12/12 15:22:30 adam Exp $	*/
2
3/* frontend.c - routines for dealing with frontend */
4/* OpenLDAP: pkg/ldap/servers/slapd/frontend.c,v 1.19.2.10 2010/04/13 20:23:15 kurt Exp */
5/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6 *
7 * Copyright 1998-2010 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 "portable.h"
31
32#include <stdio.h>
33
34#include <ac/string.h>
35#include <ac/socket.h>
36#include <sys/stat.h>
37
38#include "slap.h"
39#include "lutil.h"
40#include "lber_pvt.h"
41
42#include "ldap_rq.h"
43
44static BackendInfo	slap_frontendInfo;
45static BackendDB	slap_frontendDB;
46BackendDB	*frontendDB;
47
48static int
49fe_entry_get_rw(
50	Operation *op,
51	struct berval *ndn,
52	ObjectClass *oc,
53	AttributeDescription *at,
54	int rw,
55	Entry **e )
56{
57	BackendDB	*bd;
58	int		rc = LDAP_NO_SUCH_OBJECT;
59
60	bd = op->o_bd;
61	op->o_bd = select_backend( ndn, 0 );
62	if ( op->o_bd != NULL ) {
63		if ( op->o_bd->be_fetch ) {
64			rc = op->o_bd->be_fetch( op, ndn, oc, at, rw, e );
65		}
66	}
67	op->o_bd = bd;
68
69	return rc;
70}
71
72static int
73fe_entry_release_rw(
74	Operation *op,
75	Entry *e,
76	int rw )
77{
78	BackendDB	*bd;
79	int		rc = LDAP_NO_SUCH_OBJECT;
80
81	bd = op->o_bd;
82	op->o_bd = select_backend( &e->e_nname, 0 );
83	if ( op->o_bd != NULL ) {
84		if ( op->o_bd->be_release ) {
85			rc = op->o_bd->be_release( op, e, rw );
86		}
87	}
88	op->o_bd = bd;
89
90	return rc;
91}
92
93int
94frontend_init( void )
95{
96	/* data */
97	frontendDB = &slap_frontendDB;
98	frontendDB->bd_self = frontendDB;
99
100	/* ACLs */
101	frontendDB->be_dfltaccess = ACL_READ;
102
103	/* limits */
104	frontendDB->be_def_limit.lms_t_soft = SLAPD_DEFAULT_TIMELIMIT;	/* backward compatible limits */
105	frontendDB->be_def_limit.lms_t_hard = 0;
106	frontendDB->be_def_limit.lms_s_soft = SLAPD_DEFAULT_SIZELIMIT;	/* backward compatible limits */
107	frontendDB->be_def_limit.lms_s_hard = 0;
108	frontendDB->be_def_limit.lms_s_unchecked = -1;			/* no limit on unchecked size */
109	frontendDB->be_def_limit.lms_s_pr = 0;				/* page limit */
110	frontendDB->be_def_limit.lms_s_pr_hide = 0;			/* don't hide number of entries left */
111	frontendDB->be_def_limit.lms_s_pr_total = 0;			/* number of total entries returned by pagedResults equal to hard limit */
112
113	ldap_pvt_thread_mutex_init( &frontendDB->be_pcl_mutex );
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	{
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
177