/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

  • Committer: Teddy Hogeborn
  • Date: 2008-08-11 07:41:40 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080811074140-3wrl2jux1s0jy5kk
* mandos-client.c (print_out_password): Strip trailing '\n'.
  (main): Do not add trailing newline on fallback.

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,
485
487
    fprintf(stderr, "Bad address: %s\n", ip);
486
488
    return -1;
487
489
  }
488
 
  to.in6.sin6_port = htons(port); /* Spurious warning */
 
490
  to.in6.sin6_port = htons(port);       /* Spurious warning */
489
491
  
490
492
  to.in6.sin6_scope_id = (uint32_t)if_index;
491
493
  
865
867
                           " passwords from mandos server" };
866
868
      ret = argp_parse (&argp, argc, argv, 0, 0, NULL);
867
869
      if (ret == ARGP_ERR_UNKNOWN){
868
 
        fprintf(stderr, "Unknown error while parsing arguments\n");
 
870
        fprintf(stderr, "Unkown error while parsing arguments\n");
869
871
        exitcode = EXIT_FAILURE;
870
872
        goto end;
871
873
      }
881
883
    seckeyfile = combinepath(keydir, seckeyfile);
882
884
    if (seckeyfile == NULL){
883
885
      perror("combinepath");
884
 
      exitcode = EXIT_FAILURE;
885
886
      goto end;
886
887
    }
887
888
 
888
889
    ret = init_gnutls_global(&mc, pubkeyfile, seckeyfile);
889
890
    if (ret == -1){
890
 
      fprintf(stderr, "init_gnutls_global failed\n");
891
 
      exitcode = EXIT_FAILURE;
 
891
      fprintf(stderr, "init_gnutls_global\n");
892
892
      goto end;
893
893
    } else {
894
894
      gnutls_initalized = true;
895
895
    }
896
 
    
897
 
    /* If the interface is down, bring it up */
898
 
    {
899
 
      sd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
900
 
      if(sd < 0) {
901
 
        perror("socket");
902
 
        exitcode = EXIT_FAILURE;
903
 
        goto end;
904
 
      }
905
 
      strcpy(network.ifr_name, interface); /* Spurious warning */
906
 
      ret = ioctl(sd, SIOCGIFFLAGS, &network);
907
 
      if(ret == -1){
908
 
        perror("ioctl SIOCGIFFLAGS");
909
 
        exitcode = EXIT_FAILURE;
910
 
        goto end;
911
 
      }
912
 
      if((network.ifr_flags & IFF_UP) == 0){
913
 
        network.ifr_flags |= IFF_UP;
914
 
        ret = ioctl(sd, SIOCSIFFLAGS, &network);
915
 
        if(ret == -1){
916
 
          perror("ioctl SIOCSIFFLAGS");
917
 
          exitcode = EXIT_FAILURE;
918
 
          goto end;
919
 
        }
920
 
      }
921
 
      close(sd);
922
 
    }
923
 
    
 
896
 
924
897
    uid = getuid();
925
898
    gid = getgid();
926
 
    
 
899
 
927
900
    ret = setuid(uid);
928
901
    if (ret == -1){
929
902
      perror("setuid");
967
940
      goto end;
968
941
    }
969
942
    
 
943
    /* If the interface is down, bring it up */
 
944
    {
 
945
      sd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
 
946
      if(sd < 0) {
 
947
        perror("socket");
 
948
        exitcode = EXIT_FAILURE;
 
949
        goto end;
 
950
      }
 
951
      strcpy(network.ifr_name, interface); /* Spurious warning */
 
952
      ret = ioctl(sd, SIOCGIFFLAGS, &network);
 
953
      if(ret == -1){
 
954
        perror("ioctl SIOCGIFFLAGS");
 
955
        exitcode = EXIT_FAILURE;
 
956
        goto end;
 
957
      }
 
958
      if((network.ifr_flags & IFF_UP) == 0){
 
959
        network.ifr_flags |= IFF_UP;
 
960
        ret = ioctl(sd, SIOCSIFFLAGS, &network);
 
961
        if(ret == -1){
 
962
          perror("ioctl SIOCSIFFLAGS");
 
963
          exitcode = EXIT_FAILURE;
 
964
          goto end;
 
965
        }
 
966
      }
 
967
      close(sd);
 
968
    }
 
969
    
970
970
    if (not debug){
971
971
      avahi_set_log_function(empty_log);
972
972
    }