/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 plugins.d/askpass-fifo.c

Convert some programs to use the exit codes from <sysexits.h>.  Change
all programs using the "argp" parsing functions to use them correctly;
checking return value, using argp_error() to report parse errors etc.

* plugin-runner.c: Use <sysexits.h> exit codes.  Always use fallback,
                   even on option errors, except for "--help", etc.
  (getplugin): Make sure "errno" is set correctly on return.
  (main): Declare our own "--help", "--usage", and "--version"
          options which do not cause the fallback to be invoked.
          In all other options, use fallback on any error.
  (parse_opt, parse_opt_config_file): Reset errno at start and return
                                      errno.  No need to check "arg"
                                      for NULL.  New "--help",
                                      "--usage", and "--version"
                                      options.
  (parse_opt): Accept empty string as global option.  Do not print
               errors which will be detected and reported later.  Do
               "argp_error()" on parse error or empty plugin names.
* plugins.d/mandos-client.c: Use <sysexits.h> exit codes.  Do not
                             return successful exit code on "--help",
                             etc. since this would give the wrong
                             message to "plugin-runner".
  (main): Declare our own "--help", "--usage", and "--version"
          options which do not return a successful exit code.
  (parse_opt): Reset errno at start and return errno.  Do
               "argp_error()" on parse errors.  New "--help",
               "--usage", and "--version" options.
* plugins.d/password-prompt.c: Use exit codes from <sysexits.h>.  Do
                               not return successful exit code on
                               "--help", etc. since this would give
                               the wrong message to "plugin-runner".
  (main): Declare our own "--help", "--usage", and "--version" options
          which do not return a successful exit code.  Do
          close(STDOUT_FILENO) after writing to check its return code.
  (parse_opt): Reset errno at start and return errno.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/*
3
3
 * Askpass-FIFO - Read a password from a FIFO and output it
4
4
 * 
5
 
 * Copyright © 2008-2010 Teddy Hogeborn
6
 
 * Copyright © 2008-2010 Björn Påhlsson
 
5
 * Copyright © 2008,2009 Teddy Hogeborn
 
6
 * Copyright © 2008,2009 Björn Påhlsson
7
7
 * 
8
8
 * This program is free software: you can redistribute it and/or
9
9
 * modify it under the terms of the GNU General Public License as
31
31
                                   ENOENT, EEXIST, EFAULT, EMFILE,
32
32
                                   ENFILE, ENOMEM, EBADF, EINVAL, EIO,
33
33
                                   EISDIR, EFBIG */
34
 
#include <error.h>              /* error() */
 
34
#include <stdio.h>              /* perror() */
35
35
#include <stdlib.h>             /* EXIT_FAILURE, NULL, size_t, free(),
36
36
                                   realloc(), EXIT_SUCCESS */
37
37
#include <fcntl.h>              /* open(), O_RDONLY */
51
51
  ret = mkfifo(passfifo, S_IRUSR | S_IWUSR);
52
52
  if(ret == -1){
53
53
    int e = errno;
54
 
    error(0, errno, "mkfifo");
 
54
    perror("mkfifo");
55
55
    switch(e){
56
56
    case EACCES:
57
57
    case ENOTDIR:
73
73
  int fifo_fd = open(passfifo, O_RDONLY);
74
74
  if(fifo_fd == -1){
75
75
    int e = errno;
76
 
    error(0, errno, "open");
 
76
    perror("open");
77
77
    switch(e){
78
78
    case EACCES:
79
79
    case ENOENT:
101
101
      if(buf_len + blocksize > buf_allocated){
102
102
        char *tmp = realloc(buf, buf_allocated + blocksize);
103
103
        if(tmp == NULL){
104
 
          error(0, errno, "realloc");
 
104
          perror("realloc");
105
105
          free(buf);
106
106
          return EX_OSERR;
107
107
        }
113
113
        int e = errno;
114
114
        free(buf);
115
115
        errno = e;
116
 
        error(0, errno, "read");
 
116
        perror("read");
117
117
        switch(e){
118
118
        case EBADF:
119
119
        case EFAULT:
141
141
      int e = errno;
142
142
      free(buf);
143
143
      errno = e;
144
 
      error(0, errno, "write");
 
144
      perror("write");
145
145
      switch(e){
146
146
      case EBADF:
147
147
      case EFAULT:
161
161
  ret = close(STDOUT_FILENO);
162
162
  if(ret == -1){
163
163
    int e = errno;
164
 
    error(0, errno, "close");
 
164
    perror("close");
165
165
    switch(e){
166
166
    case EBADF:
167
167
      return EX_OSFILE;