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

  • Committer: Teddy Hogeborn
  • Date: 2008-09-21 13:42:34 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080921134234-jo8p4rwtm50yb4xj
* clients.conf ([bar]/secfile): Do not imply armored format.

* debian/control: Build-Depend on pkg-config.

* debian/mandos.prerm (remove): Bug fix; check for
                                "/etc/init.d/mandos", not
                                "/etc/init.d/ssh".

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
const char *argp_program_version = "plugin-runner 1.0";
73
73
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
74
74
 
75
 
struct plugin;
76
 
 
77
75
typedef struct plugin{
78
76
  char *name;                   /* can be NULL or any plugin name */
79
77
  char **argv;
208
206
 * Descriptor Flags".
209
207
 * *Note File Descriptor Flags:(libc)Descriptor Flags.
210
208
 */
211
 
static int set_cloexec_flag(int fd)
212
 
{
 
209
static int set_cloexec_flag(int fd){
213
210
  int ret = fcntl(fd, F_GETFD, 0);
214
211
  /* If reading the flags failed, return error indication now. */
215
212
  if(ret < 0){
222
219
 
223
220
/* Mark processes as completed when they exit, and save their exit
224
221
   status. */
225
 
void handle_sigchld(__attribute__((unused)) int sig){
 
222
static void handle_sigchld(__attribute__((unused)) int sig){
226
223
  while(true){
227
224
    plugin *proc = plugin_list;
228
225
    int status;
253
250
}
254
251
 
255
252
/* Prints out a password to stdout */
256
 
bool print_out_password(const char *buffer, size_t length){
 
253
static bool print_out_password(const char *buffer, size_t length){
257
254
  ssize_t ret;
258
 
  if(length>0 and buffer[length-1] == '\n'){
259
 
    length--;
260
 
  }
261
255
  for(size_t written = 0; written < length; written += (size_t)ret){
262
256
    ret = TEMP_FAILURE_RETRY(write(STDOUT_FILENO, buffer + written,
263
257
                                   length - written));
476
470
      debug = true;
477
471
      break;
478
472
    case ARGP_KEY_ARG:
479
 
      fprintf(stderr, "Ignoring unknown argument \"%s\"\n", arg);
 
473
      /* Cryptsetup always passes an argument, which is an empty
 
474
         string if "none" was specified in /etc/crypttab.  So if
 
475
         argument was empty, we ignore it silently. */
 
476
      if(arg[0] != '\0'){
 
477
        fprintf(stderr, "Ignoring unknown argument \"%s\"\n", arg);
 
478
      }
480
479
      break;
481
480
    case ARGP_KEY_END:
482
481
      break;
737
736
    }
738
737
 
739
738
    char *filename;
740
 
    ret = asprintf(&filename, "%s/%s", plugindir, dirst->d_name);
 
739
    if(plugindir == NULL){
 
740
      ret = asprintf(&filename, PDIR "/%s", dirst->d_name);
 
741
    } else {
 
742
      ret = asprintf(&filename, "%s/%s", plugindir, dirst->d_name);
 
743
    }
741
744
    if(ret < 0){
742
745
      perror("asprintf");
743
746
      continue;
1039
1042
    bool bret;
1040
1043
    fprintf(stderr, "Going to fallback mode using getpass(3)\n");
1041
1044
    char *passwordbuffer = getpass("Password: ");
1042
 
    bret = print_out_password(passwordbuffer, strlen(passwordbuffer));
 
1045
    size_t len = strlen(passwordbuffer);
 
1046
    /* Strip trailing newline */
 
1047
    if(len > 0 and passwordbuffer[len-1] == '\n'){
 
1048
      passwordbuffer[len-1] = '\0'; /* not strictly necessary */
 
1049
      len--;
 
1050
    }
 
1051
    bret = print_out_password(passwordbuffer, len);
1043
1052
    if(not bret){
1044
1053
      perror("print_out_password");
1045
1054
      exitstatus = EXIT_FAILURE;