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