/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos-client.c

Fixed fallback on error in mandos-client
fixed a bug in password-request

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
                                   close() */
52
52
#include <fcntl.h>              /* fcntl(), F_GETFD, F_SETFD,
53
53
                                   FD_CLOEXEC */
54
 
#include <string.h>             /* strsep, strlen(), strcpy(),
 
54
#include <string.h>             /* strtok, strlen(), strcpy(),
55
55
                                   strcat() */
56
56
#include <errno.h>              /* errno */
57
57
#include <argp.h>               /* struct argp_option, struct
66
66
 
67
67
#define BUFFER_SIZE 256
68
68
 
69
 
const char *argp_program_version = "plugin-runner 1.0";
 
69
const char *argp_program_version = "mandos-client 1.0";
70
70
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
71
71
 
72
72
struct process;
186
186
}
187
187
 
188
188
int main(int argc, char *argv[]){
189
 
  const char *plugindir = "/lib/mandos/plugins.d";
 
189
  const char *plugindir = "/conf/conf.d/mandos/plugins.d";
190
190
  size_t d_name_len;
191
191
  DIR *dir = NULL;
192
192
  struct dirent *dirst;
203
203
  char *plus_options = NULL;
204
204
  char **plus_argv = NULL;
205
205
 
 
206
  errno = 0;
 
207
  
206
208
  /* Establish a signal handler */
207
209
  sigemptyset(&sigchld_action.sa_mask);
208
210
  ret = sigaddset(&sigchld_action.sa_mask, SIGCHLD);
248
250
    switch (key) {
249
251
    case 'g':
250
252
      if (arg != NULL){
251
 
        char *p;
252
 
        while((p = strsep(&arg, ",")) != NULL){
253
 
          if(strcmp(p, "") == 0){
254
 
            continue;
255
 
          }
 
253
        char *p = strtok(arg, ",");
 
254
        do{
256
255
          addargument(getplugin(NULL, plugins), p);
257
 
        }
 
256
          p = strtok(NULL, ",");
 
257
        } while (p != NULL);
258
258
      }
259
259
      break;
260
260
    case 'o':
261
261
      if (arg != NULL){
262
 
        char *name = strsep(&arg, ":");
263
 
        if(strcmp(name, "") == 0){
264
 
          break;
265
 
        }
266
 
        char *opt = strsep(&arg, ":");
267
 
        if(strcmp(opt, "") == 0){
268
 
          break;
269
 
        }
270
 
        if(opt != NULL){
271
 
          char *p;
272
 
          while((p = strsep(&opt, ",")) != NULL){
273
 
            if(strcmp(p, "") == 0){
274
 
              continue;
275
 
            }
 
262
        char *name = strtok(arg, ":");
 
263
        char *p = strtok(NULL, ":");
 
264
        if(p != NULL){
 
265
          p = strtok(p, ",");
 
266
          do{
276
267
            addargument(getplugin(name, plugins), p);
277
 
          }
 
268
            p = strtok(NULL, ",");
 
269
          } while (p != NULL);
278
270
        }
279
271
      }
280
272
      break;
338
330
    }
339
331
    plus_argv[0] = argv[0];
340
332
    plus_argv[1] = NULL;
341
 
 
342
 
    while((arg = strsep(&plus_options, delims)) != NULL){
 
333
    arg = strtok(plus_options, delims); /* Get first argument */
 
334
    while(arg != NULL){
343
335
      new_argc++;
344
336
      plus_argv = realloc(plus_argv, sizeof(char *)
345
337
                         * ((unsigned int) new_argc + 1));
350
342
      }
351
343
      plus_argv[new_argc-1] = arg;
352
344
      plus_argv[new_argc] = NULL;
 
345
      arg = strtok(NULL, delims); /* Get next argument */
353
346
    }
354
 
    
355
347
    ret = argp_parse (&argp, new_argc, plus_argv, 0, 0, &plugin_list);
356
348
    if (ret == ARGP_ERR_UNKNOWN){
357
349
      fprintf(stderr, "Unknown error while parsing arguments\n");
465
457
    char *filename = malloc(d_name_len + strlen(plugindir) + 2);
466
458
    if (filename == NULL){
467
459
      perror("malloc");
468
 
      continue;
 
460
      exitstatus = EXIT_FAILURE;
 
461
      goto end;
469
462
    }
470
463
    strcpy(filename, plugindir); /* Spurious warning */
471
464
    strcat(filename, "/");      /* Spurious warning */
474
467
    ret = stat(filename, &st);
475
468
    if (ret == -1){
476
469
      perror("stat");
477
 
      free(filename);
478
 
      continue;
 
470
      exitstatus = EXIT_FAILURE;
 
471
      goto end;
479
472
    }
480
473
    
481
474
    if (not S_ISREG(st.st_mode) or (access(filename, X_OK) != 0)){
530
523
    }
531
524
    // Starting a new process to be watched
532
525
    pid_t pid = fork();
533
 
    if(pid == -1){
534
 
      perror("fork");
535
 
      exitstatus = EXIT_FAILURE;
536
 
      goto end;
537
 
    }
538
526
    if(pid == 0){
539
527
      /* this is the child process */
540
528
      ret = sigaction(SIGCHLD, &old_sigchld_action, NULL);
727
715
 end:
728
716
  
729
717
  if(process_list == NULL or exitstatus != EXIT_SUCCESS){
730
 
    /* Fallback if all plugins failed, none are found or an error occured */
 
718
    /* Fallback if all plugins failed or an error occured */
731
719
    bool bret;
732
720
    fprintf(stderr, "Going to fallback mode using getpass(3)\n");
733
721
    char *passwordbuffer = getpass("Password: ");