/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to plugins.d/mandosclient.c

  • Committer: Teddy Hogeborn
  • Date: 2008-07-29 03:35:39 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080729033539-08zecoj3jwlkpjhw
* server.conf: New file.

* mandos-clients.conf: Renamed to clients.conf.

* Makefile (FORTIFY): New.
  (CFLAGS): Include $(FORTIFY).

* plugins.d/mandosclient.c (main): New "if_index" variable.  Bug fix:
                                   check if interface exists.  New
                                   "--connect" option.

* server.py (serviceInterface): Removed; replaced by
                                "AvahiService.interface".  All users
                                changed.
  (AvahiError, AvahiServiceError, AvahiGroupError): New exception
                                                    classes.
  (AvahiService): New class.
  (serviceName): Removed; replaced by "AvahiService.name".  All users
                 changed.
  (serviceType): Removed; replaced by "AvahiService.type".  All users
                 changed.
  (servicePort): Removed; replaced by "AvahiService.port".  All users
                 changed.
  (serviceTXT): Removed; replaced by "AvahiService.TXT".  All users
                changed.
  (domain): Removed; replaced by "AvahiService.domain".  All users
            changed.
  (host): Removed; replaced by "AvahiService.host".  All users
          changed.
  (rename_count): Removed; replaced by "AvahiService.rename_count" and
                 "AvahiService.max_renames".  All users changed.
  (Client.__init__): If no secret or secfile, raise TypeError instead
                     of RuntimeError.
  (Client.last_seen): Renamed to "Client.last_checked_ok".  All users
                      changed.
  (Client.stop, Client.stop_checker): Use "getattr" with default value
                                      instead of "hasattr".
  (Client.still_valid): Removed "now" argument.
  (Client.handle): Separate the "no client found" and "client invalid"
                   cases for clearer code.
  (IPv6_TCPServer.__init__): "options" argument replaced by
                             "settings".  All callers changed.
  (IPv6_TCPServer.options): Replaced by "IPv6_TCPServer.settings".
                            All users changed.
  (IPv6_TCPServer.server_bind): Use getattr instead of hasattr.
  (add_service): Removed; replaced by "AvahiService.add".  All callers
                 changed.
  (remove_service): Removed; replaced by "AvahiService.remove".  All
                    callers changed.
  (entry_group_state_changed): On entry group collision, call the new
                               AvahiService.rename method.  Raise
                               AvahiGroupError on group error.
  (if_nametoindex): Use ctypes.utils.find_library to locate the C
                    library.  Cache the result.  Loop on EINTR.
  (daemon): Use os.path.devnull to locate "/dev/null".
  (killme): Removed.  All callers changed to do "sys.exit()" instead,
            except where stated otherwise.
  (main): Removed "exitstatus".  Removed all default values from all
          non-bool options.  New option "--configdir".  New variables
          "server_defaults" and "server_settings", read from
          "%(configdir)s/server.conf".  Let any supplied command line
          options override server settings.   Variable "defaults"
          renamed to "client_defaults", which is read from
          "clients.conf" instead of "mandos-clients.conf".  New global
          AvahiService object "service" replaces old global variables.
          Catch AvahiError and exit with error if caught.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 * includes the following functions: "resolve_callback",
9
9
 * "browse_callback", and parts of "main".
10
10
 * 
11
 
 * Everything else is Copyright © 2007-2008 Teddy Hogeborn and Björn
12
 
 * Påhlsson.
 
11
 * Everything else is
 
12
 * Copyright © 2007-2008 Teddy Hogeborn & Björn Påhlsson
13
13
 * 
14
14
 * This program is free software: you can redistribute it and/or
15
15
 * modify it under the terms of the GNU General Public License as
29
29
 * <https://www.fukt.bsnet.se/~teddy/>.
30
30
 */
31
31
 
32
 
#define _FORTIFY_SOURCE 2
33
 
 
 
32
/* Needed by GPGME, specifically gpgme_data_seek() */
34
33
#define _LARGEFILE_SOURCE
35
34
#define _FILE_OFFSET_BITS 64
36
35
 
358
357
  char interface[IF_NAMESIZE];
359
358
  
360
359
  if(debug){
361
 
    fprintf(stderr, "Setting up a tcp connection to %s\n", ip);
 
360
    fprintf(stderr, "Setting up a tcp connection to %s, port %d\n",
 
361
            ip, port);
362
362
  }
363
363
  
364
364
  tcp_sd = socket(PF_INET6, SOCK_STREAM, 0);
394
394
  to.sin6_scope_id = (uint32_t)if_index;
395
395
  
396
396
  if(debug){
397
 
    fprintf(stderr, "Connection to: %s\n", ip);
 
397
    fprintf(stderr, "Connection to: %s, port %d\n", ip, port);
 
398
/*     char addrstr[INET6_ADDRSTRLEN]; */
 
399
/*     if(inet_ntop(to.sin6_family, &(to.sin6_addr), addrstr, */
 
400
/*               sizeof(addrstr)) == NULL){ */
 
401
/*       perror("inet_ntop"); */
 
402
/*     } else { */
 
403
/*       fprintf(stderr, "Really connecting to: %s, port %d\n", */
 
404
/*            addrstr, ntohs(to.sin6_port)); */
 
405
/*     } */
398
406
  }
399
407
  
400
408
  ret = connect(tcp_sd, (struct sockaddr *) &to, sizeof(to));
481
489
                                               &decrypted_buffer,
482
490
                                               CERT_ROOT);
483
491
    if (decrypted_buffer_size >= 0){
484
 
      while(written < decrypted_buffer_size){
 
492
      while(written < (size_t) decrypted_buffer_size){
485
493
        ret = (int)fwrite (decrypted_buffer + written, 1,
486
494
                           (size_t)decrypted_buffer_size - written,
487
495
                           stdout);
622
630
    int ret;
623
631
    int returncode = EXIT_SUCCESS;
624
632
    const char *interface = "eth0";
 
633
    unsigned int if_index;
 
634
    char *connect_to = NULL;
625
635
    
626
636
    while (true){
627
637
      static struct option long_options[] = {
628
638
        {"debug", no_argument, (int *)&debug, 1},
 
639
        {"connect", required_argument, 0, 'c'},
629
640
        {"interface", required_argument, 0, 'i'},
630
641
        {0, 0, 0, 0} };
631
642
      
643
654
      case 'i':
644
655
        interface = optarg;
645
656
        break;
 
657
      case 'c':
 
658
        connect_to = optarg;
 
659
        break;
646
660
      default:
647
661
        exit(EXIT_FAILURE);
648
662
      }
649
663
    }
650
664
    
 
665
    if_index = if_nametoindex(interface);
 
666
    if(if_index == 0){
 
667
      fprintf(stderr, "No such interface: \"%s\"\n", interface);
 
668
      exit(EXIT_FAILURE);
 
669
    }
 
670
    
 
671
    if(connect_to != NULL){
 
672
      /* Connect directly, do not use Zeroconf */
 
673
      /* (Mainly meant for debugging) */
 
674
      char *address = strrchr(connect_to, ':');
 
675
      if(address == NULL){
 
676
        fprintf(stderr, "No colon in address\n");
 
677
        exit(EXIT_FAILURE);
 
678
      }
 
679
      errno = 0;
 
680
      uint16_t port = (uint16_t) strtol(address+1, NULL, 10);
 
681
      if(errno){
 
682
        perror("Bad port number");
 
683
        exit(EXIT_FAILURE);
 
684
      }
 
685
      *address = '\0';
 
686
      address = connect_to;
 
687
      ret = start_mandos_communication(address, port, if_index);
 
688
      if(ret < 0){
 
689
        exit(EXIT_FAILURE);
 
690
      } else {
 
691
        exit(EXIT_SUCCESS);
 
692
      }
 
693
    }
 
694
    
651
695
    if (not debug){
652
696
      avahi_set_log_function(empty_log);
653
697
    }
685
729
    }
686
730
    
687
731
    /* Create the service browser */
688
 
    sb = avahi_s_service_browser_new(server,
689
 
                                     (AvahiIfIndex)
690
 
                                     if_nametoindex(interface),
 
732
    sb = avahi_s_service_browser_new(server, (AvahiIfIndex)if_index,
691
733
                                     AVAHI_PROTO_INET6,
692
734
                                     "_mandos._tcp", NULL, 0,
693
735
                                     browse_callback, server);