Back to index

openldap  2.4.31
frontend.c
Go to the documentation of this file.
00001 /* frontend.c - routines for dealing with frontend */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 1998-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in the file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
00017  * All rights reserved.
00018  *
00019  * Redistribution and use in source and binary forms are permitted
00020  * provided that this notice is preserved and that due credit is given
00021  * to the University of Michigan at Ann Arbor. The name of the University
00022  * may not be used to endorse or promote products derived from this
00023  * software without specific prior written permission. This software
00024  * is provided ``as is'' without express or implied warranty.
00025  */
00026 
00027 
00028 #include "portable.h"
00029 
00030 #include <stdio.h>
00031 
00032 #include <ac/string.h>
00033 #include <ac/socket.h>
00034 #include <sys/stat.h>
00035 
00036 #include "slap.h"
00037 #include "lutil.h"
00038 #include "lber_pvt.h"
00039 
00040 #include "ldap_rq.h"
00041 
00042 static BackendInfo   slap_frontendInfo;
00043 static BackendDB     slap_frontendDB;
00044 BackendDB     *frontendDB;
00045 
00046 static int
00047 fe_entry_get_rw(
00048        Operation *op,
00049        struct berval *ndn,
00050        ObjectClass *oc,
00051        AttributeDescription *at,
00052        int rw,
00053        Entry **e )
00054 {
00055        BackendDB     *bd;
00056        int           rc = LDAP_NO_SUCH_OBJECT;
00057 
00058        bd = op->o_bd;
00059        op->o_bd = select_backend( ndn, 0 );
00060        if ( op->o_bd != NULL ) {
00061               if ( op->o_bd->be_fetch ) {
00062                      rc = op->o_bd->be_fetch( op, ndn, oc, at, rw, e );
00063               }
00064        }
00065        op->o_bd = bd;
00066 
00067        return rc;
00068 }
00069 
00070 static int
00071 fe_entry_release_rw(
00072        Operation *op,
00073        Entry *e,
00074        int rw )
00075 {
00076        BackendDB     *bd;
00077        int           rc = LDAP_NO_SUCH_OBJECT;
00078 
00079        bd = op->o_bd;
00080        op->o_bd = select_backend( &e->e_nname, 0 );
00081        if ( op->o_bd != NULL ) {
00082               if ( op->o_bd->be_release ) {
00083                      rc = op->o_bd->be_release( op, e, rw );
00084               }
00085        }
00086        op->o_bd = bd;
00087 
00088        return rc;
00089 }
00090 
00091 int
00092 frontend_init( void )
00093 {
00094        /* data */
00095        frontendDB = &slap_frontendDB;
00096        frontendDB->bd_self = frontendDB;
00097 
00098        /* ACLs */
00099        frontendDB->be_dfltaccess = ACL_READ;
00100 
00101        /* limits */
00102        frontendDB->be_def_limit.lms_t_soft = SLAPD_DEFAULT_TIMELIMIT; /* backward compatible limits */
00103        frontendDB->be_def_limit.lms_t_hard = 0;
00104        frontendDB->be_def_limit.lms_s_soft = SLAPD_DEFAULT_SIZELIMIT; /* backward compatible limits */
00105        frontendDB->be_def_limit.lms_s_hard = 0;
00106        frontendDB->be_def_limit.lms_s_unchecked = -1;                 /* no limit on unchecked size */
00107        frontendDB->be_def_limit.lms_s_pr = 0;                         /* page limit */
00108        frontendDB->be_def_limit.lms_s_pr_hide = 0;                    /* don't hide number of entries left */
00109        frontendDB->be_def_limit.lms_s_pr_total = 0;                   /* number of total entries returned by pagedResults equal to hard limit */
00110 
00111        ldap_pvt_thread_mutex_init( &frontendDB->be_pcl_mutex );
00112 
00113        /* suffix */
00114        frontendDB->be_suffix = ch_calloc( 2, sizeof( struct berval ) );
00115        ber_str2bv( "", 0, 1, &frontendDB->be_suffix[0] );
00116        BER_BVZERO( &frontendDB->be_suffix[1] );
00117        frontendDB->be_nsuffix = ch_calloc( 2, sizeof( struct berval ) );
00118        ber_str2bv( "", 0, 1, &frontendDB->be_nsuffix[0] );
00119        BER_BVZERO( &frontendDB->be_nsuffix[1] );
00120 
00121        /* info */
00122        frontendDB->bd_info = &slap_frontendInfo;
00123 
00124        SLAP_BFLAGS(frontendDB) |= SLAP_BFLAG_FRONTEND;
00125 
00126        /* name */
00127        frontendDB->bd_info->bi_type = "frontend";
00128 
00129        /* known controls */
00130        {
00131               int    i;
00132 
00133               frontendDB->bd_info->bi_controls = slap_known_controls;
00134 
00135               for ( i = 0; slap_known_controls[ i ]; i++ ) {
00136                      int    cid;
00137 
00138                      if ( slap_find_control_id( slap_known_controls[ i ], &cid )
00139                                    == LDAP_CONTROL_NOT_FOUND )
00140                      {
00141                             assert( 0 );
00142                             return -1;
00143                      }
00144 
00145                      frontendDB->bd_info->bi_ctrls[ cid ] = 1;
00146                      frontendDB->be_ctrls[ cid ] = 1;
00147               }
00148        }
00149 
00150        /* calls */
00151        frontendDB->bd_info->bi_op_abandon = fe_op_abandon;
00152        frontendDB->bd_info->bi_op_add = fe_op_add;
00153        frontendDB->bd_info->bi_op_bind = fe_op_bind;
00154        frontendDB->bd_info->bi_op_compare = fe_op_compare;
00155        frontendDB->bd_info->bi_op_delete = fe_op_delete;
00156        frontendDB->bd_info->bi_op_modify = fe_op_modify;
00157        frontendDB->bd_info->bi_op_modrdn = fe_op_modrdn;
00158        frontendDB->bd_info->bi_op_search = fe_op_search;
00159        frontendDB->bd_info->bi_extended = fe_extended;
00160        frontendDB->bd_info->bi_operational = fe_aux_operational;
00161        frontendDB->bd_info->bi_entry_get_rw = fe_entry_get_rw;
00162        frontendDB->bd_info->bi_entry_release_rw = fe_entry_release_rw;
00163        frontendDB->bd_info->bi_access_allowed = fe_access_allowed;
00164        frontendDB->bd_info->bi_acl_group = fe_acl_group;
00165        frontendDB->bd_info->bi_acl_attribute = fe_acl_attribute;
00166 
00167 #if 0
00168        /* FIXME: is this too early? */
00169        return backend_startup_one( frontendDB );
00170 #endif
00171 
00172        return 0;
00173 }
00174