]> git.sur5r.net Git - openldap/commitdiff
Dynamic config for back-shell
authorHoward Chu <hyc@openldap.org>
Fri, 4 Feb 2011 13:09:15 +0000 (13:09 +0000)
committerHoward Chu <hyc@openldap.org>
Fri, 4 Feb 2011 13:09:15 +0000 (13:09 +0000)
servers/slapd/back-shell/config.c
servers/slapd/back-shell/init.c
servers/slapd/back-shell/proto-shell.h
servers/slapd/bconfig.c

index e00f5964a75da61fb390f5c506536d17e358361a..54e605585ee3eb890d0c07f815eaa5428f0b3610 100644 (file)
 
 #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 <executable>\" 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 <executable>\" 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 <executable>\" 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 <executable>\" 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 <executable>\" 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 <executable>\" 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 <executable>\" 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 <executable>\" 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 );
+}
index d7348a9cb442dba4b9785faf347a9be3b207dca5..12426d10bc1e0775ba4a2ae7bb3ee7efca7a9831 100644 (file)
@@ -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
index 56f4873aaf64a8f21599c91be9e4f93f1c26743a..52663f6674c37cb196db55739dd558a8679a3b0b 100644 (file)
@@ -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 */
index 96bc7a9eb28294c14cbd975d58c5bc7717a4275b..55f9dcdf032b05ebbcf0e6cd11bf41d9cfe5a870 100644 (file)
@@ -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
  */
 
 /*