]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sql/entry-id.c
Revert ITS#3353 patch, it needs to be reworked.
[openldap] / servers / slapd / back-sql / entry-id.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 #include "ac/string.h"
28
29 #include "slap.h"
30 #include "proto-sql.h"
31
32 #ifdef BACKSQL_ARBITRARY_KEY
33 struct berval backsql_baseObject_bv = BER_BVC( BACKSQL_BASEOBJECT_IDSTR );
34 #endif /* BACKSQL_ARBITRARY_KEY */
35
36 backsql_entryID *
37 backsql_free_entryID( backsql_entryID *id, int freeit )
38 {
39         backsql_entryID         *next;
40
41         assert( id );
42
43         next = id->eid_next;
44
45         if ( !BER_BVISNULL( &id->eid_ndn ) ) {
46                 if ( !BER_BVISNULL( &id->eid_dn )
47                                 && id->eid_dn.bv_val != id->eid_ndn.bv_val )
48                 {
49                         free( id->eid_dn.bv_val );
50                         BER_BVZERO( &id->eid_dn );
51                 }
52
53                 free( id->eid_ndn.bv_val );
54                 BER_BVZERO( &id->eid_ndn );
55         }
56
57 #ifdef BACKSQL_ARBITRARY_KEY
58         if ( id->eid_id.bv_val ) {
59                 free( id->eid_id.bv_val );
60                 BER_BVZERO( &id->eid_id );
61         }
62
63         if ( id->eid_keyval.bv_val ) {
64                 free( id->eid_keyval.bv_val );
65                 BER_BVZERO( &id->eid_keyval );
66         }
67 #endif /* BACKSQL_ARBITRARY_KEY */
68
69         if ( freeit ) {
70                 free( id );
71         }
72
73         return next;
74 }
75
76 /*
77  * NOTE: the dn must be normalized
78  */
79 int
80 backsql_dn2id(
81         backsql_info            *bi,
82         backsql_entryID         *id,
83         SQLHDBC                 dbh,
84         struct berval           *ndn )
85 {
86         SQLHSTMT                sth; 
87         BACKSQL_ROW_NTS         row;
88         RETCODE                 rc;
89         int                     res;
90
91         /* TimesTen */
92         char                    upperdn[ BACKSQL_MAX_DN_LEN + 1 ];
93         struct berval           tbbDN;
94         int                     i, j;
95
96         /*
97          * NOTE: id can be NULL; in this case, the function
98          * simply checks whether the DN can be successfully 
99          * turned into an ID, returning LDAP_SUCCESS for
100          * positive cases, or the most appropriate error
101          */
102
103         Debug( LDAP_DEBUG_TRACE, "==>backsql_dn2id(): dn=\"%s\"%s\n", 
104                         ndn->bv_val, id == NULL ? " (no ID)" : "", 0 );
105
106         if ( ndn->bv_len > BACKSQL_MAX_DN_LEN ) {
107                 Debug( LDAP_DEBUG_TRACE, 
108                         "backsql_dn2id(): DN \"%s\" (%ld bytes) "
109                         "exceeds max DN length (%d):\n",
110                         ndn->bv_val, ndn->bv_len, BACKSQL_MAX_DN_LEN );
111                 return LDAP_OTHER;
112         }
113
114         /* return baseObject if available and matches */
115         if ( bi->sql_baseObject != NULL && dn_match( ndn, &bi->sql_baseObject->e_nname ) ) {
116                 if ( id != NULL ) {
117 #ifdef BACKSQL_ARBITRARY_KEY
118                         ber_dupbv( &id->eid_id, &backsql_baseObject_bv );
119                         ber_dupbv( &id->eid_keyval, &backsql_baseObject_bv );
120 #else /* ! BACKSQL_ARBITRARY_KEY */
121                         id->eid_id = BACKSQL_BASEOBJECT_ID;
122                         id->eid_keyval = BACKSQL_BASEOBJECT_KEYVAL;
123 #endif /* ! BACKSQL_ARBITRARY_KEY */
124                         id->eid_oc_id = BACKSQL_BASEOBJECT_OC;
125
126                         ber_dupbv( &id->eid_ndn, &bi->sql_baseObject->e_nname );
127                         ber_dupbv( &id->eid_dn, &bi->sql_baseObject->e_name );
128
129                         id->eid_next = NULL;
130                 }
131
132                 return LDAP_SUCCESS;
133         }
134         
135         /* begin TimesTen */
136         Debug( LDAP_DEBUG_TRACE, "id_query \"%s\"\n", bi->sql_id_query, 0, 0 );
137         assert( bi->sql_id_query );
138         rc = backsql_Prepare( dbh, &sth, bi->sql_id_query, 0 );
139         if ( rc != SQL_SUCCESS ) {
140                 Debug( LDAP_DEBUG_TRACE, 
141                         "backsql_dn2id(): error preparing SQL:\n%s", 
142                         bi->sql_id_query, 0, 0);
143                 backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
144                 SQLFreeStmt( sth, SQL_DROP );
145                 return LDAP_OTHER;
146         }
147
148         if ( BACKSQL_HAS_LDAPINFO_DN_RU( bi ) ) {
149                 /*
150                  * Prepare an upper cased, byte reversed version 
151                  * that can be searched using indexes
152                  */
153
154                 for ( i = 0, j = ndn->bv_len - 1; ndn->bv_val[ i ]; i++, j--) {
155                         upperdn[ i ] = ndn->bv_val[ j ];
156                 }
157                 upperdn[ i ] = '\0';
158                 ldap_pvt_str2upper( upperdn );
159
160                 Debug( LDAP_DEBUG_TRACE, "==>backsql_dn2id(): upperdn=\"%s\"\n",
161                                 upperdn, 0, 0 );
162                 ber_str2bv( upperdn, 0, 0, &tbbDN );
163
164         } else {
165                 if ( BACKSQL_USE_REVERSE_DN( bi ) ) {
166                         AC_MEMCPY( upperdn, ndn->bv_val, ndn->bv_len + 1 );
167                         ldap_pvt_str2upper( upperdn );
168                         Debug( LDAP_DEBUG_TRACE,
169                                 "==>backsql_dn2id(): upperdn=\"%s\"\n",
170                                 upperdn, 0, 0 );
171                         ber_str2bv( upperdn, 0, 0, &tbbDN );
172
173                 } else {
174                         tbbDN = *ndn;
175                 }
176         }
177
178         rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, &tbbDN );
179         if ( rc != SQL_SUCCESS) {
180                 /* end TimesTen */ 
181                 Debug( LDAP_DEBUG_TRACE, "backsql_dn2id(): "
182                         "error binding dn=\"%s\" parameter:\n", 
183                         tbbDN.bv_val, 0, 0 );
184                 backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
185                 SQLFreeStmt( sth, SQL_DROP );
186                 return LDAP_OTHER;
187         }
188
189         rc = SQLExecute( sth );
190         if ( rc != SQL_SUCCESS ) {
191                 Debug( LDAP_DEBUG_TRACE, "backsql_dn2id(): "
192                         "error executing query (\"%s\", \"%s\"):\n", 
193                         bi->sql_id_query, tbbDN.bv_val, 0 );
194                 backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
195                 SQLFreeStmt( sth, SQL_DROP );
196                 return LDAP_OTHER;
197         }
198
199         backsql_BindRowAsStrings( sth, &row );
200         rc = SQLFetch( sth );
201         if ( BACKSQL_SUCCESS( rc ) ) {
202                 char    buf[BUFSIZ];
203
204 #ifdef LDAP_DEBUG
205                 snprintf( buf, sizeof(buf),
206                         "id=%s keyval=%s oc_id=%s dn=%s",
207                         row.cols[ 0 ], row.cols[ 1 ],
208                         row.cols[ 2 ], row.cols[ 3 ] );
209                 Debug( LDAP_DEBUG_TRACE,
210                         "<==backsql_dn2id(): %s\n", buf, 0, 0 );
211 #endif /* LDAP_DEBUG */
212
213                 res = LDAP_SUCCESS;
214                 if ( id != NULL ) {
215                         struct berval   dn;
216
217 #ifdef BACKSQL_ARBITRARY_KEY
218                         ber_str2bv( row.cols[ 0 ], 0, 1, &id->eid_id );
219                         ber_str2bv( row.cols[ 1 ], 0, 1, &id->eid_keyval );
220 #else /* ! BACKSQL_ARBITRARY_KEY */
221                         id->eid_id = strtol( row.cols[ 0 ], NULL, 0 );
222                         id->eid_keyval = strtol( row.cols[ 1 ], NULL, 0 );
223 #endif /* ! BACKSQL_ARBITRARY_KEY */
224                         id->eid_oc_id = strtol( row.cols[ 2 ], NULL, 0 );
225
226                         ber_str2bv( row.cols[ 3 ], 0, 0, &dn );
227
228                         res = dnPrettyNormal( NULL, &dn, &id->eid_dn, &id->eid_ndn, NULL );
229                         if ( res != LDAP_SUCCESS ) {
230                                 Debug( LDAP_DEBUG_TRACE,
231                                         "<==backsql_dn2id(\"%s\"): "
232                                         "dnPrettyNormal failed (%d: %s)\n",
233                                         ndn->bv_val, res,
234                                         ldap_err2string( res ) );
235
236                                 /* cleanup... */
237                                 (void)backsql_free_entryID( id, 0 );
238                         }
239
240                         id->eid_next = NULL;
241                 }
242
243         } else {
244                 res = LDAP_NO_SUCH_OBJECT;
245                 Debug( LDAP_DEBUG_TRACE, "<==backsql_dn2id(): no match\n",
246                                 0, 0, 0 );
247         }
248         backsql_FreeRow( &row );
249
250         SQLFreeStmt( sth, SQL_DROP );
251         return res;
252 }
253
254 int
255 backsql_count_children(
256         backsql_info            *bi,
257         SQLHDBC                 dbh,
258         struct berval           *dn,
259         unsigned long           *nchildren )
260 {
261         SQLHSTMT                sth; 
262         BACKSQL_ROW_NTS         row;
263         RETCODE                 rc;
264         int                     res = LDAP_SUCCESS;
265
266         Debug( LDAP_DEBUG_TRACE, "==>backsql_count_children(): dn=\"%s\"\n", 
267                         dn->bv_val, 0, 0 );
268
269         if ( dn->bv_len > BACKSQL_MAX_DN_LEN ) {
270                 Debug( LDAP_DEBUG_TRACE, 
271                         "backsql_count_children(): DN \"%s\" (%ld bytes) "
272                         "exceeds max DN length (%d):\n",
273                         dn->bv_val, dn->bv_len, BACKSQL_MAX_DN_LEN );
274                 return LDAP_OTHER;
275         }
276         
277         /* begin TimesTen */
278         Debug(LDAP_DEBUG_TRACE, "children id query \"%s\"\n", 
279                         bi->sql_has_children_query, 0, 0);
280         assert( bi->sql_has_children_query );
281         rc = backsql_Prepare( dbh, &sth, bi->sql_has_children_query, 0 );
282         if ( rc != SQL_SUCCESS ) {
283                 Debug( LDAP_DEBUG_TRACE, 
284                         "backsql_count_children(): error preparing SQL:\n%s", 
285                         bi->sql_has_children_query, 0, 0);
286                 backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
287                 SQLFreeStmt( sth, SQL_DROP );
288                 return LDAP_OTHER;
289         }
290
291         rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, dn );
292         if ( rc != SQL_SUCCESS) {
293                 /* end TimesTen */ 
294                 Debug( LDAP_DEBUG_TRACE, "backsql_count_children(): "
295                         "error binding dn=\"%s\" parameter:\n", 
296                         dn->bv_val, 0, 0 );
297                 backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
298                 SQLFreeStmt( sth, SQL_DROP );
299                 return LDAP_OTHER;
300         }
301
302         rc = SQLExecute( sth );
303         if ( rc != SQL_SUCCESS ) {
304                 Debug( LDAP_DEBUG_TRACE, "backsql_count_children(): "
305                         "error executing query (\"%s\", \"%s\"):\n", 
306                         bi->sql_has_children_query, dn->bv_val, 0 );
307                 backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
308                 SQLFreeStmt( sth, SQL_DROP );
309                 return LDAP_OTHER;
310         }
311
312         backsql_BindRowAsStrings( sth, &row );
313         
314         rc = SQLFetch( sth );
315         if ( BACKSQL_SUCCESS( rc ) ) {
316                 char *end;
317
318                 *nchildren = strtol( row.cols[ 0 ], &end, 0 );
319                 if ( end[ 0 ] != '\0' && end[0] != '.' ) {
320                         /* FIXME: braindead RDBMSes return
321                          * a fractional number from COUNT!
322                          */
323                         res = LDAP_OTHER;
324                 }
325
326         } else {
327                 res = LDAP_OTHER;
328         }
329         backsql_FreeRow( &row );
330
331         SQLFreeStmt( sth, SQL_DROP );
332
333         Debug( LDAP_DEBUG_TRACE, "<==backsql_count_children(): %lu\n",
334                         *nchildren, 0, 0 );
335
336         return res;
337 }
338
339 int
340 backsql_has_children(
341         backsql_info            *bi,
342         SQLHDBC                 dbh,
343         struct berval           *dn )
344 {
345         unsigned long   nchildren;
346         int             rc;
347
348         rc = backsql_count_children( bi, dbh, dn, &nchildren );
349
350         if ( rc == LDAP_SUCCESS ) {
351                 return nchildren > 0 ? LDAP_COMPARE_TRUE : LDAP_COMPARE_FALSE;
352         }
353
354         return rc;
355 }
356
357 static int
358 backsql_get_attr_vals( void *v_at, void *v_bsi )
359 {
360         backsql_at_map_rec      *at = v_at;
361         backsql_srch_info       *bsi = v_bsi;
362         backsql_info            *bi = (backsql_info *)bsi->bsi_op->o_bd->be_private;
363         RETCODE                 rc;
364         SQLHSTMT                sth;
365         BACKSQL_ROW_NTS         row;
366         int                     i;
367
368         assert( at );
369         assert( bsi );
370
371 #ifdef BACKSQL_ARBITRARY_KEY
372         Debug( LDAP_DEBUG_TRACE, "==>backsql_get_attr_vals(): "
373                 "oc=\"%s\" attr=\"%s\" keyval=%s\n",
374                 BACKSQL_OC_NAME( bsi->bsi_oc ), at->bam_ad->ad_cname.bv_val, 
375                 bsi->bsi_c_eid->eid_keyval.bv_val );
376 #else /* ! BACKSQL_ARBITRARY_KEY */
377         Debug( LDAP_DEBUG_TRACE, "==>backsql_get_attr_vals(): "
378                 "oc=\"%s\" attr=\"%s\" keyval=%ld\n",
379                 BACKSQL_OC_NAME( bsi->bsi_oc ), at->bam_ad->ad_cname.bv_val, 
380                 bsi->bsi_c_eid->eid_keyval );
381 #endif /* ! BACKSQL_ARBITRARY_KEY */
382
383         rc = backsql_Prepare( bsi->bsi_dbh, &sth, at->bam_query, 0 );
384         if ( rc != SQL_SUCCESS ) {
385                 Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_values(): "
386                         "error preparing query: %s\n", at->bam_query, 0, 0 );
387                 backsql_PrintErrors( bi->sql_db_env, bsi->bsi_dbh, sth, rc );
388                 return 1;
389         }
390
391         rc = backsql_BindParamID( sth, 1, SQL_PARAM_INPUT,
392                         &bsi->bsi_c_eid->eid_keyval );
393         if ( rc != SQL_SUCCESS ) {
394                 Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_values(): "
395                         "error binding key value parameter\n", 0, 0, 0 );
396                 return 1;
397         }
398
399 #ifdef BACKSQL_TRACE
400 #ifdef BACKSQL_ARBITRARY_KEY
401         Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_values(): "
402                 "query=\"%s\" keyval=%s\n", at->bam_query,
403                 bsi->bsi_c_eid->eid_keyval.bv_val, 0 );
404 #else /* !BACKSQL_ARBITRARY_KEY */
405         Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_values(): "
406                 "query=\"%s\" keyval=%d\n", at->bam_query,
407                 bsi->bsi_c_eid->eid_keyval, 0 );
408 #endif /* ! BACKSQL_ARBITRARY_KEY */
409 #endif /* BACKSQL_TRACE */
410
411         rc = SQLExecute( sth );
412         if ( ! BACKSQL_SUCCESS( rc ) ) {
413                 Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_values(): "
414                         "error executing attribute query \"%s\"\n",
415                         at->bam_query, 0, 0 );
416                 backsql_PrintErrors( bi->sql_db_env, bsi->bsi_dbh, sth, rc );
417                 SQLFreeStmt( sth, SQL_DROP );
418                 return 1;
419         }
420
421         backsql_BindRowAsStrings( sth, &row );
422
423         rc = SQLFetch( sth );
424         for ( ; BACKSQL_SUCCESS( rc ); rc = SQLFetch( sth ) ) {
425                 for ( i = 0; i < row.ncols; i++ ) {
426                         if ( row.value_len[ i ] > 0 ) {
427                                 struct berval   bv;
428
429                                 bv.bv_val = row.cols[ i ];
430 #if 0
431                                 bv.bv_len = row.col_prec[ i ];
432 #else
433                                 /*
434                                  * FIXME: what if a binary 
435                                  * is fetched?
436                                  */
437                                 bv.bv_len = strlen( row.cols[ i ] );
438 #endif
439                                 backsql_entry_addattr( bsi->bsi_e, 
440                                                 &row.col_names[ i ], &bv,
441                                                 bsi->bsi_op->o_tmpmemctx );
442
443 #ifdef BACKSQL_TRACE
444                                 Debug( LDAP_DEBUG_TRACE, "prec=%d\n",
445                                         (int)row.col_prec[ i ], 0, 0 );
446                         } else {
447                                 Debug( LDAP_DEBUG_TRACE, "NULL value "
448                                         "in this row for attribute \"%s\"\n",
449                                         row.col_names[ i ].bv_val, 0, 0 );
450 #endif /* BACKSQL_TRACE */
451                         }
452                 }
453         }
454
455         backsql_FreeRow( &row );
456         SQLFreeStmt( sth, SQL_DROP );
457         Debug( LDAP_DEBUG_TRACE, "<==backsql_get_attr_vals()\n", 0, 0, 0 );
458
459         if ( at->bam_next ) {
460                 return backsql_get_attr_vals( at->bam_next, v_bsi );
461         }
462
463         return 1;
464 }
465
466 int
467 backsql_id2entry( backsql_srch_info *bsi, backsql_entryID *eid )
468 {
469         backsql_info            *bi = (backsql_info *)bsi->bsi_op->o_bd->be_private;
470         int                     i;
471         int                     rc;
472         AttributeDescription    *ad_oc = slap_schema.si_ad_objectClass;
473
474         Debug( LDAP_DEBUG_TRACE, "==>backsql_id2entry()\n", 0, 0, 0 );
475
476         assert( bsi->bsi_e );
477
478         memset( bsi->bsi_e, 0, sizeof( Entry ) );
479
480         if ( bi->sql_baseObject && BACKSQL_IS_BASEOBJECT_ID( &eid->eid_id ) ) {
481                 Entry   *e;
482
483                 e = entry_dup( bi->sql_baseObject );
484                 if ( e == NULL ) {
485                         return LDAP_NO_MEMORY;
486                 }
487                         
488                 *bsi->bsi_e = *e;
489                 free( e );
490                 goto done;
491         }
492
493         ber_dupbv_x( &bsi->bsi_e->e_name, &eid->eid_dn, bsi->bsi_op->o_tmpmemctx );
494         ber_dupbv_x( &bsi->bsi_e->e_nname, &eid->eid_ndn, bsi->bsi_op->o_tmpmemctx );
495
496         bsi->bsi_e->e_attrs = NULL;
497         bsi->bsi_e->e_private = NULL;
498
499         bsi->bsi_oc = backsql_id2oc( bsi->bsi_op->o_bd->be_private,
500                         eid->eid_oc_id );
501         bsi->bsi_c_eid = eid;
502
503 #ifndef BACKSQL_ARBITRARY_KEY   
504         bsi->bsi_e->e_id = eid->eid_id;
505 #endif /* ! BACKSQL_ARBITRARY_KEY */
506  
507         rc = attr_merge_normalize_one( bsi->bsi_e, ad_oc,
508                                 &bsi->bsi_oc->bom_oc->soc_cname,
509                                 bsi->bsi_op->o_tmpmemctx );
510         if ( rc != LDAP_SUCCESS ) {
511                 entry_clean( bsi->bsi_e );
512                 return rc;
513         }
514
515         if ( bsi->bsi_attrs != NULL ) {
516                 Debug( LDAP_DEBUG_TRACE, "backsql_id2entry(): "
517                         "custom attribute list\n", 0, 0, 0 );
518                 for ( i = 0; bsi->bsi_attrs[ i ].an_name.bv_val; i++ ) {
519                         backsql_at_map_rec      **vat;
520                         AttributeName           *an = &bsi->bsi_attrs[ i ];
521                         int                     j;
522
523                         /* if one of the attributes listed here is
524                          * a subtype of another, it must be ignored,
525                          * because subtypes are already dealt with
526                          * by backsql_supad2at()
527                          */
528                         for ( j = 0; bsi->bsi_attrs[ j ].an_name.bv_val; j++ ) {
529                                 /* skip self */
530                                 if ( j == i ) {
531                                         continue;
532                                 }
533
534                                 /* skip subtypes */
535                                 if ( is_at_subtype( an->an_desc->ad_type,
536                                                         bsi->bsi_attrs[ j ].an_desc->ad_type ) )
537                                 {
538                                         goto next;
539                                 }
540                         }
541
542                         rc = backsql_supad2at( bsi->bsi_oc, an->an_desc, &vat );
543                         if ( rc != 0 || vat == NULL ) {
544                                 Debug( LDAP_DEBUG_TRACE, "backsql_id2entry(): "
545                                                 "attribute \"%s\" is not defined "
546                                                 "for objectlass \"%s\"\n",
547                                                 an->an_name.bv_val, 
548                                                 BACKSQL_OC_NAME( bsi->bsi_oc ), 0 );
549                                 continue;
550                         }
551
552                         for ( j = 0; vat[j]; j++ ) {
553                                 backsql_get_attr_vals( vat[j], bsi );
554                         }
555
556                         ch_free( vat );
557
558 next:;
559                 }
560
561         } else {
562                 Debug( LDAP_DEBUG_TRACE, "backsql_id2entry(): "
563                         "retrieving all attributes\n", 0, 0, 0 );
564                 avl_apply( bsi->bsi_oc->bom_attrs, backsql_get_attr_vals,
565                                 bsi, 0, AVL_INORDER );
566         }
567
568         if ( global_schemacheck ) {
569                 const char      *text = NULL;
570                 char            textbuf[ 1024 ];
571                 size_t          textlen = sizeof( textbuf );
572                 struct berval   bv[ 2 ];
573                 struct berval   soc;
574                 int rc;
575
576                 bv[ 0 ] = bsi->bsi_oc->bom_oc->soc_cname;
577                 bv[ 1 ].bv_val = NULL;
578
579                 rc = structural_class( bv, &soc, NULL, 
580                                 &text, textbuf, textlen );
581                 if ( rc != LDAP_SUCCESS ) {
582                         Debug( LDAP_DEBUG_TRACE, "backsql_id2entry(%s): "
583                                 "structural_class() failed %d (%s)\n",
584                                 bsi->bsi_e->e_name.bv_val,
585                                 rc, text ? text : "" );
586                         entry_clean( bsi->bsi_e );
587                         return rc;
588                 }
589
590                 if ( ( bsi->bsi_flags | BSQL_SF_ALL_OPER )
591                                 || an_find( bsi->bsi_attrs, &AllOper ) ) {
592                         rc = attr_merge_normalize_one( bsi->bsi_e,
593                                         slap_schema.si_ad_structuralObjectClass,
594                                         &soc, bsi->bsi_op->o_tmpmemctx );
595                         if ( rc != LDAP_SUCCESS ) {
596                                 entry_clean( bsi->bsi_e );
597                                 return rc;
598                         }
599                 }
600         }
601
602 done:;
603         Debug( LDAP_DEBUG_TRACE, "<==backsql_id2entry()\n", 0, 0, 0 );
604
605         return LDAP_SUCCESS;
606 }
607
608 #endif /* SLAPD_SQL */
609