/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/password-request.c

  • Committer: Teddy Hogeborn
  • Date: 2008-09-03 20:31:19 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080903203119-0q6dii46hj3uf4ni
* plugins.d/password-request.xml (SYNOPSYS): Removed "--keydir".
  (OPTIONS): Removed "--keydir" and changed text of "--pubkey" and
             "--seckey".
  (EXAMPLE): Altered not to use "--keydir" anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
#include <sys/types.h>          /* socket(), inet_pton(), sockaddr,
48
48
                                   sockaddr_in6, PF_INET6,
49
49
                                   SOCK_STREAM, INET6_ADDRSTRLEN,
50
 
                                   uid_t, gid_t */
51
 
#include <inttypes.h>           /* PRIu16 */
 
50
                                   uid_t, gid_t, open(), opendir(), DIR */
 
51
#include <sys/stat.h>           /* open() */
52
52
#include <sys/socket.h>         /* socket(), struct sockaddr_in6,
53
53
                                   struct in6_addr, inet_pton(),
54
54
                                   connect() */
 
55
#include <fcntl.h>              /* open() */
 
56
#include <dirent.h>             /* opendir(), struct dirent, readdir() */
 
57
#include <inttypes.h>           /* PRIu16 */
55
58
#include <assert.h>             /* assert() */
56
59
#include <errno.h>              /* perror(), errno */
57
60
#include <time.h>               /* time() */
58
61
#include <net/if.h>             /* ioctl, ifreq, SIOCGIFFLAGS, IFF_UP,
59
62
                                   SIOCSIFFLAGS, if_indextoname(),
60
63
                                   if_nametoindex(), IF_NAMESIZE */
 
64
#include <netinet/in.h>
61
65
#include <unistd.h>             /* close(), SEEK_SET, off_t, write(),
62
66
                                   getuid(), getgid(), setuid(),
63
67
                                   setgid() */
64
 
#include <netinet/in.h>
65
68
#include <arpa/inet.h>          /* inet_pton(), htons */
66
69
#include <iso646.h>             /* not, and */
67
70
#include <argp.h>               /* struct argp_option, error_t, struct
98
101
 
99
102
#define BUFFER_SIZE 256
100
103
 
 
104
/*
 
105
  #define PATHDIR "/conf/conf.d/mandos"
 
106
*/
 
107
 
 
108
#define PATHDIR "/conf/conf.d/mandos"
 
109
#define SECKEY "seckey.txt"
 
110
#define PUBKEY "pupkey.txt"
 
111
 
101
112
bool debug = false;
102
 
static const char *keydir = "/conf/conf.d/mandos";
103
113
static const char mandos_protocol_version[] = "1";
104
114
const char *argp_program_version = "password-request 1.0";
105
115
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
112
122
  unsigned int dh_bits;
113
123
  gnutls_dh_params_t dh_params;
114
124
  const char *priority;
 
125
  gpgme_ctx_t ctx;
115
126
} mandos_context;
116
127
 
117
128
/*
132
143
}
133
144
 
134
145
/* 
135
 
 * Decrypt OpenPGP data using keyrings in HOMEDIR.
136
 
 * Returns -1 on error
 
146
 * Initialize GPGME.
137
147
 */
138
 
static ssize_t pgp_packet_decrypt (const char *cryptotext,
139
 
                                   size_t crypto_size,
140
 
                                   char **plaintext,
141
 
                                   const char *homedir){
142
 
  gpgme_data_t dh_crypto, dh_plain;
143
 
  gpgme_ctx_t ctx;
 
148
static bool init_gpgme(mandos_context *mc, const char *seckey,
 
149
                       const char *pubkey, const char *tempdir){
 
150
  int ret;
144
151
  gpgme_error_t rc;
145
 
  ssize_t ret;
146
 
  size_t plaintext_capacity = 0;
147
 
  ssize_t plaintext_length = 0;
148
152
  gpgme_engine_info_t engine_info;
 
153
 
 
154
  
 
155
  /*
 
156
   * Helper function to insert pub and seckey to the enigne keyring.
 
157
   */
 
158
  bool import_key(const char *filename){
 
159
    int fd;
 
160
    gpgme_data_t pgp_data;
 
161
    
 
162
    fd = TEMP_FAILURE_RETRY(open(filename, O_RDONLY));
 
163
    if(fd == -1){
 
164
      perror("open");
 
165
      return false;
 
166
    }
 
167
    
 
168
    rc = gpgme_data_new_from_fd(&pgp_data, fd);
 
169
    if (rc != GPG_ERR_NO_ERROR){
 
170
      fprintf(stderr, "bad gpgme_data_new_from_fd: %s: %s\n",
 
171
              gpgme_strsource(rc), gpgme_strerror(rc));
 
172
      return false;
 
173
    }
 
174
 
 
175
    rc = gpgme_op_import(mc->ctx, pgp_data);
 
176
    if (rc != GPG_ERR_NO_ERROR){
 
177
      fprintf(stderr, "bad gpgme_op_import: %s: %s\n",
 
178
              gpgme_strsource(rc), gpgme_strerror(rc));
 
179
      return false;
 
180
    }
 
181
 
 
182
    ret = TEMP_FAILURE_RETRY(close(fd));
 
183
    if(ret == -1){
 
184
      perror("close");
 
185
    }
 
186
    gpgme_data_release(pgp_data);
 
187
    return true;
 
188
  }
149
189
  
150
190
  if (debug){
151
 
    fprintf(stderr, "Trying to decrypt OpenPGP data\n");
 
191
    fprintf(stderr, "Initialize gpgme\n");
152
192
  }
153
 
  
 
193
 
154
194
  /* Init GPGME */
155
195
  gpgme_check_version(NULL);
156
196
  rc = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP);
157
197
  if (rc != GPG_ERR_NO_ERROR){
158
198
    fprintf(stderr, "bad gpgme_engine_check_version: %s: %s\n",
159
199
            gpgme_strsource(rc), gpgme_strerror(rc));
160
 
    return -1;
 
200
    return false;
161
201
  }
162
 
  
163
 
  /* Set GPGME home directory for the OpenPGP engine only */
 
202
 
 
203
    /* Set GPGME home directory for the OpenPGP engine only */
164
204
  rc = gpgme_get_engine_info (&engine_info);
165
205
  if (rc != GPG_ERR_NO_ERROR){
166
206
    fprintf(stderr, "bad gpgme_get_engine_info: %s: %s\n",
167
207
            gpgme_strsource(rc), gpgme_strerror(rc));
168
 
    return -1;
 
208
    return false;
169
209
  }
170
210
  while(engine_info != NULL){
171
211
    if(engine_info->protocol == GPGME_PROTOCOL_OpenPGP){
172
212
      gpgme_set_engine_info(GPGME_PROTOCOL_OpenPGP,
173
 
                            engine_info->file_name, homedir);
 
213
                            engine_info->file_name, tempdir);
174
214
      break;
175
215
    }
176
216
    engine_info = engine_info->next;
177
217
  }
178
218
  if(engine_info == NULL){
179
 
    fprintf(stderr, "Could not set GPGME home dir to %s\n", homedir);
180
 
    return -1;
 
219
    fprintf(stderr, "Could not set GPGME home dir to %s\n", tempdir);
 
220
    return false;
 
221
  }
 
222
 
 
223
  /* Create new GPGME "context" */
 
224
  rc = gpgme_new(&(mc->ctx));
 
225
  if (rc != GPG_ERR_NO_ERROR){
 
226
    fprintf(stderr, "bad gpgme_new: %s: %s\n",
 
227
            gpgme_strsource(rc), gpgme_strerror(rc));
 
228
    return false;
 
229
  }
 
230
  
 
231
  if (not import_key(pubkey) or not import_key(seckey)){
 
232
    return false;
 
233
  }
 
234
  
 
235
  return true; 
 
236
}
 
237
 
 
238
/* 
 
239
 * Decrypt OpenPGP data.
 
240
 * Returns -1 on error
 
241
 */
 
242
static ssize_t pgp_packet_decrypt (const mandos_context *mc,
 
243
                                   const char *cryptotext,
 
244
                                   size_t crypto_size,
 
245
                                   char **plaintext){
 
246
  gpgme_data_t dh_crypto, dh_plain;
 
247
  gpgme_error_t rc;
 
248
  ssize_t ret;
 
249
  size_t plaintext_capacity = 0;
 
250
  ssize_t plaintext_length = 0;
 
251
  
 
252
  if (debug){
 
253
    fprintf(stderr, "Trying to decrypt OpenPGP data\n");
181
254
  }
182
255
  
183
256
  /* Create new GPGME data buffer from memory cryptotext */
198
271
    return -1;
199
272
  }
200
273
  
201
 
  /* Create new GPGME "context" */
202
 
  rc = gpgme_new(&ctx);
203
 
  if (rc != GPG_ERR_NO_ERROR){
204
 
    fprintf(stderr, "bad gpgme_new: %s: %s\n",
205
 
            gpgme_strsource(rc), gpgme_strerror(rc));
206
 
    plaintext_length = -1;
207
 
    goto decrypt_end;
208
 
  }
209
 
  
210
274
  /* Decrypt data from the cryptotext data buffer to the plaintext
211
275
     data buffer */
212
 
  rc = gpgme_op_decrypt(ctx, dh_crypto, dh_plain);
 
276
  rc = gpgme_op_decrypt(mc->ctx, dh_crypto, dh_plain);
213
277
  if (rc != GPG_ERR_NO_ERROR){
214
278
    fprintf(stderr, "bad gpgme_op_decrypt: %s: %s\n",
215
279
            gpgme_strsource(rc), gpgme_strerror(rc));
216
280
    plaintext_length = -1;
217
281
    if (debug){
218
282
      gpgme_decrypt_result_t result;
219
 
      result = gpgme_op_decrypt_result(ctx);
 
283
      result = gpgme_op_decrypt_result(mc->ctx);
220
284
      if (result == NULL){
221
285
        fprintf(stderr, "gpgme_op_decrypt_result failed\n");
222
286
      } else {
281
345
    }
282
346
    plaintext_length += ret;
283
347
  }
284
 
 
 
348
  
285
349
  if(debug){
286
350
    fprintf(stderr, "Decrypted password is: ");
287
351
    for(ssize_t i = 0; i < plaintext_length; i++){
348
412
  }
349
413
  
350
414
  if(debug){
351
 
    fprintf(stderr, "Attempting to use OpenPGP certificate %s"
352
 
            " and keyfile %s as GnuTLS credentials\n", pubkeyfilename,
 
415
    fprintf(stderr, "Attempting to use OpenPGP public key %s and"
 
416
            " secret key %s as GnuTLS credentials\n", pubkeyfilename,
353
417
            seckeyfilename);
354
418
  }
355
419
  
360
424
    fprintf(stderr,
361
425
            "Error[%d] while reading the OpenPGP key pair ('%s',"
362
426
            " '%s')\n", ret, pubkeyfilename, seckeyfilename);
363
 
    fprintf(stdout, "The GnuTLS error is: %s\n",
 
427
    fprintf(stderr, "The GnuTLS error is: %s\n",
364
428
            safer_gnutls_strerror(ret));
365
429
    goto globalfail;
366
430
  }
380
444
  }
381
445
  
382
446
  gnutls_certificate_set_dh_params(mc->cred, mc->dh_params);
383
 
 
 
447
  
384
448
  return 0;
385
 
 
 
449
  
386
450
 globalfail:
387
 
 
 
451
  
388
452
  gnutls_certificate_free_credentials(mc->cred);
389
453
  gnutls_global_deinit();
390
454
  return -1;
391
 
 
392
455
}
393
456
 
394
457
static int init_gnutls_session(mandos_context *mc,
466
529
    perror("socket");
467
530
    return -1;
468
531
  }
469
 
 
 
532
  
470
533
  if(debug){
471
534
    if(if_indextoname((unsigned int)if_index, interface) == NULL){
472
535
      perror("if_indextoname");
511
574
    perror("connect");
512
575
    return -1;
513
576
  }
514
 
 
 
577
  
515
578
  const char *out = mandos_protocol_version;
516
579
  written = 0;
517
580
  while (true){
535
598
      }
536
599
    }
537
600
  }
538
 
 
 
601
  
539
602
  if(debug){
540
603
    fprintf(stderr, "Establishing TLS session with %s\n", ip);
541
604
  }
542
605
  
543
606
  gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) tcp_sd);
544
 
 
 
607
  
545
608
  do{
546
609
    ret = gnutls_handshake (session);
547
610
  } while(ret == GNUTLS_E_AGAIN or ret == GNUTLS_E_INTERRUPTED);
561
624
    fprintf(stderr, "Retrieving pgp encrypted password from %s\n",
562
625
            ip);
563
626
  }
564
 
 
 
627
  
565
628
  while(true){
566
629
    buffer_capacity = adjustbuffer(&buffer, buffer_length,
567
630
                                   buffer_capacity);
611
674
  gnutls_bye (session, GNUTLS_SHUT_RDWR);
612
675
  
613
676
  if (buffer_length > 0){
614
 
    decrypted_buffer_size = pgp_packet_decrypt(buffer,
 
677
    decrypted_buffer_size = pgp_packet_decrypt(mc, buffer,
615
678
                                               buffer_length,
616
 
                                               &decrypted_buffer,
617
 
                                               keydir);
 
679
                                               &decrypted_buffer);
618
680
    if (decrypted_buffer_size >= 0){
619
681
      written = 0;
620
682
      while(written < (size_t) decrypted_buffer_size){
643
705
  
644
706
 mandos_end:
645
707
  free(buffer);
646
 
  close(tcp_sd);
 
708
  ret = TEMP_FAILURE_RETRY(close(tcp_sd));
 
709
  if(ret == -1){
 
710
    perror("close");
 
711
  }
647
712
  gnutls_deinit (session);
648
713
  return retval;
649
714
}
745
810
  }
746
811
}
747
812
 
748
 
/* Combines file name and path and returns the malloced new
749
 
   string. some sane checks could/should be added */
750
 
static char *combinepath(const char *first, const char *second){
751
 
  char *tmp;
752
 
  int ret = asprintf(&tmp, "%s/%s", first, second);
753
 
  if(ret < 0){
754
 
    return NULL;
755
 
  }
756
 
  return tmp;
757
 
}
758
 
 
759
 
 
760
813
int main(int argc, char *argv[]){
761
814
    AvahiSServiceBrowser *sb = NULL;
762
815
    int error;
768
821
    uid_t uid;
769
822
    gid_t gid;
770
823
    char *connect_to = NULL;
 
824
    char tempdir[] = "/tmp/mandosXXXXXX";
771
825
    AvahiIfIndex if_index = AVAHI_IF_UNSPEC;
772
 
    char *pubkeyfilename = NULL;
773
 
    char *seckeyfilename = NULL;
774
 
    const char *pubkeyname = "pubkey.txt";
775
 
    const char *seckeyname = "seckey.txt";
 
826
    const char *seckey = PATHDIR "/" SECKEY;
 
827
    const char *pubkey = PATHDIR "/" PUBKEY;
 
828
    
776
829
    mandos_context mc = { .simple_poll = NULL, .server = NULL,
777
 
                          .dh_bits = 1024, .priority = "SECURE256"};
 
830
                          .dh_bits = 1024, .priority = "SECURE256"
 
831
                          ":!CTYPE-X.509:+CTYPE-OPENPGP" };
778
832
    bool gnutls_initalized = false;
 
833
    bool pgpme_initalized = false;
779
834
    
780
835
    {
781
836
      struct argp_option options[] = {
782
837
        { .name = "debug", .key = 128,
783
838
          .doc = "Debug mode", .group = 3 },
784
839
        { .name = "connect", .key = 'c',
785
 
          .arg = "IP",
786
 
          .doc = "Connect directly to a sepcified mandos server",
 
840
          .arg = "ADDRESS:PORT",
 
841
          .doc = "Connect directly to a specific Mandos server",
787
842
          .group = 1 },
788
843
        { .name = "interface", .key = 'i',
789
 
          .arg = "INTERFACE",
790
 
          .doc = "Interface that Avahi will conntect through",
791
 
          .group = 1 },
792
 
        { .name = "keydir", .key = 'd',
793
 
          .arg = "KEYDIR",
794
 
          .doc = "Directory where the openpgp keyring is",
 
844
          .arg = "NAME",
 
845
          .doc = "Interface that will be used to search for Mandos"
 
846
          " servers",
795
847
          .group = 1 },
796
848
        { .name = "seckey", .key = 's',
797
 
          .arg = "SECKEY",
798
 
          .doc = "Secret openpgp key for gnutls authentication",
 
849
          .arg = "FILE",
 
850
          .doc = "OpenPGP secret key file base name",
799
851
          .group = 1 },
800
852
        { .name = "pubkey", .key = 'p',
801
 
          .arg = "PUBKEY",
802
 
          .doc = "Public openpgp key for gnutls authentication",
 
853
          .arg = "FILE",
 
854
          .doc = "OpenPGP public key file base name",
803
855
          .group = 2 },
804
856
        { .name = "dh-bits", .key = 129,
805
857
          .arg = "BITS",
806
 
          .doc = "dh-bits to use in gnutls communication",
 
858
          .doc = "Bit length of the prime number used in the"
 
859
          " Diffie-Hellman key exchange",
807
860
          .group = 2 },
808
861
        { .name = "priority", .key = 130,
809
 
          .arg = "PRIORITY",
810
 
          .doc = "GNUTLS priority", .group = 1 },
 
862
          .arg = "STRING",
 
863
          .doc = "GnuTLS priority string for the TLS handshake",
 
864
          .group = 1 },
811
865
        { .name = NULL }
812
866
      };
813
 
 
814
867
      
815
868
      error_t parse_opt (int key, char *arg,
816
869
                         struct argp_state *state) {
817
870
        /* Get the INPUT argument from `argp_parse', which we know is
818
871
           a pointer to our plugin list pointer. */
819
872
        switch (key) {
820
 
        case 128:
 
873
        case 128:               /* --debug */
821
874
          debug = true;
822
875
          break;
823
 
        case 'c':
 
876
        case 'c':               /* --connect */
824
877
          connect_to = arg;
825
878
          break;
826
 
        case 'i':
 
879
        case 'i':               /* --interface */
827
880
          interface = arg;
828
881
          break;
829
 
        case 'd':
830
 
          keydir = arg;
831
 
          break;
832
 
        case 's':
833
 
          seckeyname = arg;
834
 
          break;
835
 
        case 'p':
836
 
          pubkeyname = arg;
837
 
          break;
838
 
        case 129:
 
882
        case 's':               /* --seckey */
 
883
          seckey = arg;
 
884
          break;
 
885
        case 'p':               /* --pubkey */
 
886
          pubkey = arg;
 
887
          break;
 
888
        case 129:               /* --dh-bits */
839
889
          errno = 0;
840
890
          mc.dh_bits = (unsigned int) strtol(arg, NULL, 10);
841
891
          if (errno){
843
893
            exit(EXIT_FAILURE);
844
894
          }
845
895
          break;
846
 
        case 130:
 
896
        case 130:               /* --priority */
847
897
          mc.priority = arg;
848
898
          break;
849
899
        case ARGP_KEY_ARG:
855
905
        }
856
906
        return 0;
857
907
      }
858
 
 
 
908
      
859
909
      struct argp argp = { .options = options, .parser = parse_opt,
860
910
                           .args_doc = "",
861
911
                           .doc = "Mandos client -- Get and decrypt"
862
 
                           " passwords from mandos server" };
 
912
                           " passwords from a Mandos server" };
863
913
      ret = argp_parse (&argp, argc, argv, 0, 0, NULL);
864
914
      if (ret == ARGP_ERR_UNKNOWN){
865
915
        fprintf(stderr, "Unknown error while parsing arguments\n");
867
917
        goto end;
868
918
      }
869
919
    }
870
 
      
871
 
    pubkeyfilename = combinepath(keydir, pubkeyname);
872
 
    if (pubkeyfilename == NULL){
873
 
      perror("combinepath");
874
 
      exitcode = EXIT_FAILURE;
875
 
      goto end;
876
 
    }
877
920
    
878
 
    seckeyfilename = combinepath(keydir, seckeyname);
879
 
    if (seckeyfilename == NULL){
880
 
      perror("combinepath");
881
 
      exitcode = EXIT_FAILURE;
882
 
      goto end;
883
 
    }
884
 
 
885
 
    ret = init_gnutls_global(&mc, pubkeyfilename, seckeyfilename);
 
921
    ret = init_gnutls_global(&mc, pubkey, seckey);
886
922
    if (ret == -1){
887
923
      fprintf(stderr, "init_gnutls_global failed\n");
888
924
      exitcode = EXIT_FAILURE;
890
926
    } else {
891
927
      gnutls_initalized = true;
892
928
    }
 
929
 
 
930
    if(mkdtemp(tempdir) == NULL){
 
931
      perror("mkdtemp");
 
932
      tempdir[0] = '\0';
 
933
      goto end;
 
934
    }
 
935
    
 
936
    if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
 
937
      fprintf(stderr, "pgpme_initalized failed\n");
 
938
      exitcode = EXIT_FAILURE;
 
939
      goto end;
 
940
    } else {
 
941
      pgpme_initalized = true;
 
942
    }
893
943
    
894
944
    /* If the interface is down, bring it up */
895
945
    {
915
965
          goto end;
916
966
        }
917
967
      }
918
 
      close(sd);
 
968
      ret = TEMP_FAILURE_RETRY(close(sd));
 
969
      if(ret == -1){
 
970
        perror("close");
 
971
      }
919
972
    }
920
973
    
921
974
    uid = getuid();
979
1032
        exitcode = EXIT_FAILURE;
980
1033
        goto end;
981
1034
    }
982
 
 
 
1035
    
983
1036
    {
984
1037
      AvahiServerConfig config;
985
1038
      /* Do not publish any local Zeroconf records */
988
1041
      config.publish_addresses = 0;
989
1042
      config.publish_workstation = 0;
990
1043
      config.publish_domain = 0;
991
 
 
 
1044
      
992
1045
      /* Allocate a new server */
993
1046
      mc.server = avahi_server_new(avahi_simple_poll_get
994
1047
                                   (mc.simple_poll), &config, NULL,
995
1048
                                   NULL, &error);
996
 
    
 
1049
      
997
1050
      /* Free the Avahi configuration data */
998
1051
      avahi_server_config_free(&config);
999
1052
    }
1019
1072
    }
1020
1073
    
1021
1074
    /* Run the main loop */
1022
 
 
 
1075
    
1023
1076
    if (debug){
1024
1077
      fprintf(stderr, "Starting Avahi loop search\n");
1025
1078
    }
1027
1080
    avahi_simple_poll_loop(mc.simple_poll);
1028
1081
    
1029
1082
 end:
1030
 
 
 
1083
    
1031
1084
    if (debug){
1032
1085
      fprintf(stderr, "%s exiting\n", argv[0]);
1033
1086
    }
1038
1091
    
1039
1092
    if (mc.server != NULL)
1040
1093
        avahi_server_free(mc.server);
1041
 
 
 
1094
    
1042
1095
    if (mc.simple_poll != NULL)
1043
1096
        avahi_simple_poll_free(mc.simple_poll);
1044
 
    free(pubkeyfilename);
1045
 
    free(seckeyfilename);
1046
 
 
 
1097
    
1047
1098
    if (gnutls_initalized){
1048
1099
      gnutls_certificate_free_credentials(mc.cred);
1049
1100
      gnutls_global_deinit ();
1050
1101
    }
1051
 
    
 
1102
 
 
1103
    if(pgpme_initalized){
 
1104
      gpgme_release(mc.ctx);
 
1105
    }
 
1106
 
 
1107
    /* Removes the temp directory used by GPGME */
 
1108
    if(tempdir[0] != '\0'){
 
1109
      DIR *d;
 
1110
      struct dirent *direntry;
 
1111
      d = opendir(tempdir);
 
1112
      if(d == NULL){
 
1113
        perror("opendir");
 
1114
      } else {
 
1115
        while(true){
 
1116
          direntry = readdir(d);
 
1117
          if(direntry == NULL){
 
1118
            break;
 
1119
          }
 
1120
          if (direntry->d_type == DT_REG){
 
1121
            char *fullname = NULL;
 
1122
            ret = asprintf(&fullname, "%s/%s", tempdir,
 
1123
                           direntry->d_name);
 
1124
            if(ret < 0){
 
1125
              perror("asprintf");
 
1126
              continue;
 
1127
            }
 
1128
            ret = unlink(fullname);
 
1129
            if(ret == -1){
 
1130
              fprintf(stderr, "unlink(\"%s\"): %s",
 
1131
                      fullname, strerror(errno));
 
1132
            }
 
1133
            free(fullname);
 
1134
          }
 
1135
        }
 
1136
      }
 
1137
      ret = rmdir(tempdir);
 
1138
      if(ret == -1){
 
1139
        perror("rmdir");
 
1140
      }
 
1141
    }
 
1142
          
1052
1143
    return exitcode;
1053
1144
}