/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

* plugin-runner.c: Whitespace changes only.

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