Back to index

openldap  2.4.31
operational.c
Go to the documentation of this file.
00001 /* operational.c - mdb backend operational attributes function */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2000-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 
00017 #include "portable.h"
00018 
00019 #include <stdio.h>
00020 
00021 #include <ac/string.h>
00022 #include <ac/socket.h>
00023 
00024 #include "slap.h"
00025 #include "back-mdb.h"
00026 
00027 /*
00028  * sets *hasSubordinates to LDAP_COMPARE_TRUE/LDAP_COMPARE_FALSE
00029  * if the entry has children or not.
00030  */
00031 int
00032 mdb_hasSubordinates(
00033        Operation     *op,
00034        Entry         *e,
00035        int           *hasSubordinates )
00036 {
00037        struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
00038        MDB_txn              *rtxn;
00039        mdb_op_info   opinfo = {{{0}}}, *moi = &opinfo;
00040        int           rc;
00041        
00042        assert( e != NULL );
00043 
00044        rc = mdb_opinfo_get(op, mdb, 1, &moi);
00045        switch(rc) {
00046        case 0:
00047               break;
00048        default:
00049               rc = LDAP_OTHER;
00050               goto done;
00051        }
00052 
00053        rtxn = moi->moi_txn;
00054 
00055        rc = mdb_dn2id_children( op, rtxn, e );
00056 
00057        switch( rc ) {
00058        case 0:
00059               *hasSubordinates = LDAP_COMPARE_TRUE;
00060               break;
00061 
00062        case MDB_NOTFOUND:
00063               *hasSubordinates = LDAP_COMPARE_FALSE;
00064               rc = LDAP_SUCCESS;
00065               break;
00066 
00067        default:
00068               Debug(LDAP_DEBUG_ARGS, 
00069                      "<=- " LDAP_XSTRING(mdb_hasSubordinates)
00070                      ": has_children failed: %s (%d)\n", 
00071                      mdb_strerror(rc), rc, 0 );
00072               rc = LDAP_OTHER;
00073        }
00074 
00075 done:;
00076        if ( moi == &opinfo ) {
00077               mdb_txn_reset( moi->moi_txn );
00078               LDAP_SLIST_REMOVE( &op->o_extra, &moi->moi_oe, OpExtra, oe_next );
00079        }
00080        return rc;
00081 }
00082 
00083 /*
00084  * sets the supported operational attributes (if required)
00085  */
00086 int
00087 mdb_operational(
00088        Operation     *op,
00089        SlapReply     *rs )
00090 {
00091        Attribute     **ap;
00092 
00093        assert( rs->sr_entry != NULL );
00094 
00095        for ( ap = &rs->sr_operational_attrs; *ap; ap = &(*ap)->a_next ) {
00096               if ( (*ap)->a_desc == slap_schema.si_ad_hasSubordinates ) {
00097                      break;
00098               }
00099        }
00100 
00101        if ( *ap == NULL &&
00102               attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_hasSubordinates ) == NULL &&
00103               ( SLAP_OPATTRS( rs->sr_attr_flags ) ||
00104                      ad_inlist( slap_schema.si_ad_hasSubordinates, rs->sr_attrs ) ) )
00105        {
00106               int    hasSubordinates, rc;
00107 
00108               rc = mdb_hasSubordinates( op, rs->sr_entry, &hasSubordinates );
00109               if ( rc == LDAP_SUCCESS ) {
00110                      *ap = slap_operational_hasSubordinate( hasSubordinates == LDAP_COMPARE_TRUE );
00111                      assert( *ap != NULL );
00112 
00113                      ap = &(*ap)->a_next;
00114               }
00115        }
00116 
00117        return LDAP_SUCCESS;
00118 }
00119