/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-02-09 18:15:18 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-20090209181518-powtql91qv3wu51d
Earlier signal handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
                                   argp_state, struct argp,
76
76
                                   argp_parse(), ARGP_KEY_ARG,
77
77
                                   ARGP_KEY_END, ARGP_ERR_UNKNOWN */
78
 
#include <signal.h>             /* sigemptyset(), sigaddset(),
79
 
                                   sigaction(), SIGTERM, sigaction,
80
 
                                   sig_atomic_t */
81
 
 
 
78
#include <signal.h>             /* sigemptyset(), sigaddset(), sigaction(), SIGTERM, sigaction */
82
79
#ifdef __linux__
83
80
#include <sys/klog.h>           /* klogctl() */
84
 
#endif  /* __linux__ */
 
81
#endif
85
82
 
86
83
/* Avahi */
87
84
/* All Avahi types, constants and functions
139
136
                      ":!CTYPE-X.509:+CTYPE-OPENPGP" };
140
137
 
141
138
/*
142
 
 * Make additional room in "buffer" for at least BUFFER_SIZE more
143
 
 * bytes. "buffer_capacity" is how much is currently allocated,
144
 
 * "buffer_length" is how much is already used.
 
139
 * Make additional room in "buffer" for at least BUFFER_SIZE
 
140
 * additional bytes. "buffer_capacity" is how much is currently
 
141
 * allocated, "buffer_length" is how much is already used.
145
142
 */
146
143
size_t incbuffer(char **buffer, size_t buffer_length,
147
144
                  size_t buffer_capacity){
201
198
  }
202
199
  
203
200
  if(debug){
204
 
    fprintf(stderr, "Initializing GPGME\n");
 
201
    fprintf(stderr, "Initialize gpgme\n");
205
202
  }
206
203
  
207
204
  /* Init GPGME */
791
788
                             AVAHI_GCC_UNUSED AvahiStringList *txt,
792
789
                             AVAHI_GCC_UNUSED AvahiLookupResultFlags
793
790
                             flags,
794
 
                             AVAHI_GCC_UNUSED void* userdata){
 
791
                             __attribute__((unused)) void* userdata){
795
792
  assert(r);
796
793
  
797
794
  /* Called whenever a service has been resolved successfully or
833
830
                            const char *domain,
834
831
                            AVAHI_GCC_UNUSED AvahiLookupResultFlags
835
832
                            flags,
836
 
                            AVAHI_GCC_UNUSED void* userdata){
 
833
                            __attribute__((unused)) void* userdata){
837
834
  assert(b);
838
835
  
839
836
  /* Called whenever a new services becomes available on the LAN or
874
871
  }
875
872
}
876
873
 
877
 
sig_atomic_t quit_now = 0;
878
 
 
879
874
/* stop main loop after sigterm has been called */
880
875
static void handle_sigterm(__attribute__((unused)) int sig){
881
 
  if(quit_now){
882
 
    return;
883
 
  }
884
 
  quit_now = 1;
885
876
  int old_errno = errno;
886
 
  if(mc.simple_poll != NULL){
887
 
    avahi_simple_poll_quit(mc.simple_poll);
888
 
  }
 
877
  avahi_simple_poll_quit(mc.simple_poll);
889
878
  errno = old_errno;
890
879
}
891
880
 
908
897
  const char *seckey = PATHDIR "/" SECKEY;
909
898
  const char *pubkey = PATHDIR "/" PUBKEY;
910
899
  
911
 
  /* Initialize Mandos context */
912
 
  mc = (mandos_context){ .simple_poll = NULL, .server = NULL,
913
 
                         .dh_bits = 1024, .priority = "SECURE256"
914
 
                         ":!CTYPE-X.509:+CTYPE-OPENPGP" };
915
900
  bool gnutls_initialized = false;
916
901
  bool gpgme_initialized = false;
917
902
  double delay = 2.5;
918
903
 
919
904
  struct sigaction old_sigterm_action;
920
905
  struct sigaction sigterm_action = { .sa_handler = handle_sigterm };
921
 
  
 
906
 
922
907
  {
923
908
    struct argp_option options[] = {
924
909
      { .name = "debug", .key = 128,
1014
999
      goto end;
1015
1000
    }
1016
1001
  }
1017
 
  
 
1002
 
1018
1003
  if(not debug){
1019
1004
    avahi_set_log_function(empty_log);
1020
1005
  }
1021
 
  
 
1006
 
1022
1007
  /* Initialize Avahi early so avahi_simple_poll_quit() can be called
1023
1008
     from the signal handler */
1024
1009
  /* Initialize the pseudo-RNG for Avahi */
1029
1014
    exitcode = EXIT_FAILURE;
1030
1015
    goto end;
1031
1016
  }
1032
 
  
 
1017
 
1033
1018
  sigemptyset(&sigterm_action.sa_mask);
1034
 
  ret = sigaddset(&sigterm_action.sa_mask, SIGINT);
1035
 
  if(ret == -1){
1036
 
    perror("sigaddset");
1037
 
    exitcode = EXIT_FAILURE;
1038
 
    goto end;
1039
 
  }
1040
 
  ret = sigaddset(&sigterm_action.sa_mask, SIGHUP);
1041
 
  if(ret == -1){
1042
 
    perror("sigaddset");
1043
 
    exitcode = EXIT_FAILURE;
1044
 
    goto end;
1045
 
  }
1046
1019
  ret = sigaddset(&sigterm_action.sa_mask, SIGTERM);
1047
1020
  if(ret == -1){
1048
1021
    perror("sigaddset");
1055
1028
    exitcode = EXIT_FAILURE;
1056
1029
    goto end;
1057
1030
  }  
 
1031
 
1058
1032
  
1059
1033
  /* If the interface is down, bring it up */
1060
1034
  if(interface[0] != '\0'){
1067
1041
      restore_loglevel = false;
1068
1042
      perror("klogctl");
1069
1043
    }
1070
 
#endif  /* __linux__ */
 
1044
#endif
1071
1045
    
1072
1046
    sd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
1073
1047
    if(sd < 0){
1080
1054
          perror("klogctl");
1081
1055
        }
1082
1056
      }
1083
 
#endif  /* __linux__ */
 
1057
#endif
1084
1058
      goto end;
1085
1059
    }
1086
1060
    strcpy(network.ifr_name, interface);
1094
1068
          perror("klogctl");
1095
1069
        }
1096
1070
      }
1097
 
#endif  /* __linux__ */
 
1071
#endif
1098
1072
      exitcode = EXIT_FAILURE;
1099
1073
      goto end;
1100
1074
    }
1111
1085
            perror("klogctl");
1112
1086
          }
1113
1087
        }
1114
 
#endif  /* __linux__ */
 
1088
#endif
1115
1089
        goto end;
1116
1090
      }
1117
1091
    }
1141
1115
        perror("klogctl");
1142
1116
      }
1143
1117
    }
1144
 
#endif  /* __linux__ */
 
1118
#endif
1145
1119
  }
1146
1120
  
1147
1121
  uid = getuid();
1217
1191
    } else {
1218
1192
      af = AF_INET;
1219
1193
    }
1220
 
    ret = start_mandos_communication(address, port, if_index, af);
 
1194
    ret = start_mandos_communication(address, port, if_index,
 
1195
                                     af);
1221
1196
    if(ret < 0){
1222
1197
      exitcode = EXIT_FAILURE;
1223
1198
    } else {