mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-23 00:29:20 +02:00
use termios to not echo password when entered on stdin
This commit is contained in:
parent
810bb39899
commit
13df3ca856
32
src/iodine.c
32
src/iodine.c
|
@ -34,6 +34,7 @@
|
||||||
#ifdef DARWIN
|
#ifdef DARWIN
|
||||||
#include <arpa/nameser8_compat.h>
|
#include <arpa/nameser8_compat.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <termios.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "encoding.h"
|
#include "encoding.h"
|
||||||
|
@ -569,6 +570,30 @@ set_nameserver(const char *cp)
|
||||||
peer.sin_addr = addr;
|
peer.sin_addr = addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
read_password(char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct termios old;
|
||||||
|
struct termios tp;
|
||||||
|
char pwd[80];
|
||||||
|
|
||||||
|
tcgetattr(0, &tp);
|
||||||
|
old = tp;
|
||||||
|
|
||||||
|
tp.c_lflag &= (~ECHO);
|
||||||
|
tcsetattr(0, TCSANOW, &tp);
|
||||||
|
|
||||||
|
printf("Enter password: ");
|
||||||
|
fflush(stdout);
|
||||||
|
scanf("%79s", pwd);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
tcsetattr(0, TCSANOW, &old);
|
||||||
|
|
||||||
|
strncpy(buf, pwd, len);
|
||||||
|
buf[len-1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage() {
|
usage() {
|
||||||
extern char *__progname;
|
extern char *__progname;
|
||||||
|
@ -700,11 +725,8 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(password) == 0) {
|
if (strlen(password) == 0)
|
||||||
printf("Enter password on stdin:\n");
|
read_password(password, sizeof(password));
|
||||||
scanf("%32s", password);
|
|
||||||
password[32] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((tun_fd = open_tun(device)) == -1)
|
if ((tun_fd = open_tun(device)) == -1)
|
||||||
goto cleanup1;
|
goto cleanup1;
|
||||||
|
|
Loading…
Reference in New Issue