1 /* operational.c - bdb backend operational attributes function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2014 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
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>.
21 #include <ac/string.h>
22 #include <ac/socket.h>
28 * sets *hasSubordinates to LDAP_COMPARE_TRUE/LDAP_COMPARE_FALSE
29 * if the entry has children or not.
35 int *hasSubordinates )
37 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
38 struct bdb_op_info *opinfo;
46 /* NOTE: this should never happen, but it actually happens
47 * when using back-relay; until we find a better way to
48 * preserve entry's private information while rewriting it,
49 * let's disable the hasSubordinate feature for back-relay.
51 if ( BEI( e ) == NULL ) {
53 rc = be_entry_get_rw( op, &e->e_nname, NULL, NULL, 0, &ee );
54 if ( rc != LDAP_SUCCESS || ee == NULL ) {
60 if ( BEI( ee ) == NULL ) {
66 /* Check for a txn in a parent op, otherwise use reader txn */
67 LDAP_SLIST_FOREACH( oex, &op->o_extra, oe_next ) {
68 if ( oex->oe_key == bdb )
71 opinfo = (struct bdb_op_info *) oex;
72 if ( opinfo && opinfo->boi_txn ) {
73 rtxn = opinfo->boi_txn;
75 rc = bdb_reader_get(op, bdb->bi_dbenv, &rtxn);
83 /* FIXME: we can no longer assume the entry's e_private
84 * field is correctly populated; so we need to reacquire
85 * it with reader lock */
86 rc = bdb_cache_children( op, rtxn, e );
89 case DB_LOCK_DEADLOCK:
90 case DB_LOCK_NOTGRANTED:
94 *hasSubordinates = LDAP_COMPARE_TRUE;
98 *hasSubordinates = LDAP_COMPARE_FALSE;
103 Debug(LDAP_DEBUG_ARGS,
104 "<=- " LDAP_XSTRING(bdb_hasSubordinates)
105 ": has_children failed: %s (%d)\n",
106 db_strerror(rc), rc, 0 );
111 if ( release && e != NULL ) be_entry_release_r( op, e );
116 * sets the supported operational attributes (if required)
125 assert( rs->sr_entry != NULL );
127 for ( ap = &rs->sr_operational_attrs; *ap; ap = &(*ap)->a_next ) {
128 if ( (*ap)->a_desc == slap_schema.si_ad_hasSubordinates ) {
134 attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_hasSubordinates ) == NULL &&
135 ( SLAP_OPATTRS( rs->sr_attr_flags ) ||
136 ad_inlist( slap_schema.si_ad_hasSubordinates, rs->sr_attrs ) ) )
138 int hasSubordinates, rc;
140 rc = bdb_hasSubordinates( op, rs->sr_entry, &hasSubordinates );
141 if ( rc == LDAP_SUCCESS ) {
142 *ap = slap_operational_hasSubordinate( hasSubordinates == LDAP_COMPARE_TRUE );
143 assert( *ap != NULL );