2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2004 The OpenLDAP Foundation.
5 * Portions Copyright 1999 Dmitry Kovalev.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
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>.
17 * This work was initially developed by Dmitry Kovalev for inclusion
18 * by OpenLDAP Software.
24 #include <sys/types.h>
27 #include "proto-sql.h"
31 * sets the supported operational attributes (if required)
35 backsql_operational_entryUUID( backsql_info *bi, backsql_entryID *id )
38 struct berval val, nval;
39 AttributeDescription *desc = slap_schema.si_ad_entryUUID;
42 backsql_entryUUID( bi, id, &val, NULL );
44 rc = (*desc->ad_type->sat_equality->smr_normalize)(
45 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
46 desc->ad_type->sat_syntax,
47 desc->ad_type->sat_equality,
49 if ( rc != LDAP_SUCCESS ) {
50 ber_memfree( val.bv_val );
54 a = ch_malloc( sizeof( Attribute ) );
57 a->a_vals = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
59 BER_BVZERO( &a->a_vals[ 1 ] );
61 a->a_nvals = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
62 a->a_nvals[ 0 ] = nval;
63 BER_BVZERO( &a->a_nvals[ 1 ] );
72 backsql_operational_entryCSN( Operation *op )
74 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
75 struct berval entryCSN;
78 a = ch_malloc( sizeof( Attribute ) );
79 a->a_desc = slap_schema.si_ad_entryCSN;
80 a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
81 BER_BVZERO( &a->a_vals[ 1 ] );
83 slap_get_csn( op, csnbuf, sizeof(csnbuf), &entryCSN, 0 );
84 ber_dupbv( &a->a_vals[ 0 ], &entryCSN );
86 a->a_nvals = a->a_vals;
100 backsql_info *bi = (backsql_info*)op->o_bd->be_private;
101 SQLHDBC dbh = SQL_NULL_HDBC;
105 BACKSQL_OP_HASSUBORDINATES = 0,
106 BACKSQL_OP_ENTRYUUID,
111 int get_conn = BACKSQL_OP_LAST,
112 got[ BACKSQL_OP_LAST ] = { 0 };
114 Debug( LDAP_DEBUG_TRACE, "==>backsql_operational(): entry \"%s\"\n",
115 rs->sr_entry->e_nname.bv_val, 0, 0 );
117 for ( ap = &rs->sr_operational_attrs; *ap; ap = &(*ap)->a_next ) {
118 if ( (*ap)->a_desc == slap_schema.si_ad_hasSubordinates ) {
120 got[ BACKSQL_OP_HASSUBORDINATES ] = 1;
122 } else if ( (*ap)->a_desc == slap_schema.si_ad_entryUUID ) {
124 got[ BACKSQL_OP_ENTRYUUID ] = 1;
126 } else if ( (*ap)->a_desc == slap_schema.si_ad_entryCSN ) {
128 got[ BACKSQL_OP_ENTRYCSN ] = 1;
136 rc = backsql_get_db_conn( op, &dbh );
137 if ( rc != LDAP_SUCCESS ) {
138 Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
139 "could not get connection handle - exiting\n",
144 if ( ( SLAP_OPATTRS( rs->sr_attr_flags ) || ad_inlist( slap_schema.si_ad_hasSubordinates, rs->sr_attrs ) )
145 && !got[ BACKSQL_OP_HASSUBORDINATES ]
146 && attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_hasSubordinates ) == NULL )
148 rc = backsql_has_children( bi, dbh, &rs->sr_entry->e_nname );
151 case LDAP_COMPARE_TRUE:
152 case LDAP_COMPARE_FALSE:
153 *ap = slap_operational_hasSubordinate( rc == LDAP_COMPARE_TRUE );
160 Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
161 "has_children failed( %d)\n", rc, 0, 0 );
166 if ( ( SLAP_OPATTRS( rs->sr_attr_flags ) || ad_inlist( slap_schema.si_ad_entryUUID, rs->sr_attrs ) )
167 && !got[ BACKSQL_OP_ENTRYUUID ]
168 && attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID ) == NULL )
171 backsql_srch_info bsi;
173 ndn = rs->sr_entry->e_nname;
174 if ( backsql_api_dn2odbc( op, rs, &ndn ) ) {
175 Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
176 "backsql_api_dn2odbc failed\n",
181 rc = backsql_init_search( &bsi, &ndn, LDAP_SCOPE_BASE,
182 -1, -1, -1, NULL, dbh, op, rs, NULL, 1 );
183 if ( rc != LDAP_SUCCESS ) {
184 Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
185 "could not retrieve entry ID - no such entry\n",
190 *ap = backsql_operational_entryUUID( bi, &bsi.bsi_base_id );
192 (void)backsql_free_entryID( &bsi.bsi_base_id, 0 );
194 if ( ndn.bv_val != rs->sr_entry->e_nname.bv_val ) {
199 Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
200 "could not retrieve entryUUID\n",
208 if ( ( SLAP_OPATTRS( rs->sr_attr_flags ) || ad_inlist( slap_schema.si_ad_entryCSN, rs->sr_attrs ) )
209 && !got[ BACKSQL_OP_ENTRYCSN ]
210 && attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryCSN ) == NULL )
212 *ap = backsql_operational_entryCSN( op );
214 Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
215 "could not retrieve entryCSN\n",
223 Debug( LDAP_DEBUG_TRACE, "<==backsql_operational(%d)\n", rc, 0, 0);