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