/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

* plugins.d/mandos-client.c: Prefix all printouts with "Mandos plugin
                             mandos-client: ".
* plugins.d/mandos-client.c (main): Wait for network hooks and check
                                    the completion status.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
                                   sockaddr_in6, PF_INET6,
54
54
                                   SOCK_STREAM, uid_t, gid_t, open(),
55
55
                                   opendir(), DIR */
56
 
#include <sys/stat.h>           /* open() */
 
56
#include <sys/stat.h>           /* open(), S_ISREG */
57
57
#include <sys/socket.h>         /* socket(), struct sockaddr_in6,
58
58
                                   inet_pton(), connect() */
59
59
#include <fcntl.h>              /* open() */
85
85
                                   raise() */
86
86
#include <sysexits.h>           /* EX_OSERR, EX_USAGE, EX_UNAVAILABLE,
87
87
                                   EX_NOHOST, EX_IOERR, EX_PROTOCOL */
 
88
#include <sys/wait.h>           /* waitpid(), WIFEXITED(),
 
89
                                   WEXITSTATUS(), WTERMSIG() */
88
90
 
89
91
#ifdef __linux__
90
92
#include <sys/klog.h>           /* klogctl() */
123
125
#define PATHDIR "/conf/conf.d/mandos"
124
126
#define SECKEY "seckey.txt"
125
127
#define PUBKEY "pubkey.txt"
 
128
#define HOOKDIR "/lib/mandos/network-hooks.d"
126
129
 
127
130
bool debug = false;
128
131
static const char mandos_protocol_version[] = "1";
250
253
    
251
254
    rc = gpgme_data_new_from_fd(&pgp_data, fd);
252
255
    if(rc != GPG_ERR_NO_ERROR){
253
 
      fprintf(stderr, "bad gpgme_data_new_from_fd: %s: %s\n",
 
256
      fprintf(stderr, "Mandos plugin mandos-client: "
 
257
              "bad gpgme_data_new_from_fd: %s: %s\n",
254
258
              gpgme_strsource(rc), gpgme_strerror(rc));
255
259
      return false;
256
260
    }
257
261
    
258
262
    rc = gpgme_op_import(mc.ctx, pgp_data);
259
263
    if(rc != GPG_ERR_NO_ERROR){
260
 
      fprintf(stderr, "bad gpgme_op_import: %s: %s\n",
 
264
      fprintf(stderr, "Mandos plugin mandos-client: "
 
265
              "bad gpgme_op_import: %s: %s\n",
261
266
              gpgme_strsource(rc), gpgme_strerror(rc));
262
267
      return false;
263
268
    }
271
276
  }
272
277
  
273
278
  if(debug){
274
 
    fprintf(stderr, "Initializing GPGME\n");
 
279
    fprintf(stderr, "Mandos plugin mandos-client: "
 
280
            "Initializing GPGME\n");
275
281
  }
276
282
  
277
283
  /* Init GPGME */
278
284
  gpgme_check_version(NULL);
279
285
  rc = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP);
280
286
  if(rc != GPG_ERR_NO_ERROR){
281
 
    fprintf(stderr, "bad gpgme_engine_check_version: %s: %s\n",
 
287
    fprintf(stderr, "Mandos plugin mandos-client: "
 
288
            "bad gpgme_engine_check_version: %s: %s\n",
282
289
            gpgme_strsource(rc), gpgme_strerror(rc));
283
290
    return false;
284
291
  }
286
293
  /* Set GPGME home directory for the OpenPGP engine only */
287
294
  rc = gpgme_get_engine_info(&engine_info);
288
295
  if(rc != GPG_ERR_NO_ERROR){
289
 
    fprintf(stderr, "bad gpgme_get_engine_info: %s: %s\n",
 
296
    fprintf(stderr, "Mandos plugin mandos-client: "
 
297
            "bad gpgme_get_engine_info: %s: %s\n",
290
298
            gpgme_strsource(rc), gpgme_strerror(rc));
291
299
    return false;
292
300
  }
299
307
    engine_info = engine_info->next;
300
308
  }
301
309
  if(engine_info == NULL){
302
 
    fprintf(stderr, "Could not set GPGME home dir to %s\n", tempdir);
 
310
    fprintf(stderr, "Mandos plugin mandos-client: "
 
311
            "Could not set GPGME home dir to %s\n", tempdir);
303
312
    return false;
304
313
  }
305
314
  
306
315
  /* Create new GPGME "context" */
307
316
  rc = gpgme_new(&(mc.ctx));
308
317
  if(rc != GPG_ERR_NO_ERROR){
309
 
    fprintf(stderr, "bad gpgme_new: %s: %s\n",
310
 
            gpgme_strsource(rc), gpgme_strerror(rc));
 
318
    fprintf(stderr, "Mandos plugin mandos-client: "
 
319
            "bad gpgme_new: %s: %s\n", gpgme_strsource(rc),
 
320
            gpgme_strerror(rc));
311
321
    return false;
312
322
  }
313
323
  
332
342
  ssize_t plaintext_length = 0;
333
343
  
334
344
  if(debug){
335
 
    fprintf(stderr, "Trying to decrypt OpenPGP data\n");
 
345
    fprintf(stderr, "Mandos plugin mandos-client: "
 
346
            "Trying to decrypt OpenPGP data\n");
336
347
  }
337
348
  
338
349
  /* Create new GPGME data buffer from memory cryptotext */
339
350
  rc = gpgme_data_new_from_mem(&dh_crypto, cryptotext, crypto_size,
340
351
                               0);
341
352
  if(rc != GPG_ERR_NO_ERROR){
342
 
    fprintf(stderr, "bad gpgme_data_new_from_mem: %s: %s\n",
 
353
    fprintf(stderr, "Mandos plugin mandos-client: "
 
354
            "bad gpgme_data_new_from_mem: %s: %s\n",
343
355
            gpgme_strsource(rc), gpgme_strerror(rc));
344
356
    return -1;
345
357
  }
347
359
  /* Create new empty GPGME data buffer for the plaintext */
348
360
  rc = gpgme_data_new(&dh_plain);
349
361
  if(rc != GPG_ERR_NO_ERROR){
350
 
    fprintf(stderr, "bad gpgme_data_new: %s: %s\n",
 
362
    fprintf(stderr, "Mandos plugin mandos-client: "
 
363
            "bad gpgme_data_new: %s: %s\n",
351
364
            gpgme_strsource(rc), gpgme_strerror(rc));
352
365
    gpgme_data_release(dh_crypto);
353
366
    return -1;
357
370
     data buffer */
358
371
  rc = gpgme_op_decrypt(mc.ctx, dh_crypto, dh_plain);
359
372
  if(rc != GPG_ERR_NO_ERROR){
360
 
    fprintf(stderr, "bad gpgme_op_decrypt: %s: %s\n",
 
373
    fprintf(stderr, "Mandos plugin mandos-client: "
 
374
            "bad gpgme_op_decrypt: %s: %s\n",
361
375
            gpgme_strsource(rc), gpgme_strerror(rc));
362
376
    plaintext_length = -1;
363
377
    if(debug){
364
378
      gpgme_decrypt_result_t result;
365
379
      result = gpgme_op_decrypt_result(mc.ctx);
366
380
      if(result == NULL){
367
 
        fprintf(stderr, "gpgme_op_decrypt_result failed\n");
 
381
        fprintf(stderr, "Mandos plugin mandos-client: "
 
382
                "gpgme_op_decrypt_result failed\n");
368
383
      } else {
369
 
        fprintf(stderr, "Unsupported algorithm: %s\n",
 
384
        fprintf(stderr, "Mandos plugin mandos-client: "
 
385
                "Unsupported algorithm: %s\n",
370
386
                result->unsupported_algorithm);
371
 
        fprintf(stderr, "Wrong key usage: %u\n",
 
387
        fprintf(stderr, "Mandos plugin mandos-client: "
 
388
                "Wrong key usage: %u\n",
372
389
                result->wrong_key_usage);
373
390
        if(result->file_name != NULL){
374
 
          fprintf(stderr, "File name: %s\n", result->file_name);
 
391
          fprintf(stderr, "Mandos plugin mandos-client: "
 
392
                  "File name: %s\n", result->file_name);
375
393
        }
376
394
        gpgme_recipient_t recipient;
377
395
        recipient = result->recipients;
378
396
        while(recipient != NULL){
379
 
          fprintf(stderr, "Public key algorithm: %s\n",
 
397
          fprintf(stderr, "Mandos plugin mandos-client: "
 
398
                  "Public key algorithm: %s\n",
380
399
                  gpgme_pubkey_algo_name(recipient->pubkey_algo));
381
 
          fprintf(stderr, "Key ID: %s\n", recipient->keyid);
382
 
          fprintf(stderr, "Secret key available: %s\n",
 
400
          fprintf(stderr, "Mandos plugin mandos-client: "
 
401
                  "Key ID: %s\n", recipient->keyid);
 
402
          fprintf(stderr, "Mandos plugin mandos-client: "
 
403
                  "Secret key available: %s\n",
383
404
                  recipient->status == GPG_ERR_NO_SECKEY
384
405
                  ? "No" : "Yes");
385
406
          recipient = recipient->next;
390
411
  }
391
412
  
392
413
  if(debug){
393
 
    fprintf(stderr, "Decryption of OpenPGP data succeeded\n");
 
414
    fprintf(stderr, "Mandos plugin mandos-client: "
 
415
            "Decryption of OpenPGP data succeeded\n");
394
416
  }
395
417
  
396
418
  /* Seek back to the beginning of the GPGME plaintext data buffer */
427
449
  }
428
450
  
429
451
  if(debug){
430
 
    fprintf(stderr, "Decrypted password is: ");
 
452
    fprintf(stderr, "Mandos plugin mandos-client: "
 
453
            "Decrypted password is: ");
431
454
    for(ssize_t i = 0; i < plaintext_length; i++){
432
455
      fprintf(stderr, "%02hhX ", (*plaintext)[i]);
433
456
    }
455
478
/* GnuTLS log function callback */
456
479
static void debuggnutls(__attribute__((unused)) int level,
457
480
                        const char* string){
458
 
  fprintf(stderr, "GnuTLS: %s", string);
 
481
  fprintf(stderr, "Mandos plugin mandos-client: GnuTLS: %s", string);
459
482
}
460
483
 
461
484
static int init_gnutls_global(const char *pubkeyfilename,
463
486
  int ret;
464
487
  
465
488
  if(debug){
466
 
    fprintf(stderr, "Initializing GnuTLS\n");
 
489
    fprintf(stderr, "Mandos plugin mandos-client: "
 
490
            "Initializing GnuTLS\n");
467
491
  }
468
492
  
469
493
  ret = gnutls_global_init();
470
494
  if(ret != GNUTLS_E_SUCCESS){
471
 
    fprintf(stderr, "GnuTLS global_init: %s\n",
472
 
            safer_gnutls_strerror(ret));
 
495
    fprintf(stderr, "Mandos plugin mandos-client: "
 
496
            "GnuTLS global_init: %s\n", safer_gnutls_strerror(ret));
473
497
    return -1;
474
498
  }
475
499
  
484
508
  /* OpenPGP credentials */
485
509
  ret = gnutls_certificate_allocate_credentials(&mc.cred);
486
510
  if(ret != GNUTLS_E_SUCCESS){
487
 
    fprintf(stderr, "GnuTLS memory error: %s\n",
488
 
            safer_gnutls_strerror(ret));
 
511
    fprintf(stderr, "Mandos plugin mandos-client: "
 
512
            "GnuTLS memory error: %s\n", safer_gnutls_strerror(ret));
489
513
    gnutls_global_deinit();
490
514
    return -1;
491
515
  }
492
516
  
493
517
  if(debug){
494
 
    fprintf(stderr, "Attempting to use OpenPGP public key %s and"
 
518
    fprintf(stderr, "Mandos plugin mandos-client: "
 
519
            "Attempting to use OpenPGP public key %s and"
495
520
            " secret key %s as GnuTLS credentials\n", pubkeyfilename,
496
521
            seckeyfilename);
497
522
  }
501
526
     GNUTLS_OPENPGP_FMT_BASE64);
502
527
  if(ret != GNUTLS_E_SUCCESS){
503
528
    fprintf(stderr,
 
529
            "Mandos plugin mandos-client: "
504
530
            "Error[%d] while reading the OpenPGP key pair ('%s',"
505
531
            " '%s')\n", ret, pubkeyfilename, seckeyfilename);
506
 
    fprintf(stderr, "The GnuTLS error is: %s\n",
507
 
            safer_gnutls_strerror(ret));
 
532
    fprintf(stderr, "Mandos plugin mandos-client: "
 
533
            "The GnuTLS error is: %s\n", safer_gnutls_strerror(ret));
508
534
    goto globalfail;
509
535
  }
510
536
  
511
537
  /* GnuTLS server initialization */
512
538
  ret = gnutls_dh_params_init(&mc.dh_params);
513
539
  if(ret != GNUTLS_E_SUCCESS){
514
 
    fprintf(stderr, "Error in GnuTLS DH parameter initialization:"
 
540
    fprintf(stderr, "Mandos plugin mandos-client: "
 
541
            "Error in GnuTLS DH parameter initialization:"
515
542
            " %s\n", safer_gnutls_strerror(ret));
516
543
    goto globalfail;
517
544
  }
518
545
  ret = gnutls_dh_params_generate2(mc.dh_params, mc.dh_bits);
519
546
  if(ret != GNUTLS_E_SUCCESS){
520
 
    fprintf(stderr, "Error in GnuTLS prime generation: %s\n",
 
547
    fprintf(stderr, "Mandos plugin mandos-client: "
 
548
            "Error in GnuTLS prime generation: %s\n",
521
549
            safer_gnutls_strerror(ret));
522
550
    goto globalfail;
523
551
  }
544
572
    }
545
573
  } while(ret == GNUTLS_E_INTERRUPTED or ret == GNUTLS_E_AGAIN);
546
574
  if(ret != GNUTLS_E_SUCCESS){
547
 
    fprintf(stderr, "Error in GnuTLS session initialization: %s\n",
 
575
    fprintf(stderr, "Mandos plugin mandos-client: "
 
576
            "Error in GnuTLS session initialization: %s\n",
548
577
            safer_gnutls_strerror(ret));
549
578
  }
550
579
  
558
587
      }
559
588
    } while(ret == GNUTLS_E_INTERRUPTED or ret == GNUTLS_E_AGAIN);
560
589
    if(ret != GNUTLS_E_SUCCESS){
561
 
      fprintf(stderr, "Syntax error at: %s\n", err);
562
 
      fprintf(stderr, "GnuTLS error: %s\n",
563
 
              safer_gnutls_strerror(ret));
 
590
      fprintf(stderr, "Mandos plugin mandos-client: "
 
591
              "Syntax error at: %s\n", err);
 
592
      fprintf(stderr, "Mandos plugin mandos-client: "
 
593
              "GnuTLS error: %s\n", safer_gnutls_strerror(ret));
564
594
      gnutls_deinit(*session);
565
595
      return -1;
566
596
    }
575
605
    }
576
606
  } while(ret == GNUTLS_E_INTERRUPTED or ret == GNUTLS_E_AGAIN);
577
607
  if(ret != GNUTLS_E_SUCCESS){
578
 
    fprintf(stderr, "Error setting GnuTLS credentials: %s\n",
 
608
    fprintf(stderr, "Mandos plugin mandos-client: "
 
609
            "Error setting GnuTLS credentials: %s\n",
579
610
            safer_gnutls_strerror(ret));
580
611
    gnutls_deinit(*session);
581
612
    return -1;
627
658
    pf = PF_INET;
628
659
    break;
629
660
  default:
630
 
    fprintf(stderr, "Bad address family: %d\n", af);
 
661
    fprintf(stderr, "Mandos plugin mandos-client: "
 
662
            "Bad address family: %d\n", af);
631
663
    errno = EINVAL;
632
664
    return -1;
633
665
  }
638
670
  }
639
671
  
640
672
  if(debug){
641
 
    fprintf(stderr, "Setting up a TCP connection to %s, port %" PRIu16
 
673
    fprintf(stderr, "Mandos plugin mandos-client: "
 
674
            "Setting up a TCP connection to %s, port %" PRIu16
642
675
            "\n", ip, port);
643
676
  }
644
677
  
671
704
  }
672
705
  if(ret == 0){
673
706
    int e = errno;
674
 
    fprintf(stderr, "Bad address: %s\n", ip);
 
707
    fprintf(stderr, "Mandos plugin mandos-client: "
 
708
            "Bad address: %s\n", ip);
675
709
    errno = e;
676
710
    goto mandos_end;
677
711
  }
684
718
       (&to.in6.sin6_addr)){ /* -Wstrict-aliasing=2 or lower and
685
719
                              -Wunreachable-code*/
686
720
      if(if_index == AVAHI_IF_UNSPEC){
687
 
        fprintf(stderr, "An IPv6 link-local address is incomplete"
 
721
        fprintf(stderr, "Mandos plugin mandos-client: "
 
722
                "An IPv6 link-local address is incomplete"
688
723
                " without a network interface\n");
689
724
        errno = EINVAL;
690
725
        goto mandos_end;
709
744
      if(if_indextoname((unsigned int)if_index, interface) == NULL){
710
745
        perror_plus("if_indextoname");
711
746
      } else {
712
 
        fprintf(stderr, "Connection to: %s%%%s, port %" PRIu16 "\n",
 
747
        fprintf(stderr, "Mandos plugin mandos-client: "
 
748
                "Connection to: %s%%%s, port %" PRIu16 "\n",
713
749
                ip, interface, port);
714
750
      }
715
751
    } else {
716
 
      fprintf(stderr, "Connection to: %s, port %" PRIu16 "\n", ip,
717
 
              port);
 
752
      fprintf(stderr, "Mandos plugin mandos-client: "
 
753
              "Connection to: %s, port %" PRIu16 "\n", ip, port);
718
754
    }
719
755
    char addrstr[(INET_ADDRSTRLEN > INET6_ADDRSTRLEN) ?
720
756
                 INET_ADDRSTRLEN : INET6_ADDRSTRLEN] = "";
730
766
      perror_plus("inet_ntop");
731
767
    } else {
732
768
      if(strcmp(addrstr, ip) != 0){
733
 
        fprintf(stderr, "Canonical address form: %s\n", addrstr);
 
769
        fprintf(stderr, "Mandos plugin mandos-client: "
 
770
                "Canonical address form: %s\n", addrstr);
734
771
      }
735
772
    }
736
773
  }
790
827
  }
791
828
  
792
829
  if(debug){
793
 
    fprintf(stderr, "Establishing TLS session with %s\n", ip);
 
830
    fprintf(stderr, "Mandos plugin mandos-client: "
 
831
            "Establishing TLS session with %s\n", ip);
794
832
  }
795
833
  
796
834
  if(quit_now){
816
854
  
817
855
  if(ret != GNUTLS_E_SUCCESS){
818
856
    if(debug){
819
 
      fprintf(stderr, "*** GnuTLS Handshake failed ***\n");
 
857
      fprintf(stderr, "Mandos plugin mandos-client: "
 
858
              "*** GnuTLS Handshake failed ***\n");
820
859
      gnutls_perror(ret);
821
860
    }
822
861
    errno = EPROTO;
826
865
  /* Read OpenPGP packet that contains the wanted password */
827
866
  
828
867
  if(debug){
829
 
    fprintf(stderr, "Retrieving OpenPGP encrypted password from %s\n",
830
 
            ip);
 
868
    fprintf(stderr, "Mandos plugin mandos-client: "
 
869
            "Retrieving OpenPGP encrypted password from %s\n", ip);
831
870
  }
832
871
  
833
872
  while(true){
871
910
          }
872
911
        } while(ret == GNUTLS_E_AGAIN or ret == GNUTLS_E_INTERRUPTED);
873
912
        if(ret < 0){
874
 
          fprintf(stderr, "*** GnuTLS Re-handshake failed ***\n");
 
913
          fprintf(stderr, "Mandos plugin mandos-client: "
 
914
                  "*** GnuTLS Re-handshake failed ***\n");
875
915
          gnutls_perror(ret);
876
916
          errno = EPROTO;
877
917
          goto mandos_end;
878
918
        }
879
919
        break;
880
920
      default:
881
 
        fprintf(stderr, "Unknown error while reading data from"
 
921
        fprintf(stderr, "Mandos plugin mandos-client: "
 
922
                "Unknown error while reading data from"
882
923
                " encrypted session with Mandos server\n");
883
924
        gnutls_bye(session, GNUTLS_SHUT_RDWR);
884
925
        errno = EIO;
890
931
  }
891
932
  
892
933
  if(debug){
893
 
    fprintf(stderr, "Closing TLS session\n");
 
934
    fprintf(stderr, "Mandos plugin mandos-client: "
 
935
            "Closing TLS session\n");
894
936
  }
895
937
  
896
938
  if(quit_now){
926
968
        if(ret == 0 and ferror(stdout)){
927
969
          int e = errno;
928
970
          if(debug){
929
 
            fprintf(stderr, "Error writing encrypted data: %s\n",
 
971
            fprintf(stderr, "Mandos plugin mandos-client: "
 
972
                    "Error writing encrypted data: %s\n",
930
973
                    strerror(errno));
931
974
          }
932
975
          errno = e;
990
1033
  switch(event){
991
1034
  default:
992
1035
  case AVAHI_RESOLVER_FAILURE:
993
 
    fprintf(stderr, "(Avahi Resolver) Failed to resolve service '%s'"
 
1036
    fprintf(stderr, "Mandos plugin mandos-client: "
 
1037
            "(Avahi Resolver) Failed to resolve service '%s'"
994
1038
            " of type '%s' in domain '%s': %s\n", name, type, domain,
995
1039
            avahi_strerror(avahi_server_errno(mc.server)));
996
1040
    break;
1000
1044
      char ip[AVAHI_ADDRESS_STR_MAX];
1001
1045
      avahi_address_snprint(ip, sizeof(ip), address);
1002
1046
      if(debug){
1003
 
        fprintf(stderr, "Mandos server \"%s\" found on %s (%s, %"
 
1047
        fprintf(stderr, "Mandos plugin mandos-client: "
 
1048
                "Mandos server \"%s\" found on %s (%s, %"
1004
1049
                PRIdMAX ") on port %" PRIu16 "\n", name, host_name,
1005
1050
                ip, (intmax_t)interface, port);
1006
1051
      }
1040
1085
  default:
1041
1086
  case AVAHI_BROWSER_FAILURE:
1042
1087
    
1043
 
    fprintf(stderr, "(Avahi browser) %s\n",
 
1088
    fprintf(stderr, "Mandos plugin mandos-client: "
 
1089
            "(Avahi browser) %s\n",
1044
1090
            avahi_strerror(avahi_server_errno(mc.server)));
1045
1091
    avahi_simple_poll_quit(mc.simple_poll);
1046
1092
    return;
1054
1100
    if(avahi_s_service_resolver_new(mc.server, interface, protocol,
1055
1101
                                    name, type, domain, protocol, 0,
1056
1102
                                    resolve_callback, NULL) == NULL)
1057
 
      fprintf(stderr, "Avahi: Failed to resolve service '%s': %s\n",
 
1103
      fprintf(stderr, "Mandos plugin mandos-client: "
 
1104
              "Avahi: Failed to resolve service '%s': %s\n",
1058
1105
              name, avahi_strerror(avahi_server_errno(mc.server)));
1059
1106
    break;
1060
1107
    
1064
1111
  case AVAHI_BROWSER_ALL_FOR_NOW:
1065
1112
  case AVAHI_BROWSER_CACHE_EXHAUSTED:
1066
1113
    if(debug){
1067
 
      fprintf(stderr, "No Mandos server found, still searching...\n");
 
1114
      fprintf(stderr, "Mandos plugin mandos-client: "
 
1115
              "No Mandos server found, still searching...\n");
1068
1116
    }
1069
1117
    break;
1070
1118
  }
1085
1133
  errno = old_errno;
1086
1134
}
1087
1135
 
1088
 
/* 
1089
 
 * This function determines if a directory entry in /sys/class/net
1090
 
 * corresponds to an acceptable network device.
1091
 
 * (This function is passed to scandir(3) as a filter function.)
1092
 
 */
1093
 
int good_interface(const struct dirent *if_entry){
1094
 
  ssize_t ssret;
1095
 
  char *flagname = NULL;
1096
 
  if(if_entry->d_name[0] == '.'){
1097
 
    return 0;
1098
 
  }
1099
 
  int ret = asprintf(&flagname, "%s/%s/flags", sys_class_net,
1100
 
                     if_entry->d_name);
1101
 
  if(ret < 0){
1102
 
    perror_plus("asprintf");
1103
 
    return 0;
1104
 
  }
1105
 
  int flags_fd = (int)TEMP_FAILURE_RETRY(open(flagname, O_RDONLY));
1106
 
  if(flags_fd == -1){
1107
 
    perror_plus("open");
1108
 
    free(flagname);
1109
 
    return 0;
1110
 
  }
1111
 
  free(flagname);
1112
 
  typedef short ifreq_flags;    /* ifreq.ifr_flags in netdevice(7) */
1113
 
  /* read line from flags_fd */
1114
 
  ssize_t to_read = 2+(sizeof(ifreq_flags)*2)+1; /* "0x1003\n" */
1115
 
  char *flagstring = malloc((size_t)to_read+1); /* +1 for final \0 */
1116
 
  flagstring[(size_t)to_read] = '\0';
1117
 
  if(flagstring == NULL){
1118
 
    perror_plus("malloc");
1119
 
    close(flags_fd);
1120
 
    return 0;
1121
 
  }
1122
 
  while(to_read > 0){
1123
 
    ssret = (ssize_t)TEMP_FAILURE_RETRY(read(flags_fd, flagstring,
1124
 
                                             (size_t)to_read));
1125
 
    if(ssret == -1){
1126
 
      perror_plus("read");
1127
 
      free(flagstring);
1128
 
      close(flags_fd);
1129
 
      return 0;
1130
 
    }
1131
 
    to_read -= ssret;
1132
 
    if(ssret == 0){
1133
 
      break;
1134
 
    }
1135
 
  }
1136
 
  close(flags_fd);
1137
 
  intmax_t tmpmax;
1138
 
  char *tmp;
1139
 
  errno = 0;
1140
 
  tmpmax = strtoimax(flagstring, &tmp, 0);
1141
 
  if(errno != 0 or tmp == flagstring or (*tmp != '\0'
1142
 
                                         and not (isspace(*tmp)))
1143
 
     or tmpmax != (ifreq_flags)tmpmax){
 
1136
bool get_flags(const char *ifname, struct ifreq *ifr){
 
1137
  int ret;
 
1138
  
 
1139
  int s = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
 
1140
  if(s < 0){
 
1141
    perror_plus("socket");
 
1142
    return false;
 
1143
  }
 
1144
  strcpy(ifr->ifr_name, ifname);
 
1145
  ret = ioctl(s, SIOCGIFFLAGS, ifr);
 
1146
  if(ret == -1){
1144
1147
    if(debug){
1145
 
      fprintf(stderr, "Invalid flags \"%s\" for interface \"%s\"\n",
1146
 
              flagstring, if_entry->d_name);
 
1148
      perror_plus("ioctl SIOCGIFFLAGS");
1147
1149
    }
1148
 
    free(flagstring);
1149
 
    return 0;
 
1150
    return false;
1150
1151
  }
1151
 
  free(flagstring);
1152
 
  ifreq_flags flags = (ifreq_flags)tmpmax;
 
1152
  return true;
 
1153
}
 
1154
 
 
1155
bool good_flags(const char *ifname, const struct ifreq *ifr){
 
1156
  
1153
1157
  /* Reject the loopback device */
1154
 
  if(flags & IFF_LOOPBACK){
 
1158
  if(ifr->ifr_flags & IFF_LOOPBACK){
1155
1159
    if(debug){
1156
 
      fprintf(stderr, "Rejecting loopback interface \"%s\"\n",
1157
 
              if_entry->d_name);
 
1160
      fprintf(stderr, "Mandos plugin mandos-client: "
 
1161
              "Rejecting loopback interface \"%s\"\n", ifname);
1158
1162
    }
1159
 
    return 0;
 
1163
    return false;
1160
1164
  }
1161
1165
  /* Accept point-to-point devices only if connect_to is specified */
1162
 
  if(connect_to != NULL and (flags & IFF_POINTOPOINT)){
 
1166
  if(connect_to != NULL and (ifr->ifr_flags & IFF_POINTOPOINT)){
1163
1167
    if(debug){
1164
 
      fprintf(stderr, "Accepting point-to-point interface \"%s\"\n",
1165
 
              if_entry->d_name);
 
1168
      fprintf(stderr, "Mandos plugin mandos-client: "
 
1169
              "Accepting point-to-point interface \"%s\"\n", ifname);
1166
1170
    }
1167
 
    return 1;
 
1171
    return true;
1168
1172
  }
1169
1173
  /* Otherwise, reject non-broadcast-capable devices */
1170
 
  if(not (flags & IFF_BROADCAST)){
 
1174
  if(not (ifr->ifr_flags & IFF_BROADCAST)){
1171
1175
    if(debug){
1172
 
      fprintf(stderr, "Rejecting non-broadcast interface \"%s\"\n",
1173
 
              if_entry->d_name);
 
1176
      fprintf(stderr, "Mandos plugin mandos-client: "
 
1177
              "Rejecting non-broadcast interface \"%s\"\n", ifname);
1174
1178
    }
1175
 
    return 0;
 
1179
    return false;
1176
1180
  }
1177
1181
  /* Reject non-ARP interfaces (including dummy interfaces) */
1178
 
  if(flags & IFF_NOARP){
 
1182
  if(ifr->ifr_flags & IFF_NOARP){
1179
1183
    if(debug){
1180
 
      fprintf(stderr, "Rejecting non-ARP interface \"%s\"\n",
1181
 
              if_entry->d_name);
 
1184
      fprintf(stderr, "Mandos plugin mandos-client: "
 
1185
              "Rejecting non-ARP interface \"%s\"\n", ifname);
1182
1186
    }
1183
 
    return 0;
 
1187
    return false;
1184
1188
  }
 
1189
  
1185
1190
  /* Accept this device */
1186
1191
  if(debug){
1187
 
    fprintf(stderr, "Interface \"%s\" is acceptable\n",
1188
 
            if_entry->d_name);
 
1192
    fprintf(stderr, "Mandos plugin mandos-client: "
 
1193
            "Interface \"%s\" is good\n", ifname);
 
1194
  }
 
1195
  return true;
 
1196
}
 
1197
 
 
1198
/* 
 
1199
 * This function determines if a directory entry in /sys/class/net
 
1200
 * corresponds to an acceptable network device.
 
1201
 * (This function is passed to scandir(3) as a filter function.)
 
1202
 */
 
1203
int good_interface(const struct dirent *if_entry){
 
1204
  if(if_entry->d_name[0] == '.'){
 
1205
    return 0;
 
1206
  }
 
1207
  
 
1208
  struct ifreq ifr;
 
1209
  if(not get_flags(if_entry->d_name, &ifr)){
 
1210
    if(debug){
 
1211
      fprintf(stderr, "Mandos plugin mandos-client: "
 
1212
              "Failed to get flags for interface \"%s\"\n",
 
1213
              if_entry->d_name);
 
1214
    }
 
1215
    return 0;
 
1216
  }
 
1217
  
 
1218
  if(not good_flags(if_entry->d_name, &ifr)){
 
1219
    return 0;
 
1220
  }
 
1221
  return 1;
 
1222
}
 
1223
 
 
1224
/* 
 
1225
 * This function determines if a directory entry in /sys/class/net
 
1226
 * corresponds to an acceptable network device which is up.
 
1227
 * (This function is passed to scandir(3) as a filter function.)
 
1228
 */
 
1229
int up_interface(const struct dirent *if_entry){
 
1230
  if(if_entry->d_name[0] == '.'){
 
1231
    return 0;
 
1232
  }
 
1233
  
 
1234
  struct ifreq ifr;
 
1235
  if(not get_flags(if_entry->d_name, &ifr)){
 
1236
    if(debug){
 
1237
      fprintf(stderr, "Mandos plugin mandos-client: "
 
1238
              "Failed to get flags for interface \"%s\"\n",
 
1239
              if_entry->d_name);
 
1240
    }
 
1241
    return 0;
 
1242
  }
 
1243
  
 
1244
  /* Reject down interfaces */
 
1245
  if(not (ifr.ifr_flags & IFF_UP)){
 
1246
    if(debug){
 
1247
      fprintf(stderr, "Mandos plugin mandos-client: "
 
1248
              "Rejecting down interface \"%s\"\n",
 
1249
              if_entry->d_name);
 
1250
    }
 
1251
    return 0;
 
1252
  }
 
1253
  
 
1254
  /* Reject non-running interfaces */
 
1255
  if(not (ifr.ifr_flags & IFF_RUNNING)){
 
1256
    if(debug){
 
1257
      fprintf(stderr, "Mandos plugin mandos-client: "
 
1258
              "Rejecting non-running interface \"%s\"\n",
 
1259
              if_entry->d_name);
 
1260
    }
 
1261
    return 0;
 
1262
  }
 
1263
  
 
1264
  if(not good_flags(if_entry->d_name, &ifr)){
 
1265
    return 0;
1189
1266
  }
1190
1267
  return 1;
1191
1268
}
1201
1278
  return 1;
1202
1279
}
1203
1280
 
 
1281
/* Is this directory entry a runnable program? */
 
1282
int runnable_hook(const struct dirent *direntry){
 
1283
  int ret;
 
1284
  struct stat st;
 
1285
  
 
1286
  if((direntry->d_name)[0] == '\0'){
 
1287
    /* Empty name? */
 
1288
    return 0;
 
1289
  }
 
1290
  
 
1291
  /* Save pointer to last character */
 
1292
  char *end = strchr(direntry->d_name, '\0')-1;
 
1293
  
 
1294
  if(*end == '~'){
 
1295
    /* Backup name~ */
 
1296
    return 0;
 
1297
  }
 
1298
  
 
1299
  if(((direntry->d_name)[0] == '#')
 
1300
     and (*end == '#')){
 
1301
    /* Temporary #name# */
 
1302
    return 0;
 
1303
  }
 
1304
  
 
1305
  /* XXX more rules here */
 
1306
  
 
1307
  ret = stat(direntry->d_name, &st);
 
1308
  if(ret == -1){
 
1309
    if(debug){
 
1310
      perror_plus("Could not stat plugin");
 
1311
    }
 
1312
    return 0;
 
1313
  }
 
1314
  if(not (S_ISREG(st.st_mode))){
 
1315
    /* Not a regular file */
 
1316
    return 0;
 
1317
  }
 
1318
  if(not (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))){
 
1319
    /* Not executable */
 
1320
    return 0;
 
1321
  }
 
1322
  return 1;
 
1323
}
 
1324
 
1204
1325
int avahi_loop_with_timeout(AvahiSimplePoll *s, int retry_interval){
1205
1326
  int ret;
1206
1327
  struct timespec now;
1210
1331
  while(true){
1211
1332
    if(mc.current_server == NULL){
1212
1333
      if (debug){
1213
 
        fprintf(stderr,
 
1334
        fprintf(stderr, "Mandos plugin mandos-client: "
1214
1335
                "Wait until first server is found. No timeout!\n");
1215
1336
      }
1216
1337
      ret = avahi_simple_poll_iterate(s, -1);
1217
1338
    } else {
1218
1339
      if (debug){
1219
 
        fprintf(stderr, "Check current_server if we should run it,"
 
1340
        fprintf(stderr, "Mandos plugin mandos-client: "
 
1341
                "Check current_server if we should run it,"
1220
1342
                " or wait\n");
1221
1343
      }
1222
1344
      /* the current time */
1239
1361
                    - ((intmax_t)waited_time.tv_nsec / 1000000));
1240
1362
      
1241
1363
      if (debug){
1242
 
        fprintf(stderr, "Blocking for %" PRIdMAX " ms\n", block_time);
 
1364
        fprintf(stderr, "Mandos plugin mandos-client: "
 
1365
                "Blocking for %" PRIdMAX " ms\n", block_time);
1243
1366
      }
1244
1367
      
1245
1368
      if(block_time <= 0){
1265
1388
      ret = avahi_simple_poll_iterate(s, (int)block_time);
1266
1389
    }
1267
1390
    if(ret != 0){
1268
 
      if (ret > 0 or errno != EINTR) {
 
1391
      if (ret > 0 or errno != EINTR){
1269
1392
        return (ret != 1) ? ret : 0;
1270
1393
      }
1271
1394
    }
1428
1551
        argp_state_help(state, state->out_stream,
1429
1552
                        ARGP_HELP_USAGE | ARGP_HELP_EXIT_ERR);
1430
1553
      case 'V':                 /* --version */
 
1554
        fprintf(state->out_stream, "Mandos plugin mandos-client: ");
1431
1555
        fprintf(state->out_stream, "%s\n", argp_program_version);
1432
1556
        exit(argp_err_exit_status);
1433
1557
        break;
1518
1642
    }
1519
1643
  }
1520
1644
  
 
1645
  /* Find network hooks and run them */
 
1646
  {
 
1647
    struct dirent **direntries;
 
1648
    struct dirent *direntry;
 
1649
    int numhooks = scandir(HOOKDIR, &direntries, runnable_hook,
 
1650
                           alphasort);
 
1651
    if(numhooks == -1){
 
1652
      perror_plus("scandir");
 
1653
    } else {
 
1654
      int devnull = open("/dev/null", O_RDONLY);
 
1655
      for(int i = 0; i < numhooks; i++){
 
1656
        direntry = direntries[0];
 
1657
        char *fullname = NULL;
 
1658
        ret = asprintf(&fullname, "%s/%s", tempdir,
 
1659
                       direntry->d_name);
 
1660
        if(ret < 0){
 
1661
          perror_plus("asprintf");
 
1662
          continue;
 
1663
        }
 
1664
        pid_t hook_pid = fork();
 
1665
        if(hook_pid == 0){
 
1666
          /* Child */
 
1667
          dup2(devnull, STDIN_FILENO);
 
1668
          close(devnull);
 
1669
          dup2(STDERR_FILENO, STDOUT_FILENO);
 
1670
          ret = setenv("DEVICE", interface, 1);
 
1671
          if(ret == -1){
 
1672
            perror_plus("setenv");
 
1673
            exit(1);
 
1674
          }
 
1675
          ret = setenv("VERBOSE", debug ? "1" : "0", 1);
 
1676
          if(ret == -1){
 
1677
            perror_plus("setenv");
 
1678
            exit(1);
 
1679
          }
 
1680
          ret = setenv("MODE", "start", 1);
 
1681
          if(ret == -1){
 
1682
            perror_plus("setenv");
 
1683
            exit(1);
 
1684
          }
 
1685
          char *delaystring;
 
1686
          ret = asprintf(&delaystring, "%f", delay);
 
1687
          if(ret == -1){
 
1688
            perror_plus("asprintf");
 
1689
            exit(1);
 
1690
          }
 
1691
          ret = setenv("DELAY", delaystring, 1);
 
1692
          if(ret == -1){
 
1693
            free(delaystring);
 
1694
            perror_plus("setenv");
 
1695
            exit(1);
 
1696
          }
 
1697
          free(delaystring);
 
1698
          ret = execl(fullname, direntry->d_name, "start", NULL);
 
1699
          perror_plus("execl");
 
1700
        } else {
 
1701
          int status;
 
1702
          if(TEMP_FAILURE_RETRY(waitpid(hook_pid, &status, 0)) == -1){
 
1703
            perror_plus("waitpid");
 
1704
            free(fullname);
 
1705
            continue;
 
1706
          }
 
1707
          if(WIFEXITED(status)){
 
1708
            if(WEXITSTATUS(status) != 0){
 
1709
              fprintf(stderr, "Mandos plugin mandos-client: "
 
1710
                      "Warning: network hook \"%s\" exited"
 
1711
                      " with status %d\n", direntry->d_name,
 
1712
                      WEXITSTATUS(status));
 
1713
              free(fullname);
 
1714
              continue;
 
1715
            }
 
1716
          } else if(WIFSIGNALED(status)){
 
1717
            fprintf(stderr, "Mandos plugin mandos-client: "
 
1718
                    "Warning: network hook \"%s\" died by"
 
1719
                    " signal %d\n", direntry->d_name,
 
1720
                    WTERMSIG(status));
 
1721
            free(fullname);
 
1722
            continue;
 
1723
          } else {
 
1724
            fprintf(stderr, "Mandos plugin mandos-client: "
 
1725
                    "Warning: network hook \"%s\" crashed\n",
 
1726
                    direntry->d_name);
 
1727
            free(fullname);
 
1728
            continue;
 
1729
          }
 
1730
        }
 
1731
        free(fullname);
 
1732
        if(quit_now){
 
1733
          goto end;
 
1734
        }
 
1735
      }
 
1736
      close(devnull);
 
1737
    }
 
1738
  }
 
1739
  
1521
1740
  if(not debug){
1522
1741
    avahi_set_log_function(empty_log);
1523
1742
  }
1524
 
 
 
1743
  
1525
1744
  if(interface[0] == '\0'){
1526
1745
    struct dirent **direntries;
1527
 
    ret = scandir(sys_class_net, &direntries, good_interface,
 
1746
    /* First look for interfaces that are up */
 
1747
    ret = scandir(sys_class_net, &direntries, up_interface,
1528
1748
                  alphasort);
 
1749
    if(ret == 0){
 
1750
      /* No up interfaces, look for any good interfaces */
 
1751
      free(direntries);
 
1752
      ret = scandir(sys_class_net, &direntries, good_interface,
 
1753
                    alphasort);
 
1754
    }
1529
1755
    if(ret >= 1){
1530
 
      /* Pick the first good interface */
 
1756
      /* Pick the first interface returned */
1531
1757
      interface = strdup(direntries[0]->d_name);
1532
1758
      if(debug){
1533
 
        fprintf(stderr, "Using interface \"%s\"\n", interface);
 
1759
        fprintf(stderr, "Mandos plugin mandos-client: "
 
1760
                "Using interface \"%s\"\n", interface);
1534
1761
      }
1535
1762
      if(interface == NULL){
1536
1763
        perror_plus("malloc");
1541
1768
      free(direntries);
1542
1769
    } else {
1543
1770
      free(direntries);
1544
 
      fprintf(stderr, "Could not find a network interface\n");
 
1771
      fprintf(stderr, "Mandos plugin mandos-client: "
 
1772
              "Could not find a network interface\n");
1545
1773
      exitcode = EXIT_FAILURE;
1546
1774
      goto end;
1547
1775
    }
1553
1781
  srand((unsigned int) time(NULL));
1554
1782
  mc.simple_poll = avahi_simple_poll_new();
1555
1783
  if(mc.simple_poll == NULL){
1556
 
    fprintf(stderr, "Avahi: Failed to create simple poll object.\n");
 
1784
    fprintf(stderr, "Mandos plugin mandos-client: "
 
1785
            "Avahi: Failed to create simple poll object.\n");
1557
1786
    exitcode = EX_UNAVAILABLE;
1558
1787
    goto end;
1559
1788
  }
1625
1854
  if(strcmp(interface, "none") != 0){
1626
1855
    if_index = (AvahiIfIndex) if_nametoindex(interface);
1627
1856
    if(if_index == 0){
1628
 
      fprintf(stderr, "No such interface: \"%s\"\n", interface);
 
1857
      fprintf(stderr, "Mandos plugin mandos-client: "
 
1858
              "No such interface: \"%s\"\n", interface);
1629
1859
      exitcode = EX_UNAVAILABLE;
1630
1860
      goto end;
1631
1861
    }
1772
2002
  
1773
2003
  ret = init_gnutls_global(pubkey, seckey);
1774
2004
  if(ret == -1){
1775
 
    fprintf(stderr, "init_gnutls_global failed\n");
 
2005
    fprintf(stderr, "Mandos plugin mandos-client: "
 
2006
            "init_gnutls_global failed\n");
1776
2007
    exitcode = EX_UNAVAILABLE;
1777
2008
    goto end;
1778
2009
  } else {
1794
2025
  }
1795
2026
  
1796
2027
  if(not init_gpgme(pubkey, seckey, tempdir)){
1797
 
    fprintf(stderr, "init_gpgme failed\n");
 
2028
    fprintf(stderr, "Mandos plugin mandos-client: "
 
2029
            "init_gpgme failed\n");
1798
2030
    exitcode = EX_UNAVAILABLE;
1799
2031
    goto end;
1800
2032
  } else {
1810
2042
    /* (Mainly meant for debugging) */
1811
2043
    char *address = strrchr(connect_to, ':');
1812
2044
    if(address == NULL){
1813
 
      fprintf(stderr, "No colon in address\n");
 
2045
      fprintf(stderr, "Mandos plugin mandos-client: "
 
2046
              "No colon in address\n");
1814
2047
      exitcode = EX_USAGE;
1815
2048
      goto end;
1816
2049
    }
1824
2057
    tmpmax = strtoimax(address+1, &tmp, 10);
1825
2058
    if(errno != 0 or tmp == address+1 or *tmp != '\0'
1826
2059
       or tmpmax != (uint16_t)tmpmax){
1827
 
      fprintf(stderr, "Bad port number\n");
 
2060
      fprintf(stderr, "Mandos plugin mandos-client: "
 
2061
              "Bad port number\n");
1828
2062
      exitcode = EX_USAGE;
1829
2063
      goto end;
1830
2064
    }
1860
2094
        break;
1861
2095
      }
1862
2096
      if(debug){
1863
 
        fprintf(stderr, "Retrying in %d seconds\n",
1864
 
                (int)retry_interval);
 
2097
        fprintf(stderr, "Mandos plugin mandos-client: "
 
2098
                "Retrying in %d seconds\n", (int)retry_interval);
1865
2099
      }
1866
2100
      sleep((int)retry_interval);
1867
2101
    }
1869
2103
    if (not quit_now){
1870
2104
      exitcode = EXIT_SUCCESS;
1871
2105
    }
1872
 
 
 
2106
    
1873
2107
    goto end;
1874
2108
  }
1875
2109
  
1897
2131
  
1898
2132
  /* Check if creating the Avahi server object succeeded */
1899
2133
  if(mc.server == NULL){
1900
 
    fprintf(stderr, "Failed to create Avahi server: %s\n",
 
2134
    fprintf(stderr, "Mandos plugin mandos-client: "
 
2135
            "Failed to create Avahi server: %s\n",
1901
2136
            avahi_strerror(error));
1902
2137
    exitcode = EX_UNAVAILABLE;
1903
2138
    goto end;
1912
2147
                                   AVAHI_PROTO_UNSPEC, "_mandos._tcp",
1913
2148
                                   NULL, 0, browse_callback, NULL);
1914
2149
  if(sb == NULL){
1915
 
    fprintf(stderr, "Failed to create service browser: %s\n",
 
2150
    fprintf(stderr, "Mandos plugin mandos-client: "
 
2151
            "Failed to create service browser: %s\n",
1916
2152
            avahi_strerror(avahi_server_errno(mc.server)));
1917
2153
    exitcode = EX_UNAVAILABLE;
1918
2154
    goto end;
1925
2161
  /* Run the main loop */
1926
2162
  
1927
2163
  if(debug){
1928
 
    fprintf(stderr, "Starting Avahi loop search\n");
 
2164
    fprintf(stderr, "Mandos plugin mandos-client: "
 
2165
            "Starting Avahi loop search\n");
1929
2166
  }
1930
2167
 
1931
2168
  ret = avahi_loop_with_timeout(mc.simple_poll,
1932
2169
                                (int)(retry_interval * 1000));
1933
2170
  if(debug){
1934
 
    fprintf(stderr, "avahi_loop_with_timeout exited %s\n",
 
2171
    fprintf(stderr, "Mandos plugin mandos-client: "
 
2172
            "avahi_loop_with_timeout exited %s\n",
1935
2173
            (ret == 0) ? "successfully" : "with error");
1936
2174
  }
1937
2175
  
1938
2176
 end:
1939
2177
  
1940
2178
  if(debug){
1941
 
    fprintf(stderr, "%s exiting\n", argv[0]);
 
2179
    fprintf(stderr, "Mandos plugin mandos-client: "
 
2180
            "%s exiting\n", argv[0]);
1942
2181
  }
1943
2182
  
1944
2183
  /* Cleanup things */
1972
2211
    }
1973
2212
  }
1974
2213
  
 
2214
  /* XXX run network hooks "stop" here  */
 
2215
  
1975
2216
  /* Take down the network interface */
1976
2217
  if(take_down_interface){
1977
2218
    /* Re-raise priviliges */
1984
2225
      ret = ioctl(sd, SIOCGIFFLAGS, &network);
1985
2226
      if(ret == -1){
1986
2227
        perror_plus("ioctl SIOCGIFFLAGS");
1987
 
      } else if(network.ifr_flags & IFF_UP) {
 
2228
      } else if(network.ifr_flags & IFF_UP){
1988
2229
        network.ifr_flags &= ~(short)IFF_UP; /* clear flag */
1989
2230
        ret = ioctl(sd, SIOCSIFFLAGS, &network);
1990
2231
        if(ret == -1){
2022
2263
        }
2023
2264
        ret = remove(fullname);
2024
2265
        if(ret == -1){
2025
 
          fprintf(stderr, "remove(\"%s\"): %s\n", fullname,
2026
 
                  strerror(errno));
 
2266
          fprintf(stderr, "Mandos plugin mandos-client: "
 
2267
                  "remove(\"%s\"): %s\n", fullname, strerror(errno));
2027
2268
        }
2028
2269
        free(fullname);
2029
2270
      }