/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/mandosclient.c

  • Committer: Teddy Hogeborn
  • Date: 2008-07-21 22:51:46 UTC
  • mfrom: (15.1.4 mandos)
  • Revision ID: teddy@fukt.bsnet.se-20080721225146-55gbo7fqocy4m930
* plugins.d/mandosclient.c (pgp_packet_decrypt): Cast "0" argument to
                                                 gpgme_data_seek.
 (start_mandos_communication): Change "ip" arg to "const char *".  New
                               variable "written".  Remove setsockopt.
                               Bug fix: Do not change decrypted_buffer.
 (resolve_callback): Removed AVAHI_GCC_UNUSED from "interface".

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
#include <avahi-common/error.h>
49
49
 
50
50
//mandos client part
51
 
#include <sys/types.h>          /* socket(), setsockopt(),
52
 
                                   inet_pton() */
53
 
#include <sys/socket.h>         /* socket(), setsockopt(),
54
 
                                   struct sockaddr_in6,
 
51
#include <sys/types.h>          /* socket(), inet_pton() */
 
52
#include <sys/socket.h>         /* socket(), struct sockaddr_in6,
55
53
                                   struct in6_addr, inet_pton() */
56
54
#include <gnutls/gnutls.h>      /* All GnuTLS stuff */
57
55
#include <gnutls/openpgp.h>     /* GnuTLS with openpgp stuff */
195
193
  gpgme_data_release(dh_crypto);
196
194
  
197
195
  /* Seek back to the beginning of the GPGME plaintext data buffer */
198
 
  gpgme_data_seek(dh_plain, 0, SEEK_SET);
 
196
  gpgme_data_seek(dh_plain, (off_t) 0, SEEK_SET);
199
197
 
200
198
  *new_packet = 0;
201
199
  while(true){
345
343
void empty_log(__attribute__((unused)) AvahiLogLevel level,
346
344
               __attribute__((unused)) const char *txt){}
347
345
 
348
 
int start_mandos_communication(char *ip, uint16_t port,
 
346
int start_mandos_communication(const char *ip, uint16_t port,
349
347
                               unsigned int if_index){
350
348
  int ret, tcp_sd;
351
349
  struct sockaddr_in6 to;
355
353
  size_t buffer_length = 0;
356
354
  size_t buffer_capacity = 0;
357
355
  ssize_t decrypted_buffer_size;
 
356
  size_t written = 0;
358
357
  int retval = 0;
359
358
  char interface[IF_NAMESIZE];
360
359
  
379
378
    fprintf(stderr, "Binding to interface %s\n", interface);
380
379
  }
381
380
  
382
 
  ret = setsockopt(tcp_sd, SOL_SOCKET, SO_BINDTODEVICE, interface, 5);
383
 
  if(ret < 0) {
384
 
    perror("setsockopt bindtodevice");
385
 
    return -1;
386
 
  }
387
 
  
388
 
  memset(&to,0,sizeof(to));
 
381
  memset(&to,0,sizeof(to));     /* Spurious warning */
389
382
  to.sin6_family = AF_INET6;
390
383
  ret = inet_pton(AF_INET6, ip, &to.sin6_addr);
391
384
  if (ret < 0 ){
396
389
    fprintf(stderr, "Bad address: %s\n", ip);
397
390
    return -1;
398
391
  }
399
 
  /* Spurious warnings for the next line, see for instance
400
 
     <http://bugs.debian.org/488884> */
401
 
  to.sin6_port = htons(port);
 
392
  to.sin6_port = htons(port);   /* Spurious warning */
402
393
  
403
394
  to.sin6_scope_id = (uint32_t)if_index;
404
395
  
488
479
                                               &decrypted_buffer,
489
480
                                               CERT_ROOT);
490
481
    if (decrypted_buffer_size >= 0){
491
 
      while(decrypted_buffer_size > 0){
492
 
        ret = fwrite (decrypted_buffer, 1, (size_t)decrypted_buffer_size,
493
 
                      stdout);
 
482
      while(written < decrypted_buffer_size){
 
483
        ret = (int)fwrite (decrypted_buffer + written, 1,
 
484
                           (size_t)decrypted_buffer_size - written,
 
485
                           stdout);
494
486
        if(ret == 0 and ferror(stdout)){
495
487
          if(debug){
496
488
            fprintf(stderr, "Error writing encrypted data: %s\n",
499
491
          retval = -1;
500
492
          break;
501
493
        }
502
 
        decrypted_buffer += ret;
503
 
        decrypted_buffer_size -= ret;
 
494
        written += (size_t)ret;
504
495
      }
505
496
      free(decrypted_buffer);
506
497
    } else {
529
520
 
530
521
static void resolve_callback(
531
522
    AvahiSServiceResolver *r,
532
 
    AVAHI_GCC_UNUSED AvahiIfIndex interface,
 
523
    AvahiIfIndex interface,
533
524
    AVAHI_GCC_UNUSED AvahiProtocol protocol,
534
525
    AvahiResolverEvent event,
535
526
    const char *name,
542
533
    AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
543
534
    AVAHI_GCC_UNUSED void* userdata) {
544
535
    
545
 
  assert(r);
546
 
 
 
536
  assert(r);                    /* Spurious warning */
 
537
  
547
538
  /* Called whenever a service has been resolved successfully or
548
539
     timed out */
549
 
 
 
540
  
550
541
  switch (event) {
551
542
  default:
552
543
  case AVAHI_RESOLVER_FAILURE:
554
545
            " type '%s' in domain '%s': %s\n", name, type, domain,
555
546
            avahi_strerror(avahi_server_errno(server)));
556
547
    break;
557
 
      
 
548
    
558
549
  case AVAHI_RESOLVER_FOUND:
559
550
    {
560
551
      char ip[AVAHI_ADDRESS_STR_MAX];
564
555
                host_name, ip, port);
565
556
      }
566
557
      int ret = start_mandos_communication(ip, port,
567
 
                                           (unsigned int)
568
 
                                           interface);
 
558
                                           (unsigned int) interface);
569
559
      if (ret == 0){
570
560
        exit(EXIT_SUCCESS);
571
561
      } else {
588
578
    void* userdata) {
589
579
    
590
580
    AvahiServer *s = userdata;
591
 
    assert(b);
592
 
 
 
581
    assert(b);                  /* Spurious warning */
 
582
    
593
583
    /* Called whenever a new services becomes available on the LAN or
594
584
       is removed from the LAN */
595
 
 
 
585
    
596
586
    switch (event) {
597
587
    default:
598
588
    case AVAHI_BROWSER_FAILURE:
638
628
        {"debug", no_argument, (int *)&debug, 1},
639
629
        {"interface", required_argument, 0, 'i'},
640
630
        {0, 0, 0, 0} };
641
 
 
 
631
      
642
632
      int option_index = 0;
643
633
      ret = getopt_long (argc, argv, "i:", long_options,
644
634
                         &option_index);
645
 
 
 
635
      
646
636
      if (ret == -1){
647
637
        break;
648
638
      }