Debian Codegraph @

servers/slapd/back-wt/operational.c

raw
1 /* OpenLDAP WiredTiger backend */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 *
5 * Copyright 2002-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 /* ACKNOWLEDGEMENTS:
17 * This work was developed by HAMANO Tsukasa <[email protected]>
18 * based on back-bdb for inclusion in OpenLDAP Software.
19 * WiredTiger is a product of MongoDB Inc.
20 */
21
22 #include "portable.h"
23
24 #include <stdio.h>
25 #include <ac/string.h>
26
27 #include "back-wt.h"
28 #include "slap-config.h"
29
30 int
31 wt_hasSubordinates(
32 Operation *op,
33 Entry *e,
34 int *hasSubordinates )
35 {
36 struct wt_info *wi = (struct wt_info *) op->o_bd->be_private;
37 wt_ctx *wc = NULL;
38 int rc;
39
40 assert( e != NULL );
41
42 wc = wt_ctx_get(op, wi);
43 if( !wc ){
44 Debug( LDAP_DEBUG_ANY,
45 "wt_hasSubordinates: wt_ctx_get failed\n" );
46 return LDAP_OTHER;
47 }
48
49 rc = wt_dn2id_has_children(op, wc, e->e_id);
50 switch(rc){
51 case 0:
52 *hasSubordinates = LDAP_COMPARE_TRUE;
53 break;
54 case WT_NOTFOUND:
55 *hasSubordinates = LDAP_COMPARE_FALSE;
56 rc = LDAP_SUCCESS;
57 break;
58 default:
59 Debug(LDAP_DEBUG_ANY,
60 "<=- wt_hasSubordinates: has_children failed: %s (%d)\n",
61 wiredtiger_strerror(rc), rc );
62 rc = LDAP_OTHER;
63 }
64 return rc;
65 }
66
67 /*
68 * sets the supported operational attributes (if required)
69 */
70 int
71 wt_operational(
72 Operation *op,
73 SlapReply *rs )
74 {
75 Attribute **ap;
76
77 assert( rs->sr_entry != NULL );
78
79 for ( ap = &rs->sr_operational_attrs; *ap; ap = &(*ap)->a_next ) {
80 if ( (*ap)->a_desc == slap_schema.si_ad_hasSubordinates ) {
81 break;
82 }
83 }
84
85 if ( *ap == NULL &&
86 attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_hasSubordinates ) == NULL &&
87 ( SLAP_OPATTRS( rs->sr_attr_flags ) ||
88 ad_inlist( slap_schema.si_ad_hasSubordinates, rs->sr_attrs ) ) )
89 {
90 int hasSubordinates, rc;
91
92 rc = wt_hasSubordinates( op, rs->sr_entry, &hasSubordinates );
93 if ( rc == LDAP_SUCCESS ) {
94 *ap = slap_operational_hasSubordinate( hasSubordinates == LDAP_COMPARE_TRUE );
95 assert( *ap != NULL );
96
97 ap = &(*ap)->a_next;
98 }
99 }
100
101 return LDAP_SUCCESS;
102 }
103
104 /*
105 * Local variables:
106 * indent-tabs-mode: t
107 * tab-width: 4
108 * c-basic-offset: 4
109 * End:
110 */