/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

Fixed unkown -> unknown
updated TODO

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() */
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){
864
865
                           " passwords from mandos server" };
865
866
      ret = argp_parse (&argp, argc, argv, 0, 0, NULL);
866
867
      if (ret == ARGP_ERR_UNKNOWN){
867
 
        fprintf(stderr, "Unkown error while parsing arguments\n");
 
868
        fprintf(stderr, "Unknown error while parsing arguments\n");
868
869
        exitcode = EXIT_FAILURE;
869
870
        goto end;
870
871
      }
890
891
    } else {
891
892
      gnutls_initalized = true;
892
893
    }
893
 
 
 
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
    
894
922
    uid = getuid();
895
923
    gid = getgid();
896
 
 
 
924
    
897
925
    ret = setuid(uid);
898
926
    if (ret == -1){
899
927
      perror("setuid");
937
965
      goto end;
938
966
    }
939
967
    
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
968
    if (not debug){
968
969
      avahi_set_log_function(empty_log);
969
970
    }