/mandos/trunk

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

« back to all changes in this revision

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

  • Committer: Teddy Hogeborn
  • Date: 2009-10-26 21:16:16 UTC
  • Revision ID: teddy@fukt.bsnet.se-20091026211616-38e9wynf4428ip2l
Merge from release branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 * "browse_callback", and parts of "main".
10
10
 * 
11
11
 * Everything else is
12
 
 * Copyright © 2008-2010 Teddy Hogeborn
13
 
 * Copyright © 2008-2010 Björn Påhlsson
 
12
 * Copyright © 2008,2009 Teddy Hogeborn
 
13
 * Copyright © 2008,2009 Björn Påhlsson
14
14
 * 
15
15
 * This program is free software: you can redistribute it and/or
16
16
 * modify it under the terms of the GNU General Public License as
43
43
                                   stdout, ferror(), remove() */
44
44
#include <stdint.h>             /* uint16_t, uint32_t */
45
45
#include <stddef.h>             /* NULL, size_t, ssize_t */
46
 
#include <stdlib.h>             /* free(), EXIT_SUCCESS, srand(),
47
 
                                   strtof(), abort() */
 
46
#include <stdlib.h>             /* free(), EXIT_SUCCESS, EXIT_FAILURE,
 
47
                                   srand(), strtof(), abort() */
48
48
#include <stdbool.h>            /* bool, false, true */
49
49
#include <string.h>             /* memset(), strcmp(), strlen(),
50
50
                                   strerror(), asprintf(), strcpy() */
63
63
                                   strtoimax() */
64
64
#include <assert.h>             /* assert() */
65
65
#include <errno.h>              /* perror(), errno */
66
 
#include <time.h>               /* nanosleep(), time(), sleep() */
 
66
#include <time.h>               /* nanosleep(), time() */
67
67
#include <net/if.h>             /* ioctl, ifreq, SIOCGIFFLAGS, IFF_UP,
68
68
                                   SIOCSIFFLAGS, if_indextoname(),
69
69
                                   if_nametoindex(), IF_NAMESIZE */
82
82
#include <signal.h>             /* sigemptyset(), sigaddset(),
83
83
                                   sigaction(), SIGTERM, sig_atomic_t,
84
84
                                   raise() */
85
 
#include <sysexits.h>           /* EX_OSERR, EX_USAGE, EX_UNAVAILABLE,
86
 
                                   EX_NOHOST, EX_IOERR, EX_PROTOCOL */
 
85
#include <sysexits.h>           /* EX_OSERR, EX_USAGE */
87
86
 
88
87
#ifdef __linux__
89
88
#include <sys/klog.h>           /* klogctl() */
127
126
static const char mandos_protocol_version[] = "1";
128
127
const char *argp_program_version = "mandos-client " VERSION;
129
128
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
130
 
static const char sys_class_net[] = "/sys/class/net";
131
 
char *connect_to = NULL;
132
129
 
133
130
/* Used for passing in values through the Avahi callback functions */
134
131
typedef struct {
556
553
  gnutls_session_t session;
557
554
  int pf;                       /* Protocol family */
558
555
  
559
 
  errno = 0;
560
 
  
561
556
  if(quit_now){
562
 
    errno = EINTR;
563
557
    return -1;
564
558
  }
565
559
  
572
566
    break;
573
567
  default:
574
568
    fprintf(stderr, "Bad address family: %d\n", af);
575
 
    errno = EINVAL;
576
569
    return -1;
577
570
  }
578
571
  
588
581
  
589
582
  tcp_sd = socket(pf, SOCK_STREAM, 0);
590
583
  if(tcp_sd < 0){
591
 
    int e = errno;
592
584
    perror("socket");
593
 
    errno = e;
594
585
    goto mandos_end;
595
586
  }
596
587
  
597
588
  if(quit_now){
598
 
    errno = EINTR;
599
589
    goto mandos_end;
600
590
  }
601
591
  
608
598
    ret = inet_pton(af, ip, &to.in.sin_addr);
609
599
  }
610
600
  if(ret < 0 ){
611
 
    int e = errno;
612
601
    perror("inet_pton");
613
 
    errno = e;
614
602
    goto mandos_end;
615
603
  }
616
604
  if(ret == 0){
617
 
    int e = errno;
618
605
    fprintf(stderr, "Bad address: %s\n", ip);
619
 
    errno = e;
620
606
    goto mandos_end;
621
607
  }
622
608
  if(af == AF_INET6){
630
616
      if(if_index == AVAHI_IF_UNSPEC){
631
617
        fprintf(stderr, "An IPv6 link-local address is incomplete"
632
618
                " without a network interface\n");
633
 
        errno = EINVAL;
634
619
        goto mandos_end;
635
620
      }
636
621
      /* Set the network interface number as scope */
643
628
  }
644
629
  
645
630
  if(quit_now){
646
 
    errno = EINTR;
647
631
    goto mandos_end;
648
632
  }
649
633
  
680
664
  }
681
665
  
682
666
  if(quit_now){
683
 
    errno = EINTR;
684
667
    goto mandos_end;
685
668
  }
686
669
  
690
673
    ret = connect(tcp_sd, &to.in, sizeof(to)); /* IPv4 */
691
674
  }
692
675
  if(ret < 0){
693
 
    if ((errno != ECONNREFUSED and errno != ENETUNREACH) or debug){
694
 
      int e = errno;
695
 
      perror("connect");
696
 
      errno = e;
697
 
    }
 
676
    perror("connect");
698
677
    goto mandos_end;
699
678
  }
700
679
  
701
680
  if(quit_now){
702
 
    errno = EINTR;
703
681
    goto mandos_end;
704
682
  }
705
683
  
710
688
    ret = (int)TEMP_FAILURE_RETRY(write(tcp_sd, out + written,
711
689
                                   out_size - written));
712
690
    if(ret == -1){
713
 
      int e = errno;
714
691
      perror("write");
715
 
      errno = e;
716
692
      goto mandos_end;
717
693
    }
718
694
    written += (size_t)ret;
728
704
    }
729
705
  
730
706
    if(quit_now){
731
 
      errno = EINTR;
732
707
      goto mandos_end;
733
708
    }
734
709
  }
738
713
  }
739
714
  
740
715
  if(quit_now){
741
 
    errno = EINTR;
742
716
    goto mandos_end;
743
717
  }
744
718
  
745
719
  gnutls_transport_set_ptr(session, (gnutls_transport_ptr_t) tcp_sd);
746
720
  
747
721
  if(quit_now){
748
 
    errno = EINTR;
749
722
    goto mandos_end;
750
723
  }
751
724
  
752
725
  do {
753
726
    ret = gnutls_handshake(session);
754
727
    if(quit_now){
755
 
      errno = EINTR;
756
728
      goto mandos_end;
757
729
    }
758
730
  } while(ret == GNUTLS_E_AGAIN or ret == GNUTLS_E_INTERRUPTED);
762
734
      fprintf(stderr, "*** GnuTLS Handshake failed ***\n");
763
735
      gnutls_perror(ret);
764
736
    }
765
 
    errno = EPROTO;
766
737
    goto mandos_end;
767
738
  }
768
739
  
776
747
  while(true){
777
748
    
778
749
    if(quit_now){
779
 
      errno = EINTR;
780
750
      goto mandos_end;
781
751
    }
782
752
    
783
753
    buffer_capacity = incbuffer(&buffer, buffer_length,
784
754
                                   buffer_capacity);
785
755
    if(buffer_capacity == 0){
786
 
      int e = errno;
787
756
      perror("incbuffer");
788
 
      errno = e;
789
757
      goto mandos_end;
790
758
    }
791
759
    
792
760
    if(quit_now){
793
 
      errno = EINTR;
794
761
      goto mandos_end;
795
762
    }
796
763
    
809
776
          ret = gnutls_handshake(session);
810
777
          
811
778
          if(quit_now){
812
 
            errno = EINTR;
813
779
            goto mandos_end;
814
780
          }
815
781
        } while(ret == GNUTLS_E_AGAIN or ret == GNUTLS_E_INTERRUPTED);
816
782
        if(ret < 0){
817
783
          fprintf(stderr, "*** GnuTLS Re-handshake failed ***\n");
818
784
          gnutls_perror(ret);
819
 
          errno = EPROTO;
820
785
          goto mandos_end;
821
786
        }
822
787
        break;
824
789
        fprintf(stderr, "Unknown error while reading data from"
825
790
                " encrypted session with Mandos server\n");
826
791
        gnutls_bye(session, GNUTLS_SHUT_RDWR);
827
 
        errno = EIO;
828
792
        goto mandos_end;
829
793
      }
830
794
    } else {
837
801
  }
838
802
  
839
803
  if(quit_now){
840
 
    errno = EINTR;
841
804
    goto mandos_end;
842
805
  }
843
806
  
844
807
  do {
845
808
    ret = gnutls_bye(session, GNUTLS_SHUT_RDWR);
846
809
    if(quit_now){
847
 
      errno = EINTR;
848
810
      goto mandos_end;
849
811
    }
850
812
  } while(ret == GNUTLS_E_AGAIN or ret == GNUTLS_E_INTERRUPTED);
859
821
      written = 0;
860
822
      while(written < (size_t) decrypted_buffer_size){
861
823
        if(quit_now){
862
 
          errno = EINTR;
863
824
          goto mandos_end;
864
825
        }
865
826
        
867
828
                          (size_t)decrypted_buffer_size - written,
868
829
                          stdout);
869
830
        if(ret == 0 and ferror(stdout)){
870
 
          int e = errno;
871
831
          if(debug){
872
832
            fprintf(stderr, "Error writing encrypted data: %s\n",
873
833
                    strerror(errno));
874
834
          }
875
 
          errno = e;
876
835
          goto mandos_end;
877
836
        }
878
837
        written += (size_t)ret;
884
843
  /* Shutdown procedure */
885
844
  
886
845
 mandos_end:
887
 
  {
888
 
    int e = errno;
889
 
    free(decrypted_buffer);
890
 
    free(buffer);
891
 
    if(tcp_sd >= 0){
892
 
      ret = (int)TEMP_FAILURE_RETRY(close(tcp_sd));
893
 
    }
894
 
    if(ret == -1){
895
 
      if(e == 0){
896
 
        e = errno;
897
 
      }
898
 
      perror("close");
899
 
    }
900
 
    gnutls_deinit(session);
901
 
    if(quit_now){
902
 
      e = EINTR;
903
 
      retval = -1;
904
 
    }
905
 
    errno = e;
 
846
  free(decrypted_buffer);
 
847
  free(buffer);
 
848
  if(tcp_sd >= 0){
 
849
    ret = (int)TEMP_FAILURE_RETRY(close(tcp_sd));
 
850
  }
 
851
  if(ret == -1){
 
852
    perror("close");
 
853
  }
 
854
  gnutls_deinit(session);
 
855
  if(quit_now){
 
856
    retval = -1;
906
857
  }
907
858
  return retval;
908
859
}
1024
975
  errno = old_errno;
1025
976
}
1026
977
 
1027
 
/* 
1028
 
 * This function determines if a directory entry in /sys/class/net
1029
 
 * corresponds to an acceptable network device.
1030
 
 * (This function is passed to scandir(3) as a filter function.)
1031
 
 */
1032
 
int good_interface(const struct dirent *if_entry){
1033
 
  ssize_t ssret;
1034
 
  char *flagname = NULL;
1035
 
  int ret = asprintf(&flagname, "%s/%s/flags", sys_class_net,
1036
 
                     if_entry->d_name);
1037
 
  if(ret < 0){
1038
 
    perror("asprintf");
1039
 
    return 0;
1040
 
  }
1041
 
  if(if_entry->d_name[0] == '.'){
1042
 
    return 0;
1043
 
  }
1044
 
  int flags_fd = (int)TEMP_FAILURE_RETRY(open(flagname, O_RDONLY));
1045
 
  if(flags_fd == -1){
1046
 
    perror("open");
1047
 
    return 0;
1048
 
  }
1049
 
  typedef short ifreq_flags;    /* ifreq.ifr_flags in netdevice(7) */
1050
 
  /* read line from flags_fd */
1051
 
  ssize_t to_read = (sizeof(ifreq_flags)*2)+3; /* "0x1003\n" */
1052
 
  char *flagstring = malloc((size_t)to_read+1); /* +1 for final \0 */
1053
 
  flagstring[(size_t)to_read] = '\0';
1054
 
  if(flagstring == NULL){
1055
 
    perror("malloc");
1056
 
    close(flags_fd);
1057
 
    return 0;
1058
 
  }
1059
 
  while(to_read > 0){
1060
 
    ssret = (ssize_t)TEMP_FAILURE_RETRY(read(flags_fd, flagstring,
1061
 
                                             (size_t)to_read));
1062
 
    if(ssret == -1){
1063
 
      perror("read");
1064
 
      free(flagstring);
1065
 
      close(flags_fd);
1066
 
      return 0;
1067
 
    }
1068
 
    to_read -= ssret;
1069
 
    if(ssret == 0){
1070
 
      break;
1071
 
    }
1072
 
  }
1073
 
  close(flags_fd);
1074
 
  intmax_t tmpmax;
1075
 
  char *tmp;
1076
 
  errno = 0;
1077
 
  tmpmax = strtoimax(flagstring, &tmp, 0);
1078
 
  if(errno != 0 or tmp == flagstring or (*tmp != '\0'
1079
 
                                         and not (isspace(*tmp)))
1080
 
     or tmpmax != (ifreq_flags)tmpmax){
1081
 
    if(debug){
1082
 
      fprintf(stderr, "Invalid flags \"%s\" for interface \"%s\"\n",
1083
 
              flagstring, if_entry->d_name);
1084
 
    }
1085
 
    free(flagstring);
1086
 
    return 0;
1087
 
  }
1088
 
  free(flagstring);
1089
 
  ifreq_flags flags = (ifreq_flags)tmpmax;
1090
 
  /* Reject the loopback device */
1091
 
  if(flags & IFF_LOOPBACK){
1092
 
    if(debug){
1093
 
      fprintf(stderr, "Rejecting loopback interface \"%s\"\n",
1094
 
              if_entry->d_name);
1095
 
    }
1096
 
    return 0;
1097
 
  }
1098
 
  /* Accept point-to-point devices only if connect_to is specified */
1099
 
  if(connect_to != NULL and (flags & IFF_POINTOPOINT)){
1100
 
    if(debug){
1101
 
      fprintf(stderr, "Accepting point-to-point interface \"%s\"\n",
1102
 
              if_entry->d_name);
1103
 
    }
1104
 
    return 1;
1105
 
  }
1106
 
  /* Otherwise, reject non-broadcast-capable devices */
1107
 
  if(not (flags & IFF_BROADCAST)){
1108
 
    if(debug){
1109
 
      fprintf(stderr, "Rejecting non-broadcast interface \"%s\"\n",
1110
 
              if_entry->d_name);
1111
 
    }
1112
 
    return 0;
1113
 
  }
1114
 
  /* Accept this device */
1115
 
  if(debug){
1116
 
    fprintf(stderr, "Interface \"%s\" is acceptable\n",
1117
 
            if_entry->d_name);
1118
 
  }
1119
 
  return 1;
1120
 
}
1121
 
 
1122
978
int main(int argc, char *argv[]){
1123
979
  AvahiSServiceBrowser *sb = NULL;
1124
980
  int error;
1126
982
  intmax_t tmpmax;
1127
983
  char *tmp;
1128
984
  int exitcode = EXIT_SUCCESS;
1129
 
  const char *interface = "";
 
985
  const char *interface = "eth0";
1130
986
  struct ifreq network;
1131
987
  int sd = -1;
1132
988
  bool take_down_interface = false;
1133
989
  uid_t uid;
1134
990
  gid_t gid;
 
991
  char *connect_to = NULL;
1135
992
  char tempdir[] = "/tmp/mandosXXXXXX";
1136
993
  bool tempdir_created = false;
1137
994
  AvahiIfIndex if_index = AVAHI_IF_UNSPEC;
1294
1151
  if(not debug){
1295
1152
    avahi_set_log_function(empty_log);
1296
1153
  }
1297
 
 
1298
 
  if(interface[0] == '\0'){
1299
 
    struct dirent **direntries;
1300
 
    ret = scandir(sys_class_net, &direntries, good_interface,
1301
 
                  alphasort);
1302
 
    if(ret >= 1){
1303
 
      /* Pick the first good interface */
1304
 
      interface = strdup(direntries[0]->d_name);
1305
 
      if(debug){
1306
 
        fprintf(stderr, "Using interface \"%s\"\n", interface);
1307
 
      }
1308
 
      if(interface == NULL){
1309
 
        perror("malloc");
1310
 
        free(direntries);
1311
 
        exitcode = EXIT_FAILURE;
1312
 
        goto end;
1313
 
      }
1314
 
      free(direntries);
1315
 
    } else {
1316
 
      free(direntries);
1317
 
      fprintf(stderr, "Could not find a network interface\n");
1318
 
      exitcode = EXIT_FAILURE;
1319
 
      goto end;
1320
 
    }
1321
 
  }
1322
1154
  
1323
1155
  /* Initialize Avahi early so avahi_simple_poll_quit() can be called
1324
1156
     from the signal handler */
1327
1159
  mc.simple_poll = avahi_simple_poll_new();
1328
1160
  if(mc.simple_poll == NULL){
1329
1161
    fprintf(stderr, "Avahi: Failed to create simple poll object.\n");
1330
 
    exitcode = EX_UNAVAILABLE;
 
1162
    exitcode = EXIT_FAILURE;
1331
1163
    goto end;
1332
1164
  }
1333
1165
  
1335
1167
  ret = sigaddset(&sigterm_action.sa_mask, SIGINT);
1336
1168
  if(ret == -1){
1337
1169
    perror("sigaddset");
1338
 
    exitcode = EX_OSERR;
 
1170
    exitcode = EXIT_FAILURE;
1339
1171
    goto end;
1340
1172
  }
1341
1173
  ret = sigaddset(&sigterm_action.sa_mask, SIGHUP);
1342
1174
  if(ret == -1){
1343
1175
    perror("sigaddset");
1344
 
    exitcode = EX_OSERR;
 
1176
    exitcode = EXIT_FAILURE;
1345
1177
    goto end;
1346
1178
  }
1347
1179
  ret = sigaddset(&sigterm_action.sa_mask, SIGTERM);
1348
1180
  if(ret == -1){
1349
1181
    perror("sigaddset");
1350
 
    exitcode = EX_OSERR;
 
1182
    exitcode = EXIT_FAILURE;
1351
1183
    goto end;
1352
1184
  }
1353
1185
  /* Need to check if the handler is SIG_IGN before handling:
1357
1189
  ret = sigaction(SIGINT, NULL, &old_sigterm_action);
1358
1190
  if(ret == -1){
1359
1191
    perror("sigaction");
1360
 
    return EX_OSERR;
 
1192
    return EXIT_FAILURE;
1361
1193
  }
1362
1194
  if(old_sigterm_action.sa_handler != SIG_IGN){
1363
1195
    ret = sigaction(SIGINT, &sigterm_action, NULL);
1364
1196
    if(ret == -1){
1365
1197
      perror("sigaction");
1366
 
      exitcode = EX_OSERR;
 
1198
      exitcode = EXIT_FAILURE;
1367
1199
      goto end;
1368
1200
    }
1369
1201
  }
1370
1202
  ret = sigaction(SIGHUP, NULL, &old_sigterm_action);
1371
1203
  if(ret == -1){
1372
1204
    perror("sigaction");
1373
 
    return EX_OSERR;
 
1205
    return EXIT_FAILURE;
1374
1206
  }
1375
1207
  if(old_sigterm_action.sa_handler != SIG_IGN){
1376
1208
    ret = sigaction(SIGHUP, &sigterm_action, NULL);
1377
1209
    if(ret == -1){
1378
1210
      perror("sigaction");
1379
 
      exitcode = EX_OSERR;
 
1211
      exitcode = EXIT_FAILURE;
1380
1212
      goto end;
1381
1213
    }
1382
1214
  }
1383
1215
  ret = sigaction(SIGTERM, NULL, &old_sigterm_action);
1384
1216
  if(ret == -1){
1385
1217
    perror("sigaction");
1386
 
    return EX_OSERR;
 
1218
    return EXIT_FAILURE;
1387
1219
  }
1388
1220
  if(old_sigterm_action.sa_handler != SIG_IGN){
1389
1221
    ret = sigaction(SIGTERM, &sigterm_action, NULL);
1390
1222
    if(ret == -1){
1391
1223
      perror("sigaction");
1392
 
      exitcode = EX_OSERR;
 
1224
      exitcode = EXIT_FAILURE;
1393
1225
      goto end;
1394
1226
    }
1395
1227
  }
1396
1228
  
1397
1229
  /* If the interface is down, bring it up */
1398
 
  if(strcmp(interface, "none") != 0){
 
1230
  if(interface[0] != '\0'){
1399
1231
    if_index = (AvahiIfIndex) if_nametoindex(interface);
1400
1232
    if(if_index == 0){
1401
1233
      fprintf(stderr, "No such interface: \"%s\"\n", interface);
1402
 
      exitcode = EX_UNAVAILABLE;
 
1234
      exitcode = EXIT_FAILURE;
1403
1235
      goto end;
1404
1236
    }
1405
1237
    
1428
1260
    sd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
1429
1261
    if(sd < 0){
1430
1262
      perror("socket");
1431
 
      exitcode = EX_OSERR;
 
1263
      exitcode = EXIT_FAILURE;
1432
1264
#ifdef __linux__
1433
1265
      if(restore_loglevel){
1434
1266
        ret = klogctl(7, NULL, 0);
1457
1289
        }
1458
1290
      }
1459
1291
#endif  /* __linux__ */
1460
 
      exitcode = EX_OSERR;
 
1292
      exitcode = EXIT_FAILURE;
1461
1293
      /* Lower privileges */
1462
1294
      errno = 0;
1463
1295
      ret = seteuid(uid);
1472
1304
      ret = ioctl(sd, SIOCSIFFLAGS, &network);
1473
1305
      if(ret == -1){
1474
1306
        take_down_interface = false;
1475
 
        perror("ioctl SIOCSIFFLAGS +IFF_UP");
1476
 
        exitcode = EX_OSERR;
 
1307
        perror("ioctl SIOCSIFFLAGS");
 
1308
        exitcode = EXIT_FAILURE;
1477
1309
#ifdef __linux__
1478
1310
        if(restore_loglevel){
1479
1311
          ret = klogctl(7, NULL, 0);
1545
1377
  ret = init_gnutls_global(pubkey, seckey);
1546
1378
  if(ret == -1){
1547
1379
    fprintf(stderr, "init_gnutls_global failed\n");
1548
 
    exitcode = EX_UNAVAILABLE;
 
1380
    exitcode = EXIT_FAILURE;
1549
1381
    goto end;
1550
1382
  } else {
1551
1383
    gnutls_initialized = true;
1568
1400
  
1569
1401
  if(not init_gpgme(pubkey, seckey, tempdir)){
1570
1402
    fprintf(stderr, "init_gpgme failed\n");
1571
 
    exitcode = EX_UNAVAILABLE;
 
1403
    exitcode = EXIT_FAILURE;
1572
1404
    goto end;
1573
1405
  } else {
1574
1406
    gpgme_initialized = true;
1584
1416
    char *address = strrchr(connect_to, ':');
1585
1417
    if(address == NULL){
1586
1418
      fprintf(stderr, "No colon in address\n");
1587
 
      exitcode = EX_USAGE;
 
1419
      exitcode = EXIT_FAILURE;
1588
1420
      goto end;
1589
1421
    }
1590
1422
    
1598
1430
    if(errno != 0 or tmp == address+1 or *tmp != '\0'
1599
1431
       or tmpmax != (uint16_t)tmpmax){
1600
1432
      fprintf(stderr, "Bad port number\n");
1601
 
      exitcode = EX_USAGE;
 
1433
      exitcode = EXIT_FAILURE;
1602
1434
      goto end;
1603
1435
    }
1604
1436
  
1620
1452
    if(quit_now){
1621
1453
      goto end;
1622
1454
    }
1623
 
 
1624
 
    while(not quit_now){
1625
 
      ret = start_mandos_communication(address, port, if_index, af);
1626
 
      if(quit_now or ret == 0){
1627
 
        break;
1628
 
      }
1629
 
      sleep(15);
1630
 
    };
1631
 
 
1632
 
    if (not quit_now){
 
1455
    
 
1456
    ret = start_mandos_communication(address, port, if_index, af);
 
1457
    if(ret < 0){
 
1458
      exitcode = EXIT_FAILURE;
 
1459
    } else {
1633
1460
      exitcode = EXIT_SUCCESS;
1634
1461
    }
1635
 
 
1636
1462
    goto end;
1637
1463
  }
1638
1464
  
1662
1488
  if(mc.server == NULL){
1663
1489
    fprintf(stderr, "Failed to create Avahi server: %s\n",
1664
1490
            avahi_strerror(error));
1665
 
    exitcode = EX_UNAVAILABLE;
 
1491
    exitcode = EXIT_FAILURE;
1666
1492
    goto end;
1667
1493
  }
1668
1494
  
1677
1503
  if(sb == NULL){
1678
1504
    fprintf(stderr, "Failed to create service browser: %s\n",
1679
1505
            avahi_strerror(avahi_server_errno(mc.server)));
1680
 
    exitcode = EX_UNAVAILABLE;
 
1506
    exitcode = EXIT_FAILURE;
1681
1507
    goto end;
1682
1508
  }
1683
1509
  
1735
1561
        network.ifr_flags &= ~(short)IFF_UP; /* clear flag */
1736
1562
        ret = ioctl(sd, SIOCSIFFLAGS, &network);
1737
1563
        if(ret == -1){
1738
 
          perror("ioctl SIOCSIFFLAGS -IFF_UP");
 
1564
          perror("ioctl SIOCSIFFLAGS");
1739
1565
        }
1740
1566
      }
1741
1567
      ret = (int)TEMP_FAILURE_RETRY(close(sd));