/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/password-request.c

  • Committer: Björn Påhlsson
  • Date: 2008-08-15 20:17:32 UTC
  • mto: (237.7.1 mandos) (24.1.154 mandos)
  • mto: This revision was merged to the branch mainline in revision 77.
  • Revision ID: belorn@braxen-20080815201732-b7uux3yqs05b3fy9
Added configuration files support for mandos-client
Removed plus argument support for mandos-client

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
#include <string.h>             /* memset(), strcmp(), strlen(),
45
45
                                   strerror(), memcpy(), strcpy() */
46
46
#include <sys/ioctl.h>          /* ioctl */
47
 
#include <net/if.h>             /* ifreq, SIOCGIFFLAGS, SIOCSIFFLAGS,
48
 
                                   IFF_UP */
49
47
#include <sys/types.h>          /* socket(), inet_pton(), sockaddr,
50
48
                                   sockaddr_in6, PF_INET6,
51
49
                                   SOCK_STREAM, INET6_ADDRSTRLEN,
52
50
                                   uid_t, gid_t */
 
51
#include <inttypes.h>           /* PRIu16 */
53
52
#include <sys/socket.h>         /* socket(), struct sockaddr_in6,
54
53
                                   struct in6_addr, inet_pton(),
55
54
                                   connect() */
100
99
bool debug = false;
101
100
static const char *keydir = "/conf/conf.d/mandos";
102
101
static const char mandos_protocol_version[] = "1";
103
 
const char *argp_program_version = "mandosclient 1.0";
 
102
const char *argp_program_version = "password-request 1.0";
104
103
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
105
104
 
106
105
/* Used for passing in values through the Avahi callback functions */
228
227
    } else {
229
228
      fprintf(stderr, "Unsupported algorithm: %s\n",
230
229
              result->unsupported_algorithm);
231
 
      fprintf(stderr, "Wrong key usage: %d\n",
 
230
      fprintf(stderr, "Wrong key usage: %u\n",
232
231
              result->wrong_key_usage);
233
232
      if(result->file_name != NULL){
234
233
        fprintf(stderr, "File name: %s\n", result->file_name);
455
454
  }
456
455
  
457
456
  if(debug){
458
 
    fprintf(stderr, "Setting up a tcp connection to %s, port %d\n",
459
 
            ip, port);
 
457
    fprintf(stderr, "Setting up a tcp connection to %s, port %" PRIu16
 
458
            "\n", ip, port);
460
459
  }
461
460
  
462
461
  tcp_sd = socket(PF_INET6, SOCK_STREAM, 0);
486
485
    fprintf(stderr, "Bad address: %s\n", ip);
487
486
    return -1;
488
487
  }
489
 
  to.in6.sin6_port = htons(port);       /* Spurious warning */
 
488
  to.in6.sin6_port = htons(port); /* Spurious warning */
490
489
  
491
490
  to.in6.sin6_scope_id = (uint32_t)if_index;
492
491
  
493
492
  if(debug){
494
 
    fprintf(stderr, "Connection to: %s, port %d\n", ip, port);
 
493
    fprintf(stderr, "Connection to: %s, port %" PRIu16 "\n", ip,
 
494
            port);
495
495
    char addrstr[INET6_ADDRSTRLEN] = "";
496
496
    if(inet_ntop(to.in6.sin6_family, &(to.in6.sin6_addr), addrstr,
497
497
                 sizeof(addrstr)) == NULL){
676
676
      char ip[AVAHI_ADDRESS_STR_MAX];
677
677
      avahi_address_snprint(ip, sizeof(ip), address);
678
678
      if(debug){
679
 
        fprintf(stderr, "Mandos server \"%s\" found on %s (%s, %d) on"
680
 
                " port %d\n", name, host_name, ip, interface, port);
 
679
        fprintf(stderr, "Mandos server \"%s\" found on %s (%s, %"
 
680
                PRIu16 ") on port %d\n", name, host_name, ip,
 
681
                interface, port);
681
682
      }
682
683
      int ret = start_mandos_communication(ip, port, interface, mc);
683
684
      if (ret == 0){
684
 
        exit(EXIT_SUCCESS);
 
685
        avahi_simple_poll_quit(mc->simple_poll);
685
686
      }
686
687
    }
687
688
  }
849
850
          break;
850
851
        case ARGP_KEY_ARG:
851
852
          argp_usage (state);
 
853
        case ARGP_KEY_END:
852
854
          break;
853
 
          case ARGP_KEY_END:
854
 
            break;
855
855
        default:
856
856
          return ARGP_ERR_UNKNOWN;
857
857
        }
864
864
                           " passwords from mandos server" };
865
865
      ret = argp_parse (&argp, argc, argv, 0, 0, NULL);
866
866
      if (ret == ARGP_ERR_UNKNOWN){
867
 
        fprintf(stderr, "Unkown error while parsing arguments\n");
 
867
        fprintf(stderr, "Unknown error while parsing arguments\n");
868
868
        exitcode = EXIT_FAILURE;
869
869
        goto end;
870
870
      }
880
880
    seckeyfile = combinepath(keydir, seckeyfile);
881
881
    if (seckeyfile == NULL){
882
882
      perror("combinepath");
 
883
      exitcode = EXIT_FAILURE;
883
884
      goto end;
884
885
    }
885
886
 
886
887
    ret = init_gnutls_global(&mc, pubkeyfile, seckeyfile);
887
888
    if (ret == -1){
888
 
      fprintf(stderr, "init_gnutls_global\n");
 
889
      fprintf(stderr, "init_gnutls_global failed\n");
 
890
      exitcode = EXIT_FAILURE;
889
891
      goto end;
890
892
    } else {
891
893
      gnutls_initalized = true;
892
894
    }
893
 
 
 
895
    
 
896
    /* If the interface is down, bring it up */
 
897
    {
 
898
      sd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
 
899
      if(sd < 0) {
 
900
        perror("socket");
 
901
        exitcode = EXIT_FAILURE;
 
902
        goto end;
 
903
      }
 
904
      strcpy(network.ifr_name, interface); /* Spurious warning */
 
905
      ret = ioctl(sd, SIOCGIFFLAGS, &network);
 
906
      if(ret == -1){
 
907
        perror("ioctl SIOCGIFFLAGS");
 
908
        exitcode = EXIT_FAILURE;
 
909
        goto end;
 
910
      }
 
911
      if((network.ifr_flags & IFF_UP) == 0){
 
912
        network.ifr_flags |= IFF_UP;
 
913
        ret = ioctl(sd, SIOCSIFFLAGS, &network);
 
914
        if(ret == -1){
 
915
          perror("ioctl SIOCSIFFLAGS");
 
916
          exitcode = EXIT_FAILURE;
 
917
          goto end;
 
918
        }
 
919
      }
 
920
      close(sd);
 
921
    }
 
922
    
894
923
    uid = getuid();
895
924
    gid = getgid();
896
 
 
 
925
    
897
926
    ret = setuid(uid);
898
927
    if (ret == -1){
899
928
      perror("setuid");
937
966
      goto end;
938
967
    }
939
968
    
940
 
    /* If the interface is down, bring it up */
941
 
    {
942
 
      sd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
943
 
      if(sd < 0) {
944
 
        perror("socket");
945
 
        exitcode = EXIT_FAILURE;
946
 
        goto end;
947
 
      }
948
 
      strcpy(network.ifr_name, interface); /* Spurious warning */
949
 
      ret = ioctl(sd, SIOCGIFFLAGS, &network);
950
 
      if(ret == -1){
951
 
        perror("ioctl SIOCGIFFLAGS");
952
 
        exitcode = EXIT_FAILURE;
953
 
        goto end;
954
 
      }
955
 
      if((network.ifr_flags & IFF_UP) == 0){
956
 
        network.ifr_flags |= IFF_UP;
957
 
        ret = ioctl(sd, SIOCSIFFLAGS, &network);
958
 
        if(ret == -1){
959
 
          perror("ioctl SIOCSIFFLAGS");
960
 
          exitcode = EXIT_FAILURE;
961
 
          goto end;
962
 
        }
963
 
      }
964
 
      close(sd);
965
 
    }
966
 
    
967
969
    if (not debug){
968
970
      avahi_set_log_function(empty_log);
969
971
    }