]> git.sur5r.net Git - openldap/blob - servers/slapd/frontend.c
1ae0233f2d732ed5c107a5d93b08d65a020c643b
[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-2005 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_aux_operational(
47         Operation *op,
48         SlapReply *rs )
49 {
50         Attribute       **ap;
51         int             rc = 0;
52         BackendDB       *be_orig;
53
54         for ( ap = &rs->sr_operational_attrs; *ap; ap = &(*ap)->a_next )
55                 /* just count them */ ;
56
57         /*
58          * If operational attributes (allegedly) are required, 
59          * and the backend supports specific operational attributes, 
60          * add them to the attribute list
61          */
62         if ( SLAP_OPATTRS( rs->sr_attr_flags ) || ( rs->sr_attrs &&
63                 ad_inlist( slap_schema.si_ad_entryDN, rs->sr_attrs ) ) )
64         {
65                 *ap = slap_operational_entryDN( rs->sr_entry );
66                 ap = &(*ap)->a_next;
67         }
68
69         if ( SLAP_OPATTRS( rs->sr_attr_flags ) || ( rs->sr_attrs &&
70                 ad_inlist( slap_schema.si_ad_subschemaSubentry, rs->sr_attrs ) ) )
71         {
72                 *ap = slap_operational_subschemaSubentry( op->o_bd );
73                 ap = &(*ap)->a_next;
74         }
75
76         if ( op->o_bd != NULL )
77         {
78                 /* Let the overlays have a chance at this */
79                 be_orig = op->o_bd;
80                 if ( SLAP_ISOVERLAY( be_orig ) )
81                         op->o_bd = select_backend( be_orig->be_nsuffix, 0, 0 );
82
83                 if ( ( SLAP_OPATTRS( rs->sr_attr_flags ) || rs->sr_attrs ) &&
84                         op->o_bd && op->o_bd->be_operational != NULL )
85                 {
86                         rc = op->o_bd->be_operational( op, rs );
87                 }
88                 op->o_bd = be_orig;
89         }
90
91         return rc;
92 }
93
94 int
95 frontend_init( void )
96 {
97         /* data */
98         frontendDB = &slap_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 #if 0
114         /* FIXME: do we need this? */
115         frontendDB->be_pcl_mutexp = &frontendDB->be_pcl_mutex;
116         ldap_pvt_thread_mutex_init( frontendDB->be_pcl_mutexp );
117 #endif
118
119         /* suffix */
120         frontendDB->be_suffix = ch_calloc( 2, sizeof( struct berval ) );
121         ber_str2bv( "", 0, 1, &frontendDB->be_suffix[0] );
122         BER_BVZERO( &frontendDB->be_suffix[1] );
123         frontendDB->be_nsuffix = ch_calloc( 2, sizeof( struct berval ) );
124         ber_str2bv( "", 0, 1, &frontendDB->be_nsuffix[0] );
125         BER_BVZERO( &frontendDB->be_nsuffix[1] );
126
127         /* info */
128         frontendDB->bd_info = &slap_frontendInfo;
129
130         SLAP_BFLAGS(frontendDB) |= SLAP_BFLAG_FRONTEND;
131
132         /* name */
133         frontendDB->bd_info->bi_type = "frontend";
134
135         /* known controls */
136         if ( slap_known_controls ) {
137                 int     i;
138
139                 frontendDB->bd_info->bi_controls = slap_known_controls;
140
141                 for ( i = 0; slap_known_controls[ i ]; i++ ) {
142                         int     cid;
143
144                         if ( slap_find_control_id( slap_known_controls[ i ], &cid )
145                                         == LDAP_CONTROL_NOT_FOUND )
146                         {
147                                 assert( 0 );
148                                 return -1;
149                         }
150
151                         frontendDB->bd_info->bi_ctrls[ cid ] = 1;
152                         frontendDB->be_ctrls[ cid ] = 1;
153                 }
154         }
155
156         /* calls */
157         frontendDB->bd_info->bi_op_abandon = fe_op_abandon;
158         frontendDB->bd_info->bi_op_add = fe_op_add;
159         frontendDB->bd_info->bi_op_bind = fe_op_bind;
160         frontendDB->bd_info->bi_op_compare = fe_op_compare;
161         frontendDB->bd_info->bi_op_delete = fe_op_delete;
162         frontendDB->bd_info->bi_op_modify = fe_op_modify;
163         frontendDB->bd_info->bi_op_modrdn = fe_op_modrdn;
164         frontendDB->bd_info->bi_op_search = fe_op_search;
165         frontendDB->bd_info->bi_extended = fe_extended;
166         frontendDB->bd_info->bi_operational = fe_aux_operational;
167
168 #if 0
169         /* FIXME: is this too early? */
170         return backend_startup_one( frontendDB );
171 #endif
172
173         return 0;
174 }
175