]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/operational.c
Fix AVL comparisons
[openldap] / servers / slapd / back-bdb / operational.c
1 /* operational.c - bdb backend operational attributes function */
2 /*
3  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #include "portable.h"
8
9 #include <stdio.h>
10
11 #include <ac/string.h>
12 #include <ac/socket.h>
13
14 #include "slap.h"
15 #include "back-bdb.h"
16 #include "proto-bdb.h"
17 #include "external.h"
18
19 /*
20  * sets *hasSubordinates to LDAP_COMPARE_TRUE/LDAP_COMPARE_FALSE
21  * if the entry has children or not.
22  */
23 int
24 bdb_hasSubordinates(
25         Operation       *op,
26         Entry           *e,
27         int             *hasSubordinates )
28 {
29         int             rc;
30         
31         assert( e );
32
33 retry:
34         rc = bdb_dn2id_children( op, NULL, e );
35         
36         switch( rc ) {
37         case DB_LOCK_DEADLOCK:
38         case DB_LOCK_NOTGRANTED:
39                 ldap_pvt_thread_yield();
40                 goto retry;
41
42         case 0:
43                 *hasSubordinates = LDAP_COMPARE_TRUE;
44                 break;
45
46         case DB_NOTFOUND:
47                 *hasSubordinates = LDAP_COMPARE_FALSE;
48                 rc = LDAP_SUCCESS;
49                 break;
50
51         default:
52 #ifdef NEW_LOGGING
53                 LDAP_LOG ( OPERATION, ERR, 
54                         "=> bdb_hasSubordinates: has_children failed: %s (%d)\n",
55                         db_strerror(rc), rc, 0 );
56 #else
57                 Debug(LDAP_DEBUG_ARGS, 
58                         "<=- bdb_hasSubordinates: has_children failed: %s (%d)\n", 
59                         db_strerror(rc), rc, 0 );
60 #endif
61                 rc = LDAP_OTHER;
62         }
63
64         return rc;
65 }
66
67 /*
68  * sets the supported operational attributes (if required)
69  */
70 int
71 bdb_operational(
72         Operation       *op,
73         SlapReply       *rs,
74         int             opattrs,
75         Attribute       **a )
76 {
77         Attribute       **aa = a;
78         
79         assert( rs->sr_entry );
80
81         if ( opattrs || ad_inlist( slap_schema.si_ad_hasSubordinates, rs->sr_attrs ) ) {
82                 int     hasSubordinates;
83
84                 rs->sr_err = bdb_hasSubordinates( op, rs->sr_entry, &hasSubordinates );
85                 if ( rs->sr_err == LDAP_SUCCESS ) {
86                         *aa = slap_operational_hasSubordinate( hasSubordinates == LDAP_COMPARE_TRUE );
87                         if ( *aa != NULL ) {
88                                 aa = &(*aa)->a_next;
89                         }
90                 }
91         }
92
93         return rs->sr_err;
94 }
95