/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 04:45:33 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090113044533-de691yv0fa5w6quw
* plugins.d/mandos-client.c: Only comment changes.

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(), sscanf(),
40
 
                                   remove() */
 
39
                                   stdout, ferror(), sscanf */
41
40
#include <stdint.h>             /* uint16_t, uint32_t */
42
41
#include <stddef.h>             /* NULL, size_t, ssize_t */
43
42
#include <stdlib.h>             /* free(), EXIT_SUCCESS, EXIT_FAILURE,
58
57
#include <fcntl.h>              /* open() */
59
58
#include <dirent.h>             /* opendir(), struct dirent, readdir()
60
59
                                 */
61
 
#include <inttypes.h>           /* PRIu16, intmax_t, SCNdMAX */
 
60
#include <inttypes.h>           /* PRIu16, SCNu16 */
62
61
#include <assert.h>             /* assert() */
63
62
#include <errno.h>              /* perror(), errno */
64
63
#include <time.h>               /* time() */
755
754
      avahi_address_snprint(ip, sizeof(ip), address);
756
755
      if(debug){
757
756
        fprintf(stderr, "Mandos server \"%s\" found on %s (%s, %"
758
 
                PRIdMAX ") on port %" PRIu16 "\n", name, host_name,
759
 
                ip, (intmax_t)interface, port);
 
757
                PRIu16 ") on port %d\n", name, host_name, ip,
 
758
                interface, port);
760
759
      }
761
760
      int ret = start_mandos_communication(ip, port, interface, mc);
762
761
      if(ret == 0){
822
821
    AvahiSServiceBrowser *sb = NULL;
823
822
    int error;
824
823
    int ret;
825
 
    intmax_t tmpmax;
826
 
    int numchars;
827
824
    int exitcode = EXIT_SUCCESS;
828
825
    const char *interface = "eth0";
829
826
    struct ifreq network;
839
836
    mandos_context mc = { .simple_poll = NULL, .server = NULL,
840
837
                          .dh_bits = 1024, .priority = "SECURE256"
841
838
                          ":!CTYPE-X.509:+CTYPE-OPENPGP" };
842
 
    bool gnutls_initialized = false;
843
 
    bool gpgme_initialized = false;
 
839
    bool gnutls_initalized = false;
 
840
    bool gpgme_initalized = false;
844
841
    
845
842
    {
846
843
      struct argp_option options[] = {
894
891
          pubkey = arg;
895
892
          break;
896
893
        case 129:               /* --dh-bits */
897
 
          ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
898
 
          if(ret < 1 or tmpmax != (typeof(mc.dh_bits))tmpmax
899
 
             or arg[numchars] != '\0'){
 
894
          ret = sscanf(arg, "%u", &mc.dh_bits);
 
895
          if(ret != 1){
900
896
            fprintf(stderr, "Bad number of DH bits\n");
901
897
            exit(EXIT_FAILURE);
902
898
          }
903
 
          mc.dh_bits = (typeof(mc.dh_bits))tmpmax;
904
899
          break;
905
900
        case 130:               /* --priority */
906
901
          mc.priority = arg;
976
971
      exitcode = EXIT_FAILURE;
977
972
      goto end;
978
973
    } else {
979
 
      gnutls_initialized = true;
 
974
      gnutls_initalized = true;
980
975
    }
981
976
    
982
977
    if(mkdtemp(tempdir) == NULL){
986
981
    }
987
982
    
988
983
    if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
989
 
      fprintf(stderr, "init_gpgme failed\n");
 
984
      fprintf(stderr, "gpgme_initalized failed\n");
990
985
      exitcode = EXIT_FAILURE;
991
986
      goto end;
992
987
    } else {
993
 
      gpgme_initialized = true;
 
988
      gpgme_initalized = true;
994
989
    }
995
990
    
996
991
    if_index = (AvahiIfIndex) if_nametoindex(interface);
1009
1004
        goto end;
1010
1005
      }
1011
1006
      uint16_t port;
1012
 
      ret = sscanf(address+1, "%" SCNdMAX "%n", &tmpmax, &numchars);
1013
 
      if(ret < 1 or tmpmax != (uint16_t)tmpmax
1014
 
         or address[numchars+1] != '\0'){
 
1007
      ret = sscanf(address+1, "%" SCNu16, &port);
 
1008
      if(ret != 1){
1015
1009
        fprintf(stderr, "Bad port number\n");
1016
1010
        exitcode = EXIT_FAILURE;
1017
1011
        goto end;
1018
1012
      }
1019
 
      port = (uint16_t)tmpmax;
1020
1013
      *address = '\0';
1021
1014
      address = connect_to;
1022
1015
      ret = start_mandos_communication(address, port, if_index, &mc);
1106
1099
    if(mc.simple_poll != NULL)
1107
1100
        avahi_simple_poll_free(mc.simple_poll);
1108
1101
    
1109
 
    if(gnutls_initialized){
 
1102
    if(gnutls_initalized){
1110
1103
      gnutls_certificate_free_credentials(mc.cred);
1111
1104
      gnutls_global_deinit();
1112
1105
      gnutls_dh_params_deinit(mc.dh_params);
1113
1106
    }
1114
1107
    
1115
 
    if(gpgme_initialized){
 
1108
    if(gpgme_initalized){
1116
1109
      gpgme_release(mc.ctx);
1117
1110
    }
1118
1111
    
1131
1124
          if(direntry == NULL){
1132
1125
            break;
1133
1126
          }
1134
 
          /* Skip "." and ".." */
1135
 
          if(direntry->d_name[0] == '.'
1136
 
             and (direntry->d_name[1] == '\0'
1137
 
                  or (direntry->d_name[1] == '.'
1138
 
                      and direntry->d_name[2] == '\0'))){
1139
 
            continue;
1140
 
          }
1141
 
          char *fullname = NULL;
1142
 
          ret = asprintf(&fullname, "%s/%s", tempdir,
1143
 
                         direntry->d_name);
1144
 
          if(ret < 0){
1145
 
            perror("asprintf");
1146
 
            continue;
1147
 
          }
1148
 
          ret = remove(fullname);
1149
 
          if(ret == -1){
1150
 
            fprintf(stderr, "remove(\"%s\"): %s\n", fullname,
1151
 
                    strerror(errno));
1152
 
          }
1153
 
          free(fullname);
 
1127
          if(direntry->d_type == DT_REG){
 
1128
            char *fullname = NULL;
 
1129
            ret = asprintf(&fullname, "%s/%s", tempdir,
 
1130
                           direntry->d_name);
 
1131
            if(ret < 0){
 
1132
              perror("asprintf");
 
1133
              continue;
 
1134
            }
 
1135
            ret = unlink(fullname);
 
1136
            if(ret == -1){
 
1137
              fprintf(stderr, "unlink(\"%s\"): %s",
 
1138
                      fullname, strerror(errno));
 
1139
            }
 
1140
            free(fullname);
 
1141
          }
1154
1142
        }
1155
1143
        closedir(d);
1156
1144
      }
1159
1147
        perror("rmdir");
1160
1148
      }
1161
1149
    }
1162
 
    
 
1150
          
1163
1151
    return exitcode;
1164
1152
}