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.
6 * Portions Copyright 2002 Pierangelo Masarati.
7 * Portions Copyright 2004 Mark Adamson.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
19 * This work was initially developed by Dmitry Kovalev for inclusion
20 * by OpenLDAP Software. Additional significant contributors include
21 * Pierangelo Masarati.
27 #include "ac/string.h"
28 #include <sys/types.h>
32 #include "proto-sql.h"
53 backsql_info *bi = (backsql_info *)be->be_private;
55 Debug( LDAP_DEBUG_TRACE, "==>backsql_db_config()\n", 0, 0, 0 );
58 if ( !strcasecmp( argv[ 0 ], "dbhost" ) ) {
60 Debug( LDAP_DEBUG_TRACE,
61 "<==backsql_db_config (%s line %d): "
62 "missing hostname in \"dbhost\" directive\n",
66 bi->sql_dbhost = ch_strdup( argv[ 1 ] );
67 Debug( LDAP_DEBUG_TRACE,
68 "<==backsql_db_config(): hostname=%s\n",
69 bi->sql_dbhost, 0, 0 );
71 } else if ( !strcasecmp( argv[ 0 ], "dbuser" ) ) {
73 Debug( LDAP_DEBUG_TRACE,
74 "<==backsql_db_config (%s line %d): "
75 "missing username in \"dbuser\" directive\n",
79 bi->sql_dbuser = ch_strdup( argv[ 1 ] );
80 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): dbuser=%s\n",
81 bi->sql_dbuser, 0, 0 );
83 } else if ( !strcasecmp( argv[ 0 ], "dbpasswd" ) ) {
85 Debug( LDAP_DEBUG_TRACE,
86 "<==backsql_db_config (%s line %d): "
87 "missing password in \"dbpasswd\" directive\n",
91 bi->sql_dbpasswd = ch_strdup( argv[ 1 ] );
92 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
93 "dbpasswd=%s\n", /* bi->sql_dbpasswd */ "xxxx", 0, 0 );
95 } else if ( !strcasecmp( argv[ 0 ], "dbname" ) ) {
97 Debug( LDAP_DEBUG_TRACE,
98 "<==backsql_db_config (%s line %d): "
99 "missing database name in \"dbname\" "
100 "directive\n", fname, lineno, 0 );
103 bi->sql_dbname = ch_strdup( argv[ 1 ] );
104 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): dbname=%s\n",
105 bi->sql_dbname, 0, 0 );
107 } else if ( !strcasecmp( argv[ 0 ], "concat_pattern" ) ) {
109 Debug( LDAP_DEBUG_TRACE,
110 "<==backsql_db_config (%s line %d): "
112 "in \"concat_pattern\" directive\n",
116 if ( backsql_split_pattern( argv[ 1 ], &bi->sql_concat_func, 2 ) ) {
117 Debug( LDAP_DEBUG_TRACE,
118 "<==backsql_db_config (%s line %d): "
119 "unable to parse pattern \"%s\"\n"
120 "in \"concat_pattern\" directive\n",
121 fname, lineno, argv[ 1 ] );
124 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
125 "concat_pattern=\"%s\"\n", argv[ 1 ], 0, 0 );
127 } else if ( !strcasecmp( argv[ 0 ], "subtree_cond" ) ) {
129 Debug( LDAP_DEBUG_TRACE,
130 "<==backsql_db_config (%s line %d): "
131 "missing SQL condition "
132 "in \"subtree_cond\" directive\n",
136 ber_str2bv( argv[ 1 ], 0, 1, &bi->sql_subtree_cond );
137 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
138 "subtree_cond=%s\n", bi->sql_subtree_cond.bv_val, 0, 0 );
140 } else if ( !strcasecmp( argv[ 0 ], "children_cond" ) ) {
142 Debug( LDAP_DEBUG_TRACE,
143 "<==backsql_db_config (%s line %d): "
144 "missing SQL condition "
145 "in \"children_cond\" directive\n",
149 ber_str2bv( argv[ 1 ], 0, 1, &bi->sql_children_cond );
150 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
151 "subtree_cond=%s\n", bi->sql_children_cond.bv_val, 0, 0 );
153 } else if ( !strcasecmp( argv[ 0 ], "oc_query" ) ) {
155 Debug( LDAP_DEBUG_TRACE,
156 "<==backsql_db_config (%s line %d): "
157 "missing SQL statement "
158 "in \"oc_query\" directive\n",
162 bi->sql_oc_query = ch_strdup( argv[ 1 ] );
163 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
164 "oc_query=%s\n", bi->sql_oc_query, 0, 0 );
166 } else if ( !strcasecmp( argv[ 0 ], "at_query" ) ) {
168 Debug( LDAP_DEBUG_TRACE,
169 "<==backsql_db_config (%s line %d): "
170 "missing SQL statement "
171 "in \"at_query\" directive\n",
175 bi->sql_at_query = ch_strdup( argv[ 1 ] );
176 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
177 "at_query=%s\n", bi->sql_at_query, 0, 0 );
179 } else if ( !strcasecmp( argv[ 0 ], "insentry_stmt" ) ||
180 !strcasecmp( argv[ 0 ], "insentry_query" ) )
183 Debug( LDAP_DEBUG_TRACE,
184 "<==backsql_db_config (%s line %d): "
185 "missing SQL statement "
186 "in \"insentry_stmt\" directive\n",
190 bi->sql_insentry_stmt = ch_strdup( argv[ 1 ] );
191 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
192 "insentry_stmt=%s\n", bi->sql_insentry_stmt, 0, 0 );
194 } else if ( !strcasecmp( argv[ 0 ], "create_needs_select" ) ) {
196 Debug( LDAP_DEBUG_TRACE,
197 "<==backsql_db_config (%s line %d): "
198 "missing { yes | no }"
199 "in \"create_needs_select\" directive\n",
204 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
205 bi->sql_flags |= BSQLF_CREATE_NEEDS_SELECT;
207 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
208 bi->sql_flags &= ~BSQLF_CREATE_NEEDS_SELECT;
211 Debug( LDAP_DEBUG_TRACE,
212 "<==backsql_db_config (%s line %d): "
213 "\"create_needs_select\" directive arg "
214 "must be \"yes\" or \"no\"\n",
219 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
220 "create_needs_select =%s\n",
221 BACKSQL_CREATE_NEEDS_SELECT( bi ) ? "yes" : "no",
224 } else if ( !strcasecmp( argv[ 0 ], "upper_func" ) ) {
226 Debug( LDAP_DEBUG_TRACE,
227 "<==backsql_db_config (%s line %d): "
228 "missing function name "
229 "in \"upper_func\" directive\n",
233 ber_str2bv( argv[ 1 ], 0, 1, &bi->sql_upper_func );
234 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
235 "upper_func=%s\n", bi->sql_upper_func.bv_val, 0, 0 );
237 } else if ( !strcasecmp( argv[ 0 ], "upper_needs_cast" ) ) {
239 Debug( LDAP_DEBUG_TRACE,
240 "<==backsql_db_config (%s line %d): "
241 "missing { yes | no }"
242 "in \"upper_needs_cast\" directive\n",
247 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
248 bi->sql_flags |= BSQLF_UPPER_NEEDS_CAST;
250 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
251 bi->sql_flags &= ~BSQLF_UPPER_NEEDS_CAST;
254 Debug( LDAP_DEBUG_TRACE,
255 "<==backsql_db_config (%s line %d): "
256 "\"upper_needs_cast\" directive arg "
257 "must be \"yes\" or \"no\"\n",
262 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
263 "upper_needs_cast =%s\n",
264 BACKSQL_UPPER_NEEDS_CAST( bi ) ? "yes" : "no", 0, 0 );
266 } else if ( !strcasecmp( argv[ 0 ], "strcast_func" ) ) {
268 Debug( LDAP_DEBUG_TRACE,
269 "<==backsql_db_config (%s line %d): "
270 "missing function name "
271 "in \"strcast_func\" directive\n",
275 ber_str2bv( argv[ 1 ], 0, 1, &bi->sql_strcast_func );
276 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
277 "strcast_func=%s\n", bi->sql_strcast_func.bv_val, 0, 0 );
279 } else if ( !strcasecmp( argv[ 0 ], "delentry_stmt" ) ||
280 !strcasecmp( argv[ 0 ], "delentry_query" ) )
283 Debug( LDAP_DEBUG_TRACE,
284 "<==backsql_db_config (%s line %d): "
285 "missing SQL statement "
286 "in \"delentry_stmt\" directive\n",
290 bi->sql_delentry_stmt = ch_strdup( argv[ 1 ] );
291 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
292 "delentry_stmt=%s\n", bi->sql_delentry_stmt, 0, 0 );
294 } else if ( !strcasecmp( argv[ 0 ], "renentry_stmt" ) ||
295 !strcasecmp( argv[ 0 ], "renentry_query" ) )
298 Debug( LDAP_DEBUG_TRACE,
299 "<==backsql_db_config (%s line %d): "
300 "missing SQL statement "
301 "in \"renentry_stmt\" directive\n",
305 bi->sql_renentry_stmt = ch_strdup( argv[ 1 ] );
306 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
307 "renentry_stmt=%s\n", bi->sql_renentry_stmt, 0, 0 );
309 } else if ( !strcasecmp( argv[ 0 ], "delobjclasses_stmt" ) ||
310 !strcasecmp( argv[ 0 ], "delobjclasses_query" ) )
313 Debug( LDAP_DEBUG_TRACE,
314 "<==backsql_db_config (%s line %d): "
315 "missing SQL statement "
316 "in \"delobjclasses_stmt\" directive\n",
320 bi->sql_delobjclasses_stmt = ch_strdup( argv[ 1 ] );
321 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
322 "delobjclasses_stmt=%s\n", bi->sql_delobjclasses_stmt, 0, 0 );
324 } else if ( !strcasecmp( argv[ 0 ], "has_ldapinfo_dn_ru") ) {
326 Debug( LDAP_DEBUG_TRACE,
327 "<==backsql_db_config (%s line %d): "
328 "missing { yes | no }"
329 "in \"has_ldapinfo_dn_ru\" directive\n",
334 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
335 bi->sql_flags |= BSQLF_HAS_LDAPINFO_DN_RU;
336 bi->sql_flags |= BSQLF_DONTCHECK_LDAPINFO_DN_RU;
338 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
339 bi->sql_flags &= ~BSQLF_HAS_LDAPINFO_DN_RU;
340 bi->sql_flags |= BSQLF_DONTCHECK_LDAPINFO_DN_RU;
343 Debug( LDAP_DEBUG_TRACE,
344 "<==backsql_db_config (%s line %d): "
345 "\"has_ldapinfo_dn_ru\" directive arg "
346 "must be \"yes\" or \"no\"\n",
351 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
352 "has_ldapinfo_dn_ru=%s\n",
353 BACKSQL_HAS_LDAPINFO_DN_RU( bi ) ? "yes" : "no", 0, 0 );
355 } else if ( !strcasecmp( argv[ 0 ], "fail_if_no_mapping") ) {
357 Debug( LDAP_DEBUG_TRACE,
358 "<==backsql_db_config (%s line %d): "
359 "missing { yes | no }"
360 "in \"fail_if_no_mapping\" directive\n",
365 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
366 bi->sql_flags |= BSQLF_FAIL_IF_NO_MAPPING;
368 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
369 bi->sql_flags &= ~BSQLF_FAIL_IF_NO_MAPPING;
372 Debug( LDAP_DEBUG_TRACE,
373 "<==backsql_db_config (%s line %d): "
374 "\"fail_if_no_mapping\" directive arg "
375 "must be \"yes\" or \"no\"\n",
380 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
381 "fail_if_no_mapping=%s\n",
382 BACKSQL_FAIL_IF_NO_MAPPING( bi ) ? "yes" : "no", 0, 0 );
384 } else if ( !strcasecmp( argv[ 0 ], "allow_orphans") ) {
386 Debug( LDAP_DEBUG_TRACE,
387 "<==backsql_db_config (%s line %d): "
388 "missing { yes | no }"
389 "in \"allow_orphans\" directive\n",
394 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
395 bi->sql_flags |= BSQLF_ALLOW_ORPHANS;
397 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
398 bi->sql_flags &= ~BSQLF_ALLOW_ORPHANS;
401 Debug( LDAP_DEBUG_TRACE,
402 "<==backsql_db_config (%s line %d): "
403 "\"allow_orphans\" directive arg "
404 "must be \"yes\" or \"no\"\n",
409 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
410 "allow_orphans=%s\n",
411 BACKSQL_ALLOW_ORPHANS( bi ) ? "yes" : "no", 0, 0 );
413 } else if ( !strcasecmp( argv[ 0 ], "baseobject" ) ) {
414 if ( be->be_suffix == NULL ) {
415 Debug( LDAP_DEBUG_TRACE,
416 "<==backsql_db_config (%s line %d): : "
417 "must be defined after \"suffix\"\n",
422 if ( bi->sql_baseObject ) {
423 Debug( LDAP_DEBUG_TRACE,
424 "<==backsql_db_config (%s line %d): : "
425 "\"baseObject\" already provided (will be overwritten)\n",
427 entry_free( bi->sql_baseObject );
432 return create_baseObject( be, fname, lineno );
435 return read_baseObject( be, argv[ 1 ] );
438 Debug( LDAP_DEBUG_TRACE,
439 "<==backsql_db_config (%s line %d): "
441 "in \"baseObject\" directive?\n",
446 } else if ( !strcasecmp( argv[ 0 ], "sqllayer") ) {
447 if ( backsql_api_config( bi, argv[ 1 ], argc - 2, &argv[ 2 ] ) )
449 Debug( LDAP_DEBUG_TRACE,
450 "<==backsql_db_config (%s line %d): "
451 "unable to load sqllayer \"%s\"\n",
452 fname, lineno, argv[ 1 ] );
456 } else if ( !strcasecmp( argv[ 0 ], "id_query" ) ) {
458 Debug( LDAP_DEBUG_TRACE,
459 "<==backsql_db_config (%s line %d): "
460 "missing SQL condition "
461 "in \"id_query\" directive\n",
465 bi->sql_id_query = ch_strdup( argv[ 1 ] );
466 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
467 "id_query=%s\n", bi->sql_id_query, 0, 0 );
469 } else if ( !strcasecmp( argv[ 0 ], "use_subtree_shortcut") ) {
471 Debug( LDAP_DEBUG_TRACE,
472 "<==backsql_db_config (%s line %d): "
473 "missing { yes | no }"
474 "in \"use_subtree_shortcut\" directive\n",
479 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
480 bi->sql_flags |= BSQLF_USE_SUBTREE_SHORTCUT;
482 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
483 bi->sql_flags &= ~BSQLF_USE_SUBTREE_SHORTCUT;
486 Debug( LDAP_DEBUG_TRACE,
487 "<==backsql_db_config (%s line %d): "
488 "\"use_subtree_shortcut\" directive arg "
489 "must be \"yes\" or \"no\"\n",
494 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
495 "use_subtree_shortcut=%s\n",
496 BACKSQL_USE_SUBTREE_SHORTCUT( bi ) ? "yes" : "no",
499 } else if ( !strcasecmp( argv[ 0 ], "fetch_all_attrs") ) {
501 Debug( LDAP_DEBUG_TRACE,
502 "<==backsql_db_config (%s line %d): "
503 "missing { yes | no }"
504 "in \"fetch_all_attrs\" directive\n",
509 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
510 bi->sql_flags |= BSQLF_FETCH_ALL_ATTRS;
512 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
513 bi->sql_flags &= ~BSQLF_FETCH_ALL_ATTRS;
516 Debug( LDAP_DEBUG_TRACE,
517 "<==backsql_db_config (%s line %d): "
518 "\"fetch_all_attrs\" directive arg "
519 "must be \"yes\" or \"no\"\n",
524 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
525 "fetch_all_attrs=%s\n",
526 BACKSQL_FETCH_ALL_ATTRS( bi ) ? "yes" : "no",
529 } else if ( !strcasecmp( argv[ 0 ], "fetch_attrs") ) {
530 char *str, *s, *next;
531 char delimstr[] = ",";
534 Debug( LDAP_DEBUG_TRACE,
535 "<==backsql_db_config (%s line %d): "
537 "in \"fetch_all_attrs <attrlist>\" directive\n",
542 str = ch_strdup( argv[ 1 ] );
543 for ( s = ldap_pvt_strtok( str, delimstr, &next );
545 s = ldap_pvt_strtok( NULL, delimstr, &next ) )
547 if ( strlen( s ) == 1 ) {
549 bi->sql_flags |= BSQLF_FETCH_ALL_USERATTRS;
550 argv[ 1 ][ s - str ] = ',';
552 } else if ( *s == '+' ) {
553 bi->sql_flags |= BSQLF_FETCH_ALL_OPATTRS;
554 argv[ 1 ][ s - str ] = ',';
559 bi->sql_anlist = str2anlist( bi->sql_anlist, argv[ 1 ], delimstr );
560 if ( bi->sql_anlist == NULL ) {
564 } else if ( !strcasecmp( argv[ 0 ], "check_schema") ) {
566 Debug( LDAP_DEBUG_TRACE,
567 "<==backsql_db_config (%s line %d): "
568 "missing { yes | no }"
569 "in \"check_schema\" directive\n",
574 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
575 bi->sql_flags |= BSQLF_CHECK_SCHEMA;
577 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
578 bi->sql_flags &= ~BSQLF_CHECK_SCHEMA;
581 Debug( LDAP_DEBUG_TRACE,
582 "<==backsql_db_config (%s line %d): "
583 "\"check_schema\" directive arg "
584 "must be \"yes\" or \"no\"\n",
589 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
591 BACKSQL_CHECK_SCHEMA( bi ) ? "yes" : "no",
595 return SLAP_CONF_UNKNOWN;
602 * Read the entries specified in fname and merge the attributes
603 * to the user defined baseObject entry. Note that if we find any errors
604 * what so ever, we will discard the entire entries, print an
605 * error message and return.
612 backsql_info *bi = (backsql_info *)be->be_private;
614 int rc = 0, lineno = 0, lmax = 0;
619 fp = ldif_open( fname, "r" );
621 Debug( LDAP_DEBUG_ANY,
622 "could not open back-sql baseObject "
623 "attr file \"%s\" - absolute path?\n",
629 bi->sql_baseObject = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
630 if ( bi->sql_baseObject == NULL ) {
631 Debug( LDAP_DEBUG_ANY,
632 "read_baseObject_file: SLAP_CALLOC failed", 0, 0, 0 );
634 return LDAP_NO_MEMORY;
636 bi->sql_baseObject->e_name = be->be_suffix[0];
637 bi->sql_baseObject->e_nname = be->be_nsuffix[0];
638 bi->sql_baseObject->e_attrs = NULL;
640 while ( ldif_read_record( fp, &lineno, &buf, &lmax ) ) {
641 Entry *e = str2entry( buf );
645 fprintf( stderr, "back-sql baseObject: "
646 "could not parse entry (line=%d)\n",
652 /* make sure the DN is the database's suffix */
653 if ( !be_issuffix( be, &e->e_nname ) ) {
655 "back-sql: invalid baseObject - "
656 "dn=\"%s\" (line=%d)\n",
657 e->e_name.bv_val, lineno );
664 * we found a valid entry, so walk thru all the attributes in the
665 * entry, and add each attribute type and description to baseObject
667 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
668 if ( attr_merge( bi->sql_baseObject, a->a_desc,
670 ( a->a_nvals == a->a_vals ) ?
671 NULL : a->a_nvals ) )
685 entry_free( bi->sql_baseObject );
686 bi->sql_baseObject = NULL;
693 Debug( LDAP_DEBUG_CONFIG, "back-sql baseObject file \"%s\" read.\n",
705 backsql_info *bi = (backsql_info *)be->be_private;
711 snprintf( buf, sizeof(buf),
713 "objectClass: extensibleObject\n"
714 "description: builtin baseObject for back-sql\n"
715 "description: all entries mapped "
716 "in the \"ldap_entries\" table\n"
717 "description: must have "
718 "\"" BACKSQL_BASEOBJECT_IDSTR "\" "
719 "in the \"parent\" column",
720 be->be_suffix[0].bv_val );
722 bi->sql_baseObject = str2entry( buf );
723 if ( bi->sql_baseObject == NULL ) {
724 Debug( LDAP_DEBUG_TRACE,
725 "<==backsql_db_config (%s line %d): "
726 "unable to parse baseObject entry\n",
731 if ( BER_BVISEMPTY( &be->be_suffix[ 0 ] ) ) {
735 rc = ldap_bv2rdn( &be->be_suffix[ 0 ], &rdn, (char **)&p,
736 LDAP_DN_FORMAT_LDAP );
737 if ( rc != LDAP_SUCCESS ) {
738 snprintf( buf, sizeof(buf),
739 "unable to extract RDN "
740 "from baseObject DN \"%s\" (%d: %s)",
741 be->be_suffix[ 0 ].bv_val,
742 rc, ldap_err2string( rc ) );
743 Debug( LDAP_DEBUG_TRACE,
744 "<==backsql_db_config (%s line %d): %s\n",
745 fname, lineno, buf );
749 for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
750 LDAPAVA *ava = rdn[ iAVA ];
751 AttributeDescription *ad = NULL;
752 slap_syntax_transform_func *transf = NULL;
753 struct berval bv = BER_BVNULL;
754 const char *text = NULL;
758 rc = slap_bv2ad( &ava->la_attr, &ad, &text );
759 if ( rc != LDAP_SUCCESS ) {
760 snprintf( buf, sizeof(buf),
761 "AttributeDescription of naming "
762 "attribute #%d from baseObject "
764 iAVA, be->be_suffix[ 0 ].bv_val,
765 rc, ldap_err2string( rc ) );
766 Debug( LDAP_DEBUG_TRACE,
767 "<==backsql_db_config (%s line %d): %s\n",
768 fname, lineno, buf );
772 transf = ad->ad_type->sat_syntax->ssyn_pretty;
775 * transform value by pretty function
776 * if value is empty, use empty_bv
778 rc = ( *transf )( ad->ad_type->sat_syntax,
781 : (struct berval *) &slap_empty_bv,
784 if ( rc != LDAP_SUCCESS ) {
785 snprintf( buf, sizeof(buf),
786 "prettying of attribute #%d "
788 "DN \"%s\" failed: %d: %s",
789 iAVA, be->be_suffix[ 0 ].bv_val,
790 rc, ldap_err2string( rc ) );
791 Debug( LDAP_DEBUG_TRACE,
792 "<==backsql_db_config (%s line %d): "
794 fname, lineno, buf );
799 if ( !BER_BVISNULL( &bv ) ) {
800 if ( ava->la_flags & LDAP_AVA_FREE_VALUE ) {
801 ber_memfree( ava->la_value.bv_val );
804 ava->la_flags |= LDAP_AVA_FREE_VALUE;
807 attr_merge_normalize_one( bi->sql_baseObject,
808 ad, &ava->la_value, NULL );