53
53
sockaddr_in6, PF_INET6,
54
54
SOCK_STREAM, uid_t, gid_t, open(),
56
#include <sys/stat.h> /* open() */
56
#include <sys/stat.h> /* open(), S_ISREG */
57
57
#include <sys/socket.h> /* socket(), struct sockaddr_in6,
58
58
inet_pton(), connect() */
59
59
#include <fcntl.h> /* open() */
86
86
#include <sysexits.h> /* EX_OSERR, EX_USAGE, EX_UNAVAILABLE,
87
87
EX_NOHOST, EX_IOERR, EX_PROTOCOL */
88
#include <sys/wait.h> /* waitpid(), WIFEXITED(),
89
WEXITSTATUS(), WTERMSIG() */
90
92
#include <sys/klog.h> /* klogctl() */
171
174
perror(print_text);
174
int fprintf_plus(FILE *stream, const char *format, ...){
176
va_start (ap, format);
178
TEMP_FAILURE_RETRY(fprintf(stream, "Mandos plugin %s: ", program_invocation_short_name));
179
return TEMP_FAILURE_RETRY(vfprintf(stream, format, ap));
183
178
* Make additional room in "buffer" for at least BUFFER_SIZE more
184
179
* bytes. "buffer_capacity" is how much is currently allocated,
185
180
* "buffer_length" is how much is already used.
187
182
size_t incbuffer(char **buffer, size_t buffer_length,
188
size_t buffer_capacity){
183
size_t buffer_capacity){
189
184
if(buffer_length + BUFFER_SIZE > buffer_capacity){
190
185
*buffer = realloc(*buffer, buffer_capacity + BUFFER_SIZE);
191
186
if(buffer == NULL){
260
254
rc = gpgme_data_new_from_fd(&pgp_data, fd);
261
255
if(rc != GPG_ERR_NO_ERROR){
262
fprintf(stderr, "bad gpgme_data_new_from_fd: %s: %s\n",
256
fprintf(stderr, "Mandos plugin mandos-client: "
257
"bad gpgme_data_new_from_fd: %s: %s\n",
263
258
gpgme_strsource(rc), gpgme_strerror(rc));
267
262
rc = gpgme_op_import(mc.ctx, pgp_data);
268
263
if(rc != GPG_ERR_NO_ERROR){
269
fprintf(stderr, "bad gpgme_op_import: %s: %s\n",
264
fprintf(stderr, "Mandos plugin mandos-client: "
265
"bad gpgme_op_import: %s: %s\n",
270
266
gpgme_strsource(rc), gpgme_strerror(rc));
283
fprintf(stderr, "Initializing GPGME\n");
279
fprintf(stderr, "Mandos plugin mandos-client: "
280
"Initializing GPGME\n");
287
284
gpgme_check_version(NULL);
288
285
rc = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP);
289
286
if(rc != GPG_ERR_NO_ERROR){
290
fprintf(stderr, "bad gpgme_engine_check_version: %s: %s\n",
287
fprintf(stderr, "Mandos plugin mandos-client: "
288
"bad gpgme_engine_check_version: %s: %s\n",
291
289
gpgme_strsource(rc), gpgme_strerror(rc));
295
293
/* Set GPGME home directory for the OpenPGP engine only */
296
294
rc = gpgme_get_engine_info(&engine_info);
297
295
if(rc != GPG_ERR_NO_ERROR){
298
fprintf(stderr, "bad gpgme_get_engine_info: %s: %s\n",
296
fprintf(stderr, "Mandos plugin mandos-client: "
297
"bad gpgme_get_engine_info: %s: %s\n",
299
298
gpgme_strsource(rc), gpgme_strerror(rc));
308
307
engine_info = engine_info->next;
310
309
if(engine_info == NULL){
311
fprintf(stderr, "Could not set GPGME home dir to %s\n", tempdir);
310
fprintf(stderr, "Mandos plugin mandos-client: "
311
"Could not set GPGME home dir to %s\n", tempdir);
315
315
/* Create new GPGME "context" */
316
316
rc = gpgme_new(&(mc.ctx));
317
317
if(rc != GPG_ERR_NO_ERROR){
318
fprintf(stderr, "bad gpgme_new: %s: %s\n",
319
gpgme_strsource(rc), gpgme_strerror(rc));
318
fprintf(stderr, "Mandos plugin mandos-client: "
319
"bad gpgme_new: %s: %s\n", gpgme_strsource(rc),
341
342
ssize_t plaintext_length = 0;
344
fprintf(stderr, "Trying to decrypt OpenPGP data\n");
345
fprintf(stderr, "Mandos plugin mandos-client: "
346
"Trying to decrypt OpenPGP data\n");
347
349
/* Create new GPGME data buffer from memory cryptotext */
348
350
rc = gpgme_data_new_from_mem(&dh_crypto, cryptotext, crypto_size,
350
352
if(rc != GPG_ERR_NO_ERROR){
351
fprintf(stderr, "bad gpgme_data_new_from_mem: %s: %s\n",
353
fprintf(stderr, "Mandos plugin mandos-client: "
354
"bad gpgme_data_new_from_mem: %s: %s\n",
352
355
gpgme_strsource(rc), gpgme_strerror(rc));
356
359
/* Create new empty GPGME data buffer for the plaintext */
357
360
rc = gpgme_data_new(&dh_plain);
358
361
if(rc != GPG_ERR_NO_ERROR){
359
fprintf(stderr, "bad gpgme_data_new: %s: %s\n",
362
fprintf(stderr, "Mandos plugin mandos-client: "
363
"bad gpgme_data_new: %s: %s\n",
360
364
gpgme_strsource(rc), gpgme_strerror(rc));
361
365
gpgme_data_release(dh_crypto);
367
371
rc = gpgme_op_decrypt(mc.ctx, dh_crypto, dh_plain);
368
372
if(rc != GPG_ERR_NO_ERROR){
369
fprintf(stderr, "bad gpgme_op_decrypt: %s: %s\n",
373
fprintf(stderr, "Mandos plugin mandos-client: "
374
"bad gpgme_op_decrypt: %s: %s\n",
370
375
gpgme_strsource(rc), gpgme_strerror(rc));
371
376
plaintext_length = -1;
373
378
gpgme_decrypt_result_t result;
374
379
result = gpgme_op_decrypt_result(mc.ctx);
375
380
if(result == NULL){
376
fprintf(stderr, "gpgme_op_decrypt_result failed\n");
381
fprintf(stderr, "Mandos plugin mandos-client: "
382
"gpgme_op_decrypt_result failed\n");
378
fprintf(stderr, "Unsupported algorithm: %s\n",
384
fprintf(stderr, "Mandos plugin mandos-client: "
385
"Unsupported algorithm: %s\n",
379
386
result->unsupported_algorithm);
380
fprintf(stderr, "Wrong key usage: %u\n",
387
fprintf(stderr, "Mandos plugin mandos-client: "
388
"Wrong key usage: %u\n",
381
389
result->wrong_key_usage);
382
390
if(result->file_name != NULL){
383
fprintf(stderr, "File name: %s\n", result->file_name);
391
fprintf(stderr, "Mandos plugin mandos-client: "
392
"File name: %s\n", result->file_name);
385
394
gpgme_recipient_t recipient;
386
395
recipient = result->recipients;
387
396
while(recipient != NULL){
388
fprintf(stderr, "Public key algorithm: %s\n",
397
fprintf(stderr, "Mandos plugin mandos-client: "
398
"Public key algorithm: %s\n",
389
399
gpgme_pubkey_algo_name(recipient->pubkey_algo));
390
fprintf(stderr, "Key ID: %s\n", recipient->keyid);
391
fprintf(stderr, "Secret key available: %s\n",
400
fprintf(stderr, "Mandos plugin mandos-client: "
401
"Key ID: %s\n", recipient->keyid);
402
fprintf(stderr, "Mandos plugin mandos-client: "
403
"Secret key available: %s\n",
392
404
recipient->status == GPG_ERR_NO_SECKEY
394
406
recipient = recipient->next;
412
425
*plaintext = NULL;
414
427
plaintext_capacity = incbuffer(plaintext,
415
(size_t)plaintext_length,
428
(size_t)plaintext_length,
417
430
if(plaintext_capacity == 0){
418
perror_plus("incbuffer");
419
plaintext_length = -1;
431
perror_plus("incbuffer");
432
plaintext_length = -1;
423
436
ret = gpgme_data_read(dh_plain, *plaintext + plaintext_length,
475
fprintf(stderr, "Initializing GnuTLS\n");
489
fprintf(stderr, "Mandos plugin mandos-client: "
490
"Initializing GnuTLS\n");
478
493
ret = gnutls_global_init();
479
494
if(ret != GNUTLS_E_SUCCESS){
480
fprintf(stderr, "GnuTLS global_init: %s\n",
481
safer_gnutls_strerror(ret));
495
fprintf(stderr, "Mandos plugin mandos-client: "
496
"GnuTLS global_init: %s\n", safer_gnutls_strerror(ret));
493
508
/* OpenPGP credentials */
494
509
ret = gnutls_certificate_allocate_credentials(&mc.cred);
495
510
if(ret != GNUTLS_E_SUCCESS){
496
fprintf(stderr, "GnuTLS memory error: %s\n",
497
safer_gnutls_strerror(ret));
511
fprintf(stderr, "Mandos plugin mandos-client: "
512
"GnuTLS memory error: %s\n", safer_gnutls_strerror(ret));
498
513
gnutls_global_deinit();
503
fprintf(stderr, "Attempting to use OpenPGP public key %s and"
518
fprintf(stderr, "Mandos plugin mandos-client: "
519
"Attempting to use OpenPGP public key %s and"
504
520
" secret key %s as GnuTLS credentials\n", pubkeyfilename,
510
526
GNUTLS_OPENPGP_FMT_BASE64);
511
527
if(ret != GNUTLS_E_SUCCESS){
529
"Mandos plugin mandos-client: "
513
530
"Error[%d] while reading the OpenPGP key pair ('%s',"
514
531
" '%s')\n", ret, pubkeyfilename, seckeyfilename);
515
fprintf(stderr, "The GnuTLS error is: %s\n",
516
safer_gnutls_strerror(ret));
532
fprintf(stderr, "Mandos plugin mandos-client: "
533
"The GnuTLS error is: %s\n", safer_gnutls_strerror(ret));
520
537
/* GnuTLS server initialization */
521
538
ret = gnutls_dh_params_init(&mc.dh_params);
522
539
if(ret != GNUTLS_E_SUCCESS){
523
fprintf(stderr, "Error in GnuTLS DH parameter initialization:"
540
fprintf(stderr, "Mandos plugin mandos-client: "
541
"Error in GnuTLS DH parameter initialization:"
524
542
" %s\n", safer_gnutls_strerror(ret));
527
545
ret = gnutls_dh_params_generate2(mc.dh_params, mc.dh_bits);
528
546
if(ret != GNUTLS_E_SUCCESS){
529
fprintf(stderr, "Error in GnuTLS prime generation: %s\n",
547
fprintf(stderr, "Mandos plugin mandos-client: "
548
"Error in GnuTLS prime generation: %s\n",
530
549
safer_gnutls_strerror(ret));
568
588
} while(ret == GNUTLS_E_INTERRUPTED or ret == GNUTLS_E_AGAIN);
569
589
if(ret != GNUTLS_E_SUCCESS){
570
fprintf(stderr, "Syntax error at: %s\n", err);
571
fprintf(stderr, "GnuTLS error: %s\n",
572
safer_gnutls_strerror(ret));
590
fprintf(stderr, "Mandos plugin mandos-client: "
591
"Syntax error at: %s\n", err);
592
fprintf(stderr, "Mandos plugin mandos-client: "
593
"GnuTLS error: %s\n", safer_gnutls_strerror(ret));
573
594
gnutls_deinit(*session);
718
744
if(if_indextoname((unsigned int)if_index, interface) == NULL){
719
745
perror_plus("if_indextoname");
721
fprintf(stderr, "Connection to: %s%%%s, port %" PRIu16 "\n",
747
fprintf(stderr, "Mandos plugin mandos-client: "
748
"Connection to: %s%%%s, port %" PRIu16 "\n",
722
749
ip, interface, port);
725
fprintf(stderr, "Connection to: %s, port %" PRIu16 "\n", ip,
752
fprintf(stderr, "Mandos plugin mandos-client: "
753
"Connection to: %s, port %" PRIu16 "\n", ip, port);
728
755
char addrstr[(INET_ADDRSTRLEN > INET6_ADDRSTRLEN) ?
729
756
INET_ADDRSTRLEN : INET6_ADDRSTRLEN] = "";
881
911
} while(ret == GNUTLS_E_AGAIN or ret == GNUTLS_E_INTERRUPTED);
883
fprintf(stderr, "*** GnuTLS Re-handshake failed ***\n");
913
fprintf(stderr, "Mandos plugin mandos-client: "
914
"*** GnuTLS Re-handshake failed ***\n");
884
915
gnutls_perror(ret);
890
fprintf(stderr, "Unknown error while reading data from"
921
fprintf(stderr, "Mandos plugin mandos-client: "
922
"Unknown error while reading data from"
891
923
" encrypted session with Mandos server\n");
892
924
gnutls_bye(session, GNUTLS_SHUT_RDWR);
1001
1034
case AVAHI_RESOLVER_FAILURE:
1002
fprintf(stderr, "(Avahi Resolver) Failed to resolve service '%s'"
1035
fprintf(stderr, "Mandos plugin mandos-client: "
1036
"(Avahi Resolver) Failed to resolve service '%s'"
1003
1037
" of type '%s' in domain '%s': %s\n", name, type, domain,
1004
1038
avahi_strerror(avahi_server_errno(mc.server)));
1009
1043
char ip[AVAHI_ADDRESS_STR_MAX];
1010
1044
avahi_address_snprint(ip, sizeof(ip), address);
1012
fprintf(stderr, "Mandos server \"%s\" found on %s (%s, %"
1046
fprintf(stderr, "Mandos plugin mandos-client: "
1047
"Mandos server \"%s\" found on %s (%s, %"
1013
1048
PRIdMAX ") on port %" PRIu16 "\n", name, host_name,
1014
1049
ip, (intmax_t)interface, port);
1063
1099
if(avahi_s_service_resolver_new(mc.server, interface, protocol,
1064
1100
name, type, domain, protocol, 0,
1065
1101
resolve_callback, NULL) == NULL)
1066
fprintf(stderr, "Avahi: Failed to resolve service '%s': %s\n",
1102
fprintf(stderr, "Mandos plugin mandos-client: "
1103
"Avahi: Failed to resolve service '%s': %s\n",
1067
1104
name, avahi_strerror(avahi_server_errno(mc.server)));
1118
1156
/* Reject the loopback device */
1119
1157
if(ifr->ifr_flags & IFF_LOOPBACK){
1121
fprintf(stderr, "Rejecting loopback interface \"%s\"\n",
1159
fprintf(stderr, "Mandos plugin mandos-client: "
1160
"Rejecting loopback interface \"%s\"\n", ifname);
1126
1164
/* Accept point-to-point devices only if connect_to is specified */
1127
1165
if(connect_to != NULL and (ifr->ifr_flags & IFF_POINTOPOINT)){
1129
fprintf(stderr, "Accepting point-to-point interface \"%s\"\n",
1167
fprintf(stderr, "Mandos plugin mandos-client: "
1168
"Accepting point-to-point interface \"%s\"\n", ifname);
1134
1172
/* Otherwise, reject non-broadcast-capable devices */
1135
1173
if(not (ifr->ifr_flags & IFF_BROADCAST)){
1137
fprintf(stderr, "Rejecting non-broadcast interface \"%s\"\n",
1175
fprintf(stderr, "Mandos plugin mandos-client: "
1176
"Rejecting non-broadcast interface \"%s\"\n", ifname);
1142
1180
/* Reject non-ARP interfaces (including dummy interfaces) */
1143
1181
if(ifr->ifr_flags & IFF_NOARP){
1145
fprintf(stderr, "Rejecting non-ARP interface \"%s\"\n", ifname);
1183
fprintf(stderr, "Mandos plugin mandos-client: "
1184
"Rejecting non-ARP interface \"%s\"\n", ifname);
1150
1189
/* Accept this device */
1152
fprintf(stderr, "Interface \"%s\" is good\n", ifname);
1191
fprintf(stderr, "Mandos plugin mandos-client: "
1192
"Interface \"%s\" is good\n", ifname);
1182
1226
* (This function is passed to scandir(3) as a filter function.)
1184
1228
int up_interface(const struct dirent *if_entry){
1186
char *flagname = NULL;
1187
1229
if(if_entry->d_name[0] == '.'){
1190
int ret = asprintf(&flagname, "%s/%s/flags", sys_class_net,
1193
perror_plus("asprintf");
1196
int flags_fd = (int)TEMP_FAILURE_RETRY(open(flagname, O_RDONLY));
1198
perror_plus("open");
1203
typedef short ifreq_flags; /* ifreq.ifr_flags in netdevice(7) */
1204
/* read line from flags_fd */
1205
ssize_t to_read = 2+(sizeof(ifreq_flags)*2)+1; /* "0x1003\n" */
1206
char *flagstring = malloc((size_t)to_read+1); /* +1 for final \0 */
1207
flagstring[(size_t)to_read] = '\0';
1208
if(flagstring == NULL){
1209
perror_plus("malloc");
1214
ssret = (ssize_t)TEMP_FAILURE_RETRY(read(flags_fd, flagstring,
1217
perror_plus("read");
1231
tmpmax = strtoimax(flagstring, &tmp, 0);
1232
if(errno != 0 or tmp == flagstring or (*tmp != '\0'
1233
and not (isspace(*tmp)))
1234
or tmpmax != (ifreq_flags)tmpmax){
1236
fprintf(stderr, "Invalid flags \"%s\" for interface \"%s\"\n",
1237
flagstring, if_entry->d_name);
1243
ifreq_flags flags = (ifreq_flags)tmpmax;
1244
/* Reject the loopback device */
1245
if(flags & IFF_LOOPBACK){
1247
fprintf(stderr, "Rejecting loopback interface \"%s\"\n",
1234
if(not get_flags(if_entry->d_name, &ifr)){
1236
fprintf(stderr, "Mandos plugin mandos-client: "
1237
"Failed to get flags for interface \"%s\"\n",
1248
1238
if_entry->d_name);
1253
1243
/* Reject down interfaces */
1254
if(not (flags & IFF_UP)){
1258
/* Accept point-to-point devices only if connect_to is specified */
1259
if(connect_to != NULL and (flags & IFF_POINTOPOINT)){
1261
fprintf(stderr, "Accepting point-to-point interface \"%s\"\n",
1266
/* Otherwise, reject non-broadcast-capable devices */
1267
if(not (flags & IFF_BROADCAST)){
1269
fprintf(stderr, "Rejecting non-broadcast interface \"%s\"\n",
1274
/* Reject non-ARP interfaces (including dummy interfaces) */
1275
if(flags & IFF_NOARP){
1277
fprintf(stderr, "Rejecting non-ARP interface \"%s\"\n",
1282
/* Accept this device */
1284
fprintf(stderr, "Interface \"%s\" is acceptable\n",
1244
if(not (ifr.ifr_flags & IFF_UP)){
1246
fprintf(stderr, "Mandos plugin mandos-client: "
1247
"Rejecting down interface \"%s\"\n",
1253
/* Reject non-running interfaces */
1254
if(not (ifr.ifr_flags & IFF_RUNNING)){
1256
fprintf(stderr, "Mandos plugin mandos-client: "
1257
"Rejecting non-running interface \"%s\"\n",
1263
if(not good_flags(if_entry->d_name, &ifr)){
1311
/* Save pointer to last character */
1312
char *end = strchr(direntry->d_name, '\0')-1;
1319
if(((direntry->d_name)[0] == '#')
1321
/* Temporary #name# */
1325
/* XXX more rules here */
1327
ret = stat(direntry->d_name, &st);
1291
sret = strspn(direntry->d_name, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1292
"abcdefghijklmnopqrstuvwxyz"
1295
if((direntry->d_name)[sret] != '\0'){
1296
/* Contains non-allowed characters */
1298
fprintf(stderr, "Mandos plugin mandos-client: "
1299
"Ignoring hook \"%s\" with bad name\n",
1305
char *fullname = NULL;
1306
ret = asprintf(&fullname, "%s/%s", hookdir, direntry->d_name);
1308
perror_plus("asprintf");
1312
ret = stat(fullname, &st);
1330
perror_plus("Could not stat plugin");
1315
perror_plus("Could not stat hook");
1334
if(not (st.st_mode & S_ISREG)){
1319
if(not (S_ISREG(st.st_mode))){
1335
1320
/* Not a regular file */
1322
fprintf(stderr, "Mandos plugin mandos-client: "
1323
"Ignoring hook \"%s\" - not a file\n",
1338
1328
if(not (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))){
1339
1329
/* Not executable */
1331
fprintf(stderr, "Mandos plugin mandos-client: "
1332
"Ignoring hook \"%s\" - not executable\n",
1352
1347
if(mc.current_server == NULL){
1349
fprintf(stderr, "Mandos plugin mandos-client: "
1355
1350
"Wait until first server is found. No timeout!\n");
1357
1352
ret = avahi_simple_poll_iterate(s, -1);
1360
fprintf(stderr, "Check current_server if we should run it,"
1355
fprintf(stderr, "Mandos plugin mandos-client: "
1356
"Check current_server if we should run it,"
1363
1359
/* the current time */
1664
1669
struct dirent **direntries;
1665
1670
struct dirent *direntry;
1666
int numhooks = scandir(HOOKDIR, &direntries, runnable_hook,
1671
int numhooks = scandir(hookdir, &direntries, runnable_hook,
1668
int devnull = open("/dev/null", O_RDONLY);
1669
for(int i = 0; i < numhooks; i++){
1670
direntry = direntries[0];
1671
char *fullname = NULL;
1672
ret = asprintf(&fullname, "%s/%s", tempdir,
1675
perror_plus("asprintf");
1678
pid_t hook_pid = fork();
1681
dup2(devnull, STDIN_FILENO);
1683
dup2(STDERR_FILENO, STDOUT_FILENO);
1684
setenv("DEVICE", interface, 1);
1685
setenv("VERBOSE", debug ? "1" : "0", 1);
1686
setenv("MODE", "start", 1);
1687
/* setenv( XXX more here */
1688
ret = execl(fullname, direntry->d_name, "start");
1689
perror_plus("execl");
1674
perror_plus("scandir");
1676
int devnull = open("/dev/null", O_RDONLY);
1677
for(int i = 0; i < numhooks; i++){
1678
direntry = direntries[0];
1679
char *fullname = NULL;
1680
ret = asprintf(&fullname, "%s/%s", hookdir, direntry->d_name);
1682
perror_plus("asprintf");
1685
pid_t hook_pid = fork();
1688
dup2(devnull, STDIN_FILENO);
1690
dup2(STDERR_FILENO, STDOUT_FILENO);
1691
ret = setenv("DEVICE", interface, 1);
1693
perror_plus("setenv");
1696
ret = setenv("VERBOSE", debug ? "1" : "0", 1);
1698
perror_plus("setenv");
1701
ret = setenv("MODE", "start", 1);
1703
perror_plus("setenv");
1707
ret = asprintf(&delaystring, "%f", delay);
1709
perror_plus("asprintf");
1712
ret = setenv("DELAY", delaystring, 1);
1715
perror_plus("setenv");
1719
ret = execl(fullname, direntry->d_name, "start", NULL);
1720
perror_plus("execl");
1723
if(TEMP_FAILURE_RETRY(waitpid(hook_pid, &status, 0)) == -1){
1724
perror_plus("waitpid");
1728
if(WIFEXITED(status)){
1729
if(WEXITSTATUS(status) != 0){
1730
fprintf(stderr, "Mandos plugin mandos-client: "
1731
"Warning: network hook \"%s\" exited"
1732
" with status %d\n", direntry->d_name,
1733
WEXITSTATUS(status));
1737
} else if(WIFSIGNALED(status)){
1738
fprintf(stderr, "Mandos plugin mandos-client: "
1739
"Warning: network hook \"%s\" died by"
1740
" signal %d\n", direntry->d_name,
1745
fprintf(stderr, "Mandos plugin mandos-client: "
1746
"Warning: network hook \"%s\" crashed\n",
1703
1765
if(interface[0] == '\0'){
1704
1766
struct dirent **direntries;
1705
ret = scandir(sys_class_net, &direntries, good_interface,
1767
/* First look for interfaces that are up */
1768
ret = scandir(sys_class_net, &direntries, up_interface,
1771
/* No up interfaces, look for any good interfaces */
1773
ret = scandir(sys_class_net, &direntries, good_interface,
1708
/* Pick the first good interface */
1777
/* Pick the first interface returned */
1709
1778
interface = strdup(direntries[0]->d_name);
1711
fprintf(stderr, "Using interface \"%s\"\n", interface);
1780
fprintf(stderr, "Mandos plugin mandos-client: "
1781
"Using interface \"%s\"\n", interface);
1713
1783
if(interface == NULL){
1714
1784
perror_plus("malloc");
1803
1875
if(strcmp(interface, "none") != 0){
1804
1876
if_index = (AvahiIfIndex) if_nametoindex(interface);
1805
1877
if(if_index == 0){
1806
fprintf(stderr, "No such interface: \"%s\"\n", interface);
1878
fprintf(stderr, "Mandos plugin mandos-client: "
1879
"No such interface: \"%s\"\n", interface);
1807
1880
exitcode = EX_UNAVAILABLE;
2090
2168
AVAHI_PROTO_UNSPEC, "_mandos._tcp",
2091
2169
NULL, 0, browse_callback, NULL);
2092
2170
if(sb == NULL){
2093
fprintf(stderr, "Failed to create service browser: %s\n",
2171
fprintf(stderr, "Mandos plugin mandos-client: "
2172
"Failed to create service browser: %s\n",
2094
2173
avahi_strerror(avahi_server_errno(mc.server)));
2095
2174
exitcode = EX_UNAVAILABLE;
2103
2182
/* Run the main loop */
2106
fprintf(stderr, "Starting Avahi loop search\n");
2185
fprintf(stderr, "Mandos plugin mandos-client: "
2186
"Starting Avahi loop search\n");
2109
2189
ret = avahi_loop_with_timeout(mc.simple_poll,
2110
2190
(int)(retry_interval * 1000));
2112
fprintf(stderr, "avahi_loop_with_timeout exited %s\n",
2192
fprintf(stderr, "Mandos plugin mandos-client: "
2193
"avahi_loop_with_timeout exited %s\n",
2113
2194
(ret == 0) ? "successfully" : "with error");
2119
fprintf(stderr, "%s exiting\n", argv[0]);
2200
fprintf(stderr, "Mandos plugin mandos-client: "
2201
"%s exiting\n", argv[0]);
2122
2204
/* Cleanup things */