/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to plugins.d/mandos-client.c

* plugins.d/mandos-client.c (main): Use remove() instead of unlink(),
                                    and use it on everything in the
                                    temporary directory, not just
                                    files.

* plugins.d/mandos-client.xml (DESCRIPTION): Better wording.
  (OPTIONS): For the "--interface" option, document the unsuitability
             of pseudo-interfaces which will not exist in the initrd.

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 */
 
39
                                   stdout, ferror(), sscanf(),
 
40
                                   remove() */
40
41
#include <stdint.h>             /* uint16_t, uint32_t */
41
42
#include <stddef.h>             /* NULL, size_t, ssize_t */
42
43
#include <stdlib.h>             /* free(), EXIT_SUCCESS, EXIT_FAILURE,
838
839
    mandos_context mc = { .simple_poll = NULL, .server = NULL,
839
840
                          .dh_bits = 1024, .priority = "SECURE256"
840
841
                          ":!CTYPE-X.509:+CTYPE-OPENPGP" };
841
 
    bool gnutls_initalized = false;
842
 
    bool gpgme_initalized = false;
 
842
    bool gnutls_initialized = false;
 
843
    bool gpgme_initialized = false;
843
844
    
844
845
    {
845
846
      struct argp_option options[] = {
975
976
      exitcode = EXIT_FAILURE;
976
977
      goto end;
977
978
    } else {
978
 
      gnutls_initalized = true;
 
979
      gnutls_initialized = true;
979
980
    }
980
981
    
981
982
    if(mkdtemp(tempdir) == NULL){
985
986
    }
986
987
    
987
988
    if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
988
 
      fprintf(stderr, "gpgme_initalized failed\n");
 
989
      fprintf(stderr, "init_gpgme failed\n");
989
990
      exitcode = EXIT_FAILURE;
990
991
      goto end;
991
992
    } else {
992
 
      gpgme_initalized = true;
 
993
      gpgme_initialized = true;
993
994
    }
994
995
    
995
996
    if_index = (AvahiIfIndex) if_nametoindex(interface);
1105
1106
    if(mc.simple_poll != NULL)
1106
1107
        avahi_simple_poll_free(mc.simple_poll);
1107
1108
    
1108
 
    if(gnutls_initalized){
 
1109
    if(gnutls_initialized){
1109
1110
      gnutls_certificate_free_credentials(mc.cred);
1110
1111
      gnutls_global_deinit();
1111
1112
      gnutls_dh_params_deinit(mc.dh_params);
1112
1113
    }
1113
1114
    
1114
 
    if(gpgme_initalized){
 
1115
    if(gpgme_initialized){
1115
1116
      gpgme_release(mc.ctx);
1116
1117
    }
1117
1118
    
1130
1131
          if(direntry == NULL){
1131
1132
            break;
1132
1133
          }
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
 
          }
 
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);
1148
1154
        }
1149
1155
        closedir(d);
1150
1156
      }
1153
1159
        perror("rmdir");
1154
1160
      }
1155
1161
    }
1156
 
          
 
1162
    
1157
1163
    return exitcode;
1158
1164
}