/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-13 01:36:46 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090113013646-1u21ie2oaotcekdz
* plugin-runner.c (main): Use "sscanf" instead of "strtol"; using the
                          correct type instead of casting.
* plugins.d/mandos-cliend.c (main): Detect an empty string when
                                    parsing DH bits and port number.
* plugins.d/splashy.c (main): Use "sscanf" instead of "strtoul"; using
                              the correct type instead of casting.
* plugins.d/usplash.c (main): - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*  -*- coding: utf-8 -*- */
2
2
/*
3
 
 * Mandos client - get and decrypt data from a Mandos server
 
3
 * Mandos-client - get and decrypt data from a Mandos server
4
4
 *
5
5
 * This program is partly derived from an example program for an Avahi
6
6
 * service browser, downloaded from
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,
156
156
    int fd;
157
157
    gpgme_data_t pgp_data;
158
158
    
159
 
    fd = TEMP_FAILURE_RETRY(open(filename, O_RDONLY));
 
159
    fd = (int)TEMP_FAILURE_RETRY(open(filename, O_RDONLY));
160
160
    if(fd == -1){
161
161
      perror("open");
162
162
      return false;
176
176
      return false;
177
177
    }
178
178
    
179
 
    ret = TEMP_FAILURE_RETRY(close(fd));
 
179
    ret = (int)TEMP_FAILURE_RETRY(close(fd));
180
180
    if(ret == -1){
181
181
      perror("close");
182
182
    }
501
501
                                      AvahiIfIndex if_index,
502
502
                                      mandos_context *mc){
503
503
  int ret, tcp_sd;
 
504
  ssize_t sret;
504
505
  union { struct sockaddr in; struct sockaddr_in6 in6; } to;
505
506
  char *buffer = NULL;
506
507
  char *decrypted_buffer;
577
578
  written = 0;
578
579
  while (true){
579
580
    size_t out_size = strlen(out);
580
 
    ret = TEMP_FAILURE_RETRY(write(tcp_sd, out + written,
 
581
    ret = (int)TEMP_FAILURE_RETRY(write(tcp_sd, out + written,
581
582
                                   out_size - written));
582
583
    if (ret == -1){
583
584
      perror("write");
632
633
      goto mandos_end;
633
634
    }
634
635
    
635
 
    ret = gnutls_record_recv(session, buffer+buffer_length,
636
 
                             BUFFER_SIZE);
637
 
    if (ret == 0){
 
636
    sret = gnutls_record_recv(session, buffer+buffer_length,
 
637
                              BUFFER_SIZE);
 
638
    if (sret == 0){
638
639
      break;
639
640
    }
640
 
    if (ret < 0){
641
 
      switch(ret){
 
641
    if (sret < 0){
 
642
      switch(sret){
642
643
      case GNUTLS_E_INTERRUPTED:
643
644
      case GNUTLS_E_AGAIN:
644
645
        break;
661
662
        goto mandos_end;
662
663
      }
663
664
    } else {
664
 
      buffer_length += (size_t) ret;
 
665
      buffer_length += (size_t) sret;
665
666
    }
666
667
  }
667
668
  
703
704
  
704
705
 mandos_end:
705
706
  free(buffer);
706
 
  ret = TEMP_FAILURE_RETRY(close(tcp_sd));
 
707
  ret = (int)TEMP_FAILURE_RETRY(close(tcp_sd));
707
708
  if(ret == -1){
708
709
    perror("close");
709
710
  }
865
866
      
866
867
      error_t parse_opt (int key, char *arg,
867
868
                         struct argp_state *state) {
868
 
        /* Get the INPUT argument from `argp_parse', which we know is
869
 
           a pointer to our plugin list pointer. */
870
869
        switch (key) {
871
870
        case 128:               /* --debug */
872
871
          debug = true;
884
883
          pubkey = arg;
885
884
          break;
886
885
        case 129:               /* --dh-bits */
887
 
          errno = 0;
888
 
          mc.dh_bits = (unsigned int) strtol(arg, NULL, 10);
889
 
          if (errno){
890
 
            perror("strtol");
 
886
          ret = sscanf(arg, "%u", &mc.dh_bits);
 
887
          if(ret != 1){
 
888
            fprintf(stderr, "Bad number of DH bits\n");
891
889
            exit(EXIT_FAILURE);
892
890
          }
893
891
          break;
940
938
          goto end;
941
939
        }
942
940
      }
943
 
      ret = TEMP_FAILURE_RETRY(close(sd));
 
941
      ret = (int)TEMP_FAILURE_RETRY(close(sd));
944
942
      if(ret == -1){
945
943
        perror("close");
946
944
      }
997
995
        exitcode = EXIT_FAILURE;
998
996
        goto end;
999
997
      }
1000
 
      errno = 0;
1001
 
      uint16_t port = (uint16_t) strtol(address+1, NULL, 10);
1002
 
      if(errno){
1003
 
        perror("Bad port number");
 
998
      uint16_t port;
 
999
      ret = sscanf(address+1, "%" SCNu16, &port);
 
1000
      if(ret != 1){
 
1001
        fprintf(stderr, "Bad port number\n");
1004
1002
        exitcode = EXIT_FAILURE;
1005
1003
        goto end;
1006
1004
      }
1109
1107
      struct dirent *direntry;
1110
1108
      d = opendir(tempdir);
1111
1109
      if(d == NULL){
1112
 
        perror("opendir");
 
1110
        if(errno != ENOENT){
 
1111
          perror("opendir");
 
1112
        }
1113
1113
      } else {
1114
1114
        while(true){
1115
1115
          direntry = readdir(d);
1135
1135
        closedir(d);
1136
1136
      }
1137
1137
      ret = rmdir(tempdir);
1138
 
      if(ret == -1){
 
1138
      if(ret == -1 and errno != ENOENT){
1139
1139
        perror("rmdir");
1140
1140
      }
1141
1141
    }