]> git.sur5r.net Git - openldap/blob - servers/slapd/back-wt/operational.c
e2485cc988c84bd3a4a7115df07b9a64bc874a34
[openldap] / servers / slapd / back-wt / operational.c
1 /* OpenLDAP WiredTiger backend */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2002-2015 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 <hamano@osstech.co.jp>
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 "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                            LDAP_XSTRING(wt_compare)
46                            ": wt_ctx_get failed\n",
47                            0, 0, 0 );
48                 return LDAP_OTHER;
49         }
50
51         rc = wt_dn2id_has_children(op, wc->session, e->e_id);
52         switch(rc){
53         case 0:
54                 *hasSubordinates = LDAP_COMPARE_TRUE;
55                 break;
56         case WT_NOTFOUND:
57                 *hasSubordinates = LDAP_COMPARE_FALSE;
58                 rc = LDAP_SUCCESS;
59                 break;
60         default:
61                 Debug(LDAP_DEBUG_ANY,
62                           "<=- " LDAP_XSTRING(wt_hasSubordinates)
63                           ": has_children failed: %s (%d)\n",
64                           wiredtiger_strerror(rc), rc, 0 );
65                 rc = LDAP_OTHER;
66         }
67         return rc;
68 }
69
70 /*
71  * sets the supported operational attributes (if required)
72  */
73 int
74 wt_operational(
75         Operation *op,
76         SlapReply *rs )
77 {
78         Attribute   **ap;
79
80         assert( rs->sr_entry != NULL );
81
82         for ( ap = &rs->sr_operational_attrs; *ap; ap = &(*ap)->a_next ) {
83                 if ( (*ap)->a_desc == slap_schema.si_ad_hasSubordinates ) {
84                         break;
85                 }
86         }
87
88         if ( *ap == NULL &&
89                  attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_hasSubordinates ) == NULL &&
90                  ( SLAP_OPATTRS( rs->sr_attr_flags ) ||
91                    ad_inlist( slap_schema.si_ad_hasSubordinates, rs->sr_attrs ) ) )
92         {
93                 int hasSubordinates, rc;
94
95                 rc = wt_hasSubordinates( op, rs->sr_entry, &hasSubordinates );
96                 if ( rc == LDAP_SUCCESS ) {
97                         *ap = slap_operational_hasSubordinate( hasSubordinates == LDAP_COMPARE_TRUE );
98                         assert( *ap != NULL );
99
100                         ap = &(*ap)->a_next;
101                 }
102         }
103
104         return LDAP_SUCCESS;
105 }
106
107 /*
108  * Local variables:
109  * indent-tabs-mode: t
110  * tab-width: 4
111  * c-basic-offset: 4
112  * End:
113  */