From d6baaffbecc8ce9f576e462d8e786a4a3c7bdafe Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Thu, 13 Sep 2007 18:34:04 +0000 Subject: [PATCH] HEADS-UP: now the list of URIs is better set by using separate arguments --- servers/slapd/back-meta/config.c | 187 +++++++++++++++++-------------- 1 file changed, 100 insertions(+), 87 deletions(-) diff --git a/servers/slapd/back-meta/config.c b/servers/slapd/back-meta/config.c index 7a113034e0..1ebeca0ef4 100644 --- a/servers/slapd/back-meta/config.c +++ b/servers/slapd/back-meta/config.c @@ -111,28 +111,18 @@ meta_back_db_config( /* URI of server to query */ if ( strcasecmp( argv[ 0 ], "uri" ) == 0 ) { int i = mi->mi_ntargets; - LDAPURLDesc *ludp, *tmpludp; + LDAPURLDesc *ludp; struct berval dn; int rc; int c; - BackendDB *tmp_bd; metatarget_t *mt; + + char **uris = NULL; - switch ( argc ) { - case 1: + if ( argc == 1 ) { Debug( LDAP_DEBUG_ANY, "%s: line %d: missing URI " - "in \"uri ://[:port]/\" line\n", - fname, lineno, 0 ); - return 1; - - case 2: - break; - - default: - Debug( LDAP_DEBUG_ANY, - "%s: line %d: too many args " "in \"uri ://[:port]/\" line\n", fname, lineno, 0 ); return 1; @@ -184,93 +174,106 @@ meta_back_db_config( mt->mt_timeout[ c ] = mi->mi_timeout[ c ]; } - /* - * uri MUST be legal! - */ - if ( ldap_url_parselist_ext( &ludp, argv[ 1 ], "\t", - LDAP_PVT_URL_PARSE_NONE ) != LDAP_SUCCESS ) - { - Debug( LDAP_DEBUG_ANY, - "%s: line %d: unable to parse URI" - " in \"uri ://[:port]/\" line\n", - fname, lineno, 0 ); - return 1; - } + for ( c = 1; c < argc; c++ ) { + char **tmpuris = ldap_str2charray( argv[ c ], "\t" ); - /* - * uri MUST have the part! - */ - if ( ludp->lud_dn == NULL ) { - Debug( LDAP_DEBUG_ANY, - "%s: line %d: missing " + if ( tmpuris == NULL ) { + Debug( LDAP_DEBUG_ANY, + "%s: line %d: unable to parse URIs #%d" " in \"uri ://[:port]/\" line\n", - fname, lineno, 0 ); - return 1; + fname, lineno, c - 1 ); + return 1; + } - } else if ( ludp->lud_dn[ 0 ] == '\0' ) { - int j = -1; + if ( c == 0 ) { + uris = tmpuris; - for ( j = 0; !BER_BVISNULL( &be->be_nsuffix[ j ] ); j++ ) { - if ( BER_BVISEMPTY( &be->be_nsuffix[ j ] ) ) { - break; - } + } else { + ldap_charray_merge( &uris, tmpuris ); + ldap_charray_free( tmpuris ); } + } + + for ( c = 0; uris[ c ] != NULL; c++ ) { - if ( BER_BVISNULL( &be->be_nsuffix[ j ] ) ) { + /* + * uri MUST be legal! + */ + if ( ldap_url_parselist_ext( &ludp, uris[ c ], "\t", + LDAP_PVT_URL_PARSE_NONE ) != LDAP_SUCCESS + || ludp->lud_next != NULL ) + { Debug( LDAP_DEBUG_ANY, - "%s: line %d: missing " + "%s: line %d: unable to parse URI #%d" " in \"uri ://[:port]/\" line\n", - fname, lineno, 0 ); + fname, lineno, c ); return 1; } - } - /* - * copies and stores uri and suffix - */ - ber_str2bv( ludp->lud_dn, 0, 0, &dn ); - rc = dnPrettyNormal( NULL, &dn, &mt->mt_psuffix, - &mt->mt_nsuffix, NULL ); - if( rc != LDAP_SUCCESS ) { - Debug( LDAP_DEBUG_ANY, "%s: line %d: " - "target \"%s\" DN is invalid\n", - fname, lineno, argv[ 1 ] ); - return( 1 ); - } + if ( c == 0 ) { - ludp->lud_dn[ 0 ] = '\0'; + /* + * uri MUST have the part! + */ + if ( ludp->lud_dn == NULL ) { + Debug( LDAP_DEBUG_ANY, + "%s: line %d: missing " + " in \"uri ://[:port]/\" line\n", + fname, lineno, 0 ); + return 1; + } - switch ( ludp->lud_scope ) { - case LDAP_SCOPE_DEFAULT: - mt->mt_scope = LDAP_SCOPE_SUBTREE; - break; + /* + * copies and stores uri and suffix + */ + ber_str2bv( ludp->lud_dn, 0, 0, &dn ); + rc = dnPrettyNormal( NULL, &dn, &mt->mt_psuffix, + &mt->mt_nsuffix, NULL ); + if ( rc != LDAP_SUCCESS ) { + Debug( LDAP_DEBUG_ANY, "%s: line %d: " + "target \"%s\" DN is invalid\n", + fname, lineno, argv[ 1 ] ); + return( 1 ); + } - case LDAP_SCOPE_SUBTREE: - case LDAP_SCOPE_SUBORDINATE: - mt->mt_scope = ludp->lud_scope; - break; + ludp->lud_dn[ 0 ] = '\0'; - default: - Debug( LDAP_DEBUG_ANY, "%s: line %d: " - "invalid scope for target \"%s\"\n", - fname, lineno, argv[ 1 ] ); - return( 1 ); - } + switch ( ludp->lud_scope ) { + case LDAP_SCOPE_DEFAULT: + mt->mt_scope = LDAP_SCOPE_SUBTREE; + break; - /* check all, to apply the scope check on the first one */ - for ( tmpludp = ludp; tmpludp; tmpludp = tmpludp->lud_next ) { - if ( tmpludp->lud_dn != NULL && tmpludp->lud_dn[ 0 ] != '\0' ) { - Debug( LDAP_DEBUG_ANY, "%s: line %d: " - "multiple URIs must have " - "no DN part\n", - fname, lineno, 0 ); - return( 1 ); + case LDAP_SCOPE_SUBTREE: + case LDAP_SCOPE_SUBORDINATE: + mt->mt_scope = ludp->lud_scope; + break; + + default: + Debug( LDAP_DEBUG_ANY, "%s: line %d: " + "invalid scope for target \"%s\"\n", + fname, lineno, argv[ 1 ] ); + return( 1 ); + } + + } else { + /* check all, to apply the scope check on the first one */ + if ( ludp->lud_dn != NULL && ludp->lud_dn[ 0 ] != '\0' ) { + Debug( LDAP_DEBUG_ANY, "%s: line %d: " + "multiple URIs must have " + "no DN part\n", + fname, lineno, 0 ); + return( 1 ); + } } + + ldap_memfree( uris[ c ] ); + uris[ c ] = ldap_url_list2urls( ludp ); + ldap_free_urllist( ludp ); } - mt->mt_uri = ldap_url_list2urls( ludp ); - ldap_free_urllist( ludp ); + mt->mt_uri = ldap_charray2str( uris, " " ); + ldap_charray_free( uris ); if ( mt->mt_uri == NULL) { Debug( LDAP_DEBUG_ANY, "%s: line %d: no memory?\n", fname, lineno, 0 ); @@ -280,11 +283,15 @@ meta_back_db_config( /* * uri MUST be a branch of suffix! */ - tmp_bd = select_backend( &mt->mt_nsuffix, 0 ); - if ( tmp_bd == NULL || tmp_bd->be_private != be->be_private ) - { + for ( c = 0; !BER_BVISNULL( &be->be_nsuffix[ c ] ); c++ ) { + if ( dnIsSuffix( &mt->mt_nsuffix, &be->be_nsuffix[ c ] ) ) { + break; + } + } + + if ( BER_BVISNULL( &be->be_nsuffix[ c ] ) ) { Debug( LDAP_DEBUG_ANY, - "%s: line %d: of URI does not resolve to this database.\n", + "%s: line %d: of URI must be within the naming context of this database.\n", fname, lineno, 0 ); return 1; } @@ -1257,7 +1264,7 @@ idassert-authzFrom "dn:" /* dn massaging */ } else if ( strcasecmp( argv[ 0 ], "suffixmassage" ) == 0 ) { BackendDB *tmp_bd; - int i = mi->mi_ntargets - 1, rc; + int i = mi->mi_ntargets - 1, c, rc; struct berval dn, nvnc, pvnc, nrnc, prnc; if ( i < 0 ) { @@ -1293,7 +1300,13 @@ idassert-authzFrom "dn:" return 1; } - if (!dnIsSuffix( &nvnc, &be->be_nsuffix[ 0 ] ) ) { + for ( c = 0; !BER_BVISNULL( &be->be_nsuffix[ c ] ); c++ ) { + if ( dnIsSuffix( &nvnc, &be->be_nsuffix[ 0 ] ) ) { + break; + } + } + + if ( BER_BVISNULL( &be->be_nsuffix[ c ] ) ) { Debug( LDAP_DEBUG_ANY, "%s: line %d: " "%s: line %d: \"%s\" must be within the database naming context, in " "\"suffixMassage \"\n", -- 2.39.5