2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2005 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 #ifdef BACKSQL_SYNCPROV
84 if ( op->o_sync && op->o_tag == LDAP_REQ_SEARCH ) {
85 assert( op->o_private );
87 entryCSN = *((struct berval *)op->o_private);
90 #endif /* BACKSQL_SYNCPROV */
92 slap_get_csn( op, csnbuf, sizeof(csnbuf), &entryCSN, 0 );
95 ber_dupbv( &a->a_vals[ 0 ], &entryCSN );
97 a->a_nvals = a->a_vals;
111 backsql_info *bi = (backsql_info*)op->o_bd->be_private;
112 SQLHDBC dbh = SQL_NULL_HDBC;
116 BACKSQL_OP_HASSUBORDINATES = 0,
117 BACKSQL_OP_ENTRYUUID,
122 int get_conn = BACKSQL_OP_LAST,
123 got[ BACKSQL_OP_LAST ] = { 0 };
125 Debug( LDAP_DEBUG_TRACE, "==>backsql_operational(): entry \"%s\"\n",
126 rs->sr_entry->e_nname.bv_val, 0, 0 );
128 for ( ap = &rs->sr_operational_attrs; *ap; ap = &(*ap)->a_next ) {
129 if ( (*ap)->a_desc == slap_schema.si_ad_hasSubordinates ) {
131 got[ BACKSQL_OP_HASSUBORDINATES ] = 1;
133 } else if ( (*ap)->a_desc == slap_schema.si_ad_entryUUID ) {
135 got[ BACKSQL_OP_ENTRYUUID ] = 1;
137 } else if ( (*ap)->a_desc == slap_schema.si_ad_entryCSN ) {
139 got[ BACKSQL_OP_ENTRYCSN ] = 1;
147 rc = backsql_get_db_conn( op, &dbh );
148 if ( rc != LDAP_SUCCESS ) {
149 Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
150 "could not get connection handle - exiting\n",
155 if ( ( SLAP_OPATTRS( rs->sr_attr_flags ) || ad_inlist( slap_schema.si_ad_hasSubordinates, rs->sr_attrs ) )
156 && !got[ BACKSQL_OP_HASSUBORDINATES ]
157 && attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_hasSubordinates ) == NULL )
159 rc = backsql_has_children( bi, dbh, &rs->sr_entry->e_nname );
162 case LDAP_COMPARE_TRUE:
163 case LDAP_COMPARE_FALSE:
164 *ap = slap_operational_hasSubordinate( rc == LDAP_COMPARE_TRUE );
171 Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
172 "has_children failed( %d)\n", rc, 0, 0 );
177 if ( ( SLAP_OPATTRS( rs->sr_attr_flags ) || ad_inlist( slap_schema.si_ad_entryUUID, rs->sr_attrs ) )
178 && !got[ BACKSQL_OP_ENTRYUUID ]
179 && attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID ) == NULL )
181 backsql_srch_info bsi;
183 rc = backsql_init_search( &bsi, &rs->sr_entry->e_nname,
185 SLAP_NO_LIMIT, SLAP_NO_LIMIT,
186 (time_t)(-1), NULL, dbh, op, rs, NULL,
187 BACKSQL_ISF_GET_ID );
188 if ( rc != LDAP_SUCCESS ) {
189 Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
190 "could not retrieve entry ID - no such entry\n",
195 *ap = backsql_operational_entryUUID( bi, &bsi.bsi_base_id );
197 (void)backsql_free_entryID( &bsi.bsi_base_id, 0 );
200 Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
201 "could not retrieve entryUUID\n",
209 if ( ( SLAP_OPATTRS( rs->sr_attr_flags ) || ad_inlist( slap_schema.si_ad_entryCSN, rs->sr_attrs ) )
210 && !got[ BACKSQL_OP_ENTRYCSN ]
211 && attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryCSN ) == NULL )
213 *ap = backsql_operational_entryCSN( op );
215 Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
216 "could not retrieve entryCSN\n",
224 Debug( LDAP_DEBUG_TRACE, "<==backsql_operational(%d)\n", rc, 0, 0);