/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 plugin-runner.c

  • Committer: Teddy Hogeborn
  • Date: 2008-08-14 02:24:59 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080814022459-rq3jt4q409l3qbj3
* Makefile (PREFIX, CONFDIR): New.

* initramfs-tools-hook: Search for Mandos in /usr/local as well as in
                        /usr.  Also copy plugin-runner.  Also chmod
                        the config dir.
  (DESTCONFDIR): Removed.
  (MANDOSDIR): New.
  (PLUGINDIR): Changed to "${MANDOSDIR}/plugins.d".

* initramfs-tools-script: New.

* mandos-client.c: Renamed to "plugin-runner.c".  All references
                   changed.
  (plugindir): Changed to "/lib/mandos/plugins.d".

* plugins.d/usplash: New.

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
 
67
67
#define BUFFER_SIZE 256
68
68
 
69
 
const char *argp_program_version = "mandos-client 1.0";
 
69
const char *argp_program_version = "plugin-runner 1.0";
70
70
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
71
71
 
72
72
struct process;
171
171
}
172
172
 
173
173
bool print_out_password(const char *buffer, size_t length){
174
 
  size_t ret;
175
 
  for(size_t written = 0; written < length; written += ret){
 
174
  ssize_t ret;
 
175
  if(length>0 and buffer[length-1] == '\n'){
 
176
    length--;
 
177
  }
 
178
  for(size_t written = 0; written < length; written += (size_t)ret){
176
179
    ret = TEMP_FAILURE_RETRY(write(STDOUT_FILENO, buffer + written,
177
180
                                   length - written));
178
181
    if(ret < 0){
183
186
}
184
187
 
185
188
int main(int argc, char *argv[]){
186
 
  const char *plugindir = "/conf/conf.d/mandos/plugins.d";
 
189
  const char *plugindir = "/lib/mandos/plugins.d";
187
190
  size_t d_name_len;
188
191
  DIR *dir = NULL;
189
192
  struct dirent *dirst;
199
202
                                      .sa_flags = SA_NOCLDSTOP };
200
203
  char *plus_options = NULL;
201
204
  char **plus_argv = NULL;
202
 
  
 
205
 
203
206
  /* Establish a signal handler */
204
207
  sigemptyset(&sigchld_action.sa_mask);
205
208
  ret = sigaddset(&sigchld_action.sa_mask, SIGCHLD);
304
307
  
305
308
  ret = argp_parse (&argp, argc, argv, 0, 0, &plugin_list);
306
309
  if (ret == ARGP_ERR_UNKNOWN){
307
 
    fprintf(stderr, "Unkown error while parsing arguments\n");
 
310
    fprintf(stderr, "Unknown error while parsing arguments\n");
308
311
    exitstatus = EXIT_FAILURE;
309
312
    goto end;
310
313
  }
341
344
    }
342
345
    ret = argp_parse (&argp, new_argc, plus_argv, 0, 0, &plugin_list);
343
346
    if (ret == ARGP_ERR_UNKNOWN){
344
 
      fprintf(stderr, "Unkown error while parsing arguments\n");
 
347
      fprintf(stderr, "Unknown error while parsing arguments\n");
345
348
      exitstatus = EXIT_FAILURE;
346
349
      goto end;
347
350
    }
452
455
    char *filename = malloc(d_name_len + strlen(plugindir) + 2);
453
456
    if (filename == NULL){
454
457
      perror("malloc");
455
 
      exitstatus = EXIT_FAILURE;
456
 
      goto end;
 
458
      continue;
457
459
    }
458
460
    strcpy(filename, plugindir); /* Spurious warning */
459
461
    strcat(filename, "/");      /* Spurious warning */
462
464
    ret = stat(filename, &st);
463
465
    if (ret == -1){
464
466
      perror("stat");
465
 
      exitstatus = EXIT_FAILURE;
466
 
      goto end;
 
467
      free(filename);
 
468
      continue;
467
469
    }
468
470
    
469
471
    if (not S_ISREG(st.st_mode) or (access(filename, X_OK) != 0)){
518
520
    }
519
521
    // Starting a new process to be watched
520
522
    pid_t pid = fork();
 
523
    if(pid == -1){
 
524
      perror("fork");
 
525
      exitstatus = EXIT_FAILURE;
 
526
      goto end;
 
527
    }
521
528
    if(pid == 0){
522
529
      /* this is the child process */
523
530
      ret = sigaction(SIGCHLD, &old_sigchld_action, NULL);
705
712
      }
706
713
    }
707
714
  }
 
715
 
 
716
 
 
717
 end:
708
718
  
709
 
  if(process_list == NULL){
 
719
  if(process_list == NULL or exitstatus != EXIT_SUCCESS){
 
720
    /* Fallback if all plugins failed, none are found or an error occured */
710
721
    bool bret;
711
722
    fprintf(stderr, "Going to fallback mode using getpass(3)\n");
712
723
    char *passwordbuffer = getpass("Password: ");
716
727
      exitstatus = EXIT_FAILURE;
717
728
      goto end;
718
729
    }
719
 
    bret = print_out_password("\n", 1);
720
 
    if(not bret){
721
 
      perror("print_out_password");
722
 
      exitstatus = EXIT_FAILURE;
723
 
    }
724
730
  }
725
 
 
726
 
 end:
727
731
  
728
732
  /* Restore old signal handler */
729
733
  sigaction(SIGCHLD, &old_sigchld_action, NULL);