/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

merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 */
31
31
 
32
32
/* Needed by GPGME, specifically gpgme_data_seek() */
 
33
#ifndef _LARGEFILE_SOURCE
33
34
#define _LARGEFILE_SOURCE
 
35
#endif
 
36
#ifndef _FILE_OFFSET_BITS
34
37
#define _FILE_OFFSET_BITS 64
 
38
#endif
35
39
 
36
40
#define _GNU_SOURCE             /* TEMP_FAILURE_RETRY(), asprintf() */
37
41
 
305
309
        }
306
310
        gpgme_recipient_t recipient;
307
311
        recipient = result->recipients;
308
 
        if(recipient){
309
 
          while(recipient != NULL){
310
 
            fprintf(stderr, "Public key algorithm: %s\n",
311
 
                    gpgme_pubkey_algo_name(recipient->pubkey_algo));
312
 
            fprintf(stderr, "Key ID: %s\n", recipient->keyid);
313
 
            fprintf(stderr, "Secret key available: %s\n",
314
 
                    recipient->status == GPG_ERR_NO_SECKEY
315
 
                    ? "No" : "Yes");
316
 
            recipient = recipient->next;
317
 
          }
 
312
        while(recipient != NULL){
 
313
          fprintf(stderr, "Public key algorithm: %s\n",
 
314
                  gpgme_pubkey_algo_name(recipient->pubkey_algo));
 
315
          fprintf(stderr, "Key ID: %s\n", recipient->keyid);
 
316
          fprintf(stderr, "Secret key available: %s\n",
 
317
                  recipient->status == GPG_ERR_NO_SECKEY
 
318
                  ? "No" : "Yes");
 
319
          recipient = recipient->next;
318
320
        }
319
321
      }
320
322
    }
562
564
  
563
565
  memset(&to, 0, sizeof(to));
564
566
  if(af == AF_INET6){
565
 
    to.in6.sin6_family = (uint16_t)af;
 
567
    to.in6.sin6_family = (sa_family_t)af;
566
568
    ret = inet_pton(af, ip, &to.in6.sin6_addr);
567
569
  } else {                      /* IPv4 */
568
570
    to.in.sin_family = (sa_family_t)af;
854
856
       the callback function is called the Avahi server will free the
855
857
       resolver for us. */
856
858
    
857
 
    if(!(avahi_s_service_resolver_new(mc.server, interface,
858
 
                                       protocol, name, type, domain,
859
 
                                       AVAHI_PROTO_INET6, 0,
860
 
                                       resolve_callback, NULL)))
 
859
    if(avahi_s_service_resolver_new(mc.server, interface, protocol,
 
860
                                    name, type, domain, protocol, 0,
 
861
                                    resolve_callback, NULL) == NULL)
861
862
      fprintf(stderr, "Avahi: Failed to resolve service '%s': %s\n",
862
863
              name, avahi_strerror(avahi_server_errno(mc.server)));
863
864
    break;
898
899
  int exitcode = EXIT_SUCCESS;
899
900
  const char *interface = "eth0";
900
901
  struct ifreq network;
901
 
  int sd;
 
902
  int sd = -1;
 
903
  bool interface_taken_up = false;
902
904
  uid_t uid;
903
905
  gid_t gid;
904
906
  char *connect_to = NULL;
908
910
  const char *seckey = PATHDIR "/" SECKEY;
909
911
  const char *pubkey = PATHDIR "/" PUBKEY;
910
912
  
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
913
  bool gnutls_initialized = false;
916
914
  bool gpgme_initialized = false;
917
915
  float delay = 2.5f;
1116
1114
#endif  /* __linux__ */
1117
1115
        goto end;
1118
1116
      }
 
1117
      interface_taken_up = true;
1119
1118
    }
1120
1119
    /* sleep checking until interface is running */
1121
1120
    for(int i=0; i < delay * 4; i++){
1131
1130
        perror("nanosleep");
1132
1131
      }
1133
1132
    }
1134
 
    ret = (int)TEMP_FAILURE_RETRY(close(sd));
1135
 
    if(ret == -1){
1136
 
      perror("close");
 
1133
    if(not interface_taken_up){
 
1134
      ret = (int)TEMP_FAILURE_RETRY(close(sd));
 
1135
      if(ret == -1){
 
1136
        perror("close");
 
1137
      }
1137
1138
    }
1138
1139
#ifdef __linux__
1139
1140
    if(restore_loglevel){
1257
1258
  
1258
1259
  /* Create the Avahi service browser */
1259
1260
  sb = avahi_s_service_browser_new(mc.server, if_index,
1260
 
                                   AVAHI_PROTO_INET6, "_mandos._tcp",
 
1261
                                   AVAHI_PROTO_UNSPEC, "_mandos._tcp",
1261
1262
                                   NULL, 0, browse_callback, NULL);
1262
1263
  if(sb == NULL){
1263
1264
    fprintf(stderr, "Failed to create service browser: %s\n",
1300
1301
    gpgme_release(mc.ctx);
1301
1302
  }
1302
1303
  
 
1304
  /* Take down the network interface */
 
1305
  if(interface_taken_up){
 
1306
    ret = ioctl(sd, SIOCGIFFLAGS, &network);
 
1307
    if(ret == -1){
 
1308
      perror("ioctl SIOCGIFFLAGS");
 
1309
    } else if(network.ifr_flags & IFF_UP) {
 
1310
      network.ifr_flags &= ~IFF_UP; /* clear flag */
 
1311
      ret = ioctl(sd, SIOCSIFFLAGS, &network);
 
1312
      if(ret == -1){
 
1313
        perror("ioctl SIOCSIFFLAGS");
 
1314
      }
 
1315
    }
 
1316
    ret = (int)TEMP_FAILURE_RETRY(close(sd));
 
1317
    if(ret == -1){
 
1318
      perror("close");
 
1319
    }
 
1320
  }
 
1321
  
1303
1322
  /* Removes the temp directory used by GPGME */
1304
1323
  if(tempdir_created){
1305
1324
    DIR *d;