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

name change for argp

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 */
47
49
#include <sys/types.h>          /* socket(), inet_pton(), sockaddr,
48
50
                                   sockaddr_in6, PF_INET6,
49
51
                                   SOCK_STREAM, INET6_ADDRSTRLEN,
50
52
                                   uid_t, gid_t */
51
 
#include <inttypes.h>           /* PRIu16 */
52
53
#include <sys/socket.h>         /* socket(), struct sockaddr_in6,
53
54
                                   struct in6_addr, inet_pton(),
54
55
                                   connect() */
227
228
    } else {
228
229
      fprintf(stderr, "Unsupported algorithm: %s\n",
229
230
              result->unsupported_algorithm);
230
 
      fprintf(stderr, "Wrong key usage: %u\n",
 
231
      fprintf(stderr, "Wrong key usage: %d\n",
231
232
              result->wrong_key_usage);
232
233
      if(result->file_name != NULL){
233
234
        fprintf(stderr, "File name: %s\n", result->file_name);
454
455
  }
455
456
  
456
457
  if(debug){
457
 
    fprintf(stderr, "Setting up a tcp connection to %s, port %" PRIu16
458
 
            "\n", ip, port);
 
458
    fprintf(stderr, "Setting up a tcp connection to %s, port %d\n",
 
459
            ip, port);
459
460
  }
460
461
  
461
462
  tcp_sd = socket(PF_INET6, SOCK_STREAM, 0);
485
486
    fprintf(stderr, "Bad address: %s\n", ip);
486
487
    return -1;
487
488
  }
488
 
  to.in6.sin6_port = htons(port); /* Spurious warning */
 
489
  to.in6.sin6_port = htons(port);       /* Spurious warning */
489
490
  
490
491
  to.in6.sin6_scope_id = (uint32_t)if_index;
491
492
  
492
493
  if(debug){
493
 
    fprintf(stderr, "Connection to: %s, port %" PRIu16 "\n", ip,
494
 
            port);
 
494
    fprintf(stderr, "Connection to: %s, port %d\n", ip, 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, %"
680
 
                PRIu16 ") on port %d\n", name, host_name, ip,
681
 
                interface, port);
 
679
        fprintf(stderr, "Mandos server \"%s\" found on %s (%s, %d) on"
 
680
                " port %d\n", name, host_name, ip, interface, port);
682
681
      }
683
682
      int ret = start_mandos_communication(ip, port, interface, mc);
684
683
      if (ret == 0){
865
864
                           " passwords from mandos server" };
866
865
      ret = argp_parse (&argp, argc, argv, 0, 0, NULL);
867
866
      if (ret == ARGP_ERR_UNKNOWN){
868
 
        fprintf(stderr, "Unknown error while parsing arguments\n");
 
867
        fprintf(stderr, "Unkown error while parsing arguments\n");
869
868
        exitcode = EXIT_FAILURE;
870
869
        goto end;
871
870
      }
891
890
    } else {
892
891
      gnutls_initalized = true;
893
892
    }
894
 
    
895
 
    /* If the interface is down, bring it up */
896
 
    {
897
 
      sd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
898
 
      if(sd < 0) {
899
 
        perror("socket");
900
 
        exitcode = EXIT_FAILURE;
901
 
        goto end;
902
 
      }
903
 
      strcpy(network.ifr_name, interface); /* Spurious warning */
904
 
      ret = ioctl(sd, SIOCGIFFLAGS, &network);
905
 
      if(ret == -1){
906
 
        perror("ioctl SIOCGIFFLAGS");
907
 
        exitcode = EXIT_FAILURE;
908
 
        goto end;
909
 
      }
910
 
      if((network.ifr_flags & IFF_UP) == 0){
911
 
        network.ifr_flags |= IFF_UP;
912
 
        ret = ioctl(sd, SIOCSIFFLAGS, &network);
913
 
        if(ret == -1){
914
 
          perror("ioctl SIOCSIFFLAGS");
915
 
          exitcode = EXIT_FAILURE;
916
 
          goto end;
917
 
        }
918
 
      }
919
 
      close(sd);
920
 
    }
921
 
    
 
893
 
922
894
    uid = getuid();
923
895
    gid = getgid();
924
 
    
 
896
 
925
897
    ret = setuid(uid);
926
898
    if (ret == -1){
927
899
      perror("setuid");
965
937
      goto end;
966
938
    }
967
939
    
 
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
    
968
967
    if (not debug){
969
968
      avahi_set_log_function(empty_log);
970
969
    }