1
1
/* -*- coding: utf-8 -*- */
3
* Mandos-client - get and decrypt data from a Mandos server
3
* Mandos client - get and decrypt data from a Mandos server
5
5
* This program is partly derived from an example program for an Avahi
6
6
* service browser, downloaded from
9
9
* "browse_callback", and parts of "main".
11
11
* Everything else is
12
* Copyright © 2008,2009 Teddy Hogeborn
13
* Copyright © 2008,2009 Björn Påhlsson
12
* Copyright © 2007-2008 Teddy Hogeborn & Björn Påhlsson
15
14
* This program is free software: you can redistribute it and/or
16
15
* modify it under the terms of the GNU General Public License as
36
35
#define _GNU_SOURCE /* TEMP_FAILURE_RETRY(), asprintf() */
38
37
#include <stdio.h> /* fprintf(), stderr, fwrite(),
39
stdout, ferror(), sscanf */
40
39
#include <stdint.h> /* uint16_t, uint32_t */
41
40
#include <stddef.h> /* NULL, size_t, ssize_t */
42
41
#include <stdlib.h> /* free(), EXIT_SUCCESS, EXIT_FAILURE,
48
47
#include <sys/types.h> /* socket(), inet_pton(), sockaddr,
49
48
sockaddr_in6, PF_INET6,
50
49
SOCK_STREAM, INET6_ADDRSTRLEN,
51
uid_t, gid_t, open(), opendir(),
50
uid_t, gid_t, open(), opendir(), DIR */
53
51
#include <sys/stat.h> /* open() */
54
52
#include <sys/socket.h> /* socket(), struct sockaddr_in6,
55
53
struct in6_addr, inet_pton(),
57
55
#include <fcntl.h> /* open() */
58
#include <dirent.h> /* opendir(), struct dirent, readdir()
60
#include <inttypes.h> /* PRIu16, intmax_t, SCNdMAX */
56
#include <dirent.h> /* opendir(), struct dirent, readdir() */
57
#include <inttypes.h> /* PRIu16 */
61
58
#include <assert.h> /* assert() */
62
59
#include <errno.h> /* perror(), errno */
63
#include <time.h> /* time(), nanosleep() */
60
#include <time.h> /* time() */
64
61
#include <net/if.h> /* ioctl, ifreq, SIOCGIFFLAGS, IFF_UP,
65
62
SIOCSIFFLAGS, if_indextoname(),
66
63
if_nametoindex(), IF_NAMESIZE */
69
66
getuid(), getgid(), setuid(),
71
68
#include <arpa/inet.h> /* inet_pton(), htons */
72
#include <iso646.h> /* not, and, or */
69
#include <iso646.h> /* not, and */
73
70
#include <argp.h> /* struct argp_option, error_t, struct
74
71
argp_state, struct argp,
75
72
argp_parse(), ARGP_KEY_ARG,
76
73
ARGP_KEY_END, ARGP_ERR_UNKNOWN */
77
#include <sys/klog.h> /* klogctl() */
80
76
/* All Avahi types, constants and functions
94
90
init_gnutls_session(),
96
#include <gnutls/openpgp.h>
97
/* gnutls_certificate_set_openpgp_key_file(),
92
#include <gnutls/openpgp.h> /* gnutls_certificate_set_openpgp_key_file(),
98
93
GNUTLS_OPENPGP_FMT_BASE64 */
107
102
#define BUFFER_SIZE 256
105
#define PATHDIR "/conf/conf.d/mandos"
109
108
#define PATHDIR "/conf/conf.d/mandos"
110
109
#define SECKEY "seckey.txt"
111
#define PUBKEY "pubkey.txt"
110
#define PUBKEY "pupkey.txt"
113
112
bool debug = false;
114
113
static const char mandos_protocol_version[] = "1";
115
const char *argp_program_version = "mandos-client " VERSION;
114
const char *argp_program_version = "password-request 1.0";
116
115
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
118
117
/* Used for passing in values through the Avahi callback functions */
134
133
size_t adjustbuffer(char **buffer, size_t buffer_length,
135
134
size_t buffer_capacity){
136
if(buffer_length + BUFFER_SIZE > buffer_capacity){
135
if (buffer_length + BUFFER_SIZE > buffer_capacity){
137
136
*buffer = realloc(*buffer, buffer_capacity + BUFFER_SIZE);
141
140
buffer_capacity += BUFFER_SIZE;
161
160
gpgme_data_t pgp_data;
163
fd = (int)TEMP_FAILURE_RETRY(open(filename, O_RDONLY));
162
fd = TEMP_FAILURE_RETRY(open(filename, O_RDONLY));
169
168
rc = gpgme_data_new_from_fd(&pgp_data, fd);
170
if(rc != GPG_ERR_NO_ERROR){
169
if (rc != GPG_ERR_NO_ERROR){
171
170
fprintf(stderr, "bad gpgme_data_new_from_fd: %s: %s\n",
172
171
gpgme_strsource(rc), gpgme_strerror(rc));
176
175
rc = gpgme_op_import(mc->ctx, pgp_data);
177
if(rc != GPG_ERR_NO_ERROR){
176
if (rc != GPG_ERR_NO_ERROR){
178
177
fprintf(stderr, "bad gpgme_op_import: %s: %s\n",
179
178
gpgme_strsource(rc), gpgme_strerror(rc));
183
ret = (int)TEMP_FAILURE_RETRY(close(fd));
182
ret = TEMP_FAILURE_RETRY(close(fd));
192
191
fprintf(stderr, "Initialize gpgme\n");
196
195
gpgme_check_version(NULL);
197
196
rc = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP);
198
if(rc != GPG_ERR_NO_ERROR){
197
if (rc != GPG_ERR_NO_ERROR){
199
198
fprintf(stderr, "bad gpgme_engine_check_version: %s: %s\n",
200
199
gpgme_strsource(rc), gpgme_strerror(rc));
204
203
/* Set GPGME home directory for the OpenPGP engine only */
205
rc = gpgme_get_engine_info(&engine_info);
206
if(rc != GPG_ERR_NO_ERROR){
204
rc = gpgme_get_engine_info (&engine_info);
205
if (rc != GPG_ERR_NO_ERROR){
207
206
fprintf(stderr, "bad gpgme_get_engine_info: %s: %s\n",
208
207
gpgme_strsource(rc), gpgme_strerror(rc));
220
219
fprintf(stderr, "Could not set GPGME home dir to %s\n", tempdir);
224
223
/* Create new GPGME "context" */
225
224
rc = gpgme_new(&(mc->ctx));
226
if(rc != GPG_ERR_NO_ERROR){
225
if (rc != GPG_ERR_NO_ERROR){
227
226
fprintf(stderr, "bad gpgme_new: %s: %s\n",
228
227
gpgme_strsource(rc), gpgme_strerror(rc));
232
if(not import_key(pubkey) or not import_key(seckey)){
231
if (not import_key(pubkey) or not import_key(seckey)){
240
239
* Decrypt OpenPGP data.
241
240
* Returns -1 on error
243
static ssize_t pgp_packet_decrypt(const mandos_context *mc,
244
const char *cryptotext,
242
static ssize_t pgp_packet_decrypt (const mandos_context *mc,
243
const char *cryptotext,
247
246
gpgme_data_t dh_crypto, dh_plain;
248
247
gpgme_error_t rc;
250
249
size_t plaintext_capacity = 0;
251
250
ssize_t plaintext_length = 0;
254
253
fprintf(stderr, "Trying to decrypt OpenPGP data\n");
257
256
/* Create new GPGME data buffer from memory cryptotext */
258
257
rc = gpgme_data_new_from_mem(&dh_crypto, cryptotext, crypto_size,
260
if(rc != GPG_ERR_NO_ERROR){
259
if (rc != GPG_ERR_NO_ERROR){
261
260
fprintf(stderr, "bad gpgme_data_new_from_mem: %s: %s\n",
262
261
gpgme_strsource(rc), gpgme_strerror(rc));
266
265
/* Create new empty GPGME data buffer for the plaintext */
267
266
rc = gpgme_data_new(&dh_plain);
268
if(rc != GPG_ERR_NO_ERROR){
267
if (rc != GPG_ERR_NO_ERROR){
269
268
fprintf(stderr, "bad gpgme_data_new: %s: %s\n",
270
269
gpgme_strsource(rc), gpgme_strerror(rc));
271
270
gpgme_data_release(dh_crypto);
275
274
/* Decrypt data from the cryptotext data buffer to the plaintext
277
276
rc = gpgme_op_decrypt(mc->ctx, dh_crypto, dh_plain);
278
if(rc != GPG_ERR_NO_ERROR){
277
if (rc != GPG_ERR_NO_ERROR){
279
278
fprintf(stderr, "bad gpgme_op_decrypt: %s: %s\n",
280
279
gpgme_strsource(rc), gpgme_strerror(rc));
281
280
plaintext_length = -1;
283
282
gpgme_decrypt_result_t result;
284
283
result = gpgme_op_decrypt_result(mc->ctx);
286
285
fprintf(stderr, "gpgme_op_decrypt_result failed\n");
288
287
fprintf(stderr, "Unsupported algorithm: %s\n",
317
316
/* Seek back to the beginning of the GPGME plaintext data buffer */
318
if(gpgme_data_seek(dh_plain, (off_t)0, SEEK_SET) == -1){
319
perror("gpgme_data_seek");
317
if (gpgme_data_seek(dh_plain, (off_t) 0, SEEK_SET) == -1){
318
perror("pgpme_data_seek");
320
319
plaintext_length = -1;
321
320
goto decrypt_end;
326
325
plaintext_capacity = adjustbuffer(plaintext,
327
326
(size_t)plaintext_length,
328
327
plaintext_capacity);
329
if(plaintext_capacity == 0){
328
if (plaintext_capacity == 0){
330
329
perror("adjustbuffer");
331
330
plaintext_length = -1;
332
331
goto decrypt_end;
365
364
return plaintext_length;
368
static const char * safer_gnutls_strerror(int value) {
369
const char *ret = gnutls_strerror(value); /* Spurious warning from
370
-Wunreachable-code */
367
static const char * safer_gnutls_strerror (int value) {
368
const char *ret = gnutls_strerror (value); /* Spurious warning */
372
370
ret = "(unknown)";
391
389
ret = gnutls_global_init();
392
if(ret != GNUTLS_E_SUCCESS) {
393
fprintf(stderr, "GnuTLS global_init: %s\n",
394
safer_gnutls_strerror(ret));
390
if (ret != GNUTLS_E_SUCCESS) {
391
fprintf (stderr, "GnuTLS global_init: %s\n",
392
safer_gnutls_strerror(ret));
399
397
/* "Use a log level over 10 to enable all debugging options."
400
398
* - GnuTLS manual
406
404
/* OpenPGP credentials */
407
405
gnutls_certificate_allocate_credentials(&mc->cred);
408
if(ret != GNUTLS_E_SUCCESS){
409
fprintf(stderr, "GnuTLS memory error: %s\n", /* Spurious warning
413
safer_gnutls_strerror(ret));
414
gnutls_global_deinit();
406
if (ret != GNUTLS_E_SUCCESS){
407
fprintf (stderr, "GnuTLS memory error: %s\n", /* Spurious
409
safer_gnutls_strerror(ret));
410
gnutls_global_deinit ();
424
420
ret = gnutls_certificate_set_openpgp_key_file
425
421
(mc->cred, pubkeyfilename, seckeyfilename,
426
422
GNUTLS_OPENPGP_FMT_BASE64);
427
if(ret != GNUTLS_E_SUCCESS) {
423
if (ret != GNUTLS_E_SUCCESS) {
429
425
"Error[%d] while reading the OpenPGP key pair ('%s',"
430
426
" '%s')\n", ret, pubkeyfilename, seckeyfilename);
436
432
/* GnuTLS server initialization */
437
433
ret = gnutls_dh_params_init(&mc->dh_params);
438
if(ret != GNUTLS_E_SUCCESS) {
439
fprintf(stderr, "Error in GnuTLS DH parameter initialization:"
440
" %s\n", safer_gnutls_strerror(ret));
434
if (ret != GNUTLS_E_SUCCESS) {
435
fprintf (stderr, "Error in GnuTLS DH parameter initialization:"
436
" %s\n", safer_gnutls_strerror(ret));
443
439
ret = gnutls_dh_params_generate2(mc->dh_params, mc->dh_bits);
444
if(ret != GNUTLS_E_SUCCESS) {
445
fprintf(stderr, "Error in GnuTLS prime generation: %s\n",
446
safer_gnutls_strerror(ret));
440
if (ret != GNUTLS_E_SUCCESS) {
441
fprintf (stderr, "Error in GnuTLS prime generation: %s\n",
442
safer_gnutls_strerror(ret));
465
460
/* GnuTLS session creation */
466
461
ret = gnutls_init(session, GNUTLS_SERVER);
467
if(ret != GNUTLS_E_SUCCESS){
462
if (ret != GNUTLS_E_SUCCESS){
468
463
fprintf(stderr, "Error in GnuTLS session initialization: %s\n",
469
464
safer_gnutls_strerror(ret));
474
469
ret = gnutls_priority_set_direct(*session, mc->priority, &err);
475
if(ret != GNUTLS_E_SUCCESS) {
470
if (ret != GNUTLS_E_SUCCESS) {
476
471
fprintf(stderr, "Syntax error at: %s\n", err);
477
472
fprintf(stderr, "GnuTLS error: %s\n",
478
473
safer_gnutls_strerror(ret));
479
gnutls_deinit(*session);
474
gnutls_deinit (*session);
484
479
ret = gnutls_credentials_set(*session, GNUTLS_CRD_CERTIFICATE,
486
if(ret != GNUTLS_E_SUCCESS) {
481
if (ret != GNUTLS_E_SUCCESS) {
487
482
fprintf(stderr, "Error setting GnuTLS credentials: %s\n",
488
483
safer_gnutls_strerror(ret));
489
gnutls_deinit(*session);
484
gnutls_deinit (*session);
493
488
/* ignore client certificate if any. */
494
gnutls_certificate_server_set_request(*session,
489
gnutls_certificate_server_set_request (*session,
497
gnutls_dh_set_prime_bits(*session, mc->dh_bits);
492
gnutls_dh_set_prime_bits (*session, mc->dh_bits);
520
514
char interface[IF_NAMESIZE];
521
515
gnutls_session_t session;
523
ret = init_gnutls_session(mc, &session);
517
ret = init_gnutls_session (mc, &session);
557
551
fprintf(stderr, "Bad address: %s\n", ip);
560
to.in6.sin6_port = htons(port); /* Spurious warnings from
562
-Wunreachable-code */
554
to.in6.sin6_port = htons(port); /* Spurious warning */
564
556
to.in6.sin6_scope_id = (uint32_t)if_index;
580
572
ret = connect(tcp_sd, &to.in, sizeof(to));
582
574
perror("connect");
586
578
const char *out = mandos_protocol_version;
589
581
size_t out_size = strlen(out);
590
ret = (int)TEMP_FAILURE_RETRY(write(tcp_sd, out + written,
582
ret = TEMP_FAILURE_RETRY(write(tcp_sd, out + written,
591
583
out_size - written));
611
603
fprintf(stderr, "Establishing TLS session with %s\n", ip);
614
gnutls_transport_set_ptr(session, (gnutls_transport_ptr_t) tcp_sd);
606
gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) tcp_sd);
617
ret = gnutls_handshake(session);
609
ret = gnutls_handshake (session);
618
610
} while(ret == GNUTLS_E_AGAIN or ret == GNUTLS_E_INTERRUPTED);
620
if(ret != GNUTLS_E_SUCCESS){
612
if (ret != GNUTLS_E_SUCCESS){
622
614
fprintf(stderr, "*** GnuTLS Handshake failed ***\n");
637
629
buffer_capacity = adjustbuffer(&buffer, buffer_length,
638
630
buffer_capacity);
639
if(buffer_capacity == 0){
631
if (buffer_capacity == 0){
640
632
perror("adjustbuffer");
645
sret = gnutls_record_recv(session, buffer+buffer_length,
637
ret = gnutls_record_recv(session, buffer+buffer_length,
652
644
case GNUTLS_E_INTERRUPTED:
653
645
case GNUTLS_E_AGAIN:
655
647
case GNUTLS_E_REHANDSHAKE:
657
ret = gnutls_handshake(session);
649
ret = gnutls_handshake (session);
658
650
} while(ret == GNUTLS_E_AGAIN or ret == GNUTLS_E_INTERRUPTED);
660
652
fprintf(stderr, "*** GnuTLS Re-handshake failed ***\n");
667
659
fprintf(stderr, "Unknown error while reading data from"
668
660
" encrypted session with Mandos server\n");
670
gnutls_bye(session, GNUTLS_SHUT_RDWR);
662
gnutls_bye (session, GNUTLS_SHUT_RDWR);
674
buffer_length += (size_t) sret;
666
buffer_length += (size_t) ret;
679
671
fprintf(stderr, "Closing TLS session\n");
682
gnutls_bye(session, GNUTLS_SHUT_RDWR);
674
gnutls_bye (session, GNUTLS_SHUT_RDWR);
684
if(buffer_length > 0){
676
if (buffer_length > 0){
685
677
decrypted_buffer_size = pgp_packet_decrypt(mc, buffer,
687
679
&decrypted_buffer);
688
if(decrypted_buffer_size >= 0){
680
if (decrypted_buffer_size >= 0){
690
682
while(written < (size_t) decrypted_buffer_size){
691
ret = (int)fwrite(decrypted_buffer + written, 1,
692
(size_t)decrypted_buffer_size - written,
683
ret = (int)fwrite (decrypted_buffer + written, 1,
684
(size_t)decrypted_buffer_size - written,
694
686
if(ret == 0 and ferror(stdout)){
696
688
fprintf(stderr, "Error writing encrypted data: %s\n",
755
747
avahi_address_snprint(ip, sizeof(ip), address);
757
749
fprintf(stderr, "Mandos server \"%s\" found on %s (%s, %"
758
PRIdMAX ") on port %" PRIu16 "\n", name, host_name,
759
ip, (intmax_t)interface, port);
750
PRIu16 ") on port %d\n", name, host_name, ip,
761
753
int ret = start_mandos_communication(ip, port, interface, mc);
763
755
avahi_simple_poll_quit(mc->simple_poll);
798
790
the callback function is called the Avahi server will free the
799
791
resolver for us. */
801
if(!(avahi_s_service_resolver_new(mc->server, interface,
793
if (!(avahi_s_service_resolver_new(mc->server, interface,
802
794
protocol, name, type, domain,
803
795
AVAHI_PROTO_INET6, 0,
804
796
resolve_callback, mc)))
840
830
.dh_bits = 1024, .priority = "SECURE256"
841
831
":!CTYPE-X.509:+CTYPE-OPENPGP" };
842
832
bool gnutls_initalized = false;
843
bool gpgme_initalized = false;
833
bool pgpme_initalized = false;
847
836
struct argp_option options[] = {
874
863
.doc = "GnuTLS priority string for the TLS handshake",
876
{ .name = "delay", .key = 131,
878
.doc = "Maximum delay to wait for interface startup",
883
error_t parse_opt(int key, char *arg,
884
struct argp_state *state) {
868
error_t parse_opt (int key, char *arg,
869
struct argp_state *state) {
870
/* Get the INPUT argument from `argp_parse', which we know is
871
a pointer to our plugin list pointer. */
886
873
case 128: /* --debug */
901
888
case 129: /* --dh-bits */
902
ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
903
if(ret < 1 or tmpmax != (typeof(mc.dh_bits))tmpmax
904
or arg[numchars] != '\0'){
905
fprintf(stderr, "Bad number of DH bits\n");
890
mc.dh_bits = (unsigned int) strtol(arg, NULL, 10);
906
893
exit(EXIT_FAILURE);
908
mc.dh_bits = (typeof(mc.dh_bits))tmpmax;
910
896
case 130: /* --priority */
911
897
mc.priority = arg;
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");
920
899
case ARGP_KEY_ARG:
922
901
case ARGP_KEY_END:
932
911
.doc = "Mandos client -- Get and decrypt"
933
912
" passwords from a Mandos server" };
934
ret = argp_parse(&argp, argc, argv, 0, 0, NULL);
935
if(ret == ARGP_ERR_UNKNOWN){
913
ret = argp_parse (&argp, argc, argv, 0, 0, NULL);
914
if (ret == ARGP_ERR_UNKNOWN){
936
915
fprintf(stderr, "Unknown error while parsing arguments\n");
937
916
exitcode = EXIT_FAILURE;
921
ret = init_gnutls_global(&mc, pubkey, seckey);
923
fprintf(stderr, "init_gnutls_global failed\n");
924
exitcode = EXIT_FAILURE;
927
gnutls_initalized = true;
930
if(mkdtemp(tempdir) == NULL){
936
if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
937
fprintf(stderr, "pgpme_initalized failed\n");
938
exitcode = EXIT_FAILURE;
941
pgpme_initalized = true;
942
944
/* If the interface is down, bring it up */
944
// Lower kernel loglevel to KERN_NOTICE to avoid
945
// KERN_INFO messages to mess up the prompt
946
ret = klogctl(8, NULL, 5);
951
946
sd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
953
948
perror("socket");
954
949
exitcode = EXIT_FAILURE;
955
ret = klogctl(7, NULL, 0);
961
952
strcpy(network.ifr_name, interface);
962
953
ret = ioctl(sd, SIOCGIFFLAGS, &network);
964
955
perror("ioctl SIOCGIFFLAGS");
965
ret = klogctl(7, NULL, 0);
969
956
exitcode = EXIT_FAILURE;
976
963
perror("ioctl SIOCSIFFLAGS");
977
964
exitcode = EXIT_FAILURE;
978
ret = klogctl(7, NULL, 0);
985
// sleep checking until interface is running
986
for(int i=0; i < delay * 4; i++){
987
ret = ioctl(sd, SIOCGIFFLAGS, &network);
989
perror("ioctl SIOCGIFFLAGS");
990
} else if(network.ifr_flags & IFF_RUNNING){
993
struct timespec sleeptime = { .tv_nsec = 250000000 };
994
nanosleep(&sleeptime, NULL);
996
ret = (int)TEMP_FAILURE_RETRY(close(sd));
968
ret = TEMP_FAILURE_RETRY(close(sd));
1000
// Restores kernel loglevel to default
1001
ret = klogctl(7, NULL, 0);
1010
977
ret = setuid(uid);
1012
979
perror("setuid");
1017
984
perror("setgid");
1020
ret = init_gnutls_global(&mc, pubkey, seckey);
1022
fprintf(stderr, "init_gnutls_global failed\n");
1023
exitcode = EXIT_FAILURE;
1026
gnutls_initalized = true;
1029
if(mkdtemp(tempdir) == NULL){
1035
if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
1036
fprintf(stderr, "gpgme_initalized failed\n");
1037
exitcode = EXIT_FAILURE;
1040
gpgme_initalized = true;
1043
987
if_index = (AvahiIfIndex) if_nametoindex(interface);
1044
988
if(if_index == 0){
1045
989
fprintf(stderr, "No such interface: \"%s\"\n", interface);
1055
999
exitcode = EXIT_FAILURE;
1059
ret = sscanf(address+1, "%" SCNdMAX "%n", &tmpmax, &numchars);
1060
if(ret < 1 or tmpmax != (uint16_t)tmpmax
1061
or address[numchars+1] != '\0'){
1062
fprintf(stderr, "Bad port number\n");
1003
uint16_t port = (uint16_t) strtol(address+1, NULL, 10);
1005
perror("Bad port number");
1063
1006
exitcode = EXIT_FAILURE;
1066
port = (uint16_t)tmpmax;
1067
1009
*address = '\0';
1068
1010
address = connect_to;
1069
1011
ret = start_mandos_communication(address, port, if_index, &mc);
1085
1027
/* Allocate main Avahi loop object */
1086
1028
mc.simple_poll = avahi_simple_poll_new();
1087
if(mc.simple_poll == NULL) {
1029
if (mc.simple_poll == NULL) {
1088
1030
fprintf(stderr, "Avahi: Failed to create simple poll"
1090
1032
exitcode = EXIT_FAILURE;
1132
1074
/* Run the main loop */
1135
1077
fprintf(stderr, "Starting Avahi loop search\n");
1138
1080
avahi_simple_poll_loop(mc.simple_poll);
1143
1085
fprintf(stderr, "%s exiting\n", argv[0]);
1146
1088
/* Cleanup things */
1148
1090
avahi_s_service_browser_free(sb);
1150
if(mc.server != NULL)
1092
if (mc.server != NULL)
1151
1093
avahi_server_free(mc.server);
1153
if(mc.simple_poll != NULL)
1095
if (mc.simple_poll != NULL)
1154
1096
avahi_simple_poll_free(mc.simple_poll);
1156
if(gnutls_initalized){
1098
if (gnutls_initalized){
1157
1099
gnutls_certificate_free_credentials(mc.cred);
1158
gnutls_global_deinit();
1159
gnutls_dh_params_deinit(mc.dh_params);
1100
gnutls_global_deinit ();
1162
if(gpgme_initalized){
1103
if(pgpme_initalized){
1163
1104
gpgme_release(mc.ctx);
1166
1107
/* Removes the temp directory used by GPGME */
1167
1108
if(tempdir[0] != '\0'){
1169
1110
struct dirent *direntry;
1170
1111
d = opendir(tempdir);
1172
if(errno != ENOENT){
1177
1116
direntry = readdir(d);
1178
1117
if(direntry == NULL){
1181
if(direntry->d_type == DT_REG){
1120
if (direntry->d_type == DT_REG){
1182
1121
char *fullname = NULL;
1183
1122
ret = asprintf(&fullname, "%s/%s", tempdir,
1184
1123
direntry->d_name);