Debian Codegraph @

servers/slapd/back-mdb/operational.c

raw
1 /* operational.c - mdb backend operational attributes function */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 *
5 * Copyright 2000-2024 The OpenLDAP Foundation.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
10 * Public License.
11 *
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>.
15 */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20
21 #include <ac/string.h>
22 #include <ac/socket.h>
23
24 #include "slap.h"
25 #include "back-mdb.h"
26
27 /*
28 * sets *hasSubordinates to LDAP_COMPARE_TRUE/LDAP_COMPARE_FALSE
29 * if the entry has children or not.
30 */
31 int
32 mdb_hasSubordinates(
33 Operation *op,
34 Entry *e,
35 int *hasSubordinates )
36 {
37 struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
38 MDB_txn *rtxn;
39 mdb_op_info opinfo = {{{0}}}, *moi = &opinfo;
40 int rc;
41
42 assert( e != NULL );
43
44 rc = mdb_opinfo_get(op, mdb, 1, &moi);
45 switch(rc) {
46 case 0:
47 break;
48 default:
49 rc = LDAP_OTHER;
50 goto done;
51 }
52
53 rtxn = moi->moi_txn;
54
55 rc = mdb_dn2id_children( op, rtxn, e );
56
57 switch( rc ) {
58 case 0:
59 *hasSubordinates = LDAP_COMPARE_TRUE;
60 break;
61
62 case MDB_NOTFOUND:
63 *hasSubordinates = LDAP_COMPARE_FALSE;
64 rc = LDAP_SUCCESS;
65 break;
66
67 default:
68 Debug(LDAP_DEBUG_ARGS,
69 "<=- " LDAP_XSTRING(mdb_hasSubordinates)
70 ": has_children failed: %s (%d)\n",
71 mdb_strerror(rc), rc );
72 rc = LDAP_OTHER;
73 }
74
75 done:;
76 if ( moi == &opinfo ) {
77 mdb_txn_reset( moi->moi_txn );
78 LDAP_SLIST_REMOVE( &op->o_extra, &moi->moi_oe, OpExtra, oe_next );
79 } else {
80 moi->moi_ref--;
81 }
82 return rc;
83 }
84
85 /*
86 * sets the supported operational attributes (if required)
87 */
88 int
89 mdb_operational(
90 Operation *op,
91 SlapReply *rs )
92 {
93 Attribute **ap;
94
95 assert( rs->sr_entry != NULL );
96
97 for ( ap = &rs->sr_operational_attrs; *ap; ap = &(*ap)->a_next ) {
98 if ( (*ap)->a_desc == slap_schema.si_ad_hasSubordinates ) {
99 break;
100 }
101 }
102
103 if ( *ap == NULL &&
104 attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_hasSubordinates ) == NULL &&
105 ( SLAP_OPATTRS( rs->sr_attr_flags ) ||
106 ad_inlist( slap_schema.si_ad_hasSubordinates, rs->sr_attrs ) ) )
107 {
108 int hasSubordinates, rc;
109
110 rc = mdb_hasSubordinates( op, rs->sr_entry, &hasSubordinates );
111 if ( rc == LDAP_SUCCESS ) {
112 *ap = slap_operational_hasSubordinate( hasSubordinates == LDAP_COMPARE_TRUE );
113 assert( *ap != NULL );
114
115 ap = &(*ap)->a_next;
116 }
117 }
118
119 return LDAP_SUCCESS;
120 }
121