/mandos/release

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

« back to all changes in this revision

Viewing changes to mandos-client.c

  • Committer: Teddy Hogeborn
  • Date: 2008-08-11 07:41:40 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080811074140-3wrl2jux1s0jy5kk
* mandos-client.c (print_out_password): Strip trailing '\n'.
  (main): Do not add trailing newline on fallback.

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
202
202
                                      .sa_flags = SA_NOCLDSTOP };
203
203
  char *plus_options = NULL;
204
204
  char **plus_argv = NULL;
205
 
 
 
205
  
206
206
  /* Establish a signal handler */
207
207
  sigemptyset(&sigchld_action.sa_mask);
208
208
  ret = sigaddset(&sigchld_action.sa_mask, SIGCHLD);
248
248
    switch (key) {
249
249
    case 'g':
250
250
      if (arg != NULL){
251
 
        char *p;
252
 
        while((p = strsep(&arg, ",")) != NULL){
253
 
          if(strcmp(p, "") == 0){
254
 
            continue;
255
 
          }
 
251
        char *p = strtok(arg, ",");
 
252
        do{
256
253
          addargument(getplugin(NULL, plugins), p);
257
 
        }
 
254
          p = strtok(NULL, ",");
 
255
        } while (p != NULL);
258
256
      }
259
257
      break;
260
258
    case 'o':
261
259
      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
 
            }
 
260
        char *name = strtok(arg, ":");
 
261
        char *p = strtok(NULL, ":");
 
262
        if(p != NULL){
 
263
          p = strtok(p, ",");
 
264
          do{
276
265
            addargument(getplugin(name, plugins), p);
277
 
          }
 
266
            p = strtok(NULL, ",");
 
267
          } while (p != NULL);
278
268
        }
279
269
      }
280
270
      break;
338
328
    }
339
329
    plus_argv[0] = argv[0];
340
330
    plus_argv[1] = NULL;
341
 
 
342
 
    while((arg = strsep(&plus_options, delims)) != NULL){
 
331
    arg = strtok(plus_options, delims); /* Get first argument */
 
332
    while(arg != NULL){
343
333
      new_argc++;
344
334
      plus_argv = realloc(plus_argv, sizeof(char *)
345
335
                         * ((unsigned int) new_argc + 1));
350
340
      }
351
341
      plus_argv[new_argc-1] = arg;
352
342
      plus_argv[new_argc] = NULL;
 
343
      arg = strtok(NULL, delims); /* Get next argument */
353
344
    }
354
 
 
355
345
    ret = argp_parse (&argp, new_argc, plus_argv, 0, 0, &plugin_list);
356
346
    if (ret == ARGP_ERR_UNKNOWN){
357
347
      fprintf(stderr, "Unknown error while parsing arguments\n");
465
455
    char *filename = malloc(d_name_len + strlen(plugindir) + 2);
466
456
    if (filename == NULL){
467
457
      perror("malloc");
468
 
      continue;
 
458
      exitstatus = EXIT_FAILURE;
 
459
      goto end;
469
460
    }
470
461
    strcpy(filename, plugindir); /* Spurious warning */
471
462
    strcat(filename, "/");      /* Spurious warning */
474
465
    ret = stat(filename, &st);
475
466
    if (ret == -1){
476
467
      perror("stat");
477
 
      free(filename);
478
 
      continue;
 
468
      exitstatus = EXIT_FAILURE;
 
469
      goto end;
479
470
    }
480
471
    
481
472
    if (not S_ISREG(st.st_mode) or (access(filename, X_OK) != 0)){
530
521
    }
531
522
    // Starting a new process to be watched
532
523
    pid_t pid = fork();
533
 
    if(pid == -1){
534
 
      perror("fork");
535
 
      exitstatus = EXIT_FAILURE;
536
 
      goto end;
537
 
    }
538
524
    if(pid == 0){
539
525
      /* this is the child process */
540
526
      ret = sigaction(SIGCHLD, &old_sigchld_action, NULL);
722
708
      }
723
709
    }
724
710
  }
725
 
 
726
 
 
727
 
 end:
728
711
  
729
 
  if(process_list == NULL or exitstatus != EXIT_SUCCESS){
730
 
    /* Fallback if all plugins failed, none are found or an error occured */
 
712
  if(process_list == NULL){
731
713
    bool bret;
732
714
    fprintf(stderr, "Going to fallback mode using getpass(3)\n");
733
715
    char *passwordbuffer = getpass("Password: ");
738
720
      goto end;
739
721
    }
740
722
  }
 
723
 
 
724
 end:
741
725
  
742
726
  /* Restore old signal handler */
743
727
  sigaction(SIGCHLD, &old_sigchld_action, NULL);