=== modified file 'TODO' --- TODO 2008-08-31 15:06:39 +0000 +++ TODO 2008-09-02 10:27:08 +0000 @@ -7,13 +7,9 @@ ** [#B] Add more if(debug) calls ** [#B] Seperate more code to function for more readability ** [#A] Man page: man8/plugin-runner.8mandos -*** EXIT STATUS -*** ENVIRONMENT - Environment is modified according to options and passed to plugins *** EXAMPLE Examples of normal usage, debug usage, debugging single or all plugins, etc. -*** FILES *** SECURITY Note the danger of using this program, since you might lock yourself out of your system without any means of entering the root === modified file 'plugin-runner.c' --- plugin-runner.c 2008-09-01 16:53:17 +0000 +++ plugin-runner.c 2008-09-02 06:13:47 +0000 @@ -344,18 +344,21 @@ { .name = "global-options", .key = 'g', .arg = "OPTION[,OPTION[,...]]", .doc = "Options passed to all plugins" }, - { .name = "global-env", .key = 'e', + { .name = "global-env", .key = 'G', .arg = "VAR=value", .doc = "Environment variable passed to all plugins" }, { .name = "options-for", .key = 'o', .arg = "PLUGIN:OPTION[,OPTION[,...]]", .doc = "Options passed only to specified plugin" }, - { .name = "env-for", .key = 'f', + { .name = "env-for", .key = 'E', .arg = "PLUGIN:ENV=value", .doc = "Environment variable passed to specified plugin" }, { .name = "disable", .key = 'd', .arg = "PLUGIN", .doc = "Disable a specific plugin", .group = 1 }, + { .name = "enable", .key = 'e', + .arg = "PLUGIN", + .doc = "Enable a specific plugin", .group = 1 }, { .name = "plugin-dir", .key = 128, .arg = "DIRECTORY", .doc = "Specify a different plugin directory", .group = 2 }, @@ -375,8 +378,6 @@ error_t parse_opt (int key, char *arg, __attribute__((unused)) struct argp_state *state) { - /* Get the INPUT argument from `argp_parse', which we know is a - pointer to our plugin list pointer. */ switch (key) { case 'g': /* --global-options */ if (arg != NULL){ @@ -392,7 +393,7 @@ } } break; - case 'e': /* --global-env */ + case 'G': /* --global-env */ if(arg == NULL){ break; } @@ -430,7 +431,7 @@ } } break; - case 'f': /* --env-for */ + case 'E': /* --env-for */ if(arg == NULL){ break; } @@ -458,6 +459,15 @@ p->disabled = true; } break; + case 'e': /* --enable */ + if (arg != NULL){ + plugin *p = getplugin(arg); + if(p == NULL){ + return ARGP_ERR_UNKNOWN; + } + p->disabled = false; + } + break; case 128: /* --plugin-dir */ plugindir = strdup(arg); if(plugindir == NULL){ @@ -465,11 +475,8 @@ } break; case 129: /* --config-file */ - argfile = strdup(arg); - if(argfile == NULL){ - perror("strdup"); - } - break; + /* This is already done by parse_opt_config_file() */ + break; case 130: /* --userid */ uid = (uid_t)strtol(arg, NULL, 10); break; @@ -490,10 +497,55 @@ return 0; } - struct argp argp = { .options = options, .parser = parse_opt, + /* This option parser is the same as parse_opt() above, except it + ignores everything but the --config-file option. */ + error_t parse_opt_config_file (int key, char *arg, + __attribute__((unused)) + struct argp_state *state) { + switch (key) { + case 'g': /* --global-options */ + case 'G': /* --global-env */ + case 'o': /* --options-for */ + case 'E': /* --env-for */ + case 'd': /* --disable */ + case 'e': /* --enable */ + case 128: /* --plugin-dir */ + break; + case 129: /* --config-file */ + argfile = strdup(arg); + if(argfile == NULL){ + perror("strdup"); + } + break; + case 130: /* --userid */ + case 131: /* --groupid */ + case 132: /* --debug */ + case ARGP_KEY_ARG: + case ARGP_KEY_END: + break; + default: + return ARGP_ERR_UNKNOWN; + } + return 0; + } + + struct argp argp = { .options = options, + .parser = parse_opt_config_file, .args_doc = "", .doc = "Mandos plugin runner -- Run plugins" }; + /* Parse using the parse_opt_config_file in order to get the custom + config file location, if any. */ + ret = argp_parse (&argp, argc, argv, ARGP_IN_ORDER, 0, NULL); + if (ret == ARGP_ERR_UNKNOWN){ + fprintf(stderr, "Unknown error while parsing arguments\n"); + exitstatus = EXIT_FAILURE; + goto fallback; + } + + /* Reset to the normal argument parser */ + argp.parser = parse_opt; + /* Open the configfile if available */ if (argfile == NULL){ conffp = fopen(AFILE, "r"); === modified file 'plugin-runner.xml' --- plugin-runner.xml 2008-09-01 16:53:17 +0000 +++ plugin-runner.xml 2008-09-02 10:27:08 +0000 @@ -3,7 +3,7 @@ "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [ - + ]> @@ -56,7 +56,7 @@ - -