/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

  • Committer: Björn Påhlsson
  • Date: 2009-01-19 05:56:10 UTC
  • mto: (237.7.1 mandos) (24.1.154 mandos)
  • mto: This revision was merged to the branch mainline in revision 250.
  • Revision ID: belorn@braxen-20090119055610-rk2wwibxou0zngqy
small stuff

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
#include <inttypes.h>           /* PRIu16, intmax_t, SCNdMAX */
61
61
#include <assert.h>             /* assert() */
62
62
#include <errno.h>              /* perror(), errno */
63
 
#include <time.h>               /* time() */
 
63
#include <time.h>               /* time(), nanosleep() */
64
64
#include <net/if.h>             /* ioctl, ifreq, SIOCGIFFLAGS, IFF_UP,
65
65
                                   SIOCSIFFLAGS, if_indextoname(),
66
66
                                   if_nametoindex(), IF_NAMESIZE */
74
74
                                   argp_state, struct argp,
75
75
                                   argp_parse(), ARGP_KEY_ARG,
76
76
                                   ARGP_KEY_END, ARGP_ERR_UNKNOWN */
 
77
#include <sys/klog.h>           /* klogctl() */
77
78
 
78
79
/* Avahi */
79
80
/* All Avahi types, constants and functions
840
841
                          ":!CTYPE-X.509:+CTYPE-OPENPGP" };
841
842
    bool gnutls_initalized = false;
842
843
    bool gpgme_initalized = false;
 
844
    double delay = 2.5;
843
845
    
844
846
    {
845
847
      struct argp_option options[] = {
871
873
          .arg = "STRING",
872
874
          .doc = "GnuTLS priority string for the TLS handshake",
873
875
          .group = 1 },
 
876
        { .name = "delay", .key = 131,
 
877
          .arg = "SECONDS",
 
878
          .doc = "Maximum delay to wait for interface startup",
 
879
          .group = 2 },
874
880
        { .name = NULL }
875
881
      };
876
882
      
904
910
        case 130:               /* --priority */
905
911
          mc.priority = arg;
906
912
          break;
 
913
        case 131:               /* --delay */
 
914
          ret = sscanf(arg, "%lf%n", &delay, &numchars);
 
915
          if(ret < 1 or arg[numchars] != '\0'){
 
916
            fprintf(stderr, "Bad delay\n");
 
917
            exit(EXIT_FAILURE);
 
918
          }
 
919
          break;
907
920
        case ARGP_KEY_ARG:
908
921
          argp_usage(state);
909
922
        case ARGP_KEY_END:
928
941
    
929
942
    /* If the interface is down, bring it up */
930
943
    {
 
944
      // Lower kernel loglevel to KERN_NOTICE to avoid
 
945
      // KERN_INFO messages to mess up the prompt
 
946
      ret = klogctl(8, NULL, 5);
 
947
      if(ret == -1){
 
948
        perror("klogctl");
 
949
      }
 
950
 
931
951
      sd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
932
952
      if(sd < 0) {
933
953
        perror("socket");
934
954
        exitcode = EXIT_FAILURE;
 
955
        ret = klogctl(7, NULL, 0);
 
956
        if(ret == -1){
 
957
          perror("klogctl");
 
958
        }
935
959
        goto end;
936
960
      }
937
961
      strcpy(network.ifr_name, interface);
938
962
      ret = ioctl(sd, SIOCGIFFLAGS, &network);
939
963
      if(ret == -1){
940
964
        perror("ioctl SIOCGIFFLAGS");
 
965
        ret = klogctl(7, NULL, 0);
 
966
        if(ret == -1){
 
967
          perror("klogctl");
 
968
        }
941
969
        exitcode = EXIT_FAILURE;
942
970
        goto end;
943
971
      }
947
975
        if(ret == -1){
948
976
          perror("ioctl SIOCSIFFLAGS");
949
977
          exitcode = EXIT_FAILURE;
 
978
          ret = klogctl(7, NULL, 0);
 
979
          if(ret == -1){
 
980
            perror("klogctl");
 
981
          }
950
982
          goto end;
951
983
        }
952
984
      }
 
985
      // sleep checking until interface is running
 
986
      for(int i=0; i < delay * 4; i++){
 
987
        ret = ioctl(sd, SIOCGIFFLAGS, &network);
 
988
        if(ret == -1){
 
989
          perror("ioctl SIOCGIFFLAGS");
 
990
        } else if(network.ifr_flags & IFF_RUNNING){
 
991
          break;
 
992
        }
 
993
        struct timespec sleeptime = { .tv_nsec = 250000000 };
 
994
        nanosleep(&sleeptime, NULL);
 
995
      }
953
996
      ret = (int)TEMP_FAILURE_RETRY(close(sd));
954
997
      if(ret == -1){
955
998
        perror("close");
956
999
      }
 
1000
      // Restores kernel loglevel to default
 
1001
      ret = klogctl(7, NULL, 0);
 
1002
      if(ret == -1){
 
1003
        perror("klogctl");
 
1004
      }
957
1005
    }
958
1006
    
959
1007
    uid = getuid();
1086
1134
    if(debug){
1087
1135
      fprintf(stderr, "Starting Avahi loop search\n");
1088
1136
    }
1089
 
    
 
1137
 
1090
1138
    avahi_simple_poll_loop(mc.simple_poll);
1091
1139
    
1092
1140
 end: