/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-23 20:09:55 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090123200955-h9oy2hwyv8uly1op
* mandos (main): Bug fix: use "getint" on the "port" config file
                 option.
* plugins.d/mandos-client.c (main): Fixed spelling of
                                    "gnutls_initalized" and
                                    "gpgme_initalized".

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,
154
153
  
155
154
  
156
155
  /*
157
 
   * Helper function to insert pub and seckey to the engine keyring.
 
156
   * Helper function to insert pub and seckey to the enigne keyring.
158
157
   */
159
158
  bool import_key(const char *filename){
160
159
    int fd;
832
831
    gid_t gid;
833
832
    char *connect_to = NULL;
834
833
    char tempdir[] = "/tmp/mandosXXXXXX";
835
 
    bool tempdir_created = false;
836
834
    AvahiIfIndex if_index = AVAHI_IF_UNSPEC;
837
835
    const char *seckey = PATHDIR "/" SECKEY;
838
836
    const char *pubkey = PATHDIR "/" PUBKEY;
961
959
    uid = getuid();
962
960
    gid = getgid();
963
961
    
 
962
    ret = setuid(uid);
 
963
    if(ret == -1){
 
964
      perror("setuid");
 
965
    }
 
966
    
964
967
    setgid(gid);
965
968
    if(ret == -1){
966
969
      perror("setgid");
967
970
    }
968
971
    
969
 
    ret = setuid(uid);
970
 
    if(ret == -1){
971
 
      perror("setuid");
972
 
    }
973
 
    
974
972
    ret = init_gnutls_global(&mc, pubkey, seckey);
975
973
    if(ret == -1){
976
974
      fprintf(stderr, "init_gnutls_global failed\n");
982
980
    
983
981
    if(mkdtemp(tempdir) == NULL){
984
982
      perror("mkdtemp");
 
983
      tempdir[0] = '\0';
985
984
      goto end;
986
985
    }
987
 
    tempdir_created = true;
988
986
    
989
987
    if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
990
988
      fprintf(stderr, "init_gpgme failed\n");
997
995
    if_index = (AvahiIfIndex) if_nametoindex(interface);
998
996
    if(if_index == 0){
999
997
      fprintf(stderr, "No such interface: \"%s\"\n", interface);
1000
 
      exitcode = EXIT_FAILURE;
1001
 
      goto end;
 
998
      exit(EXIT_FAILURE);
1002
999
    }
1003
1000
    
1004
1001
    if(connect_to != NULL){
1119
1116
    }
1120
1117
    
1121
1118
    /* Removes the temp directory used by GPGME */
1122
 
    if(tempdir_created){
 
1119
    if(tempdir[0] != '\0'){
1123
1120
      DIR *d;
1124
1121
      struct dirent *direntry;
1125
1122
      d = opendir(tempdir);
1133
1130
          if(direntry == NULL){
1134
1131
            break;
1135
1132
          }
1136
 
          /* Skip "." and ".." */
1137
 
          if(direntry->d_name[0] == '.'
1138
 
             and (direntry->d_name[1] == '\0'
1139
 
                  or (direntry->d_name[1] == '.'
1140
 
                      and direntry->d_name[2] == '\0'))){
1141
 
            continue;
1142
 
          }
1143
 
          char *fullname = NULL;
1144
 
          ret = asprintf(&fullname, "%s/%s", tempdir,
1145
 
                         direntry->d_name);
1146
 
          if(ret < 0){
1147
 
            perror("asprintf");
1148
 
            continue;
1149
 
          }
1150
 
          ret = remove(fullname);
1151
 
          if(ret == -1){
1152
 
            fprintf(stderr, "remove(\"%s\"): %s\n", fullname,
1153
 
                    strerror(errno));
1154
 
          }
1155
 
          free(fullname);
 
1133
          if(direntry->d_type == DT_REG){
 
1134
            char *fullname = NULL;
 
1135
            ret = asprintf(&fullname, "%s/%s", tempdir,
 
1136
                           direntry->d_name);
 
1137
            if(ret < 0){
 
1138
              perror("asprintf");
 
1139
              continue;
 
1140
            }
 
1141
            ret = unlink(fullname);
 
1142
            if(ret == -1){
 
1143
              fprintf(stderr, "unlink(\"%s\"): %s",
 
1144
                      fullname, strerror(errno));
 
1145
            }
 
1146
            free(fullname);
 
1147
          }
1156
1148
        }
1157
1149
        closedir(d);
1158
1150
      }
1161
1153
        perror("rmdir");
1162
1154
      }
1163
1155
    }
1164
 
    
 
1156
          
1165
1157
    return exitcode;
1166
1158
}