X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-ldap%2Fconfig.c;h=7b5cb291f134f8768501112831a71a001dc7e5f2;hb=22e5e49f267add520e92baa7abe683c9a58bbdf7;hp=e8a1b9f58adf83068e0e3ce9f1623f98f7b8dc13;hpb=4be9f57b290e4100b0cddfd06cc716a885f8d0e6;p=openldap diff --git a/servers/slapd/back-ldap/config.c b/servers/slapd/back-ldap/config.c index e8a1b9f58a..7b5cb291f1 100644 --- a/servers/slapd/back-ldap/config.c +++ b/servers/slapd/back-ldap/config.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 2003-2005 The OpenLDAP Foundation. + * Copyright 2003-2010 The OpenLDAP Foundation. * Portions Copyright 1999-2003 Howard Chu. * Portions Copyright 2000-2003 Pierangelo Masarati. * All rights reserved. @@ -41,6 +41,7 @@ static SLAP_EXTOP_MAIN_FN ldap_back_exop_whoami; static ConfigDriver ldap_back_cf_gen; +static ConfigDriver ldap_pbind_cf_gen; enum { LDAP_BACK_CFG_URI = 1, @@ -53,26 +54,43 @@ enum { LDAP_BACK_CFG_IDASSERT_AUTHCDN, LDAP_BACK_CFG_IDASSERT_PASSWD, LDAP_BACK_CFG_IDASSERT_AUTHZFROM, + LDAP_BACK_CFG_IDASSERT_PASSTHRU, LDAP_BACK_CFG_IDASSERT_METHOD, LDAP_BACK_CFG_IDASSERT_BIND, LDAP_BACK_CFG_REBIND, LDAP_BACK_CFG_CHASE, LDAP_BACK_CFG_T_F, LDAP_BACK_CFG_WHOAMI, - LDAP_BACK_CFG_REWRITE + LDAP_BACK_CFG_TIMEOUT, + LDAP_BACK_CFG_IDLE_TIMEOUT, + LDAP_BACK_CFG_CONN_TTL, + LDAP_BACK_CFG_NETWORK_TIMEOUT, + LDAP_BACK_CFG_VERSION, + LDAP_BACK_CFG_SINGLECONN, + LDAP_BACK_CFG_USETEMP, + LDAP_BACK_CFG_CONNPOOLMAX, + LDAP_BACK_CFG_CANCEL, + LDAP_BACK_CFG_QUARANTINE, + LDAP_BACK_CFG_ST_REQUEST, + LDAP_BACK_CFG_NOREFS, + LDAP_BACK_CFG_NOUNDEFFILTER, + + LDAP_BACK_CFG_REWRITE, + + LDAP_BACK_CFG_LAST }; static ConfigTable ldapcfg[] = { { "uri", "uri", 2, 2, 0, - ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_URI, + ARG_MAGIC|LDAP_BACK_CFG_URI, ldap_back_cf_gen, "( OLcfgDbAt:0.14 " "NAME 'olcDbURI' " "DESC 'URI (list) for remote DSA' " "SYNTAX OMsDirectoryString " "SINGLE-VALUE )", NULL, NULL }, - { "tls", "what", 2, 2, 0, - ARG_BERVAL|ARG_MAGIC|LDAP_BACK_CFG_TLS, + { "tls", "what", 2, 0, 0, + ARG_MAGIC|LDAP_BACK_CFG_TLS, ldap_back_cf_gen, "( OLcfgDbAt:3.1 " "NAME 'olcDbStartTLS' " "DESC 'StartTLS' " @@ -88,12 +106,12 @@ static ConfigTable ldapcfg[] = { "SYNTAX OMsDN " "SINGLE-VALUE )", NULL, NULL }, - /* deprecated; aliases "acl-authcDN" */ + /* deprecated, will be removed; aliases "acl-authcDN" */ { "binddn", "DN", 2, 2, 0, ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_ACL_AUTHCDN, ldap_back_cf_gen, NULL, NULL, NULL }, { "acl-passwd", "cred", 2, 2, 0, - ARG_BERVAL|ARG_MAGIC|LDAP_BACK_CFG_ACL_PASSWD, + ARG_MAGIC|LDAP_BACK_CFG_ACL_PASSWD, ldap_back_cf_gen, "( OLcfgDbAt:3.3 " "NAME 'olcDbACLPasswd' " "DESC 'Remote ACL administrative identity credentials' " @@ -101,22 +119,22 @@ static ConfigTable ldapcfg[] = { "SYNTAX OMsDirectoryString " "SINGLE-VALUE )", NULL, NULL }, - /* deprecated; aliases "acl-passwd" */ + /* deprecated, will be removed; aliases "acl-passwd" */ { "bindpw", "cred", 2, 2, 0, - ARG_BERVAL|ARG_MAGIC|LDAP_BACK_CFG_ACL_PASSWD, + ARG_MAGIC|LDAP_BACK_CFG_ACL_PASSWD, + ldap_back_cf_gen, NULL, NULL, NULL }, + /* deprecated, will be removed; aliases "acl-bind" */ + { "acl-method", "args", 2, 0, 0, + ARG_MAGIC|LDAP_BACK_CFG_ACL_METHOD, ldap_back_cf_gen, NULL, NULL, NULL }, { "acl-bind", "args", 2, 0, 0, - ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_ACL_BIND, + ARG_MAGIC|LDAP_BACK_CFG_ACL_BIND, ldap_back_cf_gen, "( OLcfgDbAt:3.4 " "NAME 'olcDbACLBind' " "DESC 'Remote ACL administrative identity auth bind configuration' " "SYNTAX OMsDirectoryString " "SINGLE-VALUE )", NULL, NULL }, - /* deprecated; aliases "acl-bind" */ - { "acl-method", "args", 2, 0, 0, - ARG_BERVAL|ARG_MAGIC|LDAP_BACK_CFG_ACL_BIND, - ldap_back_cf_gen, NULL, NULL, NULL }, { "idassert-authcDN", "DN", 2, 2, 0, ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHCDN, ldap_back_cf_gen, "( OLcfgDbAt:3.5 " @@ -126,12 +144,12 @@ static ConfigTable ldapcfg[] = { "SYNTAX OMsDN " "SINGLE-VALUE )", NULL, NULL }, - /* deprecated; partially aliases "idassert-authcDN" */ + /* deprecated, will be removed; partially aliases "idassert-authcDN" */ { "proxyauthzdn", "DN", 2, 2, 0, ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHCDN, ldap_back_cf_gen, NULL, NULL, NULL }, { "idassert-passwd", "cred", 2, 2, 0, - ARG_BERVAL|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSWD, + ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSWD, ldap_back_cf_gen, "( OLcfgDbAt:3.6 " "NAME 'olcDbIDAssertPasswd' " "DESC 'Remote Identity Assertion administrative identity credentials' " @@ -139,12 +157,12 @@ static ConfigTable ldapcfg[] = { "SYNTAX OMsDirectoryString " "SINGLE-VALUE )", NULL, NULL }, - /* deprecated; partially aliases "idassert-passwd" */ + /* deprecated, will be removed; partially aliases "idassert-passwd" */ { "proxyauthzpw", "cred", 2, 2, 0, - ARG_BERVAL|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSWD, + ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSWD, ldap_back_cf_gen, NULL, NULL, NULL }, { "idassert-bind", "args", 2, 0, 0, - ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_BIND, + ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_BIND, ldap_back_cf_gen, "( OLcfgDbAt:3.7 " "NAME 'olcDbIDAssertBind' " "DESC 'Remote Identity Assertion administrative identity auth bind configuration' " @@ -152,7 +170,7 @@ static ConfigTable ldapcfg[] = { "SINGLE-VALUE )", NULL, NULL }, { "idassert-method", "args", 2, 0, 0, - ARG_BERVAL|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_METHOD, + ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_METHOD, ldap_back_cf_gen, NULL, NULL, NULL }, { "idassert-mode", "mode>|u:|[dn:]", 2, 2, 0, + ARG_MAGIC|ARG_INT|LDAP_BACK_CFG_CONNPOOLMAX, + ldap_back_cf_gen, "( OLcfgDbAt:3.23 " + "NAME 'olcDbConnectionPoolMax' " + "DESC 'Max size of privileged connections pool' " + "SYNTAX OMsInteger " + "SINGLE-VALUE )", + NULL, NULL }, +#ifdef SLAP_CONTROL_X_SESSION_TRACKING + { "session-tracking-request", "true|FALSE", 2, 2, 0, + ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_ST_REQUEST, + ldap_back_cf_gen, "( OLcfgDbAt:3.24 " + "NAME 'olcDbSessionTrackingRequest' " + "DESC 'Add session tracking control to proxied requests' " + "SYNTAX OMsBoolean " + "SINGLE-VALUE )", + NULL, NULL }, +#endif /* SLAP_CONTROL_X_SESSION_TRACKING */ + { "norefs", "true|FALSE", 2, 2, 0, + ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_NOREFS, + ldap_back_cf_gen, "( OLcfgDbAt:3.25 " + "NAME 'olcDbNoRefs' " + "DESC 'Do not return search reference responses' " + "SYNTAX OMsBoolean " + "SINGLE-VALUE )", + NULL, NULL }, + { "noundeffilter", "true|FALSE", 2, 2, 0, + ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_NOUNDEFFILTER, + ldap_back_cf_gen, "( OLcfgDbAt:3.26 " + "NAME 'olcDbNoUndefFilter' " + "DESC 'Do not propagate undefined search filters' " + "SYNTAX OMsBoolean " + "SINGLE-VALUE )", + NULL, NULL }, + { "idassert-passThru", "authzRule", 2, 2, 0, + ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSTHRU, + ldap_back_cf_gen, "( OLcfgDbAt:3.27 " + "NAME 'olcDbIDAssertPassThru' " + "DESC 'Remote Identity Assertion passthru rules' " + "EQUALITY caseIgnoreMatch " + "SYNTAX OMsDirectoryString " + "X-ORDERED 'VALUES' )", + NULL, NULL }, + { "suffixmassage", "[virtual]> type ) { - case LDAP_BACK_CFG_URI: - if ( li->url != NULL ) { - c->value_string = ch_strdup( li->url ); + for ( i = 0; retrylist[ i ] != NULL; i++ ) + /* count */ ; - } else { + ri->ri_interval = ch_calloc( sizeof( time_t ), i + 1 ); + ri->ri_num = ch_calloc( sizeof( int ), i + 1 ); + + for ( i = 0; retrylist[ i ] != NULL; i++ ) { + unsigned long t; + char *sep = strchr( retrylist[ i ], ',' ); + + if ( sep == NULL ) { + snprintf( buf, buflen, + "missing comma in retry pattern #%d \"%s\"", + i, retrylist[ i ] ); + rc = 1; + goto done; + } + + *sep++ = '\0'; + + if ( lutil_parse_time( retrylist[ i ], &t ) ) { + snprintf( buf, buflen, + "unable to parse interval #%d \"%s\"", + i, retrylist[ i ] ); + rc = 1; + goto done; + } + ri->ri_interval[ i ] = (time_t)t; + + if ( strcmp( sep, "+" ) == 0 ) { + if ( retrylist[ i + 1 ] != NULL ) { + snprintf( buf, buflen, + "extra cruft after retry pattern " + "#%d \"%s,+\" with \"forever\" mark", + i, retrylist[ i ] ); rc = 1; + goto done; } - break; + ri->ri_num[ i ] = SLAP_RETRYNUM_FOREVER; + + } else if ( lutil_atoi( &ri->ri_num[ i ], sep ) ) { + snprintf( buf, buflen, + "unable to parse retry num #%d \"%s\"", + i, sep ); + rc = 1; + goto done; + } + } - case LDAP_BACK_CFG_TLS: - enum_to_verb( tls_mode, ( li->flags & LDAP_BACK_F_TLS_MASK ), &bv ); - if ( BER_BVISNULL( &bv ) ) { - /* there's something wrong... */ - assert( 0 ); - rc = 1; + ri->ri_num[ i ] = SLAP_RETRYNUM_TAIL; - } else { - c->value_bv = bv; - } - break; + ri->ri_idx = 0; + ri->ri_count = 0; + ri->ri_last = (time_t)(-1); - case LDAP_BACK_CFG_ACL_AUTHCDN: - case LDAP_BACK_CFG_ACL_PASSWD: - case LDAP_BACK_CFG_ACL_METHOD: - /* handled by LDAP_BACK_CFG_ACL_BIND */ - rc = 1; - break; +done:; + ldap_charray_free( retrylist ); - case LDAP_BACK_CFG_ACL_BIND: { - int i; + if ( rc ) { + slap_retry_info_destroy( ri ); + } - bindconf_unparse( &li->acl_sb, &bv ); + return rc; +} - for ( i = 0; isspace( bv.bv_val[ i ] ); i++ ) - /* count spaces */ ; +int +slap_retry_info_unparse( + slap_retry_info_t *ri, + struct berval *bvout ) +{ + char buf[ BUFSIZ * 2 ], + *ptr = buf; + int i, len, restlen = (int) sizeof( buf ); + struct berval bv; - if ( i ) { - bv.bv_len -= i; - AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ], - bv.bv_len + 1 ); - } + assert( ri != NULL ); + assert( bvout != NULL ); - c->value_string = bv.bv_val; - break; - } + BER_BVZERO( bvout ); - case LDAP_BACK_CFG_IDASSERT_MODE: - case LDAP_BACK_CFG_IDASSERT_AUTHCDN: - case LDAP_BACK_CFG_IDASSERT_PASSWD: - case LDAP_BACK_CFG_IDASSERT_METHOD: - /* handled by LDAP_BACK_CFG_IDASSERT_BIND */ - rc = 1; - break; + for ( i = 0; ri->ri_num[ i ] != SLAP_RETRYNUM_TAIL; i++ ) { + if ( i > 0 ) { + if ( --restlen <= 0 ) { + return 1; + } + *ptr++ = ';'; + } - case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: { - int i; + if ( lutil_unparse_time( ptr, restlen, ri->ri_interval[i] ) < 0 ) { + return 1; + } + len = (int) strlen( ptr ); + if ( (restlen -= len + 1) <= 0 ) { + return 1; + } + ptr += len; + *ptr++ = ','; - if ( li->idassert_authz == NULL ) { - rc = 1; - break; + if ( ri->ri_num[i] == SLAP_RETRYNUM_FOREVER ) { + if ( --restlen <= 0 ) { + return 1; } + *ptr++ = '+'; - for ( i = 0; !BER_BVISNULL( &li->idassert_authz[ i ] ); i++ ) - { - value_add_one( &c->rvalue_vals, &li->idassert_authz[ i ] ); + } else { + len = snprintf( ptr, restlen, "%d", ri->ri_num[i] ); + if ( (restlen -= len) <= 0 || len < 0 ) { + return 1; } - break; + ptr += len; } + } - case LDAP_BACK_CFG_IDASSERT_BIND: { - int i; - struct berval bc = BER_BVNULL; - char *ptr; + bv.bv_val = buf; + bv.bv_len = ptr - buf; + ber_dupbv( bvout, &bv ); - if ( li->idassert_authmethod != LDAP_AUTH_NONE ) { - ber_len_t len; + return 0; +} - switch ( li->idassert_mode ) { - case LDAP_BACK_IDASSERT_OTHERID: - case LDAP_BACK_IDASSERT_OTHERDN: - break; +void +slap_retry_info_destroy( + slap_retry_info_t *ri ) +{ + assert( ri != NULL ); - default: { - struct berval mode = BER_BVNULL; + assert( ri->ri_interval != NULL ); + ch_free( ri->ri_interval ); + ri->ri_interval = NULL; - enum_to_verb( idassert_mode, li->idassert_mode, &mode ); - if ( BER_BVISNULL( &mode ) ) { - /* there's something wrong... */ - assert( 0 ); - rc = 1; - - } else { - bv.bv_len = STRLENOF( "mode=" ) + mode.bv_len; - bv.bv_val = ch_malloc( bv.bv_len + 1 ); + assert( ri->ri_num != NULL ); + ch_free( ri->ri_num ); + ri->ri_num = NULL; +} - ptr = lutil_strcopy( bv.bv_val, "mode=" ); - ptr = lutil_strcopy( ptr, mode.bv_val ); - } - break; - } - } +static int +slap_idassert_authzfrom_parse( ConfigArgs *c, slap_idassert_t *si ) +{ + struct berval bv; + struct berval in; + int rc; - if ( li->idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) { - len = bv.bv_len + STRLENOF( "authz=native" ); + if ( strcmp( c->argv[ 1 ], "*" ) == 0 + || strcmp( c->argv[ 1 ], "dn:*" ) == 0 + || strcasecmp( c->argv[ 1 ], "dn.regex:.*" ) == 0 ) + { + if ( si->si_authz != NULL ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "\"idassert-authzFrom \": " + "\"%s\" conflicts with existing authz rules", + c->argv[ 1 ] ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; + } + + si->si_flags |= LDAP_BACK_AUTH_AUTHZ_ALL; + + return 0; + + } else if ( ( si->si_flags & LDAP_BACK_AUTH_AUTHZ_ALL ) ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "\"idassert-authzFrom \": " + "\"\" conflicts with \"*\"" ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; + } + + ber_str2bv( c->argv[ 1 ], 0, 0, &in ); + rc = authzNormalize( 0, NULL, NULL, &in, &bv, NULL ); + if ( rc != LDAP_SUCCESS ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "\"idassert-authzFrom \": " + "invalid syntax" ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; + } + + if ( c->valx == -1 ) { + ber_bvarray_add( &si->si_authz, &bv ); - if ( !BER_BVISEMPTY( &bv ) ) { - len += STRLENOF( " " ); - } + } else { + int i = 0; + if ( si->si_authz != NULL ) { + for ( ; !BER_BVISNULL( &si->si_authz[ i ] ); i++ ) + ; + } - bv.bv_val = ch_realloc( bv.bv_val, len + 1 ); + if ( i <= c->valx ) { + ber_bvarray_add( &si->si_authz, &bv ); - ptr = &bv.bv_val[ bv.bv_len ]; + } else { + BerVarray tmp = ber_memrealloc( si->si_authz, + sizeof( struct berval )*( i + 2 ) ); + if ( tmp == NULL ) { + return -1; + } + si->si_authz = tmp; + for ( ; i > c->valx; i-- ) { + si->si_authz[ i ] = si->si_authz[ i - 1 ]; + } + si->si_authz[ c->valx ] = bv; + } + } - if ( !BER_BVISEMPTY( &bv ) ) { - ptr = lutil_strcopy( ptr, " " ); - } + return 0; +} - (void)lutil_strcopy( ptr, "authz=native" ); - } +static int +slap_idassert_passthru_parse( ConfigArgs *c, slap_idassert_t *si ) +{ + struct berval bv; + struct berval in; + int rc; - len = bv.bv_len + STRLENOF( "flags=non-prescriptive,override" ); - /* flags */ - if ( !BER_BVISEMPTY( &bv ) ) { - len += STRLENOF( " " ); - } + ber_str2bv( c->argv[ 1 ], 0, 0, &in ); + rc = authzNormalize( 0, NULL, NULL, &in, &bv, NULL ); + if ( rc != LDAP_SUCCESS ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "\"idassert-passThru \": " + "invalid syntax" ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; + } + + if ( c->valx == -1 ) { + ber_bvarray_add( &si->si_passthru, &bv ); - bv.bv_val = ch_realloc( bv.bv_val, len + 1 ); + } else { + int i = 0; + if ( si->si_passthru != NULL ) { + for ( ; !BER_BVISNULL( &si->si_passthru[ i ] ); i++ ) + ; + } - ptr = &bv.bv_val[ bv.bv_len ]; + if ( i <= c->valx ) { + ber_bvarray_add( &si->si_passthru, &bv ); - if ( !BER_BVISEMPTY( &bv ) ) { - ptr = lutil_strcopy( ptr, " " ); - } + } else { + BerVarray tmp = ber_memrealloc( si->si_passthru, + sizeof( struct berval )*( i + 2 ) ); + if ( tmp == NULL ) { + return -1; + } + si->si_passthru = tmp; + for ( ; i > c->valx; i-- ) { + si->si_passthru[ i ] = si->si_passthru[ i - 1 ]; + } + si->si_passthru[ c->valx ] = bv; + } + } - ptr = lutil_strcopy( ptr, "flags=" ); + return 0; +} - if ( li->idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) { - ptr = lutil_strcopy( ptr, "prescriptive" ); - } else { - ptr = lutil_strcopy( ptr, "non-prescriptive" ); - } +static int +slap_idassert_parse( ConfigArgs *c, slap_idassert_t *si ) +{ + int i; - if ( li->idassert_flags & LDAP_BACK_AUTH_OVERRIDE ) { - ptr = lutil_strcopy( ptr, ",override" ); + for ( i = 1; i < c->argc; i++ ) { + if ( strncasecmp( c->argv[ i ], "mode=", STRLENOF( "mode=" ) ) == 0 ) { + char *argvi = c->argv[ i ] + STRLENOF( "mode=" ); + int j; + + j = verb_to_mask( argvi, idassert_mode ); + if ( BER_BVISNULL( &idassert_mode[ j ].word ) ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "\"idassert-bind \": " + "unknown mode \"%s\"", + argvi ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; + } + + si->si_mode = idassert_mode[ j ].mask; + + } else if ( strncasecmp( c->argv[ i ], "authz=", STRLENOF( "authz=" ) ) == 0 ) { + char *argvi = c->argv[ i ] + STRLENOF( "authz=" ); + + if ( strcasecmp( argvi, "native" ) == 0 ) { + if ( si->si_bc.sb_method != LDAP_AUTH_SASL ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "\"idassert-bind \": " + "authz=\"native\" incompatible " + "with auth method" ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; } + si->si_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ; - bv.bv_len = ( ptr - bv.bv_val ); - /* end-of-flags */ - } + } else if ( strcasecmp( argvi, "proxyAuthz" ) == 0 ) { + si->si_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ; - bindconf_unparse( &li->idassert_sb, &bc ); + } else { + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "\"idassert-bind \": " + "unknown authz \"%s\"", + argvi ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; + } - if ( !BER_BVISNULL( &bv ) ) { - ber_len_t len = bv.bv_len + bc.bv_len; + } else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 ) { + char *argvi = c->argv[ i ] + STRLENOF( "flags=" ); + char **flags = ldap_str2charray( argvi, "," ); + int j, err = 0; + + if ( flags == NULL ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "\"idassert-bind \": " + "unable to parse flags \"%s\"", + argvi ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; + } - c->value_string = ch_realloc( bv.bv_val, len + 1 ); + for ( j = 0; flags[ j ] != NULL; j++ ) { - assert( bc.bv_val[ 0 ] == ' ' ); + if ( strcasecmp( flags[ j ], "override" ) == 0 ) { + si->si_flags |= LDAP_BACK_AUTH_OVERRIDE; - (void)lutil_strcopy( &c->value_string[ bv.bv_len ], bc.bv_val ); + } else if ( strcasecmp( flags[ j ], "prescriptive" ) == 0 ) { + si->si_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE; - free( bc.bv_val ); + } else if ( strcasecmp( flags[ j ], "non-prescriptive" ) == 0 ) { + si->si_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE ); - } else { - for ( i = 0; isspace( bc.bv_val[ i ] ); i++ ) - /* count spaces */ ; + } else if ( strcasecmp( flags[ j ], "obsolete-proxy-authz" ) == 0 ) { + if ( si->si_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) { + Debug( LDAP_DEBUG_ANY, + "%s: \"obsolete-proxy-authz\" flag " + "in \"idassert-mode \" " + "incompatible with previously issued \"obsolete-encoding-workaround\" flag.\n", + c->log, 0, 0 ); + err = 1; + break; - if ( i ) { - bc.bv_len -= i; - AC_MEMCPY( bc.bv_val, &bc.bv_val[ i ], bc.bv_len + 1 ); + } else { + si->si_flags |= LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ; + } + + } else if ( strcasecmp( flags[ j ], "obsolete-encoding-workaround" ) == 0 ) { + if ( si->si_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) { + Debug( LDAP_DEBUG_ANY, + "%s: \"obsolete-encoding-workaround\" flag " + "in \"idassert-mode \" " + "incompatible with previously issued \"obsolete-proxy-authz\" flag.\n", + c->log, 0, 0 ); + err = 1; + break; + + } else { + si->si_flags |= LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND; + } + + } else if ( strcasecmp( flags[ j ], "proxy-authz-critical" ) == 0 ) { + si->si_flags |= LDAP_BACK_AUTH_PROXYAUTHZ_CRITICAL; + + } else if ( strcasecmp( flags[ j ], "proxy-authz-non-critical" ) == 0 ) { + si->si_flags &= ~LDAP_BACK_AUTH_PROXYAUTHZ_CRITICAL; + + } else { + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "\"idassert-bind \": " + "unknown flag \"%s\"", + flags[ j ] ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + err = 1; + break; } + } - c->value_string = bv.bv_val; + ldap_charray_free( flags ); + if ( err ) { + return 1; } - - break; + + } else if ( bindconf_parse( c->argv[ i ], &si->si_bc ) ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "\"idassert-bind \": " + "unable to parse field \"%s\"", + c->argv[ i ] ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; } + } - case LDAP_BACK_CFG_REBIND: - enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_SAVECRED ) == LDAP_BACK_F_SAVECRED ), &bv ); - if ( BER_BVISNULL( &bv ) ) { - /* there's something wrong... */ - assert( 0 ); - rc = 1; + if ( si->si_bc.sb_method == LDAP_AUTH_SIMPLE ) { + if ( BER_BVISNULL( &si->si_bc.sb_binddn ) + || BER_BVISNULL( &si->si_bc.sb_cred ) ) + { + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "\"idassert-bind \": " + "SIMPLE needs \"binddn\" and \"credentials\"" ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; + } + } - } else { - c->value_bv = bv; - } - break; + bindconf_tls_defaults( &si->si_bc ); - case LDAP_BACK_CFG_CHASE: - enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_CHASE_REFERRALS ) == LDAP_BACK_F_CHASE_REFERRALS ), &bv ); - if ( BER_BVISNULL( &bv ) ) { - /* there's something wrong... */ - assert( 0 ); - rc = 1; + return 0; +} - } else { - c->value_bv = bv; - } - break; +/* NOTE: temporary, until back-meta is ported to back-config */ +int +slap_idassert_authzfrom_parse_cf( const char *fname, int lineno, const char *arg, slap_idassert_t *si ) +{ + ConfigArgs c = { 0 }; + char *argv[ 3 ]; - case LDAP_BACK_CFG_T_F: - enum_to_verb( t_f_mode, ( ( li->flags & LDAP_BACK_F_SUPPORT_T_F_MASK ) == LDAP_BACK_F_SUPPORT_T_F_MASK ), &bv ); - if ( BER_BVISNULL( &bv ) ) { - /* there's something wrong... */ - assert( 0 ); - rc = 1; + snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno ); + c.argc = 2; + c.argv = argv; + argv[ 0 ] = "idassert-authzFrom"; + argv[ 1 ] = (char *)arg; + argv[ 2 ] = NULL; - } else { - c->value_bv = bv; - } - break; + return slap_idassert_authzfrom_parse( &c, si ); +} - case LDAP_BACK_CFG_WHOAMI: - enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_PROXY_WHOAMI ) == LDAP_BACK_F_PROXY_WHOAMI ), &bv ); - if ( BER_BVISNULL( &bv ) ) { - /* there's something wrong... */ - assert( 0 ); - rc = 1; +int +slap_idassert_passthru_parse_cf( const char *fname, int lineno, const char *arg, slap_idassert_t *si ) +{ + ConfigArgs c = { 0 }; + char *argv[ 3 ]; - } else { - c->value_bv = bv; - } - break; + snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno ); + c.argc = 2; + c.argv = argv; + argv[ 0 ] = "idassert-passThru"; + argv[ 1 ] = (char *)arg; + argv[ 2 ] = NULL; - default: - /* we need to handle all... */ - assert( 0 ); - break; + return slap_idassert_passthru_parse( &c, si ); +} + +int +slap_idassert_parse_cf( const char *fname, int lineno, int argc, char *argv[], slap_idassert_t *si ) +{ + ConfigArgs c = { 0 }; + + snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno ); + c.argc = argc; + c.argv = argv; + + return slap_idassert_parse( &c, si ); +} + +static int +ldap_back_cf_gen( ConfigArgs *c ) +{ + ldapinfo_t *li = ( ldapinfo_t * )c->be->be_private; + int rc = 0; + int i; + + if ( c->op == SLAP_CONFIG_EMIT ) { + struct berval bv = BER_BVNULL; + + if ( li == NULL ) { + return 1; } - return rc; - } else if ( c->op == LDAP_MOD_DELETE ) { - rc = 0; switch( c->type ) { case LDAP_BACK_CFG_URI: - if ( li->url != NULL ) { - ch_free( li->url ); - li->url = NULL; + if ( li->li_uri != NULL ) { + struct berval bv, bv2; + + ber_str2bv( li->li_uri, 0, 0, &bv ); + bv2.bv_len = bv.bv_len + STRLENOF( "\"\"" ); + bv2.bv_val = ch_malloc( bv2.bv_len + 1 ); + snprintf( bv2.bv_val, bv2.bv_len + 1, + "\"%s\"", bv.bv_val ); + ber_bvarray_add( &c->rvalue_vals, &bv2 ); + + } else { + rc = 1; } + break; - if ( li->lud != NULL ) { - ldap_free_urllist( li->lud ); - li->lud = NULL; + case LDAP_BACK_CFG_TLS: { + struct berval bc = BER_BVNULL, bv2; + enum_to_verb( tls_mode, ( li->li_flags & LDAP_BACK_F_TLS_MASK ), &bv ); + assert( !BER_BVISNULL( &bv ) ); + bindconf_tls_unparse( &li->li_tls, &bc ); + + if ( !BER_BVISEMPTY( &bc )) { + bv2.bv_len = bv.bv_len + bc.bv_len + 1; + bv2.bv_val = ch_malloc( bv2.bv_len + 1 ); + strcpy( bv2.bv_val, bv.bv_val ); + bv2.bv_val[bv.bv_len] = ' '; + strcpy( &bv2.bv_val[bv.bv_len + 1], bc.bv_val ); + ber_bvarray_add( &c->rvalue_vals, &bv2 ); + + } else { + value_add_one( &c->rvalue_vals, &bv ); + } + ber_memfree( bc.bv_val ); } - - /* better cleanup the cached connections... */ - /* NOTE: don't worry about locking: if we got here, - * other threads are suspended. */ - avl_free( li->conntree, ldap_back_conn_free ); - li->conntree = NULL; - break; - case LDAP_BACK_CFG_TLS: case LDAP_BACK_CFG_ACL_AUTHCDN: case LDAP_BACK_CFG_ACL_PASSWD: case LDAP_BACK_CFG_ACL_METHOD: @@ -547,9 +1016,27 @@ ldap_back_cf_gen( ConfigArgs *c ) rc = 1; break; - case LDAP_BACK_CFG_ACL_BIND: - bindconf_free( &li->acl_sb ); + case LDAP_BACK_CFG_ACL_BIND: { + int i; + + if ( li->li_acl_authmethod == LDAP_AUTH_NONE ) { + return 1; + } + + bindconf_unparse( &li->li_acl, &bv ); + + for ( i = 0; isspace( (unsigned char) bv.bv_val[ i ] ); i++ ) + /* count spaces */ ; + + if ( i ) { + bv.bv_len -= i; + AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ], + bv.bv_len + 1 ); + } + + ber_bvarray_add( &c->rvalue_vals, &bv ); break; + } case LDAP_BACK_CFG_IDASSERT_MODE: case LDAP_BACK_CFG_IDASSERT_AUTHCDN: @@ -560,639 +1047,520 @@ ldap_back_cf_gen( ConfigArgs *c ) break; case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: - if ( li->idassert_authz != NULL ) { - ber_bvarray_free( li->idassert_authz ); - li->idassert_authz = NULL; + case LDAP_BACK_CFG_IDASSERT_PASSTHRU: { + BerVarray *bvp; + int i; + struct berval bv = BER_BVNULL; + char buf[SLAP_TEXT_BUFLEN]; + + switch ( c->type ) { + case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: bvp = &li->li_idassert_authz; break; + case LDAP_BACK_CFG_IDASSERT_PASSTHRU: bvp = &li->li_idassert_passthru; break; + default: assert( 0 ); break; } - break; - case LDAP_BACK_CFG_IDASSERT_BIND: - bindconf_free( &li->idassert_sb ); - break; + if ( *bvp == NULL ) { + if ( bvp == &li->li_idassert_authz + && ( li->li_idassert_flags & LDAP_BACK_AUTH_AUTHZ_ALL ) ) + { + BER_BVSTR( &bv, "*" ); + value_add_one( &c->rvalue_vals, &bv ); - case LDAP_BACK_CFG_REBIND: - case LDAP_BACK_CFG_CHASE: - case LDAP_BACK_CFG_T_F: - case LDAP_BACK_CFG_WHOAMI: - rc = 1; - break; + } else { + rc = 1; + } + break; + } - default: - /* we need to handle all... */ - assert( 0 ); + for ( i = 0; !BER_BVISNULL( &((*bvp)[ i ]) ); i++ ) { + char *ptr; + int len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i ); + bv.bv_len = ((*bvp)[ i ]).bv_len + len; + bv.bv_val = ber_memrealloc( bv.bv_val, bv.bv_len + 1 ); + ptr = bv.bv_val; + ptr = lutil_strcopy( ptr, buf ); + ptr = lutil_strncopy( ptr, ((*bvp)[ i ]).bv_val, ((*bvp)[ i ]).bv_len ); + value_add_one( &c->rvalue_vals, &bv ); + } + if ( bv.bv_val ) { + ber_memfree( bv.bv_val ); + } break; } - return rc; - - } - switch( c->type ) { - case LDAP_BACK_CFG_URI: { - LDAPURLDesc *tmpludp; - char **urllist; - int urlrc, i; - - if ( c->argc != 2 ) { - fprintf( stderr, "%s: line %d: " - "missing uri " - "in \"uri \" line\n", - c->fname, c->lineno ); - return 1; - } - - if ( li->url != NULL ) { - ch_free( li->url ); - } + case LDAP_BACK_CFG_IDASSERT_BIND: { + int i; + struct berval bc = BER_BVNULL; + char *ptr; - if ( li->lud != NULL ) { - ldap_free_urllist( li->lud ); - } + if ( li->li_idassert_authmethod == LDAP_AUTH_NONE ) { + return 1; + } -#if 0 - /* PARANOID: DN and more are not required nor allowed */ - urlrc = ldap_url_parselist_ext( &li->lud, c->value_string, "\t" ); -#else - urlrc = ldap_url_parselist( &li->lud, c->value_string ); -#endif - if ( urlrc != LDAP_URL_SUCCESS ) { - char *why; + if ( li->li_idassert_authmethod != LDAP_AUTH_NONE ) { + ber_len_t len; - switch ( urlrc ) { - case LDAP_URL_ERR_MEM: - why = "no memory"; - break; - case LDAP_URL_ERR_PARAM: - why = "parameter is bad"; - break; - case LDAP_URL_ERR_BADSCHEME: - why = "URL doesn't begin with \"[c]ldap[si]://\""; - break; - case LDAP_URL_ERR_BADENCLOSURE: - why = "URL is missing trailing \">\""; - break; - case LDAP_URL_ERR_BADURL: - why = "URL is bad"; - case LDAP_URL_ERR_BADHOST: - why = "host/port is bad"; - break; - case LDAP_URL_ERR_BADATTRS: - why = "bad (or missing) attributes"; - break; - case LDAP_URL_ERR_BADSCOPE: - why = "scope string is invalid (or missing)"; - break; - case LDAP_URL_ERR_BADFILTER: - why = "bad or missing filter"; - break; - case LDAP_URL_ERR_BADEXTS: - why = "bad or missing extensions"; - break; - default: - why = "unknown reason"; - break; - } - fprintf( stderr, "%s: line %d: " - "unable to parse uri \"%s\" " - "in \"uri \" line: %s\n", - c->fname, c->lineno, c->value_string, why ); - return 1; - } + switch ( li->li_idassert_mode ) { + case LDAP_BACK_IDASSERT_OTHERID: + case LDAP_BACK_IDASSERT_OTHERDN: + break; - for ( i = 0, tmpludp = li->lud; - tmpludp; - i++, tmpludp = tmpludp->lud_next ) - { - if ( ( tmpludp->lud_dn != NULL - && tmpludp->lud_dn[0] != '\0' ) - || tmpludp->lud_attrs != NULL - /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */ - || tmpludp->lud_filter != NULL - || tmpludp->lud_exts != NULL ) - { - fprintf( stderr, "%s: line %d: " - "warning, only protocol, " - "host and port allowed " - "in \"uri \" statement " - "for uri #%d of \"%s\"\n", - c->fname, c->lineno, i, c->value_string ); - } - } + default: { + struct berval mode = BER_BVNULL; -#if 0 - for ( i = 0, tmpludp = li->lud; - tmpludp; - i++, tmpludp = tmpludp->lud_next ) - /* just count */ - - urllist = ch_calloc( sizeof( char * ), i + 1 ); + enum_to_verb( idassert_mode, li->li_idassert_mode, &mode ); + if ( BER_BVISNULL( &mode ) ) { + /* there's something wrong... */ + assert( 0 ); + rc = 1; + + } else { + bv.bv_len = STRLENOF( "mode=" ) + mode.bv_len; + bv.bv_val = ch_malloc( bv.bv_len + 1 ); - for ( i = 0, tmpludp = li->lud; - tmpludp; - i++, tmpludp = tmpludp->lud_next ) - { - LDAPURLDesc tmplud; - ber_len_t oldlen = 0, len; + ptr = lutil_strcopy( bv.bv_val, "mode=" ); + ptr = lutil_strcopy( ptr, mode.bv_val ); + } + break; + } + } - tmplud = *tmpludp; - tmplud.lud_dn = ""; - tmplud.lud_attrs = NULL; - tmplud.lud_filter = NULL; - if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) { - tmplud.lud_exts = NULL; - tmplud.lud_crit_exts = 0; - } + if ( li->li_idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) { + len = bv.bv_len + STRLENOF( "authz=native" ); - urllist[ i ] = ldap_url_desc2str( &tmplud ); + if ( !BER_BVISEMPTY( &bv ) ) { + len += STRLENOF( " " ); + } - if ( urllist[ i ] == NULL ) { - fprintf( stderr, "%s: line %d: " - "unable to rebuild uri " - "in \"uri \" statement " - "for \"%s\"\n", - c->fname, c->lineno, argv[ 1 ] ); - return 1; - } - } + bv.bv_val = ch_realloc( bv.bv_val, len + 1 ); - li->url = ldap_charray2str( urllist, " " ); - ldap_charray_free( urllist ); -#else - li->url = ch_strdup( c->value_string ); -#endif - break; - } + ptr = &bv.bv_val[ bv.bv_len ]; - case LDAP_BACK_CFG_TLS: - i = verb_to_mask( c->argv[1], tls_mode ); - if ( BER_BVISNULL( &tls_mode[i].word ) ) { - return 1; - } - li->flags &= ~LDAP_BACK_F_TLS_MASK; - li->flags |= tls_mode[i].mask; - break; + if ( !BER_BVISEMPTY( &bv ) ) { + ptr = lutil_strcopy( ptr, " " ); + } - case LDAP_BACK_CFG_ACL_AUTHCDN: - switch ( li->acl_authmethod ) { - case LDAP_AUTH_NONE: - li->acl_authmethod = LDAP_AUTH_SIMPLE; - break; + (void)lutil_strcopy( ptr, "authz=native" ); + } - case LDAP_AUTH_SIMPLE: - break; + len = bv.bv_len + STRLENOF( "flags=non-prescriptive,override,obsolete-encoding-workaround,proxy-authz-non-critical" ); + /* flags */ + if ( !BER_BVISEMPTY( &bv ) ) { + len += STRLENOF( " " ); + } - default: - fprintf( stderr, "%s: line %d: " - "\"acl-authcDN \" incompatible " - "with auth method %d.", - c->fname, c->lineno, li->acl_authmethod ); - return 1; - } - if ( !BER_BVISNULL( &li->acl_authcDN ) ) { - free( li->acl_authcDN.bv_val ); - } - li->acl_authcDN = c->value_ndn; - break; + bv.bv_val = ch_realloc( bv.bv_val, len + 1 ); - case LDAP_BACK_CFG_ACL_PASSWD: - switch ( li->acl_authmethod ) { - case LDAP_AUTH_NONE: - li->acl_authmethod = LDAP_AUTH_SIMPLE; - break; + ptr = &bv.bv_val[ bv.bv_len ]; - case LDAP_AUTH_SIMPLE: - break; + if ( !BER_BVISEMPTY( &bv ) ) { + ptr = lutil_strcopy( ptr, " " ); + } - default: - fprintf( stderr, "%s: line %d: " - "\"acl-passwd \" incompatible " - "with auth method %d.", - c->fname, c->lineno, li->acl_authmethod ); - return 1; - } - if ( !BER_BVISNULL( &li->acl_passwd ) ) { - free( li->acl_passwd.bv_val ); - } - li->acl_passwd = c->value_bv; - break; + ptr = lutil_strcopy( ptr, "flags=" ); - case LDAP_BACK_CFG_ACL_METHOD: - case LDAP_BACK_CFG_ACL_BIND: - for ( i = 1; i < c->argc; i++ ) { - if ( bindconf_parse( c->argv[ i ], &li->acl_sb ) ) { - return 1; - } - } - break; + if ( li->li_idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) { + ptr = lutil_strcopy( ptr, "prescriptive" ); + } else { + ptr = lutil_strcopy( ptr, "non-prescriptive" ); + } - case LDAP_BACK_CFG_IDASSERT_MODE: - i = verb_to_mask( c->argv[1], idassert_mode ); - if ( BER_BVISNULL( &idassert_mode[i].word ) ) { - if ( strncasecmp( c->argv[1], "u:", STRLENOF( "u:" ) ) == 0 ) { - li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID; - ber_str2bv( c->argv[1], 0, 1, &li->idassert_authzID ); - li->idassert_authzID.bv_val[ 0 ] = 'u'; - - } else { - struct berval id, ndn; + if ( li->li_idassert_flags & LDAP_BACK_AUTH_OVERRIDE ) { + ptr = lutil_strcopy( ptr, ",override" ); + } - ber_str2bv( c->argv[1], 0, 0, &id ); + if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) { + ptr = lutil_strcopy( ptr, ",obsolete-proxy-authz" ); - if ( strncasecmp( c->argv[1], "dn:", STRLENOF( "dn:" ) ) == 0 ) { - id.bv_val += STRLENOF( "dn:" ); - id.bv_len -= STRLENOF( "dn:" ); + } else if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) { + ptr = lutil_strcopy( ptr, ",obsolete-encoding-workaround" ); } - rc = dnNormalize( 0, NULL, NULL, &id, &ndn, NULL ); - if ( rc != LDAP_SUCCESS ) { - Debug( LDAP_DEBUG_ANY, - "%s: line %d: idassert ID \"%s\" is not a valid DN\n", - c->fname, c->lineno, c->argv[1] ); - return 1; - } + if ( li->li_idassert_flags & LDAP_BACK_AUTH_PROXYAUTHZ_CRITICAL ) { + ptr = lutil_strcopy( ptr, ",proxy-authz-critical" ); - li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + ndn.bv_len; - li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 ); - AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) ); - AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], ndn.bv_val, ndn.bv_len + 1 ); - ch_free( ndn.bv_val ); + } else { + ptr = lutil_strcopy( ptr, ",proxy-authz-non-critical" ); + } - li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN; + bv.bv_len = ( ptr - bv.bv_val ); + /* end-of-flags */ } - } else { - li->idassert_mode = idassert_mode[i].mask; - } + bindconf_unparse( &li->li_idassert.si_bc, &bc ); - if ( c->argc > 2 ) { - int i; + if ( !BER_BVISNULL( &bv ) ) { + ber_len_t len = bv.bv_len + bc.bv_len; - for ( i = 2; i < c->argc; i++ ) { - if ( strcasecmp( c->argv[ i ], "override" ) == 0 ) { - li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE; + bv.bv_val = ch_realloc( bv.bv_val, len + 1 ); - } else if ( strcasecmp( c->argv[ i ], "prescriptive" ) == 0 ) { - li->idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE; + assert( bc.bv_val[ 0 ] == ' ' ); - } else if ( strcasecmp( c->argv[ i ], "non-prescriptive" ) == 0 ) { - li->idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE ); + ptr = lutil_strcopy( &bv.bv_val[ bv.bv_len ], bc.bv_val ); + free( bc.bv_val ); + bv.bv_len = ptr - bv.bv_val; - } else { - Debug( LDAP_DEBUG_ANY, - "%s: line %d: unknown flag #%d " - "in \"idassert-mode " - "[]\" line.\n", - c->fname, c->lineno, i - 2 ); - return 1; + } else { + for ( i = 0; isspace( (unsigned char) bc.bv_val[ i ] ); i++ ) + /* count spaces */ ; + + if ( i ) { + bc.bv_len -= i; + AC_MEMCPY( bc.bv_val, &bc.bv_val[ i ], bc.bv_len + 1 ); } - } - } - break; - case LDAP_BACK_CFG_IDASSERT_AUTHCDN: - switch ( li->idassert_authmethod ) { - case LDAP_AUTH_NONE: - li->idassert_authmethod = LDAP_AUTH_SIMPLE; - break; + bv = bc; + } + + ber_bvarray_add( &c->rvalue_vals, &bv ); - case LDAP_AUTH_SIMPLE: break; - - default: - fprintf( stderr, "%s: line %d: " - "\"idassert-authcDN \" incompatible " - "with auth method %d.", - c->fname, c->lineno, li->idassert_authmethod ); - return 1; - } - if ( !BER_BVISNULL( &li->idassert_authcDN ) ) { - free( li->idassert_authcDN.bv_val ); } - li->idassert_authcDN = c->value_ndn; - break; - case LDAP_BACK_CFG_IDASSERT_PASSWD: - switch ( li->idassert_authmethod ) { - case LDAP_AUTH_NONE: - li->idassert_authmethod = LDAP_AUTH_SIMPLE; + case LDAP_BACK_CFG_REBIND: + c->value_int = LDAP_BACK_SAVECRED( li ); break; - case LDAP_AUTH_SIMPLE: + case LDAP_BACK_CFG_CHASE: + c->value_int = LDAP_BACK_CHASE_REFERRALS( li ); break; - default: - fprintf( stderr, "%s: line %d: " - "\"idassert-passwd \" incompatible " - "with auth method %d.", - c->fname, c->lineno, li->idassert_authmethod ); - return 1; - } - if ( !BER_BVISNULL( &li->idassert_passwd ) ) { - free( li->idassert_passwd.bv_val ); - } - li->idassert_passwd = c->value_bv; - break; + case LDAP_BACK_CFG_T_F: + enum_to_verb( t_f_mode, (li->li_flags & LDAP_BACK_F_T_F_MASK2), &bv ); + if ( BER_BVISNULL( &bv ) ) { + /* there's something wrong... */ + assert( 0 ); + rc = 1; - case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: - ber_bvarray_add( &li->idassert_authz, &c->value_bv ); - break; + } else { + value_add_one( &c->rvalue_vals, &bv ); + } + break; - case LDAP_BACK_CFG_IDASSERT_METHOD: - /* no longer supported */ - fprintf( stderr, "%s: %d: " - "\"idassert-method \": " - "no longer supported; use \"idassert-bind\".\n", - c->fname, c->lineno ); - return 1; + case LDAP_BACK_CFG_WHOAMI: + c->value_int = LDAP_BACK_PROXY_WHOAMI( li ); + break; - case LDAP_BACK_CFG_IDASSERT_BIND: - for ( i = 1; i < c->argc; i++ ) { - if ( strncasecmp( c->argv[ i ], "mode=", STRLENOF( "mode=" ) ) == 0 ) { - char *argvi = c->argv[ i ] + STRLENOF( "mode=" ); - int j; + case LDAP_BACK_CFG_TIMEOUT: + BER_BVZERO( &bv ); - j = verb_to_mask( argvi, idassert_mode ); - if ( BER_BVISNULL( &idassert_mode[ j ].word ) ) { - fprintf( stderr, "%s: %d: " - "\"idassert-bind \": " - "unknown mode \"%s\".\n", - c->fname, c->lineno, argvi ); - return 1; + for ( i = 0; i < SLAP_OP_LAST; i++ ) { + if ( li->li_timeout[ i ] != 0 ) { + break; } + } - li->idassert_mode = idassert_mode[ j ].mask; - - } else if ( strncasecmp( c->argv[ i ], "authz=", STRLENOF( "authz=" ) ) == 0 ) { - char *argvi = c->argv[ i ] + STRLENOF( "authz=" ); - - if ( strcasecmp( argvi, "native" ) == 0 ) { - if ( li->idassert_authmethod != LDAP_AUTH_SASL ) { - fprintf( stderr, "%s: %d: " - "\"idassert-bind \": " - "authz=\"native\" incompatible " - "with auth method.\n", - c->fname, c->lineno ); - return 1; - } - li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ; + if ( i == SLAP_OP_LAST ) { + return 1; + } - } else if ( strcasecmp( argvi, "proxyAuthz" ) == 0 ) { - li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ; + slap_cf_aux_table_unparse( li->li_timeout, &bv, timeout_table ); - } else { - fprintf( stderr, "%s: %d: " - "\"idassert-bind \": " - "unknown authz \"%s\".\n", - c->fname, c->lineno, argvi ); - return 1; - } + if ( BER_BVISNULL( &bv ) ) { + return 1; + } - } else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 ) { - char *argvi = c->argv[ i ] + STRLENOF( "flags=" ); - char **flags = ldap_str2charray( argvi, "," ); - int j; + for ( i = 0; isspace( (unsigned char) bv.bv_val[ i ] ); i++ ) + /* count spaces */ ; - if ( flags == NULL ) { - fprintf( stderr, "%s: %d: " - "\"idassert-bind \": " - "unable to parse flags \"%s\".\n", - c->fname, c->lineno, argvi ); - return 1; - } + if ( i ) { + bv.bv_len -= i; + AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ], + bv.bv_len + 1 ); + } - for ( j = 0; flags[ j ] != NULL; j++ ) { - if ( strcasecmp( flags[ j ], "override" ) == 0 ) { - li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE; + ber_bvarray_add( &c->rvalue_vals, &bv ); + break; - } else if ( strcasecmp( flags[ j ], "prescriptive" ) == 0 ) { - li->idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE; + case LDAP_BACK_CFG_IDLE_TIMEOUT: { + char buf[ SLAP_TEXT_BUFLEN ]; - } else if ( strcasecmp( flags[ j ], "non-prescriptive" ) == 0 ) { - li->idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE ); + if ( li->li_idle_timeout == 0 ) { + return 1; + } - } else { - fprintf( stderr, "%s: %d: " - "\"idassert-bind \": " - "unknown flag \"%s\".\n", - c->fname, c->lineno, flags[ j ] ); - return 1; - } - } + lutil_unparse_time( buf, sizeof( buf ), li->li_idle_timeout ); + ber_str2bv( buf, 0, 0, &bv ); + value_add_one( &c->rvalue_vals, &bv ); + } break; - ldap_charray_free( flags ); + case LDAP_BACK_CFG_CONN_TTL: { + char buf[ SLAP_TEXT_BUFLEN ]; - } else if ( bindconf_parse( c->argv[ i ], &li->idassert_sb ) ) { + if ( li->li_conn_ttl == 0 ) { return 1; } - } - break; - case LDAP_BACK_CFG_REBIND: { - int dorebind = 0; + lutil_unparse_time( buf, sizeof( buf ), li->li_conn_ttl ); + ber_str2bv( buf, 0, 0, &bv ); + value_add_one( &c->rvalue_vals, &bv ); + } break; - if ( c->argc == 1 ) { - /* legacy */ - dorebind = 1; + case LDAP_BACK_CFG_NETWORK_TIMEOUT: { + char buf[ SLAP_TEXT_BUFLEN ]; - } else { - i = verb_to_mask( c->argv[1], yn_mode ); - if ( BER_BVISNULL( &yn_mode[i].word ) ) { + if ( li->li_network_timeout == 0 ) { return 1; } - if ( yn_mode[i].mask & LDAP_BACK_C_YES ) { - dorebind = 1; + + snprintf( buf, sizeof( buf ), "%ld", + (long)li->li_network_timeout ); + ber_str2bv( buf, 0, 0, &bv ); + value_add_one( &c->rvalue_vals, &bv ); + } break; + + case LDAP_BACK_CFG_VERSION: + if ( li->li_version == 0 ) { + return 1; } - } - if ( dorebind ) { - li->flags |= LDAP_BACK_F_SAVECRED; + c->value_int = li->li_version; + break; - } else { - li->flags &= ~LDAP_BACK_F_SAVECRED; - } - break; - } + case LDAP_BACK_CFG_SINGLECONN: + c->value_int = LDAP_BACK_SINGLECONN( li ); + break; + + case LDAP_BACK_CFG_USETEMP: + c->value_int = LDAP_BACK_USE_TEMPORARIES( li ); + break; - case LDAP_BACK_CFG_CHASE: { - int dochase = 0; + case LDAP_BACK_CFG_CONNPOOLMAX: + c->value_int = li->li_conn_priv_max; + break; - if ( c->argc == 1 ) { - /* legacy */ - dochase = 1; + case LDAP_BACK_CFG_CANCEL: { + slap_mask_t mask = LDAP_BACK_F_CANCEL_MASK2; - } else { - i = verb_to_mask( c->argv[1], yn_mode ); - if ( BER_BVISNULL( &yn_mode[i].word ) ) { - return 1; + if ( LDAP_BACK_CANCEL_DISCOVER( li ) ) { + mask &= ~LDAP_BACK_F_CANCEL_EXOP; } - if ( yn_mode[i].mask & LDAP_BACK_C_YES ) { - dochase = 1; + enum_to_verb( cancel_mode, (li->li_flags & mask), &bv ); + if ( BER_BVISNULL( &bv ) ) { + /* there's something wrong... */ + assert( 0 ); + rc = 1; + + } else { + value_add_one( &c->rvalue_vals, &bv ); + } + } break; + + case LDAP_BACK_CFG_QUARANTINE: + if ( !LDAP_BACK_QUARANTINE( li ) ) { + rc = 1; + break; } - } - if ( dochase ) { - li->flags |= LDAP_BACK_F_CHASE_REFERRALS; + rc = slap_retry_info_unparse( &li->li_quarantine, &bv ); + if ( rc == 0 ) { + ber_bvarray_add( &c->rvalue_vals, &bv ); + } + break; - } else { - li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS; - } - break; - } +#ifdef SLAP_CONTROL_X_SESSION_TRACKING + case LDAP_BACK_CFG_ST_REQUEST: + c->value_int = LDAP_BACK_ST_REQUEST( li ); + break; +#endif /* SLAP_CONTROL_X_SESSION_TRACKING */ - case LDAP_BACK_CFG_T_F: - i = verb_to_mask( c->argv[1], t_f_mode ); - if ( BER_BVISNULL( &t_f_mode[i].word ) ) { - return 1; + case LDAP_BACK_CFG_NOREFS: + c->value_int = LDAP_BACK_NOREFS( li ); + break; + + case LDAP_BACK_CFG_NOUNDEFFILTER: + c->value_int = LDAP_BACK_NOUNDEFFILTER( li ); + break; + + default: + /* FIXME: we need to handle all... */ + assert( 0 ); + break; } - li->flags &= ~LDAP_BACK_F_SUPPORT_T_F_MASK; - li->flags |= t_f_mode[i].mask; - break; + return rc; - case LDAP_BACK_CFG_WHOAMI: { - int dowhoami = 0; + } else if ( c->op == LDAP_MOD_DELETE ) { + switch( c->type ) { + case LDAP_BACK_CFG_URI: + if ( li->li_uri != NULL ) { + ch_free( li->li_uri ); + li->li_uri = NULL; - if ( c->argc == 1 ) { - /* legacy */ - dowhoami = 1; + assert( li->li_bvuri != NULL ); + ber_bvarray_free( li->li_bvuri ); + li->li_bvuri = NULL; + } - } else { - i = verb_to_mask( c->argv[1], yn_mode ); - if ( BER_BVISNULL( &yn_mode[i].word ) ) { - return 1; + /* better cleanup the cached connections... */ + /* NOTE: don't worry about locking: if we got here, + * other threads are suspended. */ + if ( li->li_conninfo.lai_tree != NULL ) { + avl_free( li->li_conninfo.lai_tree, ldap_back_conn_free ); + li->li_conninfo.lai_tree = NULL; } - if ( yn_mode[i].mask & LDAP_BACK_C_YES ) { - dowhoami = 1; + + break; + + case LDAP_BACK_CFG_TLS: + rc = 1; + break; + + case LDAP_BACK_CFG_ACL_AUTHCDN: + case LDAP_BACK_CFG_ACL_PASSWD: + case LDAP_BACK_CFG_ACL_METHOD: + /* handled by LDAP_BACK_CFG_ACL_BIND */ + rc = 1; + break; + + case LDAP_BACK_CFG_ACL_BIND: + bindconf_free( &li->li_acl ); + break; + + case LDAP_BACK_CFG_IDASSERT_MODE: + case LDAP_BACK_CFG_IDASSERT_AUTHCDN: + case LDAP_BACK_CFG_IDASSERT_PASSWD: + case LDAP_BACK_CFG_IDASSERT_METHOD: + /* handled by LDAP_BACK_CFG_IDASSERT_BIND */ + rc = 1; + break; + + case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: + case LDAP_BACK_CFG_IDASSERT_PASSTHRU: { + BerVarray *bvp; + + switch ( c->type ) { + case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: bvp = &li->li_idassert_authz; break; + case LDAP_BACK_CFG_IDASSERT_PASSTHRU: bvp = &li->li_idassert_passthru; break; + default: assert( 0 ); break; } - } - if ( dowhoami ) { - li->flags |= LDAP_BACK_F_PROXY_WHOAMI; + if ( c->valx < 0 ) { + if ( *bvp != NULL ) { + ber_bvarray_free( *bvp ); + *bvp = NULL; + } - load_extop( (struct berval *)&slap_EXOP_WHOAMI, - 0, ldap_back_exop_whoami ); + } else { + int i; - } else { - li->flags &= ~LDAP_BACK_F_PROXY_WHOAMI; - } - break; - } + if ( *bvp == NULL ) { + rc = 1; + break; + } - case LDAP_BACK_CFG_REWRITE: - fprintf( stderr, "%s: line %d: " - "rewrite/remap capabilities have been moved " - "to the \"rwm\" overlay; see slapo-rwm(5) " - "for details (hint: add \"overlay rwm\" " - "and prefix all directives with \"rwm-\").\n", - c->fname, c->lineno ); - return 1; - - default: - assert( 0 ); - } + for ( i = 0; !BER_BVISNULL( &((*bvp)[ i ]) ); i++ ) + ; - return 0; -} + if ( i >= c->valx ) { + rc = 1; + break; + } + ber_memfree( ((*bvp)[ c->valx ]).bv_val ); + for ( i = c->valx; !BER_BVISNULL( &((*bvp)[ i + 1 ]) ); i++ ) { + (*bvp)[ i ] = (*bvp)[ i + 1 ]; + } + BER_BVZERO( &((*bvp)[ i ]) ); + } + } break; -int -ldap_back_init_cf( BackendInfo *bi ) -{ - int rc; - AttributeDescription *ad = NULL; - const char *text; + case LDAP_BACK_CFG_IDASSERT_BIND: + bindconf_free( &li->li_idassert.si_bc ); + memset( &li->li_idassert, 0, sizeof( slap_idassert_t ) ); + break; - bi->bi_cf_ocs = ldapocs; + case LDAP_BACK_CFG_REBIND: + case LDAP_BACK_CFG_CHASE: + case LDAP_BACK_CFG_T_F: + case LDAP_BACK_CFG_WHOAMI: + case LDAP_BACK_CFG_CANCEL: + rc = 1; + break; - rc = config_register_schema( ldapcfg, ldapocs ); - if ( rc ) { - return rc; - } + case LDAP_BACK_CFG_TIMEOUT: + for ( i = 0; i < SLAP_OP_LAST; i++ ) { + li->li_timeout[ i ] = 0; + } + break; + + case LDAP_BACK_CFG_IDLE_TIMEOUT: + li->li_idle_timeout = 0; + break; + + case LDAP_BACK_CFG_CONN_TTL: + li->li_conn_ttl = 0; + break; + + case LDAP_BACK_CFG_NETWORK_TIMEOUT: + li->li_network_timeout = 0; + break; + + case LDAP_BACK_CFG_VERSION: + li->li_version = 0; + break; - /* setup olcDbAclPasswd and olcDbIDAssertPasswd - * to be base64-encoded when written in LDIF form; - * basically, we don't care if it fails */ - rc = slap_str2ad( "olcDbACLPasswd", &ad, &text ); - if ( rc ) { - Debug( LDAP_DEBUG_ANY, "config_back_initialize: " - "warning, unable to get \"olcDbACLPasswd\" " - "attribute description: %d: %s\n", - rc, text, 0 ); - } else { - (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val, - ad->ad_type->sat_oid ); - } + case LDAP_BACK_CFG_SINGLECONN: + li->li_flags &= ~LDAP_BACK_F_SINGLECONN; + break; - ad = NULL; - rc = slap_str2ad( "olcDbIDAssertPasswd", &ad, &text ); - if ( rc ) { - Debug( LDAP_DEBUG_ANY, "config_back_initialize: " - "warning, unable to get \"olcDbIDAssertPasswd\" " - "attribute description: %d: %s\n", - rc, text, 0 ); - } else { - (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val, - ad->ad_type->sat_oid ); - } + case LDAP_BACK_CFG_USETEMP: + li->li_flags &= ~LDAP_BACK_F_USE_TEMPORARIES; + break; - return 0; -} + case LDAP_BACK_CFG_CONNPOOLMAX: + li->li_conn_priv_max = LDAP_BACK_CONN_PRIV_MIN; + break; + case LDAP_BACK_CFG_QUARANTINE: + if ( !LDAP_BACK_QUARANTINE( li ) ) { + break; + } -static int -parse_idassert( BackendDB *be, const char *fname, int lineno, - int argc, char **argv ); + slap_retry_info_destroy( &li->li_quarantine ); + ldap_pvt_thread_mutex_destroy( &li->li_quarantine_mutex ); + li->li_isquarantined = 0; + li->li_flags &= ~LDAP_BACK_F_QUARANTINE; + break; -static int -parse_acl_auth( BackendDB *be, const char *fname, int lineno, - int argc, char **argv ); +#ifdef SLAP_CONTROL_X_SESSION_TRACKING + case LDAP_BACK_CFG_ST_REQUEST: + li->li_flags &= ~LDAP_BACK_F_ST_REQUEST; + break; +#endif /* SLAP_CONTROL_X_SESSION_TRACKING */ -int -ldap_back_db_config( - BackendDB *be, - const char *fname, - int lineno, - int argc, - char **argv ) -{ - struct ldapinfo *li = (struct ldapinfo *) be->be_private; + case LDAP_BACK_CFG_NOREFS: + li->li_flags &= ~LDAP_BACK_F_NOREFS; + break; + + case LDAP_BACK_CFG_NOUNDEFFILTER: + li->li_flags &= ~LDAP_BACK_F_NOUNDEFFILTER; + break; + + default: + /* FIXME: we need to handle all... */ + assert( 0 ); + break; + } + return rc; - if ( li == NULL ) { - fprintf( stderr, "%s: line %d: ldap backend info is null!\n", - fname, lineno ); - return 1; } - /* server address to query (no longer supported, use "uri" directive) */ - if ( strcasecmp( argv[0], "server" ) == 0 ) { - fprintf( stderr, - "%s: line %d: \"server
\" directive is no longer supported.\n", - fname, lineno ); - return 1; + switch( c->type ) { + case LDAP_BACK_CFG_URI: { + LDAPURLDesc *tmpludp, *lud; + char **urllist = NULL; + int urlrc = LDAP_URL_SUCCESS, i; - /* URI of server to query (obsoletes "server" directive) */ - } else if ( strcasecmp( argv[0], "uri" ) == 0 ) { - LDAPURLDesc *tmpludp; - char **urllist; - int urlrc, i; - - if ( argc != 2 ) { - fprintf( stderr, "%s: line %d: " - "missing uri " - "in \"uri \" line\n", - fname, lineno ); - return 1; - } - if ( li->url != NULL ) { - ch_free( li->url ); - } - if ( li->lud != NULL ) { - ldap_free_urllist( li->lud ); + if ( li->li_uri != NULL ) { + ch_free( li->li_uri ); + li->li_uri = NULL; + + assert( li->li_bvuri != NULL ); + ber_bvarray_free( li->li_bvuri ); + li->li_bvuri = NULL; } -#if 0 /* PARANOID: DN and more are not required nor allowed */ - urlrc = ldap_url_parselist_ext( &li->lud, argv[ 1 ], "\t" ); -#else - urlrc = ldap_url_parselist( &li->lud, argv[ 1 ] ); -#endif + urlrc = ldap_url_parselist_ext( &lud, c->argv[ 1 ], ", \t", LDAP_PVT_URL_PARSE_NONE ); if ( urlrc != LDAP_URL_SUCCESS ) { char *why; @@ -1211,6 +1579,7 @@ ldap_back_db_config( break; case LDAP_URL_ERR_BADURL: why = "URL is bad"; + break; case LDAP_URL_ERR_BADHOST: why = "host/port is bad"; break; @@ -1230,14 +1599,16 @@ ldap_back_db_config( why = "unknown reason"; break; } - fprintf( stderr, "%s: line %d: " + snprintf( c->cr_msg, sizeof( c->cr_msg), "unable to parse uri \"%s\" " - "in \"uri \" line: %s\n", - fname, lineno, argv[ 1 ], why ); - return 1; + "in \"uri \" line: %s", + c->value_string, why ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + urlrc = 1; + goto done_url; } - for ( i = 0, tmpludp = li->lud; + for ( i = 0, tmpludp = lud; tmpludp; i++, tmpludp = tmpludp->lud_next ) { @@ -1248,29 +1619,28 @@ ldap_back_db_config( || tmpludp->lud_filter != NULL || tmpludp->lud_exts != NULL ) { - fprintf( stderr, "%s: line %d: " + snprintf( c->cr_msg, sizeof( c->cr_msg ), "warning, only protocol, " "host and port allowed " "in \"uri \" statement " - "for uri #%d of \"%s\"\n", - fname, lineno, i, argv[1] ); + "for uri #%d of \"%s\"", + i, c->argv[ 1 ] ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); } } -#if 0 - for ( i = 0, tmpludp = li->lud; + for ( i = 0, tmpludp = lud; tmpludp; i++, tmpludp = tmpludp->lud_next ) /* just count */ - + ; urllist = ch_calloc( sizeof( char * ), i + 1 ); - for ( i = 0, tmpludp = li->lud; + for ( i = 0, tmpludp = lud; tmpludp; i++, tmpludp = tmpludp->lud_next ) { LDAPURLDesc tmplud; - ber_len_t oldlen = 0, len; tmplud = *tmpludp; tmplud.lud_dn = ""; @@ -1284,895 +1654,738 @@ ldap_back_db_config( urllist[ i ] = ldap_url_desc2str( &tmplud ); if ( urllist[ i ] == NULL ) { - fprintf( stderr, "%s: line %d: " + snprintf( c->cr_msg, sizeof( c->cr_msg), "unable to rebuild uri " "in \"uri \" statement " - "for \"%s\"\n", - fname, lineno, argv[ 1 ] ); - return 1; + "for \"%s\"", + c->argv[ 1 ] ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + urlrc = 1; + goto done_url; } } - li->url = ldap_charray2str( urllist, " " ); - ldap_charray_free( urllist ); -#else - li->url = ch_strdup( argv[ 1 ] ); -#endif + li->li_uri = ldap_charray2str( urllist, " " ); + for ( i = 0; urllist[ i ] != NULL; i++ ) { + struct berval bv; - } else if ( strcasecmp( argv[0], "tls" ) == 0 ) { - if ( argc != 2 ) { - fprintf( stderr, - "%s: line %d: \"tls \" needs 1 argument.\n", - fname, lineno ); - return( 1 ); + ber_str2bv( urllist[ i ], 0, 0, &bv ); + ber_bvarray_add( &li->li_bvuri, &bv ); + urllist[ i ] = NULL; } + ldap_memfree( urllist ); + urllist = NULL; - /* none */ - if ( strcasecmp( argv[1], "none" ) == 0 ) { - li->flags &= ~LDAP_BACK_F_TLS_MASK; - - /* try start tls */ - } else if ( strcasecmp( argv[1], "start" ) == 0 ) { - li->flags |= LDAP_BACK_F_TLS_USE_MASK; - - /* try start tls */ - } else if ( strcasecmp( argv[1], "try-start" ) == 0 ) { - li->flags &= ~LDAP_BACK_F_TLS_CRITICAL; - li->flags |= LDAP_BACK_F_USE_TLS; - - /* propagate start tls */ - } else if ( strcasecmp( argv[1], "propagate" ) == 0 ) { - li->flags |= LDAP_BACK_F_TLS_PROPAGATE_MASK; - - /* try start tls */ - } else if ( strcasecmp( argv[1], "try-propagate" ) == 0 ) { - li->flags &= ~LDAP_BACK_F_TLS_CRITICAL; - li->flags |= LDAP_BACK_F_PROPAGATE_TLS; - - } else { - fprintf( stderr, - "%s: line %d: \"tls \": unknown argument \"%s\".\n", - fname, lineno, argv[1] ); - return( 1 ); +done_url:; + if ( urllist ) { + ldap_charray_free( urllist ); } - - /* remote ACL stuff... */ - } else if ( strncasecmp( argv[0], "acl-", STRLENOF( "acl-" ) ) == 0 - || strncasecmp( argv[0], "bind", STRLENOF( "bind" ) ) == 0 ) - { - /* NOTE: "bind{DN,pw}" was initially used; it's now - * deprected and undocumented, it can be dropped at some - * point, since nobody should be really using it */ - return parse_acl_auth( be, fname, lineno, argc, argv ); - - /* identity assertion stuff... */ - } else if ( strncasecmp( argv[0], "idassert-", STRLENOF( "idassert-" ) ) == 0 - || strncasecmp( argv[0], "proxyauthz", STRLENOF( "proxyauthz" ) ) == 0 ) - { - /* NOTE: "proxyauthz{DN,pw}" was initially used; it's now - * deprected and undocumented, it can be dropped at some - * point, since nobody should be really using it */ - return parse_idassert( be, fname, lineno, argc, argv ); - - /* save bind creds for referral rebinds? */ - } else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) { - switch ( argc ) { - case 1: - fprintf( stderr, - "%s: line %d: \"rebind-as-user {NO|yes}\": use without args is deprecated.\n", - fname, lineno ); - - li->flags |= LDAP_BACK_F_SAVECRED; - break; + if ( lud ) { + ldap_free_urllist( lud ); + } + if ( urlrc != LDAP_URL_SUCCESS ) { + return 1; + } + break; + } - case 2: - if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) { - li->flags |= LDAP_BACK_F_SAVECRED; + case LDAP_BACK_CFG_TLS: + i = verb_to_mask( c->argv[1], tls_mode ); + if ( BER_BVISNULL( &tls_mode[i].word ) ) { + return 1; + } + li->li_flags &= ~LDAP_BACK_F_TLS_MASK; + li->li_flags |= tls_mode[i].mask; + if ( c->argc > 2 ) { + for ( i=2; iargc; i++ ) { + if ( bindconf_tls_parse( c->argv[i], &li->li_tls )) + return 1; + } + bindconf_tls_defaults( &li->li_tls ); + } + break; - } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) { - li->flags &= ~LDAP_BACK_F_SAVECRED; + case LDAP_BACK_CFG_ACL_AUTHCDN: + switch ( li->li_acl_authmethod ) { + case LDAP_AUTH_NONE: + li->li_acl_authmethod = LDAP_AUTH_SIMPLE; + break; - } else { - fprintf( stderr, - "%s: line %d: \"rebind-as-user {NO|yes}\": unknown argument \"%s\".\n", - fname, lineno, argv[ 1 ] ); - return( 1 ); - } + case LDAP_AUTH_SIMPLE: break; default: - fprintf( stderr, - "%s: line %d: \"rebind-as-user {NO|yes}\" needs 1 argument.\n", - fname, lineno ); - return( 1 ); + snprintf( c->cr_msg, sizeof( c->cr_msg), + "\"acl-authcDN \" incompatible " + "with auth method %d", + li->li_acl_authmethod ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; } - - } else if ( strcasecmp( argv[0], "chase-referrals" ) == 0 ) { - if ( argc != 2 ) { - fprintf( stderr, - "%s: line %d: \"chase-referrals {YES|no}\" needs 1 argument.\n", - fname, lineno ); - return( 1 ); + if ( !BER_BVISNULL( &li->li_acl_authcDN ) ) { + free( li->li_acl_authcDN.bv_val ); } + ber_memfree_x( c->value_dn.bv_val, NULL ); + li->li_acl_authcDN = c->value_ndn; + BER_BVZERO( &c->value_dn ); + BER_BVZERO( &c->value_ndn ); + break; - /* this is the default; we add it because the default might change... */ - if ( strcasecmp( argv[1], "yes" ) == 0 ) { - li->flags |= LDAP_BACK_F_CHASE_REFERRALS; + case LDAP_BACK_CFG_ACL_PASSWD: + switch ( li->li_acl_authmethod ) { + case LDAP_AUTH_NONE: + li->li_acl_authmethod = LDAP_AUTH_SIMPLE; + break; - } else if ( strcasecmp( argv[1], "no" ) == 0 ) { - li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS; + case LDAP_AUTH_SIMPLE: + break; - } else { - fprintf( stderr, - "%s: line %d: \"chase-referrals {YES|no}\": unknown argument \"%s\".\n", - fname, lineno, argv[1] ); - return( 1 ); + default: + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "\"acl-passwd \" incompatible " + "with auth method %d", + li->li_acl_authmethod ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; } - - } else if ( strcasecmp( argv[ 0 ], "t-f-support" ) == 0 ) { - if ( argc != 2 ) { - fprintf( stderr, - "%s: line %d: \"t-f-support {NO|yes|discover}\" needs 1 argument.\n", - fname, lineno ); - return( 1 ); + if ( !BER_BVISNULL( &li->li_acl_passwd ) ) { + free( li->li_acl_passwd.bv_val ); } + ber_str2bv( c->argv[ 1 ], 0, 1, &li->li_acl_passwd ); + break; - if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) { - li->flags &= ~(LDAP_BACK_F_SUPPORT_T_F|LDAP_BACK_F_SUPPORT_T_F_DISCOVER); - - } else if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) { - li->flags |= LDAP_BACK_F_SUPPORT_T_F; + case LDAP_BACK_CFG_ACL_METHOD: + case LDAP_BACK_CFG_ACL_BIND: + for ( i = 1; i < c->argc; i++ ) { + if ( bindconf_parse( c->argv[ i ], &li->li_acl ) ) { + return 1; + } + } + bindconf_tls_defaults( &li->li_acl ); + break; - } else if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) { - li->flags |= LDAP_BACK_F_SUPPORT_T_F_DISCOVER; + case LDAP_BACK_CFG_IDASSERT_MODE: + i = verb_to_mask( c->argv[1], idassert_mode ); + if ( BER_BVISNULL( &idassert_mode[i].word ) ) { + if ( strncasecmp( c->argv[1], "u:", STRLENOF( "u:" ) ) == 0 ) { + li->li_idassert_mode = LDAP_BACK_IDASSERT_OTHERID; + ber_str2bv( c->argv[1], 0, 1, &li->li_idassert_authzID ); + li->li_idassert_authzID.bv_val[ 0 ] = 'u'; + + } else { + struct berval id, ndn; - } else { - fprintf( stderr, - "%s: line %d: \"t-f-support {NO|yes|discover}\": unknown argument \"%s\".\n", - fname, lineno, argv[ 1 ] ); - return 1; - } + ber_str2bv( c->argv[1], 0, 0, &id ); - /* intercept exop_who_am_i? */ - } else if ( strcasecmp( argv[0], "proxy-whoami" ) == 0 ) { - int doload_extop = 0; + if ( strncasecmp( c->argv[1], "dn:", STRLENOF( "dn:" ) ) == 0 ) { + id.bv_val += STRLENOF( "dn:" ); + id.bv_len -= STRLENOF( "dn:" ); + } - switch ( argc ) { - case 1: - fprintf( stderr, - "%s: line %d: \"proxy-whoami {NO|yes}\": use without args is deprecated.\n", - fname, lineno ); - - doload_extop = 1; - break; + rc = dnNormalize( 0, NULL, NULL, &id, &ndn, NULL ); + if ( rc != LDAP_SUCCESS ) { + Debug( LDAP_DEBUG_ANY, + "%s: line %d: idassert ID \"%s\" is not a valid DN\n", + c->fname, c->lineno, c->argv[1] ); + return 1; + } - case 2: - if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) { - doload_extop = 1; + li->li_idassert_authzID.bv_len = STRLENOF( "dn:" ) + ndn.bv_len; + li->li_idassert_authzID.bv_val = ch_malloc( li->li_idassert_authzID.bv_len + 1 ); + AC_MEMCPY( li->li_idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) ); + AC_MEMCPY( &li->li_idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], ndn.bv_val, ndn.bv_len + 1 ); + ch_free( ndn.bv_val ); - } else if ( strcasecmp( argv[ 1 ], "no" ) != 0 ) { - fprintf( stderr, - "%s: line %d: \"proxy-whoami {NO|yes}\": unknown argument \"%s\".\n", - fname, lineno, argv[ 1 ] ); - return( 1 ); + li->li_idassert_mode = LDAP_BACK_IDASSERT_OTHERDN; } - break; - default: - fprintf( stderr, - "%s: line %d: \"proxy-whoami {NO|yes}\" needs 1 argument.\n", - fname, lineno ); - return( 1 ); + } else { + li->li_idassert_mode = idassert_mode[i].mask; } - if ( doload_extop ) { - li->flags |= LDAP_BACK_F_PROXY_WHOAMI; - - load_extop( (struct berval *)&slap_EXOP_WHOAMI, - 0, ldap_back_exop_whoami ); - } + if ( c->argc > 2 ) { + int i; - /* FIXME: legacy: intercept old rewrite/remap directives - * and try to start the rwm overlay */ - } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0 - || strcasecmp( argv[0], "map" ) == 0 - || strncasecmp( argv[0], "rewrite", STRLENOF( "rewrite" ) ) == 0 ) - { -#if 0 - fprintf( stderr, "%s: line %d: " - "rewrite/remap capabilities have been moved " - "to the \"rwm\" overlay; see slapo-rwm(5) " - "for details. I'm trying to do my best " - "to preserve backwards compatibility...\n", - fname, lineno ); - - if ( li->rwm_started == 0 ) { - if ( overlay_config( be, "rwm" ) ) { - fprintf( stderr, "%s: line %d: " - "unable to configure the \"rwm\" " - "overlay, required by directive " - "\"%s\".\n", - fname, lineno, argv[0] ); -#if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC - fprintf( stderr, "\thint: try loading the \"rwm.la\" dynamic module.\n" ); -#endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */ - return( 1 ); - } + for ( i = 2; i < c->argc; i++ ) { + if ( strcasecmp( c->argv[ i ], "override" ) == 0 ) { + li->li_idassert_flags |= LDAP_BACK_AUTH_OVERRIDE; - fprintf( stderr, "%s: line %d: back-ldap: " - "automatically starting \"rwm\" overlay, " - "triggered by \"%s\" directive.\n", - fname, lineno, argv[ 0 ] ); + } else if ( strcasecmp( c->argv[ i ], "prescriptive" ) == 0 ) { + li->li_idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE; - /* this is the default; we add it because the default might change... */ - li->rwm_started = 1; + } else if ( strcasecmp( c->argv[ i ], "non-prescriptive" ) == 0 ) { + li->li_idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE ); - return ( *be->bd_info->bi_db_config )( be, fname, lineno, argc, argv ); - } -#else - fprintf( stderr, "%s: line %d: " - "rewrite/remap capabilities have been moved " - "to the \"rwm\" overlay; see slapo-rwm(5) " - "for details (hint: add \"overlay rwm\" " - "and prefix all directives with \"rwm-\").\n", - fname, lineno ); -#endif + } else if ( strcasecmp( c->argv[ i ], "obsolete-proxy-authz" ) == 0 ) { + if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) { + Debug( LDAP_DEBUG_ANY, + "%s: line %d: \"obsolete-proxy-authz\" flag " + "in \"idassert-mode \" " + "incompatible with previously issued \"obsolete-encoding-workaround\" flag.\n", + c->fname, c->lineno, 0 ); + return 1; + } + li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ; - return 1; - - /* anything else */ - } else { - return SLAP_CONF_UNKNOWN; - } + } else if ( strcasecmp( c->argv[ i ], "obsolete-encoding-workaround" ) == 0 ) { + if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) { + Debug( LDAP_DEBUG_ANY, + "%s: line %d: \"obsolete-encoding-workaround\" flag " + "in \"idassert-mode \" " + "incompatible with previously issued \"obsolete-proxy-authz\" flag.\n", + c->fname, c->lineno, 0 ); + return 1; + } + li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND; - return 0; -} + } else { + Debug( LDAP_DEBUG_ANY, + "%s: line %d: unknown flag #%d " + "in \"idassert-mode " + "[]\" line.\n", + c->fname, c->lineno, i - 2 ); + return 1; + } + } + } + break; -static int -ldap_back_exop_whoami( - Operation *op, - SlapReply *rs ) -{ - struct berval *bv = NULL; + case LDAP_BACK_CFG_IDASSERT_AUTHCDN: + switch ( li->li_idassert_authmethod ) { + case LDAP_AUTH_NONE: + li->li_idassert_authmethod = LDAP_AUTH_SIMPLE; + break; - if ( op->oq_extended.rs_reqdata != NULL ) { - /* no request data should be provided */ - rs->sr_text = "no request data expected"; - return rs->sr_err = LDAP_PROTOCOL_ERROR; - } + case LDAP_AUTH_SIMPLE: + break; - rs->sr_err = backend_check_restrictions( op, rs, - (struct berval *)&slap_EXOP_WHOAMI ); - if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err; + default: + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "\"idassert-authcDN \" incompatible " + "with auth method %d", + li->li_idassert_authmethod ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; + } + if ( !BER_BVISNULL( &li->li_idassert_authcDN ) ) { + free( li->li_idassert_authcDN.bv_val ); + } + ber_memfree_x( c->value_dn.bv_val, NULL ); + li->li_idassert_authcDN = c->value_ndn; + BER_BVZERO( &c->value_dn ); + BER_BVZERO( &c->value_ndn ); + break; - /* if auth'd by back-ldap and request is proxied, forward it */ - if ( op->o_conn->c_authz_backend && !strcmp(op->o_conn->c_authz_backend->be_type, "ldap" ) && !dn_match(&op->o_ndn, &op->o_conn->c_ndn)) { - struct ldapconn *lc; + case LDAP_BACK_CFG_IDASSERT_PASSWD: + switch ( li->li_idassert_authmethod ) { + case LDAP_AUTH_NONE: + li->li_idassert_authmethod = LDAP_AUTH_SIMPLE; + break; - LDAPControl c, *ctrls[2] = {NULL, NULL}; - LDAPMessage *res; - Operation op2 = *op; - ber_int_t msgid; - int doretry = 1; + case LDAP_AUTH_SIMPLE: + break; - ctrls[0] = &c; - op2.o_ndn = op->o_conn->c_ndn; - lc = ldap_back_getconn(&op2, rs, LDAP_BACK_SENDERR); - if (!lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR )) { - return -1; + default: + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "\"idassert-passwd \" incompatible " + "with auth method %d", + li->li_idassert_authmethod ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; } - c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ; - c.ldctl_iscritical = 1; - c.ldctl_value.bv_val = ch_malloc(op->o_ndn.bv_len+4); - c.ldctl_value.bv_len = op->o_ndn.bv_len + 3; - strcpy(c.ldctl_value.bv_val, "dn:"); - strcpy(c.ldctl_value.bv_val+3, op->o_ndn.bv_val); + if ( !BER_BVISNULL( &li->li_idassert_passwd ) ) { + free( li->li_idassert_passwd.bv_val ); + } + ber_str2bv( c->argv[ 1 ], 0, 1, &li->li_idassert_passwd ); + break; -retry: - rs->sr_err = ldap_whoami(lc->lc_ld, ctrls, NULL, &msgid); - if (rs->sr_err == LDAP_SUCCESS) { - if (ldap_result(lc->lc_ld, msgid, 1, NULL, &res) == -1) { - ldap_get_option(lc->lc_ld, LDAP_OPT_ERROR_NUMBER, - &rs->sr_err); - if ( rs->sr_err == LDAP_SERVER_DOWN && doretry ) { - doretry = 0; - if ( ldap_back_retry( lc, op, rs, LDAP_BACK_SENDERR ) ) - goto retry; - } - ldap_back_freeconn( op, lc ); - lc = NULL; + case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: + rc = slap_idassert_authzfrom_parse( c, &li->li_idassert ); + break; - } else { - rs->sr_err = ldap_parse_whoami(lc->lc_ld, res, &bv); - ldap_msgfree(res); - } - } - ch_free(c.ldctl_value.bv_val); - if (rs->sr_err != LDAP_SUCCESS) { - rs->sr_err = slap_map_api2result( rs ); - } + case LDAP_BACK_CFG_IDASSERT_PASSTHRU: + rc = slap_idassert_passthru_parse( c, &li->li_idassert ); + break; - if ( lc != NULL ) { - ldap_back_release_conn( &op2, rs, lc ); + case LDAP_BACK_CFG_IDASSERT_METHOD: + /* no longer supported */ + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "\"idassert-method \": " + "no longer supported; use \"idassert-bind\"" ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; + + case LDAP_BACK_CFG_IDASSERT_BIND: + rc = slap_idassert_parse( c, &li->li_idassert ); + break; + + case LDAP_BACK_CFG_REBIND: + if ( c->argc == 1 || c->value_int ) { + li->li_flags |= LDAP_BACK_F_SAVECRED; + + } else { + li->li_flags &= ~LDAP_BACK_F_SAVECRED; } + break; + + case LDAP_BACK_CFG_CHASE: + if ( c->argc == 1 || c->value_int ) { + li->li_flags |= LDAP_BACK_F_CHASE_REFERRALS; - } else { - /* else just do the same as before */ - bv = (struct berval *) ch_malloc( sizeof(struct berval) ); - if ( !BER_BVISEMPTY( &op->o_dn ) ) { - bv->bv_len = op->o_dn.bv_len + STRLENOF("dn:"); - bv->bv_val = ch_malloc( bv->bv_len + 1 ); - AC_MEMCPY( bv->bv_val, "dn:", STRLENOF("dn:") ); - AC_MEMCPY( &bv->bv_val[STRLENOF("dn:")], op->o_dn.bv_val, - op->o_dn.bv_len ); - bv->bv_val[bv->bv_len] = '\0'; } else { - bv->bv_len = 0; - bv->bv_val = NULL; + li->li_flags &= ~LDAP_BACK_F_CHASE_REFERRALS; } - } - - rs->sr_rspdata = bv; - return rs->sr_err; -} + break; + case LDAP_BACK_CFG_T_F: { + slap_mask_t mask; -static int -parse_idassert( - BackendDB *be, - const char *fname, - int lineno, - int argc, - char **argv -) -{ - struct ldapinfo *li = (struct ldapinfo *) be->be_private; - - /* identity assertion mode */ - if ( strcasecmp( argv[0], "idassert-mode" ) == 0 ) { - if ( argc < 2 ) { - Debug( LDAP_DEBUG_ANY, - "%s: line %d: illegal args number %d in \"idassert-mode [ [...]]\" line.\n", - fname, lineno, argc ); + i = verb_to_mask( c->argv[1], t_f_mode ); + if ( BER_BVISNULL( &t_f_mode[i].word ) ) { return 1; } - if ( strcasecmp( argv[1], "legacy" ) == 0 ) { - /* will proxyAuthz as client's identity only if bound */ - li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY; + mask = t_f_mode[i].mask; - } else if ( strcasecmp( argv[1], "self" ) == 0 ) { - /* will proxyAuthz as client's identity */ - li->idassert_mode = LDAP_BACK_IDASSERT_SELF; - - } else if ( strcasecmp( argv[1], "anonymous" ) == 0 ) { - /* will proxyAuthz as anonymous */ - li->idassert_mode = LDAP_BACK_IDASSERT_ANONYMOUS; + if ( LDAP_BACK_ISOPEN( li ) + && mask == LDAP_BACK_F_T_F_DISCOVER + && !LDAP_BACK_T_F( li ) ) + { + slap_bindconf sb = { BER_BVNULL }; + int rc; - } else if ( strcasecmp( argv[1], "none" ) == 0 ) { - /* will not proxyAuthz */ - li->idassert_mode = LDAP_BACK_IDASSERT_NOASSERT; + if ( li->li_uri == NULL ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "need URI to discover absolute filters support " + "in \"t-f-support discover\"" ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; + } - } else { - struct berval id; - int rc; + ber_str2bv( li->li_uri, 0, 0, &sb.sb_uri ); + sb.sb_version = li->li_version; + sb.sb_method = LDAP_AUTH_SIMPLE; + BER_BVSTR( &sb.sb_binddn, "" ); - /* will proxyAuthz as argv[1] */ - ber_str2bv( argv[1], 0, 0, &id ); + rc = slap_discover_feature( &sb, + slap_schema.si_ad_supportedFeatures->ad_cname.bv_val, + LDAP_FEATURE_ABSOLUTE_FILTERS ); + if ( rc == LDAP_COMPARE_TRUE ) { + mask |= LDAP_BACK_F_T_F; + } + } - if ( strncasecmp( id.bv_val, "u:", STRLENOF( "u:" ) ) == 0 ) { - /* force lowercase... */ - id.bv_val[0] = 'u'; - li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID; - ber_dupbv( &li->idassert_authzID, &id ); + li->li_flags &= ~LDAP_BACK_F_T_F_MASK2; + li->li_flags |= mask; + } break; - } else { - struct berval dn; + case LDAP_BACK_CFG_WHOAMI: + if ( c->argc == 1 || c->value_int ) { + li->li_flags |= LDAP_BACK_F_PROXY_WHOAMI; + load_extop( (struct berval *)&slap_EXOP_WHOAMI, + 0, ldap_back_exop_whoami ); - /* default is DN? */ - if ( strncasecmp( id.bv_val, "dn:", STRLENOF( "dn:" ) ) == 0 ) { - id.bv_val += STRLENOF( "dn:" ); - id.bv_len -= STRLENOF( "dn:" ); - } + } else { + li->li_flags &= ~LDAP_BACK_F_PROXY_WHOAMI; + } + break; - rc = dnNormalize( 0, NULL, NULL, &id, &dn, NULL ); - if ( rc != LDAP_SUCCESS ) { - Debug( LDAP_DEBUG_ANY, - "%s: line %d: idassert ID \"%s\" is not a valid DN\n", - fname, lineno, argv[1] ); + case LDAP_BACK_CFG_TIMEOUT: + for ( i = 1; i < c->argc; i++ ) { + if ( isdigit( (unsigned char) c->argv[ i ][ 0 ] ) ) { + int j; + unsigned u; + + if ( lutil_atoux( &u, c->argv[ i ], 0 ) != 0 ) { + snprintf( c->cr_msg, sizeof( c->cr_msg), + "unable to parse timeout \"%s\"", + c->argv[ i ] ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); return 1; } - li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + dn.bv_len; - li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 ); - AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) ); - AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], dn.bv_val, dn.bv_len + 1 ); - ch_free( dn.bv_val ); + for ( j = 0; j < SLAP_OP_LAST; j++ ) { + li->li_timeout[ j ] = u; + } - li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN; + continue; } - } - for ( argc -= 2, argv += 2; argc--; argv++ ) { - if ( strcasecmp( argv[0], "override" ) == 0 ) { - li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE; - - } else { - Debug( LDAP_DEBUG_ANY, - "%s: line %d: unknown flag \"%s\" " - "in \"idassert-mode " - "[]\" line.\n", - fname, lineno, argv[0] ); + if ( slap_cf_aux_table_parse( c->argv[ i ], li->li_timeout, timeout_table, "slapd-ldap timeout" ) ) { + snprintf( c->cr_msg, sizeof( c->cr_msg), + "unable to parse timeout \"%s\"", + c->argv[ i ] ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); return 1; } } + break; - /* name to use for proxyAuthz propagation */ - } else if ( strcasecmp( argv[0], "idassert-authcdn" ) == 0 - || strcasecmp( argv[0], "proxyauthzdn" ) == 0 ) - { - struct berval dn; - int rc; - - /* FIXME: "proxyauthzdn" is no longer documented, and - * temporarily supported for backwards compatibility */ + case LDAP_BACK_CFG_IDLE_TIMEOUT: { + unsigned long t; - if ( argc != 2 ) { - fprintf( stderr, - "%s: line %d: missing name in \"%s \" line\n", - fname, lineno, argv[0] ); - return( 1 ); + if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) { + snprintf( c->cr_msg, sizeof( c->cr_msg), + "unable to parse idle timeout \"%s\"", + c->argv[ 1 ] ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; } + li->li_idle_timeout = (time_t)t; + } break; - if ( !BER_BVISNULL( &li->idassert_authcDN ) ) { - fprintf( stderr, "%s: line %d: " - "authcDN already defined; replacing...\n", - fname, lineno ); - ch_free( li->idassert_authcDN.bv_val ); - } - - ber_str2bv( argv[1], 0, 0, &dn ); - rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL ); - if ( rc != LDAP_SUCCESS ) { - Debug( LDAP_DEBUG_ANY, - "%s: line %d: idassert ID \"%s\" is not a valid DN\n", - fname, lineno, argv[1] ); + case LDAP_BACK_CFG_CONN_TTL: { + unsigned long t; + + if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) { + snprintf( c->cr_msg, sizeof( c->cr_msg), + "unable to parse conn ttl\"%s\"", + c->argv[ 1 ] ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); return 1; } + li->li_conn_ttl = (time_t)t; + } break; - /* password to use for proxyAuthz propagation */ - } else if ( strcasecmp( argv[0], "idassert-passwd" ) == 0 - || strcasecmp( argv[0], "proxyauthzpw" ) == 0 ) - { - /* FIXME: "proxyauthzpw" is no longer documented, and - * temporarily supported for backwards compatibility */ + case LDAP_BACK_CFG_NETWORK_TIMEOUT: { + unsigned long t; - if ( argc != 2 ) { - fprintf( stderr, - "%s: line %d: missing password in \"%s \" line\n", - fname, lineno, argv[0] ); - return( 1 ); + if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) { + snprintf( c->cr_msg, sizeof( c->cr_msg), + "unable to parse network timeout \"%s\"", + c->argv[ 1 ] ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; } + li->li_network_timeout = (time_t)t; + } break; - if ( !BER_BVISNULL( &li->idassert_passwd ) ) { - fprintf( stderr, "%s: line %d: " - "passwd already defined; replacing...\n", - fname, lineno ); - ch_free( li->idassert_passwd.bv_val ); + case LDAP_BACK_CFG_VERSION: + if ( c->value_int != 0 && ( c->value_int < LDAP_VERSION_MIN || c->value_int > LDAP_VERSION_MAX ) ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "unsupported version \"%s\" " + "in \"protocol-version \"", + c->argv[ 1 ] ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; } - - ber_str2bv( argv[1], 0, 1, &li->idassert_passwd ); - /* rules to accept identity assertion... */ - } else if ( strcasecmp( argv[0], "idassert-authzFrom" ) == 0 ) { - struct berval rule; + li->li_version = c->value_int; + break; - ber_str2bv( argv[1], 0, 1, &rule ); + case LDAP_BACK_CFG_SINGLECONN: + if ( c->value_int ) { + li->li_flags |= LDAP_BACK_F_SINGLECONN; - ber_bvarray_add( &li->idassert_authz, &rule ); + } else { + li->li_flags &= ~LDAP_BACK_F_SINGLECONN; + } + break; - } else if ( strcasecmp( argv[0], "idassert-method" ) == 0 ) { - char *argv1; + case LDAP_BACK_CFG_USETEMP: + if ( c->value_int ) { + li->li_flags |= LDAP_BACK_F_USE_TEMPORARIES; - if ( argc < 2 ) { - fprintf( stderr, - "%s: line %d: missing method in \"%s \" line\n", - fname, lineno, argv[0] ); - return( 1 ); + } else { + li->li_flags &= ~LDAP_BACK_F_USE_TEMPORARIES; } + break; - argv1 = argv[1]; - if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) { - argv1 += STRLENOF( "bindmethod=" ); + case LDAP_BACK_CFG_CONNPOOLMAX: + if ( c->value_int < LDAP_BACK_CONN_PRIV_MIN + || c->value_int > LDAP_BACK_CONN_PRIV_MAX ) + { + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "invalid max size " "of privileged " + "connections pool \"%s\" " + "in \"conn-pool-max " + "(must be between %d and %d)\"", + c->argv[ 1 ], + LDAP_BACK_CONN_PRIV_MIN, + LDAP_BACK_CONN_PRIV_MAX ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; } + li->li_conn_priv_max = c->value_int; + break; - if ( strcasecmp( argv1, "none" ) == 0 ) { - /* FIXME: is this at all useful? */ - li->idassert_authmethod = LDAP_AUTH_NONE; - - if ( argc != 2 ) { - fprintf( stderr, - "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n", - fname, lineno, argv[0], argv[1] ); - } - - } else if ( strcasecmp( argv1, "simple" ) == 0 ) { - int arg; - - for ( arg = 2; arg < argc; arg++ ) { - if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) { - char *val = argv[arg] + STRLENOF( "authcdn=" ); - struct berval dn; - int rc; - - if ( !BER_BVISNULL( &li->idassert_authcDN ) ) { - fprintf( stderr, "%s: line %d: " - "SASL authcDN already defined; replacing...\n", - fname, lineno ); - ch_free( li->idassert_authcDN.bv_val ); - } - if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) { - val += STRLENOF( "dn:" ); - } + case LDAP_BACK_CFG_CANCEL: { + slap_mask_t mask; - ber_str2bv( val, 0, 0, &dn ); - rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL ); - if ( rc != LDAP_SUCCESS ) { - Debug( LDAP_DEBUG_ANY, - "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n", - fname, lineno, val ); - return 1; - } + i = verb_to_mask( c->argv[1], cancel_mode ); + if ( BER_BVISNULL( &cancel_mode[i].word ) ) { + return 1; + } - } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) { - char *val = argv[arg] + STRLENOF( "cred=" ); + mask = cancel_mode[i].mask; - if ( !BER_BVISNULL( &li->idassert_passwd ) ) { - fprintf( stderr, "%s: line %d: " - "SASL cred already defined; replacing...\n", - fname, lineno ); - ch_free( li->idassert_passwd.bv_val ); - } - ber_str2bv( val, 0, 1, &li->idassert_passwd ); + if ( LDAP_BACK_ISOPEN( li ) + && mask == LDAP_BACK_F_CANCEL_EXOP_DISCOVER + && !LDAP_BACK_CANCEL( li ) ) + { + slap_bindconf sb = { BER_BVNULL }; + int rc; - } else { - fprintf( stderr, "%s: line %d: " - "unknown parameter %s\n", - fname, lineno, argv[arg] ); - return 1; - } + if ( li->li_uri == NULL ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "need URI to discover \"cancel\" support " + "in \"cancel exop-discover\"" ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; } - li->idassert_authmethod = LDAP_AUTH_SIMPLE; + ber_str2bv( li->li_uri, 0, 0, &sb.sb_uri ); + sb.sb_version = li->li_version; + sb.sb_method = LDAP_AUTH_SIMPLE; + BER_BVSTR( &sb.sb_binddn, "" ); - } else if ( strcasecmp( argv1, "sasl" ) == 0 ) { -#ifdef HAVE_CYRUS_SASL - int arg; - - for ( arg = 2; arg < argc; arg++ ) { - if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) { - char *val = argv[arg] + STRLENOF( "mech=" ); + rc = slap_discover_feature( &sb, + slap_schema.si_ad_supportedExtension->ad_cname.bv_val, + LDAP_EXOP_CANCEL ); + if ( rc == LDAP_COMPARE_TRUE ) { + mask |= LDAP_BACK_F_CANCEL_EXOP; + } + } - if ( !BER_BVISNULL( &li->idassert_sasl_mech ) ) { - fprintf( stderr, "%s: line %d: " - "SASL mech already defined; replacing...\n", - fname, lineno ); - ch_free( li->idassert_sasl_mech.bv_val ); - } - ber_str2bv( val, 0, 1, &li->idassert_sasl_mech ); + li->li_flags &= ~LDAP_BACK_F_CANCEL_MASK2; + li->li_flags |= mask; + } break; - } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) { - char *val = argv[arg] + STRLENOF( "realm=" ); + case LDAP_BACK_CFG_QUARANTINE: + if ( LDAP_BACK_QUARANTINE( li ) ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "quarantine already defined" ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; + } + rc = slap_retry_info_parse( c->argv[1], &li->li_quarantine, + c->cr_msg, sizeof( c->cr_msg ) ); + if ( rc ) { + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); - if ( !BER_BVISNULL( &li->idassert_sasl_realm ) ) { - fprintf( stderr, "%s: line %d: " - "SASL realm already defined; replacing...\n", - fname, lineno ); - ch_free( li->idassert_sasl_realm.bv_val ); - } - ber_str2bv( val, 0, 1, &li->idassert_sasl_realm ); - - } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) { - char *val = argv[arg] + STRLENOF( "authcdn=" ); - struct berval dn; - int rc; - - if ( !BER_BVISNULL( &li->idassert_authcDN ) ) { - fprintf( stderr, "%s: line %d: " - "SASL authcDN already defined; replacing...\n", - fname, lineno ); - ch_free( li->idassert_authcDN.bv_val ); - } - if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) { - val += STRLENOF( "dn:" ); - } + } else { + ldap_pvt_thread_mutex_init( &li->li_quarantine_mutex ); + /* give it a chance to retry if the pattern gets reset + * via back-config */ + li->li_isquarantined = 0; + li->li_flags |= LDAP_BACK_F_QUARANTINE; + } + break; - ber_str2bv( val, 0, 0, &dn ); - rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL ); - if ( rc != LDAP_SUCCESS ) { - Debug( LDAP_DEBUG_ANY, - "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n", - fname, lineno, val ); - return 1; - } +#ifdef SLAP_CONTROL_X_SESSION_TRACKING + case LDAP_BACK_CFG_ST_REQUEST: + if ( c->value_int ) { + li->li_flags |= LDAP_BACK_F_ST_REQUEST; - } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) { - char *val = argv[arg] + STRLENOF( "authcid=" ); + } else { + li->li_flags &= ~LDAP_BACK_F_ST_REQUEST; + } + break; +#endif /* SLAP_CONTROL_X_SESSION_TRACKING */ - if ( !BER_BVISNULL( &li->idassert_authcID ) ) { - fprintf( stderr, "%s: line %d: " - "SASL authcID already defined; replacing...\n", - fname, lineno ); - ch_free( li->idassert_authcID.bv_val ); - } - if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) { - val += STRLENOF( "u:" ); - } - ber_str2bv( val, 0, 1, &li->idassert_authcID ); + case LDAP_BACK_CFG_NOREFS: + if ( c->value_int ) { + li->li_flags |= LDAP_BACK_F_NOREFS; - } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) { - char *val = argv[arg] + STRLENOF( "cred=" ); + } else { + li->li_flags &= ~LDAP_BACK_F_NOREFS; + } + break; - if ( !BER_BVISNULL( &li->idassert_passwd ) ) { - fprintf( stderr, "%s: line %d: " - "SASL cred already defined; replacing...\n", - fname, lineno ); - ch_free( li->idassert_passwd.bv_val ); - } - ber_str2bv( val, 0, 1, &li->idassert_passwd ); + case LDAP_BACK_CFG_NOUNDEFFILTER: + if ( c->value_int ) { + li->li_flags |= LDAP_BACK_F_NOUNDEFFILTER; - } else if ( strncasecmp( argv[arg], "authz=", STRLENOF( "authz=" ) ) == 0 ) { - char *val = argv[arg] + STRLENOF( "authz=" ); + } else { + li->li_flags &= ~LDAP_BACK_F_NOUNDEFFILTER; + } + break; - if ( strcasecmp( val, "proxyauthz" ) == 0 ) { - li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ; + case LDAP_BACK_CFG_REWRITE: + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "rewrite/remap capabilities have been moved " + "to the \"rwm\" overlay; see slapo-rwm(5) " + "for details (hint: add \"overlay rwm\" " + "and prefix all directives with \"rwm-\")" ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); + return 1; + + default: + /* FIXME: try to catch inconsistencies */ + assert( 0 ); + break; + } - } else if ( strcasecmp( val, "native" ) == 0 ) { - li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ; + return rc; +} - } else { - fprintf( stderr, "%s: line %d: " - "unknown authz mode \"%s\"\n", - fname, lineno, val ); - return 1; - } +int +ldap_back_init_cf( BackendInfo *bi ) +{ + int rc; + AttributeDescription *ad = NULL; + const char *text; - } else { - fprintf( stderr, "%s: line %d: " - "unknown SASL parameter %s\n", - fname, lineno, argv[arg] ); - return 1; - } - } + /* Make sure we don't exceed the bits reserved for userland */ + config_check_userland( LDAP_BACK_CFG_LAST ); - li->idassert_authmethod = LDAP_AUTH_SASL; + bi->bi_cf_ocs = ldapocs; -#else /* !HAVE_CYRUS_SASL */ - fprintf( stderr, "%s: line %d: " - "compile --with-cyrus-sasl to enable SASL auth\n", - fname, lineno ); - return 1; -#endif /* !HAVE_CYRUS_SASL */ + rc = config_register_schema( ldapcfg, ldapocs ); + if ( rc ) { + return rc; + } - } else { - fprintf( stderr, "%s: line %d: " - "unhandled idassert-method method %s\n", - fname, lineno, argv[1] ); - return 1; - } + /* setup olcDbAclPasswd and olcDbIDAssertPasswd + * to be base64-encoded when written in LDIF form; + * basically, we don't care if it fails */ + rc = slap_str2ad( "olcDbACLPasswd", &ad, &text ); + if ( rc ) { + Debug( LDAP_DEBUG_ANY, "config_back_initialize: " + "warning, unable to get \"olcDbACLPasswd\" " + "attribute description: %d: %s\n", + rc, text, 0 ); + } else { + (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val, + ad->ad_type->sat_oid ); + } + ad = NULL; + rc = slap_str2ad( "olcDbIDAssertPasswd", &ad, &text ); + if ( rc ) { + Debug( LDAP_DEBUG_ANY, "config_back_initialize: " + "warning, unable to get \"olcDbIDAssertPasswd\" " + "attribute description: %d: %s\n", + rc, text, 0 ); } else { - return SLAP_CONF_UNKNOWN; + (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val, + ad->ad_type->sat_oid ); } return 0; } static int -parse_acl_auth( - BackendDB *be, - const char *fname, - int lineno, - int argc, - char **argv -) +ldap_pbind_cf_gen( ConfigArgs *c ) { - struct ldapinfo *li = (struct ldapinfo *) be->be_private; - - /* name to use for remote ACL access */ - if ( strcasecmp( argv[0], "acl-authcdn" ) == 0 - || strcasecmp( argv[0], "binddn" ) == 0 ) - { - struct berval dn; - int rc; + slap_overinst *on = (slap_overinst *)c->bi; + void *private = c->be->be_private; + int rc; - /* FIXME: "binddn" is no longer documented, and - * temporarily supported for backwards compatibility */ + c->be->be_private = on->on_bi.bi_private; + rc = ldap_back_cf_gen( c ); + c->be->be_private = private; + return rc; +} - if ( argc != 2 ) { - fprintf( stderr, - "%s: line %d: missing name in \"%s \" line\n", - fname, lineno, argv[0] ); - return( 1 ); - } +int +ldap_pbind_init_cf( BackendInfo *bi ) +{ + bi->bi_cf_ocs = pbindocs; - if ( !BER_BVISNULL( &li->acl_authcDN ) ) { - fprintf( stderr, "%s: line %d: " - "authcDN already defined; replacing...\n", - fname, lineno ); - ch_free( li->acl_authcDN.bv_val ); - } - - ber_str2bv( argv[1], 0, 0, &dn ); - rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL ); - if ( rc != LDAP_SUCCESS ) { - Debug( LDAP_DEBUG_ANY, - "%s: line %d: acl ID \"%s\" is not a valid DN\n", - fname, lineno, argv[1] ); - return 1; - } + return config_register_schema( pbindcfg, pbindocs ); +} - /* password to use for remote ACL access */ - } else if ( strcasecmp( argv[0], "acl-passwd" ) == 0 - || strcasecmp( argv[0], "bindpw" ) == 0 ) - { - /* FIXME: "bindpw" is no longer documented, and - * temporarily supported for backwards compatibility */ +static int +ldap_back_exop_whoami( + Operation *op, + SlapReply *rs ) +{ + struct berval *bv = NULL; - if ( argc != 2 ) { - fprintf( stderr, - "%s: line %d: missing password in \"%s \" line\n", - fname, lineno, argv[0] ); - return( 1 ); - } + if ( op->oq_extended.rs_reqdata != NULL ) { + /* no request data should be provided */ + rs->sr_text = "no request data expected"; + return rs->sr_err = LDAP_PROTOCOL_ERROR; + } - if ( !BER_BVISNULL( &li->acl_passwd ) ) { - fprintf( stderr, "%s: line %d: " - "passwd already defined; replacing...\n", - fname, lineno ); - ch_free( li->acl_passwd.bv_val ); - } - - ber_str2bv( argv[1], 0, 1, &li->acl_passwd ); + Statslog( LDAP_DEBUG_STATS, "%s WHOAMI\n", + op->o_log_prefix, 0, 0, 0, 0 ); - } else if ( strcasecmp( argv[0], "acl-method" ) == 0 ) { - char *argv1; + rs->sr_err = backend_check_restrictions( op, rs, + (struct berval *)&slap_EXOP_WHOAMI ); + if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err; - if ( argc < 2 ) { - fprintf( stderr, - "%s: line %d: missing method in \"%s \" line\n", - fname, lineno, argv[0] ); - return( 1 ); - } + /* if auth'd by back-ldap and request is proxied, forward it */ + if ( op->o_conn->c_authz_backend + && !strcmp( op->o_conn->c_authz_backend->be_type, "ldap" ) + && !dn_match( &op->o_ndn, &op->o_conn->c_ndn ) ) + { + ldapconn_t *lc = NULL; + LDAPControl c, *ctrls[2] = {NULL, NULL}; + LDAPMessage *res; + Operation op2 = *op; + ber_int_t msgid; + int doretry = 1; + char *ptr; - argv1 = argv[1]; - if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) { - argv1 += STRLENOF( "bindmethod=" ); + ctrls[0] = &c; + op2.o_ndn = op->o_conn->c_ndn; + if ( !ldap_back_dobind( &lc, &op2, rs, LDAP_BACK_SENDERR ) ) { + return -1; } + c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ; + c.ldctl_iscritical = 1; + c.ldctl_value.bv_val = op->o_tmpalloc( + op->o_ndn.bv_len + STRLENOF( "dn:" ) + 1, + op->o_tmpmemctx ); + c.ldctl_value.bv_len = op->o_ndn.bv_len + 3; + ptr = c.ldctl_value.bv_val; + ptr = lutil_strcopy( ptr, "dn:" ); + ptr = lutil_strncopy( ptr, op->o_ndn.bv_val, op->o_ndn.bv_len ); + ptr[ 0 ] = '\0'; - if ( strcasecmp( argv1, "none" ) == 0 ) { - /* FIXME: is this at all useful? */ - li->acl_authmethod = LDAP_AUTH_NONE; - - if ( argc != 2 ) { - fprintf( stderr, - "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n", - fname, lineno, argv[0], argv[1] ); - } - - } else if ( strcasecmp( argv1, "simple" ) == 0 ) { - li->acl_authmethod = LDAP_AUTH_SIMPLE; - - if ( argc != 2 ) { - fprintf( stderr, - "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n", - fname, lineno, argv[0], argv[1] ); - } - - } else if ( strcasecmp( argv1, "sasl" ) == 0 ) { -#ifdef HAVE_CYRUS_SASL - int arg; - - for ( arg = 2; arg < argc; arg++ ) { - if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) { - char *val = argv[arg] + STRLENOF( "mech=" ); - - if ( !BER_BVISNULL( &li->acl_sasl_mech ) ) { - fprintf( stderr, "%s: line %d: " - "SASL mech already defined; replacing...\n", - fname, lineno ); - ch_free( li->acl_sasl_mech.bv_val ); - } - ber_str2bv( val, 0, 1, &li->acl_sasl_mech ); - - } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) { - char *val = argv[arg] + STRLENOF( "realm=" ); - - if ( !BER_BVISNULL( &li->acl_sasl_realm ) ) { - fprintf( stderr, "%s: line %d: " - "SASL realm already defined; replacing...\n", - fname, lineno ); - ch_free( li->acl_sasl_realm.bv_val ); - } - ber_str2bv( val, 0, 1, &li->acl_sasl_realm ); - - } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) { - char *val = argv[arg] + STRLENOF( "authcdn=" ); - struct berval dn; - int rc; - - if ( !BER_BVISNULL( &li->acl_authcDN ) ) { - fprintf( stderr, "%s: line %d: " - "SASL authcDN already defined; replacing...\n", - fname, lineno ); - ch_free( li->acl_authcDN.bv_val ); - } - if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) { - val += STRLENOF( "dn:" ); - } - - ber_str2bv( val, 0, 0, &dn ); - rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL ); - if ( rc != LDAP_SUCCESS ) { - Debug( LDAP_DEBUG_ANY, - "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n", - fname, lineno, val ); - return 1; - } - - } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) { - char *val = argv[arg] + STRLENOF( "authcid=" ); - - if ( !BER_BVISNULL( &li->acl_authcID ) ) { - fprintf( stderr, "%s: line %d: " - "SASL authcID already defined; replacing...\n", - fname, lineno ); - ch_free( li->acl_authcID.bv_val ); - } - if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) { - val += STRLENOF( "u:" ); - } - ber_str2bv( val, 0, 1, &li->acl_authcID ); - - } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) { - char *val = argv[arg] + STRLENOF( "cred=" ); - - if ( !BER_BVISNULL( &li->acl_passwd ) ) { - fprintf( stderr, "%s: line %d: " - "SASL cred already defined; replacing...\n", - fname, lineno ); - ch_free( li->acl_passwd.bv_val ); +retry: + rs->sr_err = ldap_whoami( lc->lc_ld, ctrls, NULL, &msgid ); + if ( rs->sr_err == LDAP_SUCCESS ) { + /* by now, make sure no timeout is used (ITS#6282) */ + struct timeval tv; + tv.tv_sec = -1; + if ( ldap_result( lc->lc_ld, msgid, LDAP_MSG_ALL, &tv, &res ) == -1 ) { + ldap_get_option( lc->lc_ld, LDAP_OPT_ERROR_NUMBER, + &rs->sr_err ); + if ( rs->sr_err == LDAP_SERVER_DOWN && doretry ) { + doretry = 0; + if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) { + goto retry; } - ber_str2bv( val, 0, 1, &li->acl_passwd ); - - } else { - fprintf( stderr, "%s: line %d: " - "unknown SASL parameter %s\n", - fname, lineno, argv[arg] ); - return 1; } + + } else { + /* NOTE: are we sure "bv" will be malloc'ed + * with the appropriate memory? */ + rs->sr_err = ldap_parse_whoami( lc->lc_ld, res, &bv ); + ldap_msgfree(res); } + } + op->o_tmpfree( c.ldctl_value.bv_val, op->o_tmpmemctx ); + if ( rs->sr_err != LDAP_SUCCESS ) { + rs->sr_err = slap_map_api2result( rs ); + } - li->acl_authmethod = LDAP_AUTH_SASL; + if ( lc != NULL ) { + ldap_back_release_conn( (ldapinfo_t *)op2.o_bd->be_private, lc ); + } -#else /* !HAVE_CYRUS_SASL */ - fprintf( stderr, "%s: line %d: " - "compile --with-cyrus-sasl to enable SASL auth\n", - fname, lineno ); - return 1; -#endif /* !HAVE_CYRUS_SASL */ + } else { + /* else just do the same as before */ + bv = (struct berval *) ch_malloc( sizeof( struct berval ) ); + if ( !BER_BVISEMPTY( &op->o_dn ) ) { + bv->bv_len = op->o_dn.bv_len + STRLENOF( "dn:" ); + bv->bv_val = ch_malloc( bv->bv_len + 1 ); + AC_MEMCPY( bv->bv_val, "dn:", STRLENOF( "dn:" ) ); + AC_MEMCPY( &bv->bv_val[ STRLENOF( "dn:" ) ], op->o_dn.bv_val, + op->o_dn.bv_len ); + bv->bv_val[ bv->bv_len ] = '\0'; } else { - fprintf( stderr, "%s: line %d: " - "unhandled acl-method method %s\n", - fname, lineno, argv[1] ); - return 1; + bv->bv_len = 0; + bv->bv_val = NULL; } - - } else { - return SLAP_CONF_UNKNOWN; } - return 0; + rs->sr_rspdata = bv; + return rs->sr_err; } +