/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

* mandos (ClientDBus.notifychangeproperty): Bug fix: Use instance
                                            attributes instead of
                                            class attributes.

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