X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-sql%2Fconfig.c;h=817435f94c538ddce3a43db78f5553a2e5a0180e;hb=fe3b6d00714d551a4c781ee24627e2586d06459f;hp=8dc1f46d275796cebdba3041a7fb3750890e0874;hpb=dc0eacd40b625258355eea866d62188e5aa7ce3b;p=openldap diff --git a/servers/slapd/back-sql/config.c b/servers/slapd/back-sql/config.c index 8dc1f46d27..817435f94c 100644 --- a/servers/slapd/back-sql/config.c +++ b/servers/slapd/back-sql/config.c @@ -1,8 +1,9 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1999-2005 The OpenLDAP Foundation. + * Copyright 1999-2006 The OpenLDAP Foundation. * Portions Copyright 1999 Dmitry Kovalev. + * Portions Copyright 2002 Pierangelo Masarati. * Portions Copyright 2004 Mark Adamson. * All rights reserved. * @@ -16,7 +17,8 @@ */ /* ACKNOWLEDGEMENTS: * This work was initially developed by Dmitry Kovalev for inclusion - * by OpenLDAP Software. + * by OpenLDAP Software. Additional significant contributors include + * Pierangelo Masarati. */ #include "portable.h" @@ -51,7 +53,7 @@ backsql_db_config( backsql_info *bi = (backsql_info *)be->be_private; Debug( LDAP_DEBUG_TRACE, "==>backsql_db_config()\n", 0, 0, 0 ); - assert( bi ); + assert( bi != NULL ); if ( !strcasecmp( argv[ 0 ], "dbhost" ) ) { if ( argc < 2 ) { @@ -174,18 +176,20 @@ backsql_db_config( Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): " "at_query=%s\n", bi->sql_at_query, 0, 0 ); - } else if ( !strcasecmp( argv[ 0 ], "insentry_query" ) ) { + } else if ( !strcasecmp( argv[ 0 ], "insentry_stmt" ) || + !strcasecmp( argv[ 0 ], "insentry_query" ) ) + { if ( argc < 2 ) { Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config (%s line %d): " "missing SQL statement " - "in \"insentry_query\" directive\n", + "in \"insentry_stmt\" directive\n", fname, lineno, 0 ); return 1; } - bi->sql_insentry_query = ch_strdup( argv[ 1 ] ); + bi->sql_insentry_stmt = ch_strdup( argv[ 1 ] ); Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): " - "insentry_query=%s\n", bi->sql_insentry_query, 0, 0 ); + "insentry_stmt=%s\n", bi->sql_insentry_stmt, 0, 0 ); } else if ( !strcasecmp( argv[ 0 ], "create_needs_select" ) ) { if ( argc < 2 ) { @@ -272,46 +276,52 @@ backsql_db_config( Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): " "strcast_func=%s\n", bi->sql_strcast_func.bv_val, 0, 0 ); - } else if ( !strcasecmp( argv[ 0 ], "delentry_query" ) ) { + } else if ( !strcasecmp( argv[ 0 ], "delentry_stmt" ) || + !strcasecmp( argv[ 0 ], "delentry_query" ) ) + { if ( argc < 2 ) { Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config (%s line %d): " "missing SQL statement " - "in \"delentry_query\" directive\n", + "in \"delentry_stmt\" directive\n", fname, lineno, 0 ); return 1; } - bi->sql_delentry_query = ch_strdup( argv[ 1 ] ); + bi->sql_delentry_stmt = ch_strdup( argv[ 1 ] ); Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): " - "delentry_query=%s\n", bi->sql_delentry_query, 0, 0 ); + "delentry_stmt=%s\n", bi->sql_delentry_stmt, 0, 0 ); - } else if ( !strcasecmp( argv[ 0 ], "delobjclasses_query" ) ) { + } else if ( !strcasecmp( argv[ 0 ], "renentry_stmt" ) || + !strcasecmp( argv[ 0 ], "renentry_query" ) ) + { if ( argc < 2 ) { Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config (%s line %d): " "missing SQL statement " - "in \"delobjclasses_query\" directive\n", + "in \"renentry_stmt\" directive\n", fname, lineno, 0 ); return 1; } - bi->sql_delobjclasses_query = ch_strdup( argv[ 1 ] ); + bi->sql_renentry_stmt = ch_strdup( argv[ 1 ] ); Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): " - "delobjclasses_query=%s\n", bi->sql_delobjclasses_query, 0, 0 ); + "renentry_stmt=%s\n", bi->sql_renentry_stmt, 0, 0 ); - } else if ( !strcasecmp( argv[ 0 ], "delreferrals_query" ) ) { + } else if ( !strcasecmp( argv[ 0 ], "delobjclasses_stmt" ) || + !strcasecmp( argv[ 0 ], "delobjclasses_query" ) ) + { if ( argc < 2 ) { Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config (%s line %d): " "missing SQL statement " - "in \"delreferrals_query\" directive\n", + "in \"delobjclasses_stmt\" directive\n", fname, lineno, 0 ); return 1; } - bi->sql_delreferrals_query = ch_strdup( argv[ 1 ] ); + bi->sql_delobjclasses_stmt = ch_strdup( argv[ 1 ] ); Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): " - "delreferrals_query=%s\n", bi->sql_delreferrals_query, 0, 0 ); + "delobjclasses_stmt=%s\n", bi->sql_delobjclasses_stmt, 0, 0 ); - } else if ( !strcasecmp( argv[ 0 ], "has_ldapinfo_dn_ru") ) { + } else if ( !strcasecmp( argv[ 0 ], "has_ldapinfo_dn_ru" ) ) { if ( argc < 2 ) { Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config (%s line %d): " @@ -342,7 +352,7 @@ backsql_db_config( "has_ldapinfo_dn_ru=%s\n", BACKSQL_HAS_LDAPINFO_DN_RU( bi ) ? "yes" : "no", 0, 0 ); - } else if ( !strcasecmp( argv[ 0 ], "fail_if_no_mapping") ) { + } else if ( !strcasecmp( argv[ 0 ], "fail_if_no_mapping" ) ) { if ( argc < 2 ) { Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config (%s line %d): " @@ -371,7 +381,7 @@ backsql_db_config( "fail_if_no_mapping=%s\n", BACKSQL_FAIL_IF_NO_MAPPING( bi ) ? "yes" : "no", 0, 0 ); - } else if ( !strcasecmp( argv[ 0 ], "allow_orphans") ) { + } else if ( !strcasecmp( argv[ 0 ], "allow_orphans" ) ) { if ( argc < 2 ) { Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config (%s line %d): " @@ -433,8 +443,9 @@ backsql_db_config( return 1; } - } else if ( !strcasecmp( argv[ 0 ], "sqllayer") ) { - if ( backsql_api_config( bi, argv[ 1 ] ) ) { + } else if ( !strcasecmp( argv[ 0 ], "sqllayer" ) ) { + if ( backsql_api_config( bi, argv[ 1 ], argc - 2, &argv[ 2 ] ) ) + { Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config (%s line %d): " "unable to load sqllayer \"%s\"\n", @@ -455,7 +466,7 @@ backsql_db_config( Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): " "id_query=%s\n", bi->sql_id_query, 0, 0 ); - } else if ( !strcasecmp( argv[ 0 ], "use_subtree_shortcut") ) { + } else if ( !strcasecmp( argv[ 0 ], "use_subtree_shortcut" ) ) { if ( argc < 2 ) { Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config (%s line %d): " @@ -482,7 +493,138 @@ backsql_db_config( } Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): " "use_subtree_shortcut=%s\n", - BACKSQL_USE_SUBTREE_SHORTCUT( bi ) ? "yes" : "no", 0, 0 ); + BACKSQL_USE_SUBTREE_SHORTCUT( bi ) ? "yes" : "no", + 0, 0 ); + + } else if ( !strcasecmp( argv[ 0 ], "fetch_all_attrs" ) ) { + if ( argc < 2 ) { + Debug( LDAP_DEBUG_TRACE, + "<==backsql_db_config (%s line %d): " + "missing { yes | no }" + "in \"fetch_all_attrs\" directive\n", + fname, lineno, 0 ); + return 1; + } + + if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) { + bi->sql_flags |= BSQLF_FETCH_ALL_ATTRS; + + } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) { + bi->sql_flags &= ~BSQLF_FETCH_ALL_ATTRS; + + } else { + Debug( LDAP_DEBUG_TRACE, + "<==backsql_db_config (%s line %d): " + "\"fetch_all_attrs\" directive arg " + "must be \"yes\" or \"no\"\n", + fname, lineno, 0 ); + return 1; + + } + Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): " + "fetch_all_attrs=%s\n", + BACKSQL_FETCH_ALL_ATTRS( bi ) ? "yes" : "no", + 0, 0 ); + + } else if ( !strcasecmp( argv[ 0 ], "fetch_attrs" ) ) { + char *str, *s, *next; + char delimstr[] = ","; + + if ( argc < 2 ) { + Debug( LDAP_DEBUG_TRACE, + "<==backsql_db_config (%s line %d): " + "missing " + "in \"fetch_all_attrs \" directive\n", + fname, lineno, 0 ); + return 1; + } + + str = ch_strdup( argv[ 1 ] ); + for ( s = ldap_pvt_strtok( str, delimstr, &next ); + s != NULL; + s = ldap_pvt_strtok( NULL, delimstr, &next ) ) + { + if ( strlen( s ) == 1 ) { + if ( *s == '*' ) { + bi->sql_flags |= BSQLF_FETCH_ALL_USERATTRS; + argv[ 1 ][ s - str ] = ','; + + } else if ( *s == '+' ) { + bi->sql_flags |= BSQLF_FETCH_ALL_OPATTRS; + argv[ 1 ][ s - str ] = ','; + } + } + } + ch_free( str ); + bi->sql_anlist = str2anlist( bi->sql_anlist, argv[ 1 ], delimstr ); + if ( bi->sql_anlist == NULL ) { + return -1; + } + + } else if ( !strcasecmp( argv[ 0 ], "check_schema" ) ) { + if ( argc != 2 ) { + Debug( LDAP_DEBUG_TRACE, + "<==backsql_db_config (%s line %d): " + "missing { yes | no }" + "in \"check_schema\" directive\n", + fname, lineno, 0 ); + return 1; + } + + if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) { + bi->sql_flags |= BSQLF_CHECK_SCHEMA; + + } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) { + bi->sql_flags &= ~BSQLF_CHECK_SCHEMA; + + } else { + Debug( LDAP_DEBUG_TRACE, + "<==backsql_db_config (%s line %d): " + "\"check_schema\" directive arg " + "must be \"yes\" or \"no\"\n", + fname, lineno, 0 ); + return 1; + + } + Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): " + "check_schema=%s\n", + BACKSQL_CHECK_SCHEMA( bi ) ? "yes" : "no", + 0, 0 ); + + } else if ( !strcasecmp( argv[ 0 ], "aliasing_keyword" ) ) { + if ( argc != 2 ) { + Debug( LDAP_DEBUG_TRACE, + "<==backsql_db_config (%s line %d): " + "missing arg " + "in \"aliasing_keyword \" directive\n", + fname, lineno, 0 ); + return 1; + } + + if ( ! BER_BVISNULL( &bi->sql_aliasing ) ) { + ch_free( bi->sql_aliasing.bv_val ); + } + + ber_str2bv( argv[ 1 ], strlen( argv[ 1 ] ) + 1, 1, + &bi->sql_aliasing ); + /* add a trailing space... */ + bi->sql_aliasing.bv_val[ bi->sql_aliasing.bv_len - 1] = ' '; + + } else if ( !strcasecmp( argv[ 0 ], "aliasing_quote" ) ) { + if ( argc != 2 ) { + Debug( LDAP_DEBUG_TRACE, + "<==backsql_db_config (%s line %d): " + "missing arg " + "in \"aliasing_quote \" directive\n", + fname, lineno, 0 ); + return 1; + } + + if ( ! BER_BVISNULL( &bi->sql_aliasing_quote ) ) { + ch_free( bi->sql_aliasing_quote.bv_val ); + } + + ber_str2bv( argv[ 1 ], 0, 1, &bi->sql_aliasing_quote ); } else { return SLAP_CONF_UNKNOWN; @@ -503,16 +645,17 @@ read_baseObject( const char *fname ) { backsql_info *bi = (backsql_info *)be->be_private; - FILE *fp; + LDIFFP *fp; int rc = 0, lineno = 0, lmax = 0; char *buf = NULL; - assert( fname ); + assert( fname != NULL ); - fp = fopen( fname, "r" ); + fp = ldif_open( fname, "r" ); if ( fp == NULL ) { Debug( LDAP_DEBUG_ANY, - "could not open back-sql baseObject attr file \"%s\" - absolute path?\n", + "could not open back-sql baseObject " + "attr file \"%s\" - absolute path?\n", fname, 0, 0 ); perror( fname ); return LDAP_OTHER; @@ -522,7 +665,7 @@ read_baseObject( if ( bi->sql_baseObject == NULL ) { Debug( LDAP_DEBUG_ANY, "read_baseObject_file: SLAP_CALLOC failed", 0, 0, 0 ); - fclose( fp ); + ldif_close( fp ); return LDAP_NO_MEMORY; } bi->sql_baseObject->e_name = be->be_suffix[0]; @@ -534,8 +677,9 @@ read_baseObject( Attribute *a; if( e == NULL ) { - fprintf( stderr, "back-sql baseObject: could not parse entry (line=%d)\n", - lineno ); + fprintf( stderr, "back-sql baseObject: " + "could not parse entry (line=%d)\n", + lineno ); rc = LDAP_OTHER; break; } @@ -543,8 +687,9 @@ read_baseObject( /* make sure the DN is the database's suffix */ if ( !be_issuffix( be, &e->e_nname ) ) { fprintf( stderr, - "back-sql: invalid baseObject - dn=\"%s\" (line=%d)\n", - e->e_dn, lineno ); + "back-sql: invalid baseObject - " + "dn=\"%s\" (line=%d)\n", + e->e_name.bv_val, lineno ); entry_free( e ); rc = EXIT_FAILURE; break; @@ -555,8 +700,10 @@ read_baseObject( * entry, and add each attribute type and description to baseObject */ for ( a = e->e_attrs; a != NULL; a = a->a_next ) { - if ( attr_merge( bi->sql_baseObject, a->a_desc, a->a_vals, - ( a->a_nvals == a->a_vals ) ? NULL : a->a_nvals ) ) + if ( attr_merge( bi->sql_baseObject, a->a_desc, + a->a_vals, + ( a->a_nvals == a->a_vals ) ? + NULL : a->a_nvals ) ) { rc = LDAP_OTHER; break; @@ -576,9 +723,10 @@ read_baseObject( ch_free( buf ); - fclose( fp ); + ldif_close( fp ); - Debug( LDAP_DEBUG_CONFIG, "back-sql baseObject file \"%s\" read.\n", fname, 0, 0 ); + Debug( LDAP_DEBUG_CONFIG, "back-sql baseObject file \"%s\" read.\n", + fname, 0, 0 ); return rc; } @@ -599,9 +747,11 @@ create_baseObject( "dn: %s\n" "objectClass: extensibleObject\n" "description: builtin baseObject for back-sql\n" - "description: all entries mapped in the \"ldap_entries\" table\n" - "description: must have \"" BACKSQL_BASEOBJECT_IDSTR "\" " - "in the \"parent\" column", + "description: all entries mapped " + "in the \"ldap_entries\" table\n" + "description: must have " + "\"" BACKSQL_BASEOBJECT_IDSTR "\" " + "in the \"parent\" column", be->be_suffix[0].bv_val ); bi->sql_baseObject = str2entry( buf ); @@ -617,11 +767,14 @@ create_baseObject( return 0; } - rc = ldap_bv2rdn( &be->be_suffix[ 0 ], &rdn, (char **) &p, LDAP_DN_FORMAT_LDAP ); + rc = ldap_bv2rdn( &be->be_suffix[ 0 ], &rdn, (char **)&p, + LDAP_DN_FORMAT_LDAP ); if ( rc != LDAP_SUCCESS ) { snprintf( buf, sizeof(buf), - "unable to extract RDN from baseObject DN \"%s\" (%d: %s)", - be->be_suffix[ 0 ].bv_val, rc, ldap_err2string( rc ) ); + "unable to extract RDN " + "from baseObject DN \"%s\" (%d: %s)", + be->be_suffix[ 0 ].bv_val, + rc, ldap_err2string( rc ) ); Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config (%s line %d): %s\n", fname, lineno, buf ); @@ -635,7 +788,7 @@ create_baseObject( struct berval bv = BER_BVNULL; const char *text = NULL; - assert( ava ); + assert( ava != NULL ); rc = slap_bv2ad( &ava->la_attr, &ad, &text ); if ( rc != LDAP_SUCCESS ) { @@ -665,12 +818,14 @@ create_baseObject( if ( rc != LDAP_SUCCESS ) { snprintf( buf, sizeof(buf), - "prettying of attribute #%d from baseObject " + "prettying of attribute #%d " + "from baseObject " "DN \"%s\" failed: %d: %s", iAVA, be->be_suffix[ 0 ].bv_val, rc, ldap_err2string( rc ) ); Debug( LDAP_DEBUG_TRACE, - "<==backsql_db_config (%s line %d): %s\n", + "<==backsql_db_config (%s line %d): " + "%s\n", fname, lineno, buf ); return 1; }