From: Howard Chu Date: Wed, 15 Nov 2006 01:18:37 +0000 (+0000) Subject: Convert schema parsers to ConfigArgs so they can pass errors back to clients X-Git-Tag: OPENLDAP_REL_ENG_2_4_4ALPHA~8^2~472 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=4b6a3e8b6d9ef0a450e532514dcbccdc71ae8007;p=openldap Convert schema parsers to ConfigArgs so they can pass errors back to clients --- diff --git a/servers/slapd/back-bdb/monitor.c b/servers/slapd/back-bdb/monitor.c index fd8d308362..6697b82c03 100644 --- a/servers/slapd/back-bdb/monitor.c +++ b/servers/slapd/back-bdb/monitor.c @@ -27,6 +27,8 @@ #include "../back-monitor/back-monitor.h" +#include "config.h" + static ObjectClass *oc_olmBDBDatabase; static AttributeDescription *ad_olmBDBEntryCache, @@ -207,6 +209,8 @@ static int bdb_monitor_initialize( void ) { int i, code; + ConfigArgs c; + char *argv[ 3 ]; static int bdb_monitor_initialized = 0; @@ -220,14 +224,17 @@ bdb_monitor_initialize( void ) /* register schema here */ + argv[ 0 ] = "back-bdb/back-hdb monitor"; + c.argv = argv; + c.argc = 3; + c.fname = argv[0]; + for ( i = 0; s_oid[ i ].name; i++ ) { - char *argv[ 3 ]; - - argv[ 0 ] = "back-bdb/back-hdb monitor"; + c.lineno = i; argv[ 1 ] = s_oid[ i ].name; argv[ 2 ] = s_oid[ i ].oid; - if ( parse_oidm( argv[ 0 ], i, 3, argv, 0, NULL ) != 0 ) { + if ( parse_oidm( &c, 0, NULL ) != 0 ) { Debug( LDAP_DEBUG_ANY, "bdb_monitor_initialize: unable to add " "objectIdentifier \"%s=%s\"\n", diff --git a/servers/slapd/back-ldap/monitor.c b/servers/slapd/back-ldap/monitor.c index 44f4145ba7..288ff6a440 100644 --- a/servers/slapd/back-ldap/monitor.c +++ b/servers/slapd/back-ldap/monitor.c @@ -32,6 +32,8 @@ #include "lutil.h" #include "back-ldap.h" +#include "config.h" + static ObjectClass *oc_olmLDAPDatabase; static AttributeDescription *ad_olmDbURIList; @@ -305,6 +307,8 @@ ldap_back_monitor_initialize( void ) { int i, code; const char *err; + ConfigArgs c; + char *argv[ 3 ]; static int ldap_back_monitor_initialized = 0; @@ -319,14 +323,16 @@ ldap_back_monitor_initialize( void ) return -1; } + argv[ 0 ] = "back-ldap monitor"; + c.argv = argv; + c.argc = 3; + c.fname = argv[0]; for ( i = 0; s_oid[ i ].name; i++ ) { - char *argv[ 3 ]; - argv[ 0 ] = "back-ldap monitor"; argv[ 1 ] = s_oid[ i ].name; argv[ 2 ] = s_oid[ i ].oid; - if ( parse_oidm( argv[ 0 ], i, 3, argv, 0, NULL ) != 0 ) { + if ( parse_oidm( &c, 0, NULL ) != 0 ) { Debug( LDAP_DEBUG_ANY, "ldap_back_monitor_initialize: unable to add " "objectIdentifier \"%s=%s\"\n", diff --git a/servers/slapd/back-monitor/init.c b/servers/slapd/back-monitor/init.c index bc5448f178..6543fed041 100644 --- a/servers/slapd/back-monitor/init.c +++ b/servers/slapd/back-monitor/init.c @@ -30,6 +30,8 @@ #include "lber_pvt.h" #include "back-monitor.h" +#include "config.h" + #undef INTEGRATE_CORE_SCHEMA /* @@ -1837,15 +1839,19 @@ monitor_back_initialize( int i, rc; const char *text; monitor_info_t *mi = &monitor_info; + ConfigArgs c; + char *argv[ 3 ]; + + argv[ 0 ] = "monitor"; + c.argv = argv; + c.argc = 3; + c.fname = argv[0]; for ( i = 0; s_oid[ i ].name; i++ ) { - char *argv[ 3 ]; - - argv[ 0 ] = "monitor"; argv[ 1 ] = s_oid[ i ].name; argv[ 2 ] = s_oid[ i ].oid; - if ( parse_oidm( argv[ 0 ], i, 3, argv, 0, NULL ) != 0 ) { + if ( parse_oidm( &c, 0, NULL ) != 0 ) { Debug( LDAP_DEBUG_ANY, "monitor_back_initialize: unable to add " "objectIdentifier \"%s=%s\"\n", diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index 77249df4de..89b59891ab 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -393,7 +393,7 @@ static ConfigTable config_back_cf_table[] = { "EQUALITY caseIgnoreMatch " "SYNTAX OMsDirectoryString X-ORDERED 'VALUES' )", NULL, NULL }, - { "objectidentifier", NULL, 0, 0, 0, ARG_MAGIC|CFG_OID, + { "objectidentifier", "name> op == SLAP_CONFIG_EMIT ) { @@ -1195,8 +1194,6 @@ config_generic(ConfigArgs *c) { return rc; } - p = strchr(c->line,'(' /*')'*/); - switch(c->type) { case CFG_BACKEND: if(!(c->bi = backend_info(c->argv[1]))) { @@ -1313,7 +1310,7 @@ config_generic(ConfigArgs *c) { if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private ) cfn = c->private; - if(parse_oidm(c->fname, c->lineno, c->argc, c->argv, 1, &om)) + if(parse_oidm(c, 1, &om)) return(1); if (!cfn->c_om_head) cfn->c_om_head = om; cfn->c_om_tail = om; @@ -1346,7 +1343,7 @@ config_generic(ConfigArgs *c) { } /* else prev is NULL, append to end of global list */ } - if(parse_oc(c->fname, c->lineno, p, c->argv, &oc, prev)) return(1); + if(parse_oc(c, &oc, prev)) return(1); if (!cfn->c_oc_head) cfn->c_oc_head = oc; if (cfn->c_oc_tail == prev) cfn->c_oc_tail = oc; } @@ -1378,7 +1375,7 @@ config_generic(ConfigArgs *c) { } /* else prev is NULL, append to end of global list */ } - if(parse_at(c->fname, c->lineno, p, c->argv, &at, prev)) return(1); + if(parse_at(c, &at, prev)) return(1); if (!cfn->c_at_head) cfn->c_at_head = at; if (cfn->c_at_tail == prev) cfn->c_at_tail = at; } @@ -1389,7 +1386,7 @@ config_generic(ConfigArgs *c) { if ( c->op == LDAP_MOD_ADD && c->private && cfn != c->private ) cfn = c->private; - if(parse_cr(c->fname, c->lineno, p, c->argv, &cr)) return(1); + if(parse_cr(c, &cr)) return(1); if (!cfn->c_cr_head) cfn->c_cr_head = cr; cfn->c_cr_tail = cr; } @@ -5182,6 +5179,7 @@ int config_back_initialize( BackendInfo *bi ) { ConfigTable *ct = config_back_cf_table; + ConfigArgs ca; char *argv[4]; int i; AttributeDescription *ad = NULL; @@ -5233,11 +5231,17 @@ config_back_initialize( BackendInfo *bi ) bi->bi_tool_entry_get = config_tool_entry_get; bi->bi_tool_entry_put = config_tool_entry_put; + ca.argv = argv; + argv[ 0 ] = "slapd"; + ca.argv = argv; + ca.argc = 3; + ca.fname = argv[0]; + argv[3] = NULL; for (i=0; OidMacros[i].name; i++ ) { argv[1] = OidMacros[i].name; argv[2] = OidMacros[i].oid; - parse_oidm( "slapd", i, 3, argv, 0, NULL ); + parse_oidm( &ca, 0, NULL ); } bi->bi_cf_ocs = cf_ocs; diff --git a/servers/slapd/oidm.c b/servers/slapd/oidm.c index 24ed7d1b21..9d2cef857e 100644 --- a/servers/slapd/oidm.c +++ b/servers/slapd/oidm.c @@ -24,6 +24,7 @@ #include "slap.h" #include "lutil.h" +#include "config.h" static LDAP_STAILQ_HEAD(OidMacroList, slap_oid_macro) om_list = LDAP_STAILQ_HEAD_INITIALIZER(om_list); @@ -92,10 +93,7 @@ oidm_destroy() int parse_oidm( - const char *fname, - int lineno, - int argc, - char **argv, + struct config_args_s *c, int user, OidMacro **rom) { @@ -103,46 +101,46 @@ parse_oidm( OidMacro *om = NULL; struct berval bv; - if (argc != 3) { - fprintf( stderr, "%s: line %d: too many arguments\n", - fname, lineno ); -usage: fprintf( stderr, "\tObjectIdentifier \n"); - if (om) SLAP_FREE( om ); - return 1; - } - - oid = oidm_find( argv[1] ); + oid = oidm_find( c->argv[1] ); if( oid != NULL ) { - fprintf( stderr, - "%s: line %d: " - "ObjectIdentifier \"%s\" previously defined \"%s\"", - fname, lineno, argv[1], oid ); + snprintf( c->msg, sizeof( c->msg ), + "%s: \"%s\" previously defined \"%s\"", + c->argv[0], c->argv[1], oid ); + Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, + "%s %s\n", c->log, c->msg, 0 ); SLAP_FREE( oid ); return 1; } om = (OidMacro *) SLAP_CALLOC( sizeof(OidMacro), 1 ); if( om == NULL ) { - Debug( LDAP_DEBUG_ANY, "parse_oidm: SLAP_CALLOC failed", 0, 0, 0 ); + snprintf( c->msg, sizeof( c->msg ), + "%s: SLAP_CALLOC failed", c->argv[0] ); + Debug( LDAP_DEBUG_ANY, + "%s %s\n", c->log, c->msg, 0 ); return 1; } om->som_names = NULL; om->som_subs = NULL; - ber_str2bv( argv[1], 0, 1, &bv ); + ber_str2bv( c->argv[1], 0, 1, &bv ); ber_bvarray_add( &om->som_names, &bv ); - ber_str2bv( argv[2], 0, 1, &bv ); + ber_str2bv( c->argv[2], 0, 1, &bv ); ber_bvarray_add( &om->som_subs, &bv ); - om->som_oid.bv_val = oidm_find( argv[2] ); + om->som_oid.bv_val = oidm_find( c->argv[2] ); if (!om->som_oid.bv_val) { - fprintf( stderr, "%s: line %d: OID %s not recognized\n", - fname, lineno, argv[2] ); - goto usage; + snprintf( c->msg, sizeof( c->msg ), + "%s: OID %s not recognized", + c->argv[0], c->argv[2] ); + Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, + "%s %s\n", c->log, c->msg, 0 ); + SLAP_FREE( om ); + return 1; } - if (om->som_oid.bv_val == argv[2]) { - om->som_oid.bv_val = ch_strdup( argv[2] ); + if (om->som_oid.bv_val == c->argv[2]) { + om->som_oid.bv_val = ch_strdup( c->argv[2] ); } om->som_oid.bv_len = strlen( om->som_oid.bv_val ); diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index a0cfa0674c..6fc5bcc4cf 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -31,6 +31,8 @@ LDAP_BEGIN_DECL +struct config_args_s; /* config.h */ + /* * aci.c */ @@ -1264,8 +1266,7 @@ LDAP_SLAPD_F (void) oidm_destroy LDAP_P(( void )); LDAP_SLAPD_F (void) oidm_unparse LDAP_P(( BerVarray *bva, OidMacro *start, OidMacro *end, int system )); LDAP_SLAPD_F (int) parse_oidm LDAP_P(( - const char *fname, int lineno, int argc, char **argv, int user, - OidMacro **om )); + struct config_args_s *ca, int user, OidMacro **om )); /* * operation.c @@ -1571,14 +1572,11 @@ LDAP_SLAPD_F (int) slap_schema_check LDAP_P((void)); LDAP_SLAPD_F( int ) slap_valid_descr( const char * ); LDAP_SLAPD_F (int) parse_cr LDAP_P(( - const char *fname, int lineno, char *line, char **argv, - ContentRule **scr )); + struct config_args_s *ca, ContentRule **scr )); LDAP_SLAPD_F (int) parse_oc LDAP_P(( - const char *fname, int lineno, char *line, char **argv, - ObjectClass **soc, ObjectClass *prev )); + struct config_args_s *ca, ObjectClass **soc, ObjectClass *prev )); LDAP_SLAPD_F (int) parse_at LDAP_P(( - const char *fname, int lineno, char *line, char **argv, - AttributeType **sat, AttributeType *prev )); + struct config_args_s *ca, AttributeType **sat, AttributeType *prev )); LDAP_SLAPD_F (char *) scherr2str LDAP_P((int code)) LDAP_GCCATTR((const)); LDAP_SLAPD_F (int) dscompare LDAP_P(( const char *s1, const char *s2del, char delim )); diff --git a/servers/slapd/schemaparse.c b/servers/slapd/schemaparse.c index e00d3af70e..bf37c50c37 100644 --- a/servers/slapd/schemaparse.c +++ b/servers/slapd/schemaparse.c @@ -24,6 +24,7 @@ #include "slap.h" #include "ldap_schema.h" +#include "config.h" static void oc_usage(void); static void at_usage(void); @@ -124,28 +125,29 @@ cr_usage( void ) int parse_cr( - const char *fname, - int lineno, - char *line, - char **argv, + struct config_args_s *c, ContentRule **scr ) { LDAPContentRule *cr; int code; const char *err; + char *line = strchr( c->line, '(' ); cr = ldap_str2contentrule( line, &code, &err, LDAP_SCHEMA_ALLOW_ALL ); if ( !cr ) { - fprintf( stderr, "%s: line %d: %s before %s\n", - fname, lineno, ldap_scherr2str(code), err ); + snprintf( c->msg, sizeof( c->msg ), "%s: %s before %s", + c->argv[0], ldap_scherr2str( code ), err ); + Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, + "%s %s\n", c->log, c->msg, 0 ); cr_usage(); return 1; } if ( cr->cr_oid == NULL ) { - fprintf( stderr, - "%s: line %d: Content rule has no OID\n", - fname, lineno ); + snprintf( c->msg, sizeof( c->msg ), "%s: OID is missing", + c->argv[0] ); + Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, + "%s %s\n", c->log, c->msg, 0 ); cr_usage(); code = 1; goto done; @@ -153,8 +155,10 @@ parse_cr( code = cr_add( cr, 1, scr, &err ); if ( code ) { - fprintf( stderr, "%s: line %d: %s: \"%s\"\n", - fname, lineno, scherr2str( code ), err ); + snprintf( c->msg, sizeof( c->msg ), "%s: %s: \"%s\"", + c->argv[0], scherr2str(code), err); + Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, + "%s %s\n", c->log, c->msg, 0 ); code = 1; goto done; } @@ -172,29 +176,30 @@ done:; int parse_oc( - const char *fname, - int lineno, - char *line, - char **argv, + struct config_args_s *c, ObjectClass **soc, ObjectClass *prev ) { LDAPObjectClass *oc; int code; const char *err; + char *line = strchr( c->line, '(' ); oc = ldap_str2objectclass(line, &code, &err, LDAP_SCHEMA_ALLOW_ALL ); if ( !oc ) { - fprintf( stderr, "%s: line %d: %s before %s\n", - fname, lineno, ldap_scherr2str( code ), err ); + snprintf( c->msg, sizeof( c->msg ), "%s: %s before %s", + c->argv[0], ldap_scherr2str( code ), err ); + Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, + "%s %s\n", c->log, c->msg, 0 ); oc_usage(); return 1; } if ( oc->oc_oid == NULL ) { - fprintf( stderr, - "%s: line %d: objectclass has no OID\n", - fname, lineno ); + snprintf( c->msg, sizeof( c->msg ), "%s: OID is missing", + c->argv[0] ); + Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, + "%s %s\n", c->log, c->msg, 0 ); oc_usage(); code = 1; goto done; @@ -202,8 +207,10 @@ parse_oc( code = oc_add( oc, 1, soc, prev, &err ); if ( code ) { - fprintf( stderr, "%s: line %d: %s: \"%s\"\n", - fname, lineno, scherr2str( code ), err ); + snprintf( c->msg, sizeof( c->msg ), "%s: %s: \"%s\"", + c->argv[0], scherr2str(code), err); + Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, + "%s %s\n", c->log, c->msg, 0 ); code = 1; goto done; } @@ -264,29 +271,30 @@ at_usage( void ) int parse_at( - const char *fname, - int lineno, - char *line, - char **argv, + struct config_args_s *c, AttributeType **sat, AttributeType *prev ) { LDAPAttributeType *at; int code; const char *err; + char *line = strchr( c->line, '(' ); at = ldap_str2attributetype( line, &code, &err, LDAP_SCHEMA_ALLOW_ALL ); if ( !at ) { - fprintf( stderr, "%s: line %d: %s before %s\n", - fname, lineno, ldap_scherr2str(code), err ); + snprintf( c->msg, sizeof( c->msg ), "%s: %s before %s", + c->argv[0], ldap_scherr2str(code), err ); + Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, + "%s %s\n", c->log, c->msg, 0 ); at_usage(); return 1; } if ( at->at_oid == NULL ) { - fprintf( stderr, - "%s: line %d: attributeType has no OID\n", - fname, lineno ); + snprintf( c->msg, sizeof( c->msg ), "%s: OID is missing", + c->argv[0] ); + Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, + "%s %s\n", c->log, c->msg, 0 ); at_usage(); code = 1; goto done; @@ -294,16 +302,20 @@ parse_at( /* operational attributes should be defined internally */ if ( at->at_usage ) { - fprintf( stderr, "%s: line %d: attribute type \"%s\" is operational\n", - fname, lineno, at->at_oid ); + snprintf( c->msg, sizeof( c->msg ), "%s: \"%s\" is operational", + c->argv[0], at->at_oid ); + Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, + "%s %s\n", c->log, c->msg, 0 ); code = 1; goto done; } code = at_add( at, 1, sat, prev, &err); if ( code ) { - fprintf( stderr, "%s: line %d: %s: \"%s\"\n", - fname, lineno, scherr2str(code), err); + snprintf( c->msg, sizeof( c->msg ), "%s: %s: \"%s\"", + c->argv[0], scherr2str(code), err); + Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, + "%s %s\n", c->log, c->msg, 0 ); code = 1; goto done; }