35
35
#define _GNU_SOURCE /* TEMP_FAILURE_RETRY() */
37
#include <stdio.h> /* fprintf(), stderr, fwrite(), stdout,
37
#include <stdio.h> /* fprintf(), stderr, fwrite(), stdout, ferror() */
39
38
#include <stdint.h> /* uint16_t, uint32_t */
40
39
#include <stddef.h> /* NULL, size_t, ssize_t */
41
#include <stdlib.h> /* free(), EXIT_SUCCESS, EXIT_FAILURE,
40
#include <stdlib.h> /* free() */
43
41
#include <stdbool.h> /* bool, true */
44
#include <string.h> /* memset(), strcmp(), strlen(),
45
strerror(), memcpy(), strcpy() */
46
#include <sys/ioctl.h> /* ioctl */
42
#include <string.h> /* memset(), strcmp(), strlen, strerror() */
43
#include <sys/ioctl.h> /* ioctl, ifreq, SIOCGIFFLAGS, IFF_UP,
47
45
#include <sys/types.h> /* socket(), inet_pton(), sockaddr,
48
sockaddr_in6, PF_INET6,
49
SOCK_STREAM, INET6_ADDRSTRLEN,
51
#include <inttypes.h> /* PRIu16 */
46
sockaddr_in6, PF_INET6, SOCK_STREAM, INET6_ADDRSTRLEN */
52
47
#include <sys/socket.h> /* socket(), struct sockaddr_in6,
53
48
struct in6_addr, inet_pton(),
55
#include <assert.h> /* assert() */
56
#include <errno.h> /* perror(), errno */
57
#include <time.h> /* time() */
51
#include <errno.h> /* perror() */
58
53
#include <net/if.h> /* ioctl, ifreq, SIOCGIFFLAGS, IFF_UP,
59
54
SIOCSIFFLAGS, if_indextoname(),
60
55
if_nametoindex(), IF_NAMESIZE */
61
#include <unistd.h> /* close(), SEEK_SET, off_t, write(),
62
getuid(), getgid(), setuid(),
56
#include <unistd.h> /* close(), SEEK_SET, off_t, write()*/
64
57
#include <netinet/in.h>
65
58
#include <arpa/inet.h> /* inet_pton(), htons */
66
#include <iso646.h> /* not, and */
67
#include <argp.h> /* struct argp_option, error_t, struct
68
argp_state, struct argp,
69
argp_parse(), ARGP_KEY_ARG,
70
ARGP_KEY_END, ARGP_ERR_UNKNOWN */
59
#include <iso646.h> /* not */
60
#include <argp.h> /* struct argp_option,
61
struct argp_state, struct argp,
73
/* All Avahi types, constants and functions
76
#include <avahi-core/core.h>
65
#include <avahi-core/core.h> /* AvahiSimplePoll, AvahiServer,
77
67
#include <avahi-core/lookup.h>
78
#include <avahi-core/log.h>
68
#include <avahi-core/log.h> /* AvahiLogLevel */
79
69
#include <avahi-common/simple-watch.h>
80
70
#include <avahi-common/malloc.h>
81
71
#include <avahi-common/error.h>
84
#include <gnutls/gnutls.h> /* All GnuTLS types, constants and functions
74
#include <gnutls/gnutls.h> /* gnutls_certificate_credentials_t,
78
gnutls_global_set_log_level(),
79
gnutls_global_set_log_function(),
80
gnutls_certificate_allocate_credentials(),
81
gnutls_global_deinit(),
82
gnutls_dh_params_init(),
83
gnutls_dh_params_generate(),
84
gnutls_certificate_set_dh_params(),
85
gnutls_certificate_free_credentials(),
86
gnutls_session_t, gnutls_init(),
87
gnutls_priority_set_direct(),
89
gnutls_credentials_set(),
90
gnutls_certificate_server_set_request(),
91
gnutls_dh_set_prime_bits(),
92
gnutls_transport_set_ptr(),
93
gnutls_transport_ptr_t,
96
gnutls_perror(), gnutls_bye(),
86
97
init_gnutls_session(),
88
#include <gnutls/openpgp.h> /* gnutls_certificate_set_openpgp_key_file(),
89
GNUTLS_OPENPGP_FMT_BASE64 */
99
GNUTLS_CRD_CERTIFICATE,
101
GNUTLS_E_INTERRUPTED,
103
GNUTLS_E_REHANDSHAKE,
105
#include <gnutls/openpgp.h> /* gnutls_certificate_set_openpgp_key_file(),
106
GNUTLS_OPENPGP_FMT_BASE64 */
92
#include <gpgme.h> /* All GPGME types, constants and functions
109
#include <gpgme.h> /* gpgme_data_t, gpgme_ctx_t,
110
gpgme_error_t, gpgme_engine_info_t,
111
gpgme_check_version(),
112
gpgme_engine_check_version(),
115
gpgme_get_engine_info(),
116
gpgme_set_engine_info(),
117
gpgme_data_new_from_mem(),
118
gpgme_data_new(), gpgme_new(),
120
gpgme_decrypt_result_t,
121
gpgme_op_decrypt_result(),
123
gpgme_pubkey_algo_name(),
94
127
GPGME_PROTOCOL_OpenPGP,
129
GPG_ERR_NO_SECKEY, */
97
131
#define BUFFER_SIZE 256
99
133
bool debug = false;
100
134
static const char *keydir = "/conf/conf.d/mandos";
101
135
static const char mandos_protocol_version[] = "1";
102
const char *argp_program_version = "password-request 1.0";
136
const char *argp_program_version = "mandosclient 0.9";
103
137
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
105
139
/* Used for passing in values through the Avahi callback functions */