]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/operational.c
Happy new year! (belated)
[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-2008 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 != NULL );
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                 goto retry;
60
61         case 0:
62                 *hasSubordinates = LDAP_COMPARE_TRUE;
63                 break;
64
65         case DB_NOTFOUND:
66                 *hasSubordinates = LDAP_COMPARE_FALSE;
67                 rc = LDAP_SUCCESS;
68                 break;
69
70         default:
71                 Debug(LDAP_DEBUG_ARGS, 
72                         "<=- " LDAP_XSTRING(bdb_hasSubordinates)
73                         ": has_children failed: %s (%d)\n", 
74                         db_strerror(rc), rc, 0 );
75                 rc = LDAP_OTHER;
76         }
77
78         return rc;
79 }
80
81 /*
82  * sets the supported operational attributes (if required)
83  */
84 int
85 bdb_operational(
86         Operation       *op,
87         SlapReply       *rs )
88 {
89         Attribute       **ap;
90
91         assert( rs->sr_entry != NULL );
92
93         for ( ap = &rs->sr_operational_attrs; *ap; ap = &(*ap)->a_next )
94                 /* just count */ ;
95
96         if ( SLAP_OPATTRS( rs->sr_attr_flags ) ||
97                         ad_inlist( slap_schema.si_ad_hasSubordinates, rs->sr_attrs ) )
98         {
99                 int     hasSubordinates, rc;
100
101                 rc = bdb_hasSubordinates( op, rs->sr_entry, &hasSubordinates );
102                 if ( rc == LDAP_SUCCESS ) {
103                         *ap = slap_operational_hasSubordinate( hasSubordinates == LDAP_COMPARE_TRUE );
104                         assert( *ap != NULL );
105
106                         ap = &(*ap)->a_next;
107                 }
108         }
109
110         return LDAP_SUCCESS;
111 }
112