diff --git a/servers/slapd/aci.c b/servers/slapd/aci.c index 33e60744dd9273425155a240c14f92436538423d..c8cc41d2a5ec20ef45bc79ce58dffdafd719422e 100644 --- a/servers/slapd/aci.c +++ b/servers/slapd/aci.c @@ -39,6 +39,7 @@ #include "slap.h" #include "lber_pvt.h" #include "lutil.h" +#include "slap-config.h" /* use most appropriate size */ #define ACI_BUF_SIZE 1024 @@ -741,8 +742,7 @@ aci_init( void ) static int dynacl_aci_parse( - const char *fname, - int lineno, + ConfigArgs *c, const char *opts, slap_style_t sty, const char *right, @@ -752,17 +752,19 @@ dynacl_aci_parse( const char *text = NULL; if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) { - fprintf( stderr, "%s: line %d: " - "inappropriate style \"%s\" in \"aci\" by clause\n", - fname, lineno, style_strings[sty] ); + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "inappropriate style \"%s\" in \"aci\" by clause", + style_strings[sty] ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg ); return -1; } if ( right != NULL && *right != '\0' ) { if ( slap_str2ad( right, &ad, &text ) != LDAP_SUCCESS ) { - fprintf( stderr, - "%s: line %d: aci \"%s\": %s\n", - fname, lineno, right, text ); + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "aci \"%s\": %s", + right, text ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg ); return -1; } @@ -771,10 +773,10 @@ dynacl_aci_parse( } if ( !is_at_syntax( ad->ad_type, SLAPD_ACI_SYNTAX) ) { - fprintf( stderr, "%s: line %d: " - "aci \"%s\": inappropriate syntax: %s\n", - fname, lineno, right, - ad->ad_type->sat_syntax_oid ); + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "aci \"%s\": inappropriate syntax: %s", + right, ad->ad_type->sat_syntax_oid ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg ); return -1; } diff --git a/servers/slapd/aclparse.c b/servers/slapd/aclparse.c index 60b74e32f2ce2b092f5e407135bf3495c063ed66..f2cbdf1a33648199d2429d879b725c85c1438c9c 100644 --- a/servers/slapd/aclparse.c +++ b/servers/slapd/aclparse.c @@ -37,6 +37,7 @@ #include "slap.h" #include "lber_pvt.h" #include "lutil.h" +#include "slap-config.h" static const char style_base[] = "base"; const char *style_strings[] = { @@ -76,8 +77,7 @@ static int check_scope( BackendDB *be, AccessControl *a ); #ifdef SLAP_DYNACL static int slap_dynacl_config( - const char *fname, - int lineno, + struct config_args_s *c, Access *b, const char *name, const char *opts, @@ -89,9 +89,10 @@ slap_dynacl_config( for ( da = b->a_dynacl; da; da = da->da_next ) { if ( strcasecmp( da->da_name, name ) == 0 ) { - Debug( LDAP_DEBUG_ANY, - "%s: line %d: dynacl \"%s\" already specified.\n", - fname, lineno, name ); + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "dynacl \"%s\" already specified", + name ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg ); return acl_usage(); } } @@ -105,7 +106,7 @@ slap_dynacl_config( *tmp = *da; if ( tmp->da_parse ) { - rc = ( *tmp->da_parse )( fname, lineno, opts, sty, right, &tmp->da_private ); + rc = ( *tmp->da_parse )( c, opts, sty, right, &tmp->da_private ); if ( rc ) { ch_free( tmp ); return rc; @@ -319,11 +320,7 @@ regex_done:; int parse_acl( - Backend *be, - const char *fname, - int lineno, - int argc, - char **argv, + struct config_args_s *c, int pos ) { int i; @@ -333,14 +330,19 @@ parse_acl( Access *b = NULL; int rc; const char *text; + Backend *be = c->be; + const char *fname = c->fname; + int lineno = c->lineno; + int argc = c->argc; + char **argv = c->argv; for ( i = 1; i < argc; i++ ) { /* to clause - select which entries are protected */ if ( strcasecmp( argv[i], "to" ) == 0 ) { if ( a != NULL ) { - Debug( LDAP_DEBUG_ANY, "%s: line %d: " - "only one to clause allowed in access line\n", - fname, lineno ); + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "only one to clause allowed in access line" ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg ); goto fail; } a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) ); @@ -1599,7 +1601,7 @@ parse_acl( } if ( name ) { - if ( slap_dynacl_config( fname, lineno, b, name, opts, sty, right ) ) { + if ( slap_dynacl_config( c, b, name, opts, sty, right ) ) { Debug( LDAP_DEBUG_ANY, "%s: line %d: " "unable to configure dynacl \"%s\".\n", fname, lineno, name ); diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index 705f54f42cad2665541fe0e51614dff0d529f747..1b04e57e41d45839571cad0d4afec81a65cddcbe 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -2282,7 +2282,7 @@ sortval_reject: for ( a=c->be->be_acl; a; a = a->acl_next ) i++; } - if ( parse_acl(c->be, c->fname, c->lineno, c->argc, c->argv, i ) ) { + if ( parse_acl( c, i ) ) { if ( SLAP_CONFIG( c->be ) && !c->be->be_acl) { c->be->be_acl = defacl_parsed; } @@ -2558,7 +2558,7 @@ sortval_reject: #ifdef LDAP_SLAPI case CFG_PLUGIN: - if(slapi_int_read_config(c->be, c->fname, c->lineno, c->argc, c->argv, c->valx) != LDAP_SUCCESS) + if(slapi_int_read_config(c) != LDAP_SUCCESS) return(1); slapi_plugins_used++; break; @@ -7328,7 +7328,12 @@ config_back_db_open( BackendDB *be, ConfigReply *cr ) */ save_access = be->bd_self->be_acl; be->bd_self->be_acl = NULL; - parse_acl(be->bd_self, "config_back_db_open", 0, 6, (char **)defacl, 0 ); + c.be = be->bd_self; + c.fname = "config_back_db_open"; + c.lineno = 0; + c.argc = 6; + c.argv = (char **)defacl; + parse_acl( &c, 0 ); defacl_parsed = be->bd_self->be_acl; if ( save_access ) { be->bd_self->be_acl = save_access; diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 978a77ebe28c3e9399ffc7cddfe4f7fdb60f2c29..b622d2e4489672a8a9acc68f5748b2c3e95f9f51 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -100,9 +100,7 @@ LDAP_SLAPD_F (int) acl_string_expand LDAP_P(( */ LDAP_SLAPD_V (LDAP_CONST char *) style_strings[]; -LDAP_SLAPD_F (int) parse_acl LDAP_P(( Backend *be, - const char *fname, int lineno, - int argc, char **argv, int pos )); +LDAP_SLAPD_F (int) parse_acl LDAP_P(( struct config_args_s *ca, int pos )); LDAP_SLAPD_F (char *) access2str LDAP_P(( slap_access_t access )); LDAP_SLAPD_F (slap_access_t) str2access LDAP_P(( const char *str )); diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index fee283f372f7cc273ec70269d437da41f017db02..6973cb96f9d076a3ea6e8e3d8918adaeb206e5ea 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -1322,12 +1322,15 @@ typedef struct AuthorizationInformation { slap_ssf_t sai_sasl_ssf; /* SASL SSF */ } AuthorizationInformation; +typedef struct config_args_s ConfigArgs; /* slap-config.h */ +typedef struct config_reply_s ConfigReply; /* slap-config.h */ + #ifdef SLAP_DYNACL /* * "dynamic" ACL infrastructure (for ACIs and more) */ -typedef int (slap_dynacl_parse) LDAP_P(( const char *fname, int lineno, +typedef int (slap_dynacl_parse) LDAP_P(( ConfigArgs *ca, const char *opts, slap_style_t, const char *, void **privp )); typedef int (slap_dynacl_unparse) LDAP_P(( void *priv, struct berval *bv )); typedef int (slap_dynacl_mask) LDAP_P(( @@ -2022,7 +2025,6 @@ typedef int (BI_config) LDAP_P((BackendInfo *bi, const char *fname, int lineno, int argc, char **argv)); -typedef struct config_reply_s ConfigReply; /* slap-config.h */ typedef int (BI_db_func) LDAP_P((Backend *bd, ConfigReply *cr)); typedef BI_db_func BI_db_init; typedef BI_db_func BI_db_open; diff --git a/servers/slapd/slapi/plugin.c b/servers/slapd/slapi/plugin.c index de8c60d94b5545a19a107421d17c9e2e61c70a10..ca5dbead595c31f0d9981c349d5a41948ba73264 100644 --- a/servers/slapd/slapi/plugin.c +++ b/servers/slapd/slapi/plugin.c @@ -36,7 +36,7 @@ #include static int slapi_int_load_plugin( Slapi_PBlock *, const char *, const char *, int, - SLAPI_FUNC *, lt_dlhandle * ); + SLAPI_FUNC *, lt_dlhandle *, ConfigArgs *c ); /* pointer to link list of extended objects */ static ExtendedOp *pGExtendedOps = NULL; @@ -68,15 +68,15 @@ static Slapi_PBlock * plugin_pblock_new( int type, int argc, - char *argv[] ) + ConfigArgs *c ) { Slapi_PBlock *pPlugin = NULL; Slapi_PluginDesc *pPluginDesc = NULL; lt_dlhandle hdLoadHandle; int rc; char **av2 = NULL, **ppPluginArgv; - char *path = argv[2]; - char *initfunc = argv[3]; + char *path = c->argv[2]; + char *initfunc = c->argv[3]; pPlugin = slapi_pblock_new(); if ( pPlugin == NULL ) { @@ -87,7 +87,7 @@ plugin_pblock_new( slapi_pblock_set( pPlugin, SLAPI_PLUGIN_TYPE, (void *)&type ); slapi_pblock_set( pPlugin, SLAPI_PLUGIN_ARGC, (void *)&argc ); - av2 = ldap_charray_dup( argv ); + av2 = ldap_charray_dup( c->argv ); if ( av2 == NULL ) { rc = LDAP_NO_MEMORY; goto done; @@ -102,7 +102,7 @@ plugin_pblock_new( slapi_pblock_set( pPlugin, SLAPI_PLUGIN_ARGV, (void *)ppPluginArgv ); slapi_pblock_set( pPlugin, SLAPI_X_CONFIG_ARGV, (void *)av2 ); - rc = slapi_int_load_plugin( pPlugin, path, initfunc, 1, NULL, &hdLoadHandle ); + rc = slapi_int_load_plugin( pPlugin, path, initfunc, 1, NULL, &hdLoadHandle, c ); if ( rc != 0 ) { goto done; } @@ -556,7 +556,8 @@ slapi_int_load_plugin( const char *initfunc, int doInit, SLAPI_FUNC *pInitFunc, - lt_dlhandle *pLdHandle ) + lt_dlhandle *pLdHandle, + ConfigArgs *c ) { int rc = LDAP_SUCCESS; SLAPI_FUNC fpInitFunc = NULL; @@ -570,15 +571,17 @@ slapi_int_load_plugin( /* load in the module */ *pLdHandle = lt_dlopen( path ); if ( *pLdHandle == NULL ) { - fprintf( stderr, "failed to load plugin %s: %s\n", + snprintf( c->cr_msg, sizeof( c->cr_msg ), "failed to load plugin %s: %s", path, lt_dlerror() ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg ); return LDAP_LOCAL_ERROR; } fpInitFunc = (SLAPI_FUNC)lt_dlsym( *pLdHandle, initfunc ); if ( fpInitFunc == NULL ) { - fprintf( stderr, "failed to find symbol %s in plugin %s: %s\n", + snprintf( c->cr_msg, sizeof( c->cr_msg ), "failed to find symbol %s in plugin %s: %s", initfunc, path, lt_dlerror() ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg ); lt_dlclose( *pLdHandle ); return LDAP_LOCAL_ERROR; } @@ -643,50 +646,46 @@ slapi_int_call_plugins( int slapi_int_read_config( - Backend *be, - const char *fname, - int lineno, - int argc, - char **argv, - int index ) + struct config_args_s *c ) { int iType = -1; int numPluginArgc = 0; - if ( argc < 4 ) { - fprintf( stderr, - "%s: line %d: missing arguments " + if ( c->argc < 4 ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "missing arguments " "in \"plugin " - " []\" line\n", - fname, lineno ); + " []\" line" ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg ); return 1; } /* automatically instantiate overlay if necessary */ - if ( !slapi_over_is_inst( be ) ) { - ConfigReply cr = { 0 }; - if ( slapi_over_config( be, &cr ) != 0 ) { - fprintf( stderr, "Failed to instantiate SLAPI overlay: " - "err=%d msg=\"%s\"\n", cr.err, cr.msg ); + if ( !slapi_over_is_inst( c->be ) ) { + if ( slapi_over_config( c->be, &c->reply ) != 0 ) { + Debug( LDAP_DEBUG_ANY, "%s: " + "Failed to instantiate SLAPI overlay: " + "err=%d msg=\"%s\"\n", c->log, c->reply.err, c->reply.msg ); return -1; } } - if ( strcasecmp( argv[1], "preoperation" ) == 0 ) { + if ( strcasecmp( c->argv[1], "preoperation" ) == 0 ) { iType = SLAPI_PLUGIN_PREOPERATION; - } else if ( strcasecmp( argv[1], "postoperation" ) == 0 ) { + } else if ( strcasecmp( c->argv[1], "postoperation" ) == 0 ) { iType = SLAPI_PLUGIN_POSTOPERATION; - } else if ( strcasecmp( argv[1], "extendedop" ) == 0 ) { + } else if ( strcasecmp( c->argv[1], "extendedop" ) == 0 ) { iType = SLAPI_PLUGIN_EXTENDEDOP; - } else if ( strcasecmp( argv[1], "object" ) == 0 ) { + } else if ( strcasecmp( c->argv[1], "object" ) == 0 ) { iType = SLAPI_PLUGIN_OBJECT; } else { - fprintf( stderr, "%s: line %d: invalid plugin type \"%s\".\n", - fname, lineno, argv[1] ); + snprintf( c->cr_msg, sizeof( c->cr_msg ), + "invalid plugin type \"%s\"", c->argv[1] ); + Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg ); return 1; } - numPluginArgc = argc - 4; + numPluginArgc = c->argc - 4; if ( iType == SLAPI_PLUGIN_PREOPERATION || iType == SLAPI_PLUGIN_EXTENDEDOP || @@ -695,23 +694,23 @@ slapi_int_read_config( int rc; Slapi_PBlock *pPlugin; - pPlugin = plugin_pblock_new( iType, numPluginArgc, argv ); + pPlugin = plugin_pblock_new( iType, numPluginArgc, c->argv ); if (pPlugin == NULL) { return 1; } if (iType == SLAPI_PLUGIN_EXTENDEDOP) { - rc = slapi_int_register_extop(be, &pGExtendedOps, pPlugin); + rc = slapi_int_register_extop(c->be, &pGExtendedOps, pPlugin); if ( rc != LDAP_SUCCESS ) { slapi_pblock_destroy( pPlugin ); return 1; } } - rc = slapi_int_register_plugin_index( be, pPlugin, index ); + rc = slapi_int_register_plugin_index( c->be, pPlugin, c->valx ); if ( rc != LDAP_SUCCESS ) { if ( iType == SLAPI_PLUGIN_EXTENDEDOP ) { - slapi_int_unregister_extop( be, &pGExtendedOps, pPlugin ); + slapi_int_unregister_extop( c->be, &pGExtendedOps, pPlugin ); } slapi_pblock_destroy( pPlugin ); return 1; diff --git a/servers/slapd/slapi/proto-slapi.h b/servers/slapd/slapi/proto-slapi.h index 9d5251045d0ad7457a6bfc07483072756006e684..e9eb76ba17f10585cda6117ade946205ece975b0 100644 --- a/servers/slapd/slapi/proto-slapi.h +++ b/servers/slapd/slapi/proto-slapi.h @@ -72,8 +72,7 @@ LDAP_SLAPI_F (int) slapi_int_register_extop LDAP_P((Backend *pBE, ExtendedOp **o LDAP_SLAPI_F (int) slapi_int_get_extop_plugin LDAP_P((struct berval *reqoid, SLAPI_FUNC *pFuncAddr )); LDAP_SLAPI_F (struct berval *) slapi_int_get_supported_extop LDAP_P(( int )); LDAP_SLAPI_F (int) slapi_int_unregister_plugins LDAP_P((Backend *be, int index)); -LDAP_SLAPI_F (int) slapi_int_read_config LDAP_P((Backend *be, const char *fname, int lineno, - int argc, char **argv, int index )); +LDAP_SLAPI_F (int) slapi_int_read_config LDAP_P(( struct config_args_s *c )); LDAP_SLAPI_F (void) slapi_int_plugin_unparse LDAP_P((Backend *be, BerVarray *out )); LDAP_SLAPI_F (int) slapi_int_initialize LDAP_P((void));