From e3eecf85c47e5b3b7b89d3afb586383d3ab188c8 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Fri, 4 Feb 2011 13:09:15 +0000 Subject: [PATCH] Dynamic config for back-shell --- servers/slapd/back-shell/config.c | 193 ++++++++++++------------- servers/slapd/back-shell/init.c | 4 +- servers/slapd/back-shell/proto-shell.h | 2 +- servers/slapd/bconfig.c | 1 + 4 files changed, 97 insertions(+), 103 deletions(-) diff --git a/servers/slapd/back-shell/config.c b/servers/slapd/back-shell/config.c index e00f5964a7..54e605585e 100644 --- a/servers/slapd/back-shell/config.c +++ b/servers/slapd/back-shell/config.c @@ -37,108 +37,101 @@ #include "slap.h" #include "shell.h" - -int -shell_back_db_config( - BackendDB *be, - const char *fname, - int lineno, - int argc, - char **argv -) +#include "config.h" + +static ConfigDriver shell_cf; + +enum { + SHELL_BIND = 0, + SHELL_UNBIND = 1, + SHELL_SEARCH, + SHELL_COMPARE, + SHELL_MODIFY, + SHELL_MODRDN, + SHELL_ADD, + SHELL_DELETE +}; + +static ConfigTable shellcfg[] = { + { "bind", "args", 2, 0, 0, ARG_STRING|ARG_MAGIC|SHELL_BIND, shell_cf, + "( OLcfgDbAt:10.1 NAME 'olcShellBind' " + "DESC 'Bind command and arguments' " + "EQUALITY caseExactMatch " + "SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL }, + { "unbind", "args", 2, 0, 0, ARG_STRING|ARG_MAGIC|SHELL_UNBIND, shell_cf, + "( OLcfgDbAt:10.2 NAME 'olcShellUnbind' " + "DESC 'Unbind command and arguments' " + "EQUALITY caseExactMatch " + "SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL }, + { "search", "args", 2, 0, 0, ARG_STRING|ARG_MAGIC|SHELL_SEARCH, shell_cf, + "( OLcfgDbAt:10.3 NAME 'olcShellSearch' " + "DESC 'Search command and arguments' " + "EQUALITY caseExactMatch " + "SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL }, + { "compare", "args", 2, 0, 0, ARG_STRING|ARG_MAGIC|SHELL_COMPARE, shell_cf, + "( OLcfgDbAt:10.4 NAME 'olcShellCompare' " + "DESC 'Compare command and arguments' " + "EQUALITY caseExactMatch " + "SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL }, + { "modify", "args", 2, 0, 0, ARG_STRING|ARG_MAGIC|SHELL_MODIFY, shell_cf, + "( OLcfgDbAt:10.5 NAME 'olcShellModify' " + "DESC 'Modify command and arguments' " + "EQUALITY caseExactMatch " + "SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL }, + { "modrdn", "args", 2, 0, 0, ARG_STRING|ARG_MAGIC|SHELL_MODRDN, shell_cf, + "( OLcfgDbAt:10.6 NAME 'olcShellModRDN' " + "DESC 'ModRDN command and arguments' " + "EQUALITY caseExactMatch " + "SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL }, + { "add", "args", 2, 0, 0, ARG_STRING|ARG_MAGIC|SHELL_ADD, shell_cf, + "( OLcfgDbAt:10.7 NAME 'olcShellAdd' " + "DESC 'Add command and arguments' " + "EQUALITY caseExactMatch " + "SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL }, + { "delete", "args", 2, 0, 0, ARG_STRING|ARG_MAGIC|SHELL_DELETE, shell_cf, + "( OLcfgDbAt:10.8 NAME 'olcShellDelete' " + "DESC 'Delete command and arguments' " + "EQUALITY caseExactMatch " + "SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL }, + { NULL } +}; + +static ConfigOCs shellocs[] = { + { "( OLcfgDbOc:10.1 " + "NAME 'olcShellConfig' " + "DESC 'Shell backend configuration' " + "SUP olcDatabaseConfig " + "MAY ( olcShellBind $ olcShellUnbind $ olcShellSearch $ " + "olcShellCompare $ olcShellModify $ olcShellModRDN $ " + "olcShellAdd $ olcShellDelete ) )", + Cft_Database, shellcfg }, + { NULL } +}; + +static int +shell_cf( ConfigArgs *c ) { - struct shellinfo *si = (struct shellinfo *) be->be_private; - - if ( si == NULL ) { - fprintf( stderr, "%s: line %d: shell backend info is null!\n", - fname, lineno ); - return( 1 ); - } - - /* command + args to exec for binds */ - if ( strcasecmp( argv[0], "bind" ) == 0 ) { - if ( argc < 2 ) { - fprintf( stderr, - "%s: line %d: missing executable in \"bind \" line\n", - fname, lineno ); - return( 1 ); - } - si->si_bind = ldap_charray_dup( &argv[1] ); - - /* command + args to exec for unbinds */ - } else if ( strcasecmp( argv[0], "unbind" ) == 0 ) { - if ( argc < 2 ) { - fprintf( stderr, - "%s: line %d: missing executable in \"unbind \" line\n", - fname, lineno ); - return( 1 ); - } - si->si_unbind = ldap_charray_dup( &argv[1] ); - - /* command + args to exec for searches */ - } else if ( strcasecmp( argv[0], "search" ) == 0 ) { - if ( argc < 2 ) { - fprintf( stderr, - "%s: line %d: missing executable in \"search \" line\n", - fname, lineno ); - return( 1 ); - } - si->si_search = ldap_charray_dup( &argv[1] ); - - /* command + args to exec for compares */ - } else if ( strcasecmp( argv[0], "compare" ) == 0 ) { - if ( argc < 2 ) { - fprintf( stderr, - "%s: line %d: missing executable in \"compare \" line\n", - fname, lineno ); - return( 1 ); - } - si->si_compare = ldap_charray_dup( &argv[1] ); - - /* command + args to exec for modifies */ - } else if ( strcasecmp( argv[0], "modify" ) == 0 ) { - if ( argc < 2 ) { - fprintf( stderr, - "%s: line %d: missing executable in \"modify \" line\n", - fname, lineno ); - return( 1 ); - } - si->si_modify = ldap_charray_dup( &argv[1] ); - - /* command + args to exec for modrdn */ - } else if ( strcasecmp( argv[0], "modrdn" ) == 0 ) { - if ( argc < 2 ) { - fprintf( stderr, - "%s: line %d: missing executable in \"modrdn \" line\n", - fname, lineno ); - return( 1 ); - } - si->si_modrdn = ldap_charray_dup( &argv[1] ); - - /* command + args to exec for add */ - } else if ( strcasecmp( argv[0], "add" ) == 0 ) { - if ( argc < 2 ) { - fprintf( stderr, - "%s: line %d: missing executable in \"add \" line\n", - fname, lineno ); - return( 1 ); - } - si->si_add = ldap_charray_dup( &argv[1] ); - - /* command + args to exec for delete */ - } else if ( strcasecmp( argv[0], "delete" ) == 0 ) { - if ( argc < 2 ) { - fprintf( stderr, - "%s: line %d: missing executable in \"delete \" line\n", - fname, lineno ); - return( 1 ); - } - si->si_delete = ldap_charray_dup( &argv[1] ); - - /* anything else */ + struct shellinfo *si = (struct shellinfo *) c->be->be_private; + char ***arr = &si->si_bind; + + if ( c->op == SLAP_CONFIG_EMIT ) { + struct berval bv; + if ( !arr[c->type] ) return 1; + bv.bv_val = ldap_charray2str( arr[c->type], " " ); + bv.bv_len = strlen( bv.bv_val ); + ber_bvarray_add( &c->rvalue_vals, &bv ); + } else if ( c->op == LDAP_MOD_DELETE ) { + ldap_charray_free( arr[c->type] ); + arr[c->type] = NULL; } else { - return SLAP_CONF_UNKNOWN; + arr[c->type] = ldap_charray_dup( &c->argv[1] ); } - return 0; } + +int +shell_back_init_cf( BackendInfo *bi ) +{ + bi->bi_cf_ocs = shellocs; + return config_register_schema( shellcfg, shellocs ); +} diff --git a/servers/slapd/back-shell/init.c b/servers/slapd/back-shell/init.c index d7348a9cb4..12426d10bc 100644 --- a/servers/slapd/back-shell/init.c +++ b/servers/slapd/back-shell/init.c @@ -51,7 +51,7 @@ shell_back_initialize( bi->bi_destroy = 0; bi->bi_db_init = shell_back_db_init; - bi->bi_db_config = shell_back_db_config; + bi->bi_db_config = 0; bi->bi_db_open = 0; bi->bi_db_close = 0; bi->bi_db_destroy = shell_back_db_destroy; @@ -73,7 +73,7 @@ shell_back_initialize( bi->bi_connection_init = 0; bi->bi_connection_destroy = 0; - return 0; + return shell_back_init_cf( bi ); } int diff --git a/servers/slapd/back-shell/proto-shell.h b/servers/slapd/back-shell/proto-shell.h index 56f4873aaf..52663f6674 100644 --- a/servers/slapd/back-shell/proto-shell.h +++ b/servers/slapd/back-shell/proto-shell.h @@ -40,7 +40,6 @@ extern BI_destroy shell_back_destroy; extern BI_db_init shell_back_db_init; extern BI_db_destroy shell_back_db_destroy; -extern BI_db_config shell_back_db_config; extern BI_op_bind shell_back_bind; extern BI_op_unbind shell_back_unbind; @@ -51,6 +50,7 @@ extern BI_op_modrdn shell_back_modrdn; extern BI_op_add shell_back_add; extern BI_op_delete shell_back_delete; +extern int shell_back_init_cf( BackendInfo *bi ); LDAP_END_DECL #endif /* PROTO_SHELL_H */ diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index 96bc7a9eb2..55f9dcdf03 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -248,6 +248,7 @@ static OidRec OidMacros[] = { * OLcfg{Bk|Db}{Oc|At}:7 -> back-sock * OLcfg{Bk|Db}{Oc|At}:8 -> back-null * OLcfg{Bk|Db}{Oc|At}:9 -> back-passwd + * OLcfg{Bk|Db}{Oc|At}:10 -> back-shell */ /* -- 2.39.5