162
162
int ret, maxfd = 0;
163
165
bool debug = false;
164
166
int exitstatus = EXIT_SUCCESS;
167
struct sigaction old_sigchld_action;
168
struct sigaction sigchld_action = { .sa_handler = handle_sigchld,
169
.sa_flags = SA_NOCLDSTOP };
170
char *plus_options = NULL;
171
char **plus_argv = NULL;
166
173
/* Establish a signal handler */
167
struct sigaction old_sigchld_action,
168
sigchld_action = { .sa_handler = handle_sigchld,
169
.sa_flags = SA_NOCLDSTOP };
170
174
sigemptyset(&sigchld_action.sa_mask);
171
175
ret = sigaddset(&sigchld_action.sa_mask, SIGCHLD);
193
197
{ .name = "plugin-dir", .key = 128,
194
198
.arg = "DIRECTORY",
195
199
.doc = "Specify a different plugin directory", .group = 2 },
196
{ .name = "debug", .key = 129,
200
{ .name = "userid", .key = 129,
201
.arg = "ID", .flags = 0,
202
.doc = "User ID the plugins will run as", .group = 2 },
203
{ .name = "groupid", .key = 130,
204
.arg = "ID", .flags = 0,
205
.doc = "Group ID the plugins will run as", .group = 2 },
206
{ .name = "debug", .key = 131,
197
207
.doc = "Debug mode", .group = 3 },
210
220
addargument(getplugin(NULL, plugins), p);
211
221
p = strtok(NULL, ",");
216
226
if (arg != NULL){
217
227
char *name = strtok(arg, ":");
218
228
char *p = strtok(NULL, ":");
220
230
p = strtok(p, ",");
222
232
addargument(getplugin(name, plugins), p);
223
233
p = strtok(NULL, ",");
247
uid = (uid_t)strtol(arg, NULL, 10);
250
gid = (gid_t)strtol(arg, NULL, 10);
239
255
case ARGP_KEY_ARG:
256
if(plus_options != NULL or arg == NULL or arg[0] != '+'){
242
261
case ARGP_KEY_END:
250
269
plugin *plugin_list = NULL;
252
271
struct argp argp = { .options = options, .parser = parse_opt,
272
.args_doc = "[+PLUS_SEPARATED_OPTIONS]",
254
273
.doc = "Mandos plugin runner -- Run plugins" };
256
argp_parse (&argp, argc, argv, 0, 0, &plugin_list);
275
argp_parse (&argp, argc, argv, 0, 0, &plugin_list);
278
/* This is a mangled argument in the form of
279
"+--option+--other-option=parameter+--yet-another-option", etc */
280
/* Make new argc and argv vars, and call argp_parse() again. */
281
plus_options++; /* skip the first '+' character */
282
const char delims[] = "+";
285
plus_argv = malloc(sizeof(char*) * 2);
286
if(plus_argv == NULL){
288
exitstatus = EXIT_FAILURE;
291
plus_argv[0] = argv[0];
293
arg = strtok(plus_options, delims); /* Get first argument */
296
plus_argv = realloc(plus_argv, sizeof(char *)
297
* ((unsigned int) new_argc + 1));
298
if(plus_argv == NULL){
300
exitstatus = EXIT_FAILURE;
303
plus_argv[new_argc-1] = arg;
304
plus_argv[new_argc] = NULL;
305
arg = strtok(NULL, delims); /* Get next argument */
307
argp_parse (&argp, new_argc, plus_argv, 0, 0, &plugin_list);
259
311
for(plugin *p = plugin_list; p != NULL; p=p->next){
600
662
/* Restore old signal handler */
601
663
sigaction(SIGCHLD, &old_sigchld_action, NULL);
603
667
/* Free the plugin list */
604
668
for(plugin *next; plugin_list != NULL; plugin_list = next){
605
669
next = plugin_list->next;