/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/mandos-client.c

  • Committer: Teddy Hogeborn
  • Date: 2009-01-12 22:02:33 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090112220233-lawxo4uvyzb38u1f
* README (The Plugin System): Removed redundant text about options and
                              files for the plugins, this is now
                              documented in the manuals for the
                              plugins.

* plugins.d/mandos-client.c (main): Remove comment which was copied
                                    from another program by mistake.
                                    Use "sscanf" instead of "strtol"
                                    to parse numbers; this uses the
                                    correct type instead of casting.
                                    Don't report errors when removing
                                    temporary directory if directory
                                    is already gone.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#define _GNU_SOURCE             /* TEMP_FAILURE_RETRY(), asprintf() */
37
37
 
38
38
#include <stdio.h>              /* fprintf(), stderr, fwrite(),
39
 
                                   stdout, ferror() */
 
39
                                   stdout, ferror(), sscanf */
40
40
#include <stdint.h>             /* uint16_t, uint32_t */
41
41
#include <stddef.h>             /* NULL, size_t, ssize_t */
42
42
#include <stdlib.h>             /* free(), EXIT_SUCCESS, EXIT_FAILURE,
55
55
                                   connect() */
56
56
#include <fcntl.h>              /* open() */
57
57
#include <dirent.h>             /* opendir(), struct dirent, readdir() */
58
 
#include <inttypes.h>           /* PRIu16 */
 
58
#include <inttypes.h>           /* PRIu16, SCNu16 */
59
59
#include <assert.h>             /* assert() */
60
60
#include <errno.h>              /* perror(), errno */
61
61
#include <time.h>               /* time() */
67
67
                                   getuid(), getgid(), setuid(),
68
68
                                   setgid() */
69
69
#include <arpa/inet.h>          /* inet_pton(), htons */
70
 
#include <iso646.h>             /* not, and */
 
70
#include <iso646.h>             /* not, and, or */
71
71
#include <argp.h>               /* struct argp_option, error_t, struct
72
72
                                   argp_state, struct argp,
73
73
                                   argp_parse(), ARGP_KEY_ARG,
866
866
      
867
867
      error_t parse_opt (int key, char *arg,
868
868
                         struct argp_state *state) {
869
 
        /* Get the INPUT argument from `argp_parse', which we know is
870
 
           a pointer to our plugin list pointer. */
871
869
        switch (key) {
872
870
        case 128:               /* --debug */
873
871
          debug = true;
885
883
          pubkey = arg;
886
884
          break;
887
885
        case 129:               /* --dh-bits */
888
 
          errno = 0;
889
 
          mc.dh_bits = (unsigned int) strtol(arg, NULL, 10);
890
 
          if (errno){
891
 
            perror("strtol");
 
886
          ret = sscanf(arg, "%u", &mc.dh_bits);
 
887
          if(ret == 0 or mc.dh_bits == 0){
 
888
            fprintf(stderr, "Bad number of DH bits\n");
892
889
            exit(EXIT_FAILURE);
893
890
          }
894
891
          break;
998
995
        exitcode = EXIT_FAILURE;
999
996
        goto end;
1000
997
      }
1001
 
      errno = 0;
1002
 
      uint16_t port = (uint16_t) strtol(address+1, NULL, 10);
1003
 
      if(errno){
1004
 
        perror("Bad port number");
 
998
      uint16_t port;
 
999
      ret = sscanf(address+1, "%" SCNu16, &port);
 
1000
      if(ret == 0 or port == 0){
 
1001
        fprintf(stderr, "Bad port number\n");
1005
1002
        exitcode = EXIT_FAILURE;
1006
1003
        goto end;
1007
1004
      }
1110
1107
      struct dirent *direntry;
1111
1108
      d = opendir(tempdir);
1112
1109
      if(d == NULL){
1113
 
        perror("opendir");
 
1110
        if(errno != ENOENT){
 
1111
          perror("opendir");
 
1112
        }
1114
1113
      } else {
1115
1114
        while(true){
1116
1115
          direntry = readdir(d);
1136
1135
        closedir(d);
1137
1136
      }
1138
1137
      ret = rmdir(tempdir);
1139
 
      if(ret == -1){
 
1138
      if(ret == -1 and errno != ENOENT){
1140
1139
        perror("rmdir");
1141
1140
      }
1142
1141
    }