]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sql/operational.c
rework op/rs structures to deal with opeartional attributes
[openldap] / servers / slapd / back-sql / operational.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1999-2004 The OpenLDAP Foundation.
5  * Portions Copyright 1999 Dmitry Kovalev.
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 /* ACKNOWLEDGEMENTS:
17  * This work was initially developed by Dmitry Kovalev for inclusion
18  * by OpenLDAP Software.
19  */
20
21 #include "portable.h"
22
23 #ifdef SLAPD_SQL
24
25 #include <stdio.h>
26 #include <sys/types.h>
27
28 #include "slap.h"
29 #include "proto-sql.h"
30
31 /*
32  * sets the supported operational attributes (if required)
33  */
34
35 int
36 backsql_operational(
37         Operation       *op,
38         SlapReply       *rs )
39 {
40
41         backsql_info    *bi = (backsql_info*)op->o_bd->be_private;
42         SQLHDBC         dbh = SQL_NULL_HDBC;
43         int             rc = 0;
44         Attribute       **ap;
45
46         Debug( LDAP_DEBUG_TRACE, "==>backsql_operational(): entry \"%s\"\n",
47                         rs->sr_entry->e_nname.bv_val, 0, 0 );
48
49         for ( ap = &rs->sr_operational_attrs; *ap; ap = &(*ap)->a_next )
50                 /* just count */ ;
51
52         if ( ( rs->sr_opattrs == SLAP_OPATTRS || ad_inlist( slap_schema.si_ad_hasSubordinates, rs->sr_attrs ) ) 
53                         && attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_hasSubordinates ) == NULL ) {
54                 
55                 rc = backsql_get_db_conn( op, &dbh );
56                 if ( rc != LDAP_SUCCESS ) {
57                         Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
58                                 "could not get connection handle - exiting\n", 
59                                 0, 0, 0 );
60                         return 1;
61                 }
62                 
63                 rc = backsql_has_children( bi, dbh, &rs->sr_entry->e_nname );
64
65                 switch( rc ) {
66                 case LDAP_COMPARE_TRUE:
67                 case LDAP_COMPARE_FALSE:
68                         *ap = slap_operational_hasSubordinate( rc == LDAP_COMPARE_TRUE );
69                         assert( *ap );
70                         ap = &(*ap)->a_next;
71                         rc = 0;
72                         break;
73
74                 default:
75                         Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
76                                 "has_children failed( %d)\n", rc, 0, 0 );
77                         rc = 1;
78                         break;
79                 }
80         }
81
82         Debug( LDAP_DEBUG_TRACE, "<==backsql_operational()\n", 0, 0, 0);
83
84         return rc;
85 }
86
87 #endif /* SLAPD_SQL */
88