263
262
rc = gpgme_data_new_from_fd(&pgp_data, fd);
264
263
if(rc != GPG_ERR_NO_ERROR){
265
fprintf_plus(stderr, "bad gpgme_data_new_from_fd: %s: %s\n",
266
gpgme_strsource(rc), gpgme_strerror(rc));
264
fprintf(stderr, "Mandos plugin mandos-client: "
265
"bad gpgme_data_new_from_fd: %s: %s\n",
266
gpgme_strsource(rc), gpgme_strerror(rc));
270
270
rc = gpgme_op_import(mc.ctx, pgp_data);
271
271
if(rc != GPG_ERR_NO_ERROR){
272
fprintf_plus(stderr, "bad gpgme_op_import: %s: %s\n",
273
gpgme_strsource(rc), gpgme_strerror(rc));
272
fprintf(stderr, "Mandos plugin mandos-client: "
273
"bad gpgme_op_import: %s: %s\n",
274
gpgme_strsource(rc), gpgme_strerror(rc));
286
fprintf_plus(stderr, "Initializing GPGME\n");
287
fprintf(stderr, "Mandos plugin mandos-client: "
288
"Initializing GPGME\n");
290
292
gpgme_check_version(NULL);
291
293
rc = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP);
292
294
if(rc != GPG_ERR_NO_ERROR){
293
fprintf_plus(stderr, "bad gpgme_engine_check_version: %s: %s\n",
294
gpgme_strsource(rc), gpgme_strerror(rc));
295
fprintf(stderr, "Mandos plugin mandos-client: "
296
"bad gpgme_engine_check_version: %s: %s\n",
297
gpgme_strsource(rc), gpgme_strerror(rc));
298
301
/* Set GPGME home directory for the OpenPGP engine only */
299
302
rc = gpgme_get_engine_info(&engine_info);
300
303
if(rc != GPG_ERR_NO_ERROR){
301
fprintf_plus(stderr, "bad gpgme_get_engine_info: %s: %s\n",
302
gpgme_strsource(rc), gpgme_strerror(rc));
304
fprintf(stderr, "Mandos plugin mandos-client: "
305
"bad gpgme_get_engine_info: %s: %s\n",
306
gpgme_strsource(rc), gpgme_strerror(rc));
305
309
while(engine_info != NULL){
311
315
engine_info = engine_info->next;
313
317
if(engine_info == NULL){
314
fprintf_plus(stderr, "Could not set GPGME home dir to %s\n",
318
fprintf(stderr, "Mandos plugin mandos-client: "
319
"Could not set GPGME home dir to %s\n", tempdir);
319
323
/* Create new GPGME "context" */
320
324
rc = gpgme_new(&(mc.ctx));
321
325
if(rc != GPG_ERR_NO_ERROR){
322
fprintf_plus(stderr, "Mandos plugin mandos-client: "
323
"bad gpgme_new: %s: %s\n", gpgme_strsource(rc),
326
fprintf(stderr, "Mandos plugin mandos-client: "
327
"bad gpgme_new: %s: %s\n", gpgme_strsource(rc),
346
350
ssize_t plaintext_length = 0;
349
fprintf_plus(stderr, "Trying to decrypt OpenPGP data\n");
353
fprintf(stderr, "Mandos plugin mandos-client: "
354
"Trying to decrypt OpenPGP data\n");
352
357
/* Create new GPGME data buffer from memory cryptotext */
353
358
rc = gpgme_data_new_from_mem(&dh_crypto, cryptotext, crypto_size,
355
360
if(rc != GPG_ERR_NO_ERROR){
356
fprintf_plus(stderr, "bad gpgme_data_new_from_mem: %s: %s\n",
357
gpgme_strsource(rc), gpgme_strerror(rc));
361
fprintf(stderr, "Mandos plugin mandos-client: "
362
"bad gpgme_data_new_from_mem: %s: %s\n",
363
gpgme_strsource(rc), gpgme_strerror(rc));
361
367
/* Create new empty GPGME data buffer for the plaintext */
362
368
rc = gpgme_data_new(&dh_plain);
363
369
if(rc != GPG_ERR_NO_ERROR){
364
fprintf_plus(stderr, "Mandos plugin mandos-client: "
365
"bad gpgme_data_new: %s: %s\n",
366
gpgme_strsource(rc), gpgme_strerror(rc));
370
fprintf(stderr, "Mandos plugin mandos-client: "
371
"bad gpgme_data_new: %s: %s\n",
372
gpgme_strsource(rc), gpgme_strerror(rc));
367
373
gpgme_data_release(dh_crypto);
373
379
rc = gpgme_op_decrypt(mc.ctx, dh_crypto, dh_plain);
374
380
if(rc != GPG_ERR_NO_ERROR){
375
fprintf_plus(stderr, "bad gpgme_op_decrypt: %s: %s\n",
376
gpgme_strsource(rc), gpgme_strerror(rc));
381
fprintf(stderr, "Mandos plugin mandos-client: "
382
"bad gpgme_op_decrypt: %s: %s\n",
383
gpgme_strsource(rc), gpgme_strerror(rc));
377
384
plaintext_length = -1;
379
386
gpgme_decrypt_result_t result;
380
387
result = gpgme_op_decrypt_result(mc.ctx);
381
388
if(result == NULL){
382
fprintf_plus(stderr, "gpgme_op_decrypt_result failed\n");
389
fprintf(stderr, "Mandos plugin mandos-client: "
390
"gpgme_op_decrypt_result failed\n");
384
fprintf_plus(stderr, "Unsupported algorithm: %s\n",
385
result->unsupported_algorithm);
386
fprintf_plus(stderr, "Wrong key usage: %u\n",
387
result->wrong_key_usage);
392
fprintf(stderr, "Mandos plugin mandos-client: "
393
"Unsupported algorithm: %s\n",
394
result->unsupported_algorithm);
395
fprintf(stderr, "Mandos plugin mandos-client: "
396
"Wrong key usage: %u\n",
397
result->wrong_key_usage);
388
398
if(result->file_name != NULL){
389
fprintf_plus(stderr, "File name: %s\n", result->file_name);
399
fprintf(stderr, "Mandos plugin mandos-client: "
400
"File name: %s\n", result->file_name);
391
402
gpgme_recipient_t recipient;
392
403
recipient = result->recipients;
393
404
while(recipient != NULL){
394
fprintf_plus(stderr, "Public key algorithm: %s\n",
395
gpgme_pubkey_algo_name
396
(recipient->pubkey_algo));
397
fprintf_plus(stderr, "Key ID: %s\n", recipient->keyid);
398
fprintf_plus(stderr, "Secret key available: %s\n",
399
recipient->status == GPG_ERR_NO_SECKEY
405
fprintf(stderr, "Mandos plugin mandos-client: "
406
"Public key algorithm: %s\n",
407
gpgme_pubkey_algo_name(recipient->pubkey_algo));
408
fprintf(stderr, "Mandos plugin mandos-client: "
409
"Key ID: %s\n", recipient->keyid);
410
fprintf(stderr, "Mandos plugin mandos-client: "
411
"Secret key available: %s\n",
412
recipient->status == GPG_ERR_NO_SECKEY
401
414
recipient = recipient->next;
482
fprintf_plus(stderr, "Initializing GnuTLS\n");
497
fprintf(stderr, "Mandos plugin mandos-client: "
498
"Initializing GnuTLS\n");
485
501
ret = gnutls_global_init();
486
502
if(ret != GNUTLS_E_SUCCESS){
487
fprintf_plus(stderr, "GnuTLS global_init: %s\n",
488
safer_gnutls_strerror(ret));
503
fprintf(stderr, "Mandos plugin mandos-client: "
504
"GnuTLS global_init: %s\n", safer_gnutls_strerror(ret));
500
516
/* OpenPGP credentials */
501
517
ret = gnutls_certificate_allocate_credentials(&mc.cred);
502
518
if(ret != GNUTLS_E_SUCCESS){
503
fprintf_plus(stderr, "GnuTLS memory error: %s\n",
504
safer_gnutls_strerror(ret));
519
fprintf(stderr, "Mandos plugin mandos-client: "
520
"GnuTLS memory error: %s\n", safer_gnutls_strerror(ret));
505
521
gnutls_global_deinit();
510
fprintf_plus(stderr, "Attempting to use OpenPGP public key %s and"
511
" secret key %s as GnuTLS credentials\n",
526
fprintf(stderr, "Mandos plugin mandos-client: "
527
"Attempting to use OpenPGP public key %s and"
528
" secret key %s as GnuTLS credentials\n", pubkeyfilename,
516
532
ret = gnutls_certificate_set_openpgp_key_file
517
533
(mc.cred, pubkeyfilename, seckeyfilename,
518
534
GNUTLS_OPENPGP_FMT_BASE64);
519
535
if(ret != GNUTLS_E_SUCCESS){
521
"Error[%d] while reading the OpenPGP key pair ('%s',"
522
" '%s')\n", ret, pubkeyfilename, seckeyfilename);
523
fprintf_plus(stderr, "The GnuTLS error is: %s\n",
524
safer_gnutls_strerror(ret));
537
"Mandos plugin mandos-client: "
538
"Error[%d] while reading the OpenPGP key pair ('%s',"
539
" '%s')\n", ret, pubkeyfilename, seckeyfilename);
540
fprintf(stderr, "Mandos plugin mandos-client: "
541
"The GnuTLS error is: %s\n", safer_gnutls_strerror(ret));
528
545
/* GnuTLS server initialization */
529
546
ret = gnutls_dh_params_init(&mc.dh_params);
530
547
if(ret != GNUTLS_E_SUCCESS){
531
fprintf_plus(stderr, "Error in GnuTLS DH parameter"
532
" initialization: %s\n",
533
safer_gnutls_strerror(ret));
548
fprintf(stderr, "Mandos plugin mandos-client: "
549
"Error in GnuTLS DH parameter initialization:"
550
" %s\n", safer_gnutls_strerror(ret));
536
553
ret = gnutls_dh_params_generate2(mc.dh_params, mc.dh_bits);
537
554
if(ret != GNUTLS_E_SUCCESS){
538
fprintf_plus(stderr, "Error in GnuTLS prime generation: %s\n",
539
safer_gnutls_strerror(ret));
555
fprintf(stderr, "Mandos plugin mandos-client: "
556
"Error in GnuTLS prime generation: %s\n",
557
safer_gnutls_strerror(ret));
563
581
} while(ret == GNUTLS_E_INTERRUPTED or ret == GNUTLS_E_AGAIN);
564
582
if(ret != GNUTLS_E_SUCCESS){
566
"Error in GnuTLS session initialization: %s\n",
567
safer_gnutls_strerror(ret));
583
fprintf(stderr, "Mandos plugin mandos-client: "
584
"Error in GnuTLS session initialization: %s\n",
585
safer_gnutls_strerror(ret));
578
596
} while(ret == GNUTLS_E_INTERRUPTED or ret == GNUTLS_E_AGAIN);
579
597
if(ret != GNUTLS_E_SUCCESS){
580
fprintf_plus(stderr, "Syntax error at: %s\n", err);
581
fprintf_plus(stderr, "GnuTLS error: %s\n",
582
safer_gnutls_strerror(ret));
598
fprintf(stderr, "Mandos plugin mandos-client: "
599
"Syntax error at: %s\n", err);
600
fprintf(stderr, "Mandos plugin mandos-client: "
601
"GnuTLS error: %s\n", safer_gnutls_strerror(ret));
583
602
gnutls_deinit(*session);
595
614
} while(ret == GNUTLS_E_INTERRUPTED or ret == GNUTLS_E_AGAIN);
596
615
if(ret != GNUTLS_E_SUCCESS){
597
fprintf_plus(stderr, "Error setting GnuTLS credentials: %s\n",
598
safer_gnutls_strerror(ret));
616
fprintf(stderr, "Mandos plugin mandos-client: "
617
"Error setting GnuTLS credentials: %s\n",
618
safer_gnutls_strerror(ret));
599
619
gnutls_deinit(*session);
703
726
(&to.in6.sin6_addr)){ /* -Wstrict-aliasing=2 or lower and
704
727
-Wunreachable-code*/
705
728
if(if_index == AVAHI_IF_UNSPEC){
706
fprintf_plus(stderr, "An IPv6 link-local address is"
707
" incomplete without a network interface\n");
729
fprintf(stderr, "Mandos plugin mandos-client: "
730
"An IPv6 link-local address is incomplete"
731
" without a network interface\n");
728
752
if(if_indextoname((unsigned int)if_index, interface) == NULL){
729
753
perror_plus("if_indextoname");
731
fprintf_plus(stderr, "Connection to: %s%%%s, port %" PRIu16
732
"\n", ip, interface, port);
755
fprintf(stderr, "Mandos plugin mandos-client: "
756
"Connection to: %s%%%s, port %" PRIu16 "\n",
757
ip, interface, port);
735
fprintf_plus(stderr, "Connection to: %s, port %" PRIu16 "\n",
760
fprintf(stderr, "Mandos plugin mandos-client: "
761
"Connection to: %s, port %" PRIu16 "\n", ip, port);
738
763
char addrstr[(INET_ADDRSTRLEN > INET6_ADDRSTRLEN) ?
739
764
INET_ADDRSTRLEN : INET6_ADDRSTRLEN] = "";
891
919
} while(ret == GNUTLS_E_AGAIN or ret == GNUTLS_E_INTERRUPTED);
893
fprintf_plus(stderr, "*** GnuTLS Re-handshake failed "
921
fprintf(stderr, "Mandos plugin mandos-client: "
922
"*** GnuTLS Re-handshake failed ***\n");
895
923
gnutls_perror(ret);
901
fprintf_plus(stderr, "Unknown error while reading data from"
902
" encrypted session with Mandos server\n");
929
fprintf(stderr, "Mandos plugin mandos-client: "
930
"Unknown error while reading data from"
931
" encrypted session with Mandos server\n");
903
932
gnutls_bye(session, GNUTLS_SHUT_RDWR);
1011
1042
case AVAHI_RESOLVER_FAILURE:
1012
fprintf_plus(stderr, "(Avahi Resolver) Failed to resolve service "
1013
"'%s' of type '%s' in domain '%s': %s\n", name, type,
1015
avahi_strerror(avahi_server_errno(mc.server)));
1043
fprintf(stderr, "Mandos plugin mandos-client: "
1044
"(Avahi Resolver) Failed to resolve service '%s'"
1045
" of type '%s' in domain '%s': %s\n", name, type, domain,
1046
avahi_strerror(avahi_server_errno(mc.server)));
1018
1049
case AVAHI_RESOLVER_FOUND:
1020
1051
char ip[AVAHI_ADDRESS_STR_MAX];
1021
1052
avahi_address_snprint(ip, sizeof(ip), address);
1023
fprintf_plus(stderr, "Mandos server \"%s\" found on %s (%s, %"
1024
PRIdMAX ") on port %" PRIu16 "\n", name,
1025
host_name, ip, (intmax_t)interface, port);
1054
fprintf(stderr, "Mandos plugin mandos-client: "
1055
"Mandos server \"%s\" found on %s (%s, %"
1056
PRIdMAX ") on port %" PRIu16 "\n", name, host_name,
1057
ip, (intmax_t)interface, port);
1027
1059
int ret = start_mandos_communication(ip, port, interface,
1028
1060
avahi_proto_to_af(proto));
1074
1107
if(avahi_s_service_resolver_new(mc.server, interface, protocol,
1075
1108
name, type, domain, protocol, 0,
1076
1109
resolve_callback, NULL) == NULL)
1077
fprintf_plus(stderr, "Avahi: Failed to resolve service '%s':"
1079
avahi_strerror(avahi_server_errno(mc.server)));
1110
fprintf(stderr, "Mandos plugin mandos-client: "
1111
"Avahi: Failed to resolve service '%s': %s\n",
1112
name, avahi_strerror(avahi_server_errno(mc.server)));
1082
1115
case AVAHI_BROWSER_REMOVE:
1131
1164
/* Reject the loopback device */
1132
1165
if(ifr->ifr_flags & IFF_LOOPBACK){
1134
fprintf_plus(stderr, "Rejecting loopback interface \"%s\"\n",
1167
fprintf(stderr, "Mandos plugin mandos-client: "
1168
"Rejecting loopback interface \"%s\"\n", ifname);
1139
1172
/* Accept point-to-point devices only if connect_to is specified */
1140
1173
if(connect_to != NULL and (ifr->ifr_flags & IFF_POINTOPOINT)){
1142
fprintf_plus(stderr, "Accepting point-to-point interface"
1143
" \"%s\"\n", ifname);
1175
fprintf(stderr, "Mandos plugin mandos-client: "
1176
"Accepting point-to-point interface \"%s\"\n", ifname);
1147
1180
/* Otherwise, reject non-broadcast-capable devices */
1148
1181
if(not (ifr->ifr_flags & IFF_BROADCAST)){
1150
fprintf_plus(stderr, "Rejecting non-broadcast interface"
1151
" \"%s\"\n", ifname);
1183
fprintf(stderr, "Mandos plugin mandos-client: "
1184
"Rejecting non-broadcast interface \"%s\"\n", ifname);
1155
1188
/* Reject non-ARP interfaces (including dummy interfaces) */
1156
1189
if(ifr->ifr_flags & IFF_NOARP){
1158
fprintf_plus(stderr, "Rejecting non-ARP interface \"%s\"\n",
1191
fprintf(stderr, "Mandos plugin mandos-client: "
1192
"Rejecting non-ARP interface \"%s\"\n", ifname);
1164
1197
/* Accept this device */
1166
fprintf_plus(stderr, "Interface \"%s\" is good\n", ifname);
1199
fprintf(stderr, "Mandos plugin mandos-client: "
1200
"Interface \"%s\" is good\n", ifname);
1288
1327
if(not (S_ISREG(st.st_mode))){
1289
1328
/* Not a regular file */
1291
fprintf_plus(stderr, "Ignoring hook \"%s\" - not a file\n",
1330
fprintf(stderr, "Mandos plugin mandos-client: "
1331
"Ignoring hook \"%s\" - not a file\n",
1296
1336
if(not (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))){
1297
1337
/* Not executable */
1299
fprintf_plus(stderr, "Ignoring hook \"%s\" - not executable\n",
1339
fprintf(stderr, "Mandos plugin mandos-client: "
1340
"Ignoring hook \"%s\" - not executable\n",
1314
1355
if(mc.current_server == NULL){
1316
fprintf_plus(stderr, "Wait until first server is found."
1357
fprintf(stderr, "Mandos plugin mandos-client: "
1358
"Wait until first server is found. No timeout!\n");
1319
1360
ret = avahi_simple_poll_iterate(s, -1);
1322
fprintf_plus(stderr, "Check current_server if we should run"
1363
fprintf(stderr, "Mandos plugin mandos-client: "
1364
"Check current_server if we should run it,"
1325
1367
/* the current time */
1326
1368
ret = clock_gettime(CLOCK_MONOTONIC, &now);
1379
bool run_network_hooks(const char *mode, const char *interface,
1381
struct dirent **direntries;
1382
struct dirent *direntry;
1384
int numhooks = scandir(hookdir, &direntries, runnable_hook,
1387
perror_plus("scandir");
1389
int devnull = open("/dev/null", O_RDONLY);
1390
for(int i = 0; i < numhooks; i++){
1391
direntry = direntries[0];
1392
char *fullname = NULL;
1393
ret = asprintf(&fullname, "%s/%s", hookdir, direntry->d_name);
1395
perror_plus("asprintf");
1398
pid_t hook_pid = fork();
1401
dup2(devnull, STDIN_FILENO);
1403
dup2(STDERR_FILENO, STDOUT_FILENO);
1404
ret = setenv("MANDOSNETHOOKDIR", hookdir, 1);
1406
perror_plus("setenv");
1409
ret = setenv("DEVICE", interface, 1);
1411
perror_plus("setenv");
1414
ret = setenv("VERBOSE", debug ? "1" : "0", 1);
1416
perror_plus("setenv");
1419
ret = setenv("MODE", mode, 1);
1421
perror_plus("setenv");
1425
ret = asprintf(&delaystring, "%f", delay);
1427
perror_plus("asprintf");
1430
ret = setenv("DELAY", delaystring, 1);
1433
perror_plus("setenv");
1437
ret = execl(fullname, direntry->d_name, mode, NULL);
1438
perror_plus("execl");
1441
if(TEMP_FAILURE_RETRY(waitpid(hook_pid, &status, 0)) == -1){
1442
perror_plus("waitpid");
1446
if(WIFEXITED(status)){
1447
if(WEXITSTATUS(status) != 0){
1448
fprintf_plus(stderr, "Warning: network hook \"%s\" exited"
1449
" with status %d\n", direntry->d_name,
1450
WEXITSTATUS(status));
1454
} else if(WIFSIGNALED(status)){
1455
fprintf_plus(stderr, "Warning: network hook \"%s\" died by"
1456
" signal %d\n", direntry->d_name,
1461
fprintf_plus(stderr, "Warning: network hook \"%s\""
1462
" crashed\n", direntry->d_name);
1477
1421
int main(int argc, char *argv[]){
1478
1422
AvahiSServiceBrowser *sb = NULL;
1637
1581
argp_state_help(state, state->out_stream,
1638
1582
ARGP_HELP_USAGE | ARGP_HELP_EXIT_ERR);
1639
1583
case 'V': /* --version */
1640
fprintf_plus(state->out_stream,
1641
"Mandos plugin mandos-client: ");
1642
fprintf_plus(state->out_stream, "%s\n", argp_program_version);
1584
fprintf(state->out_stream, "Mandos plugin mandos-client: ");
1585
fprintf(state->out_stream, "%s\n", argp_program_version);
1643
1586
exit(argp_err_exit_status);
1734
/* Run network hooks */
1675
/* Find network hooks and run them */
1736
/* Re-raise priviliges */
1740
perror_plus("seteuid");
1742
if(not run_network_hooks("start", interface, delay)){
1745
/* Lower privileges */
1749
perror_plus("seteuid");
1677
struct dirent **direntries;
1678
struct dirent *direntry;
1679
int numhooks = scandir(hookdir, &direntries, runnable_hook,
1682
perror_plus("scandir");
1684
int devnull = open("/dev/null", O_RDONLY);
1685
for(int i = 0; i < numhooks; i++){
1686
direntry = direntries[0];
1687
char *fullname = NULL;
1688
ret = asprintf(&fullname, "%s/%s", hookdir, direntry->d_name);
1690
perror_plus("asprintf");
1693
pid_t hook_pid = fork();
1696
dup2(devnull, STDIN_FILENO);
1698
dup2(STDERR_FILENO, STDOUT_FILENO);
1699
ret = setenv("MANDOSNETHOOKDIR", hookdir, 1);
1701
perror_plus("setenv");
1704
ret = setenv("DEVICE", interface, 1);
1706
perror_plus("setenv");
1709
ret = setenv("VERBOSE", debug ? "1" : "0", 1);
1711
perror_plus("setenv");
1714
ret = setenv("MODE", "start", 1);
1716
perror_plus("setenv");
1720
ret = asprintf(&delaystring, "%f", delay);
1722
perror_plus("asprintf");
1725
ret = setenv("DELAY", delaystring, 1);
1728
perror_plus("setenv");
1732
ret = execl(fullname, direntry->d_name, "start", NULL);
1733
perror_plus("execl");
1736
if(TEMP_FAILURE_RETRY(waitpid(hook_pid, &status, 0)) == -1){
1737
perror_plus("waitpid");
1741
if(WIFEXITED(status)){
1742
if(WEXITSTATUS(status) != 0){
1743
fprintf(stderr, "Mandos plugin mandos-client: "
1744
"Warning: network hook \"%s\" exited"
1745
" with status %d\n", direntry->d_name,
1746
WEXITSTATUS(status));
1750
} else if(WIFSIGNALED(status)){
1751
fprintf(stderr, "Mandos plugin mandos-client: "
1752
"Warning: network hook \"%s\" died by"
1753
" signal %d\n", direntry->d_name,
1758
fprintf(stderr, "Mandos plugin mandos-client: "
1759
"Warning: network hook \"%s\" crashed\n",
1865
1888
if(strcmp(interface, "none") != 0){
1866
1889
if_index = (AvahiIfIndex) if_nametoindex(interface);
1867
1890
if(if_index == 0){
1868
fprintf_plus(stderr, "No such interface: \"%s\"\n", interface);
1891
fprintf(stderr, "Mandos plugin mandos-client: "
1892
"No such interface: \"%s\"\n", interface);
1869
1893
exitcode = EX_UNAVAILABLE;
2144
2181
AVAHI_PROTO_UNSPEC, "_mandos._tcp",
2145
2182
NULL, 0, browse_callback, NULL);
2146
2183
if(sb == NULL){
2147
fprintf_plus(stderr, "Failed to create service browser: %s\n",
2148
avahi_strerror(avahi_server_errno(mc.server)));
2184
fprintf(stderr, "Mandos plugin mandos-client: "
2185
"Failed to create service browser: %s\n",
2186
avahi_strerror(avahi_server_errno(mc.server)));
2149
2187
exitcode = EX_UNAVAILABLE;
2157
2195
/* Run the main loop */
2160
fprintf_plus(stderr, "Starting Avahi loop search\n");
2198
fprintf(stderr, "Mandos plugin mandos-client: "
2199
"Starting Avahi loop search\n");
2163
2202
ret = avahi_loop_with_timeout(mc.simple_poll,
2164
2203
(int)(retry_interval * 1000));
2166
fprintf_plus(stderr, "avahi_loop_with_timeout exited %s\n",
2167
(ret == 0) ? "successfully" : "with error");
2205
fprintf(stderr, "Mandos plugin mandos-client: "
2206
"avahi_loop_with_timeout exited %s\n",
2207
(ret == 0) ? "successfully" : "with error");
2173
fprintf_plus(stderr, "%s exiting\n", argv[0]);
2213
fprintf(stderr, "Mandos plugin mandos-client: "
2214
"%s exiting\n", argv[0]);
2176
2217
/* Cleanup things */
2207
/* Re-raise priviliges */
2248
/* XXX run network hooks "stop" here */
2250
/* Take down the network interface */
2251
if(take_down_interface){
2252
/* Re-raise priviliges */
2210
2254
ret = seteuid(0);
2212
2256
perror_plus("seteuid");
2214
/* Run network hooks */
2215
if(not run_network_hooks("stop", interface, delay)){
2219
/* Take down the network interface */
2220
if(take_down_interface and geteuid() == 0){
2221
2259
ret = ioctl(sd, SIOCGIFFLAGS, &network);
2223
2261
perror_plus("ioctl SIOCGIFFLAGS");