]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/operational.c
silence warning
[openldap] / servers / slapd / back-bdb / operational.c
1 /* operational.c - bdb backend operational attributes function */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2000-2004 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-bdb.h"
26 #include "external.h"
27
28 /*
29  * sets *hasSubordinates to LDAP_COMPARE_TRUE/LDAP_COMPARE_FALSE
30  * if the entry has children or not.
31  */
32 int
33 bdb_hasSubordinates(
34         Operation       *op,
35         Entry           *e,
36         int             *hasSubordinates )
37 {
38         int             rc;
39         
40         assert( e );
41
42         /* NOTE: this should never happen, but it actually happens
43          * when using back-relay; until we find a better way to
44          * preserve entry's private information while rewriting it,
45          * let's disable the hasSubordinate feature for back-relay.
46          */
47         if ( BEI( e ) == NULL ) {
48                 return LDAP_OTHER;
49         }
50
51 retry:
52         /* FIXME: we can no longer assume the entry's e_private
53          * field is correctly populated; so we need to reacquire
54          * it with reader lock */
55         rc = bdb_cache_children( op, NULL, e );
56         
57         switch( rc ) {
58         case DB_LOCK_DEADLOCK:
59         case DB_LOCK_NOTGRANTED:
60                 ldap_pvt_thread_yield();
61                 goto retry;
62
63         case 0:
64                 *hasSubordinates = LDAP_COMPARE_TRUE;
65                 break;
66
67         case DB_NOTFOUND:
68                 *hasSubordinates = LDAP_COMPARE_FALSE;
69                 rc = LDAP_SUCCESS;
70                 break;
71
72         default:
73 #ifdef NEW_LOGGING
74                 LDAP_LOG ( OPERATION, ERR, 
75                         "=> bdb_hasSubordinates: has_children failed: %s (%d)\n",
76                         db_strerror(rc), rc, 0 );
77 #else
78                 Debug(LDAP_DEBUG_ARGS, 
79                         "<=- bdb_hasSubordinates: has_children failed: %s (%d)\n", 
80                         db_strerror(rc), rc, 0 );
81 #endif
82                 rc = LDAP_OTHER;
83         }
84
85         return rc;
86 }
87
88 /*
89  * sets the supported operational attributes (if required)
90  */
91 int
92 bdb_operational(
93         Operation       *op,
94         SlapReply       *rs,
95         int             opattrs,
96         Attribute       **a )
97 {
98         Attribute       **aa = a;
99         
100         assert( rs->sr_entry );
101
102         if ( opattrs || ad_inlist( slap_schema.si_ad_hasSubordinates, rs->sr_attrs ) ) {
103                 int     hasSubordinates;
104
105                 rs->sr_err = bdb_hasSubordinates( op, rs->sr_entry, &hasSubordinates );
106                 if ( rs->sr_err == LDAP_SUCCESS ) {
107                         *aa = slap_operational_hasSubordinate( hasSubordinates == LDAP_COMPARE_TRUE );
108                         if ( *aa != NULL ) {
109                                 aa = &(*aa)->a_next;
110                         }
111                 }
112         }
113
114         return rs->sr_err;
115 }
116