52
52
#include <fcntl.h> /* fcntl(), F_GETFD, F_SETFD,
54
#include <string.h> /* strsep, strlen(), strcpy(),
54
#include <string.h> /* strtok, strlen(), strcpy(),
56
56
#include <errno.h> /* errno */
57
57
#include <argp.h> /* struct argp_option, struct
189
char ** addcustomargument(char **argv, int *argc, char *arg){
193
argv = malloc(sizeof(char*) * 2);
197
argv[0] = NULL; /* Will be set to argv[0] in main before parsing */
201
argv = realloc(argv, sizeof(char *)
202
* ((unsigned int) *argc + 1));
211
185
int main(int argc, char *argv[]){
212
186
const char *plugindir = "/conf/conf.d/mandos/plugins.d";
213
const char *conffile = CONFFILE;
215
187
size_t d_name_len;
217
189
struct dirent *dirst;
275
247
if (arg != NULL){
277
while((p = strsep(&arg, ",")) != NULL){
248
char *p = strtok(arg, ",");
281
250
addargument(getplugin(NULL, plugins), p);
251
p = strtok(NULL, ",");
286
256
if (arg != NULL){
287
char *name = strsep(&arg, ":");
291
char *opt = strsep(&arg, ":");
297
while((p = strsep(&opt, ",")) != NULL){
257
char *name = strtok(arg, ":");
258
char *p = strtok(NULL, ":");
301
262
addargument(getplugin(name, plugins), p);
263
p = strtok(NULL, ",");
340
305
ret = argp_parse (&argp, argc, argv, 0, 0, &plugin_list);
341
306
if (ret == ARGP_ERR_UNKNOWN){
342
fprintf(stderr, "Unknown error while parsing arguments\n");
307
fprintf(stderr, "Unkown error while parsing arguments\n");
343
308
exitstatus = EXIT_FAILURE;
347
conffp = fopen(conffile, "r");
349
char *org_line = NULL;
352
char *p, *arg, *new_arg, *line;
353
const char whitespace_delims[] = " \r\t\f\v\n";
354
const char comment_delim[] = "#";
357
sret = getline(&org_line, &size, conffp);
363
arg = strsep(&line, comment_delim);
364
while((p = strsep(&arg, whitespace_delims)) != NULL){
369
custom_argv = addcustomargument(custom_argv, &custom_argc, new_arg);
370
if (custom_argv == NULL){
371
perror("addcustomargument");
372
exitstatus = EXIT_FAILURE;
379
/* check for harmfull errors */
380
if (errno == EMFILE or errno == ENFILE or errno == ENOMEM){
313
/* This is a mangled argument in the form of
314
"+--option+--other-option=parameter+--yet-another-option", etc */
315
/* Make new argc and argv vars, and call argp_parse() again. */
316
plus_options++; /* skip the first '+' character */
317
const char delims[] = "+";
320
plus_argv = malloc(sizeof(char*) * 2);
321
if(plus_argv == NULL){
382
323
exitstatus = EXIT_FAILURE;
387
if(custom_argv != NULL){
388
custom_argv[0] = argv[0];
389
ret = argp_parse (&argp, custom_argc, custom_argv, 0, 0, &plugin_list);
326
plus_argv[0] = argv[0];
328
arg = strtok(plus_options, delims); /* Get first argument */
331
plus_argv = realloc(plus_argv, sizeof(char *)
332
* ((unsigned int) new_argc + 1));
333
if(plus_argv == NULL){
335
exitstatus = EXIT_FAILURE;
338
plus_argv[new_argc-1] = arg;
339
plus_argv[new_argc] = NULL;
340
arg = strtok(NULL, delims); /* Get next argument */
342
ret = argp_parse (&argp, new_argc, plus_argv, 0, 0, &plugin_list);
390
343
if (ret == ARGP_ERR_UNKNOWN){
391
fprintf(stderr, "Unknown error while parsing arguments\n");
344
fprintf(stderr, "Unkown error while parsing arguments\n");
392
345
exitstatus = EXIT_FAILURE;
771
716
exitstatus = EXIT_FAILURE;
719
bret = print_out_password("\n", 1);
721
perror("print_out_password");
722
exitstatus = EXIT_FAILURE;
776
728
/* Restore old signal handler */
777
729
sigaction(SIGCHLD, &old_sigchld_action, NULL);
781
733
/* Free the plugin list */
782
734
for(plugin *next; plugin_list != NULL; plugin_list = next){