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