]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/operational.c
NVALUES: fix a couple of value_find_ex() calls
[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
18 /*
19  * sets *hasSubordinates to LDAP_COMPARE_TRUE/LDAP_COMPARE_FALSE
20  * if the entry has children or not.
21  */
22 int
23 bdb_hasSubordinates(
24         BackendDB       *be,
25         Connection      *conn, 
26         Operation       *op,
27         Entry           *e,
28         int             *hasSubordinates )
29 {
30         int             rc;
31         
32         assert( e );
33         assert( hasSubordinates );
34
35 retry:
36         rc = bdb_dn2id_children( be, NULL, &e->e_nname, 0 );
37         
38         switch( rc ) {
39         case DB_LOCK_DEADLOCK:
40         case DB_LOCK_NOTGRANTED:
41                 ldap_pvt_thread_yield();
42                 goto retry;
43
44         case 0:
45                 *hasSubordinates = LDAP_COMPARE_TRUE;
46                 break;
47
48         case DB_NOTFOUND:
49                 *hasSubordinates = LDAP_COMPARE_FALSE;
50                 rc = LDAP_SUCCESS;
51                 break;
52
53         default:
54 #ifdef NEW_LOGGING
55                 LDAP_LOG ( OPERATION, ERR, 
56                         "=> bdb_hasSubordinates: has_children failed: %s (%d)\n",
57                         db_strerror(rc), rc, 0 );
58 #else
59                 Debug(LDAP_DEBUG_ARGS, 
60                         "<=- bdb_hasSubordinates: has_children failed: %s (%d)\n", 
61                         db_strerror(rc), rc, 0 );
62 #endif
63                 rc = LDAP_OTHER;
64         }
65
66         return rc;
67 }
68
69 /*
70  * sets the supported operational attributes (if required)
71  */
72 int
73 bdb_operational(
74         BackendDB       *be,
75         Connection      *conn, 
76         Operation       *op,
77         Entry           *e,
78         AttributeName           *attrs,
79         int             opattrs,
80         Attribute       **a )
81 {
82         Attribute       **aa = a;
83         int             rc = 0;
84         
85         assert( e );
86
87         if ( opattrs || ad_inlist( slap_schema.si_ad_hasSubordinates, attrs ) ) {
88                 int     hasSubordinates;
89
90                 rc = bdb_hasSubordinates( be, conn, op, e, &hasSubordinates );
91                 if ( rc == LDAP_SUCCESS ) {
92                         *aa = slap_operational_hasSubordinate( hasSubordinates == LDAP_COMPARE_TRUE );
93                         if ( *aa != NULL ) {
94                                 aa = &(*aa)->a_next;
95                         }
96                 }
97         }
98
99         return rc;
100 }
101