X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-relay%2Fconfig.c;h=b8f85830115a5883ff1840862c1cc422a80f933c;hb=324431062bff39a1bd3969bd37d4913526dd583f;hp=2839e14186358182adcc31a87d35e51aed8472aa;hpb=b3d238465d0c43adda933485a97ab4e4daac18e0;p=openldap diff --git a/servers/slapd/back-relay/config.c b/servers/slapd/back-relay/config.c index 2839e14186..b8f8583011 100644 --- a/servers/slapd/back-relay/config.c +++ b/servers/slapd/back-relay/config.c @@ -1,7 +1,7 @@ /* config.c - relay backend configuration file routine */ /* This work is part of OpenLDAP Software . * - * Copyright 2003-2004 The OpenLDAP Foundation. + * Copyright 2004-2006 The OpenLDAP Foundation. * Portions Copyright 2004 Pierangelo Masarati. * All rights reserved. * @@ -27,105 +27,155 @@ int relay_back_db_config( - BackendDB *be, - const char *fname, - int lineno, - int argc, - char **argv -) + BackendDB *be, + const char *fname, + int lineno, + int argc, + char **argv ) { relay_back_info *ri = (struct relay_back_info *)be->be_private; if ( ri == NULL ) { - fprintf( stderr, "%s: line %d: relay backend info is null!\n", - fname, lineno ); + Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, + "%s: line %d: relay backend info is null.\n", + fname, lineno ); return 1; } /* real naming context */ - if ( strcasecmp( argv[0], "relay" ) == 0 ) { + if ( strcasecmp( argv[ 0 ], "relay" ) == 0 ) { struct berval dn, ndn, pdn; int rc; + BackendDB *bd; + + switch ( argc ) { + case 3: + if ( strcmp( argv[ 2 ], "massage" ) != 0 ) { + Log3( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, + "%s: line %d: " + "unknown arg[#2]=\"%s\" " + "in \"relay [massage]\" line\n", + fname, lineno, argv[ 2 ] ); + return 1; + } + + if ( be->be_nsuffix == NULL ) { + Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, + "%s: line %d: " + "\"relay\" directive " + "must appear after \"suffix\".\n", + fname, lineno ); + return 1; + } - if ( argc < 2 ) { - fprintf( stderr, - "%s: line %d: missing relay suffix in \"relay [massage]\" line\n", - fname, lineno ); + if ( !BER_BVISNULL( &be->be_nsuffix[ 1 ] ) ) { + Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, + "%s: line %d: " + "relayng of multiple suffix " + "database not supported.\n", + fname, lineno ); + return 1; + } + /* fallthru */ + + case 2: + break; + + case 1: + Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, + "%s: line %d: missing relay suffix " + "in \"relay [massage]\" line.\n", + fname, lineno ); return 1; - } else if ( argc > 3 ) { - fprintf( stderr, - "%s: line %d: too many args in \"relay [massage]\" line\n", - fname, lineno ); + default: + Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, + "%s: line %d: extra cruft " + "in \"relay [massage]\" line.\n", + fname, lineno ); return 1; } - dn.bv_val = argv[ 1 ]; - dn.bv_len = strlen( argv[ 1 ] ); - rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL ); - if ( rc != LDAP_SUCCESS ) { - fprintf( stderr, "%s: line %d: " - "relay dn \"%s\" is invalid\n", - fname, lineno, argv[ 1 ] ); + if ( !BER_BVISNULL( &ri->ri_realsuffix ) ) { + Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, + "%s: line %d: " + "relay dn already specified.\n", + fname, lineno ); return 1; } - ri->ri_bd = select_backend( &ndn, 0, 1 ); - if ( ri->ri_bd == NULL ) { - fprintf( stderr, "%s: line %d: " - "cannot find database " - "of relay dn \"%s\"\n", - fname, lineno, argv[ 1 ] ); + /* The man page says that the "relay" directive + * automatically instantiates slapo-rwm; I don't + * like this very much any more, I'd prefer to + * have automatic instantiation only when "massage" + * is specified, so one has better control on + * where the overlay gets instantiated, but this + * would break compatibility. One can still control + * where the overlay is instantiated by moving + * around the "relay" directive, although this could + * make slapd.conf a bit confusing. */ + if ( overlay_config( be, "rwm" ) ) { + Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, + "%s: line %d: unable to install " + "rwm overlay " + "in \"relay [massage]\" line\n", + fname, lineno ); return 1; + } - } else if ( ri->ri_bd == be ) { - fprintf( stderr, "%s: line %d: " - "relay dn \"%s\" would call self\n", - fname, lineno, pdn.bv_val ); + dn.bv_val = argv[ 1 ]; + dn.bv_len = strlen( argv[ 1 ] ); + rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL ); + if ( rc != LDAP_SUCCESS ) { + Log3( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, + "%s: line %d: " + "relay dn \"%s\" is invalid " + "in \"relay [massage]\" line\n", + fname, lineno, argv[ 1 ] ); return 1; - } + } - if ( overlay_config( be, "rewrite-remap" ) ) { - fprintf( stderr, "%s: line %d: unable to install " - "rewrite-remap overlay " - "in back-relay\n", - fname, lineno ); - return 1; + bd = select_backend( &ndn, 0, 1 ); + if ( bd == NULL ) { + Log3( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, + "%s: line %d: " + "cannot find database " + "of relay dn \"%s\" " + "in \"relay [massage]\" line\n", + fname, lineno, argv[ 1 ] ); + rc = 1; + goto relay_done; + + } else if ( bd->be_private == be->be_private ) { + Log3( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, + "%s: line %d: " + "relay dn \"%s\" would call self " + "in \"relay [massage]\" line\n", + fname, lineno, pdn.bv_val ); + rc = 1; + goto relay_done; } + ri->ri_realsuffix = ndn; + if ( argc == 3 ) { char *cargv[ 4 ]; - if ( strcmp( argv[2], "massage" ) ) { - fprintf( stderr, "%s: line %d: " - "unknown directive \"%s\" " - "in \"relay [massage]\" line\n", - fname, lineno, argv[2] ); - return 1; - } - - if ( be->be_suffix[0].bv_val == NULL ) { - fprintf( stderr, "%s: line %d: " - "relay line must come after \"suffix\"\n", - fname, lineno ); - return 1; - } - - cargv[ 0 ] = "suffixmassage"; + cargv[ 0 ] = "rwm-suffixmassage"; cargv[ 1 ] = be->be_suffix[0].bv_val; - cargv[ 2 ] = ri->ri_bd->be_suffix[0].bv_val; + cargv[ 2 ] = pdn.bv_val; cargv[ 3 ] = NULL; - if ( be->be_config( be, "back-relay", 1, 3, cargv ) ) { - return 1; - } + rc = be->be_config( be, fname, lineno, 3, cargv ); } - /* anything else */ - } else { - return SLAP_CONF_UNKNOWN; +relay_done:; + ch_free( pdn.bv_val ); + + return rc; } - return 0; + /* anything else */ + return SLAP_CONF_UNKNOWN; }