X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-sql%2Fconfig.c;h=197787ce5a39d1e5b34c41db39320b80550d44fd;hb=569344fb86fd1e7b4b304598839c157aa92e5447;hp=1a89a0da84c1b818418aea03b1641d4bc3feb686;hpb=740835dff9c50a3b71bc12d2e9d1b2e43965e1d3;p=openldap diff --git a/servers/slapd/back-sql/config.c b/servers/slapd/back-sql/config.c index 1a89a0da84..197787ce5a 100644 --- a/servers/slapd/back-sql/config.c +++ b/servers/slapd/back-sql/config.c @@ -1,7 +1,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1999-2005 The OpenLDAP Foundation. + * Copyright 1999-2011 The OpenLDAP Foundation. * Portions Copyright 1999 Dmitry Kovalev. * Portions Copyright 2002 Pierangelo Masarati. * Portions Copyright 2004 Mark Adamson. @@ -53,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 ) { @@ -148,7 +148,20 @@ backsql_db_config( } ber_str2bv( argv[ 1 ], 0, 1, &bi->sql_children_cond ); Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): " - "subtree_cond=%s\n", bi->sql_children_cond.bv_val, 0, 0 ); + "children_cond=%s\n", bi->sql_children_cond.bv_val, 0, 0 ); + + } else if ( !strcasecmp( argv[ 0 ], "dn_match_cond" ) ) { + if ( argc < 2 ) { + Debug( LDAP_DEBUG_TRACE, + "<==backsql_db_config (%s line %d): " + "missing SQL condition " + "in \"dn_match_cond\" directive\n", + fname, lineno, 0 ); + return 1; + } + ber_str2bv( argv[ 1 ], 0, 1, &bi->sql_dn_match_cond ); + Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): " + "children_cond=%s\n", bi->sql_dn_match_cond.bv_val, 0, 0 ); } else if ( !strcasecmp( argv[ 0 ], "oc_query" ) ) { if ( argc < 2 ) { @@ -321,7 +334,7 @@ backsql_db_config( Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): " "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): " @@ -352,7 +365,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): " @@ -381,7 +394,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): " @@ -443,7 +456,7 @@ backsql_db_config( return 1; } - } else if ( !strcasecmp( argv[ 0 ], "sqllayer") ) { + } else if ( !strcasecmp( argv[ 0 ], "sqllayer" ) ) { if ( backsql_api_config( bi, argv[ 1 ], argc - 2, &argv[ 2 ] ) ) { Debug( LDAP_DEBUG_TRACE, @@ -466,7 +479,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): " @@ -496,7 +509,7 @@ backsql_db_config( BACKSQL_USE_SUBTREE_SHORTCUT( bi ) ? "yes" : "no", 0, 0 ); - } else if ( !strcasecmp( argv[ 0 ], "fetch_all_attrs") ) { + } else if ( !strcasecmp( argv[ 0 ], "fetch_all_attrs" ) ) { if ( argc < 2 ) { Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config (%s line %d): " @@ -526,9 +539,9 @@ backsql_db_config( BACKSQL_FETCH_ALL_ATTRS( bi ) ? "yes" : "no", 0, 0 ); - } else if ( !strcasecmp( argv[ 0 ], "fetch_attrs") ) { - char *str, *s, *next; - char delimstr[] = ","; + } else if ( !strcasecmp( argv[ 0 ], "fetch_attrs" ) ) { + char *str, *s, *next; + const char *delimstr = ","; if ( argc < 2 ) { Debug( LDAP_DEBUG_TRACE, @@ -561,8 +574,8 @@ backsql_db_config( return -1; } - } else if ( !strcasecmp( argv[ 0 ], "check_schema") ) { - if ( argc < 2 ) { + } else if ( !strcasecmp( argv[ 0 ], "check_schema" ) ) { + if ( argc != 2 ) { Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config (%s line %d): " "missing { yes | no }" @@ -591,6 +604,72 @@ backsql_db_config( 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 if ( !strcasecmp( argv[ 0 ], "autocommit" ) ) { + if ( argc != 2 ) { + Debug( LDAP_DEBUG_TRACE, + "<==backsql_db_config (%s line %d): " + "missing arg " + "in \"autocommit {NO|yes}\" directive\n", + fname, lineno, 0 ); + return 1; + } + + if ( !strcasecmp( argv[ 1 ], "yes" ) || + !strcasecmp( argv[ 1 ], "TRUE" ) || + !strcasecmp( argv[ 1 ], "on" ) ) + { + bi->sql_flags |= BSQLF_AUTOCOMMIT_ON; + + } else if ( !strcasecmp( argv[ 1 ], "no" ) || + !strcasecmp( argv[ 1 ], "FALSE" ) || + !strcasecmp( argv[ 1 ], "off" ) ) + { + bi->sql_flags &= ~BSQLF_AUTOCOMMIT_ON; + + } else { + Debug( LDAP_DEBUG_TRACE, + "<==backsql_db_config (%s line %d): " + "invalid arg " + "in \"autocommit {NO|yes}\" directive\n", + fname, lineno, 0 ); + return 1; + } + } else { return SLAP_CONF_UNKNOWN; } @@ -610,13 +689,13 @@ read_baseObject( const char *fname ) { backsql_info *bi = (backsql_info *)be->be_private; - FILE *fp; - int rc = 0, lineno = 0, lmax = 0; + LDIFFP *fp; + int rc = 0, lineno = 0, lmax = 0, ldifrc; 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 " @@ -626,18 +705,18 @@ read_baseObject( return LDAP_OTHER; } - bi->sql_baseObject = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) ); + bi->sql_baseObject = entry_alloc(); if ( bi->sql_baseObject == NULL ) { Debug( LDAP_DEBUG_ANY, - "read_baseObject_file: SLAP_CALLOC failed", 0, 0, 0 ); - fclose( fp ); + "read_baseObject_file: entry_alloc failed", 0, 0, 0 ); + ldif_close( fp ); return LDAP_NO_MEMORY; } bi->sql_baseObject->e_name = be->be_suffix[0]; bi->sql_baseObject->e_nname = be->be_nsuffix[0]; bi->sql_baseObject->e_attrs = NULL; - while ( ldif_read_record( fp, &lineno, &buf, &lmax ) ) { + while (( ldifrc = ldif_read_record( fp, &lineno, &buf, &lmax )) > 0 ) { Entry *e = str2entry( buf ); Attribute *a; @@ -656,7 +735,7 @@ read_baseObject( "dn=\"%s\" (line=%d)\n", e->e_name.bv_val, lineno ); entry_free( e ); - rc = EXIT_FAILURE; + rc = LDAP_OTHER; break; } @@ -681,6 +760,9 @@ read_baseObject( } } + if ( ldifrc < 0 ) + rc = LDAP_OTHER; + if ( rc ) { entry_free( bi->sql_baseObject ); bi->sql_baseObject = NULL; @@ -688,7 +770,7 @@ read_baseObject( ch_free( buf ); - fclose( fp ); + ldif_close( fp ); Debug( LDAP_DEBUG_CONFIG, "back-sql baseObject file \"%s\" read.\n", fname, 0, 0 ); @@ -713,10 +795,10 @@ create_baseObject( "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", + "in table \"ldap_entries\" " + "must have " + "\"" BACKSQL_BASEOBJECT_IDSTR "\" " + "in the \"parent\" column", be->be_suffix[0].bv_val ); bi->sql_baseObject = str2entry( buf ); @@ -753,7 +835,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 ) {