/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 plugins.d/password-prompt.c

  • Committer: Teddy Hogeborn
  • Date: 2009-10-24 19:17:52 UTC
  • Revision ID: teddy@fukt.bsnet.se-20091024191752-7g6xlf6wpp2pdexb
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:
46
46
                                */
47
47
#include <iso646.h>             /* or, not */
48
48
#include <stdbool.h>            /* bool, false, true */
49
 
#include <string.h>             /* strlen, rindex */
 
49
#include <string.h>             /* strlen, rindex, strncmp, strcmp */
50
50
#include <argp.h>               /* struct argp_option, struct
51
51
                                   argp_state, struct argp,
52
52
                                   argp_parse(), error_t,
258
258
      fprintf(stderr, "%s ", prefix);
259
259
    }
260
260
    {
261
 
      const char *cryptsource = getenv("CRYPTTAB_SOURCE");
262
 
      const char *crypttarget = getenv("CRYPTTAB_NAME");
263
 
      /* Before cryptsetup 1.1.0~rc2 */
264
 
      if(cryptsource == NULL){
265
 
        cryptsource = getenv("cryptsource");
266
 
      }
267
 
      if(crypttarget == NULL){
268
 
        crypttarget = getenv("crypttarget");
269
 
      }
270
 
      const char *const prompt1 = "Unlocking the disk";
271
 
      const char *const prompt2 = "Enter passphrase";
 
261
      const char *cryptsource = getenv("cryptsource");
 
262
      const char *crypttarget = getenv("crypttarget");
 
263
      const char *const prompt
 
264
        = "Enter passphrase to unlock the disk";
272
265
      if(cryptsource == NULL){
273
266
        if(crypttarget == NULL){
274
 
          fprintf(stderr, "%s to unlock the disk: ", prompt2);
 
267
          fprintf(stderr, "%s: ", prompt);
275
268
        } else {
276
 
          fprintf(stderr, "%s (%s)\n%s: ", prompt1, crypttarget,
277
 
                  prompt2);
 
269
          fprintf(stderr, "%s (%s): ", prompt, crypttarget);
278
270
        }
279
271
      } else {
280
272
        if(crypttarget == NULL){
281
 
          fprintf(stderr, "%s %s\n%s: ", prompt1, cryptsource,
282
 
                  prompt2);
 
273
          fprintf(stderr, "%s %s: ", prompt, cryptsource);
283
274
        } else {
284
 
          fprintf(stderr, "%s %s (%s)\n%s: ", prompt1, cryptsource,
285
 
                  crypttarget, prompt2);
 
275
          fprintf(stderr, "%s %s (%s): ", prompt, cryptsource,
 
276
                  crypttarget);
286
277
        }
287
278
      }
288
279
    }