stdin-echo fix in server too
This commit is contained in:
parent
71973f13ef
commit
879e73a4c2
25
src/common.c
25
src/common.c
|
@ -29,6 +29,7 @@
|
|||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
@ -86,3 +87,27 @@ do_detach()
|
|||
umask(0);
|
||||
alarm(0);
|
||||
}
|
||||
|
||||
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';
|
||||
}
|
||||
|
|
|
@ -50,4 +50,6 @@ void close_dns(int);
|
|||
void do_chroot(char *);
|
||||
void do_detach();
|
||||
|
||||
void read_password(char*, size_t);
|
||||
|
||||
#endif
|
||||
|
|
25
src/iodine.c
25
src/iodine.c
|
@ -34,7 +34,6 @@
|
|||
#ifdef DARWIN
|
||||
#include <arpa/nameser8_compat.h>
|
||||
#endif
|
||||
#include <termios.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "encoding.h"
|
||||
|
@ -570,30 +569,6 @@ set_nameserver(const char *cp)
|
|||
nameserv.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
|
||||
usage() {
|
||||
extern char *__progname;
|
||||
|
|
|
@ -514,7 +514,7 @@ main(int argc, char **argv)
|
|||
argv += optind;
|
||||
|
||||
if (geteuid() != 0) {
|
||||
printf("Run as root and you'll be happy.\n");
|
||||
warnx("Run as root and you'll be happy.\n");
|
||||
usage();
|
||||
}
|
||||
|
||||
|
@ -523,33 +523,29 @@ main(int argc, char **argv)
|
|||
|
||||
topdomain = strdup(argv[1]);
|
||||
if (strlen(topdomain) > 128 || topdomain[0] == '.') {
|
||||
printf("Use a topdomain max 128 chars long. Do not start it with a dot.\n");
|
||||
warnx("Use a topdomain max 128 chars long. Do not start it with a dot.\n");
|
||||
usage();
|
||||
}
|
||||
|
||||
if (username) {
|
||||
pw = getpwnam(username);
|
||||
if (!pw) {
|
||||
printf("User %s does not exist!\n", username);
|
||||
if (username != NULL) {
|
||||
if ((pw = getpwnam(username)) == NULL) {
|
||||
warnx("User %s does not exist!\n", username);
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (mtu == 0) {
|
||||
printf("Bad MTU given.\n");
|
||||
warnx("Bad MTU given.\n");
|
||||
usage();
|
||||
}
|
||||
|
||||
if (listen_ip == INADDR_NONE) {
|
||||
printf("Bad IP address to listen on.\n");
|
||||
warnx("Bad IP address to listen on.\n");
|
||||
usage();
|
||||
}
|
||||
|
||||
if (strlen(password) == 0) {
|
||||
printf("Enter password on stdin:\n");
|
||||
scanf("%32s", password);
|
||||
password[32] = 0;
|
||||
}
|
||||
if (strlen(password) == 0)
|
||||
read_password(password, sizeof(password));
|
||||
|
||||
if ((tun_fd = open_tun(device)) == -1)
|
||||
goto cleanup0;
|
||||
|
@ -562,22 +558,21 @@ main(int argc, char **argv)
|
|||
my_mtu = mtu;
|
||||
init_users(my_ip);
|
||||
|
||||
printf("Listening to dns for domain %s\n", argv[1]);
|
||||
printf("Listening to dns for domain %s\n", topdomain);
|
||||
|
||||
if (newroot != NULL)
|
||||
do_chroot(newroot);
|
||||
|
||||
signal(SIGINT, sigint);
|
||||
if (username) {
|
||||
if (username != NULL) {
|
||||
if (setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0) {
|
||||
printf("Could not switch to user %s!\n", username);
|
||||
warnx("Could not switch to user %s!\n", username);
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (!foreground) {
|
||||
if (foreground == 0)
|
||||
do_detach();
|
||||
}
|
||||
|
||||
tunnel(tun_fd, dnsd_fd);
|
||||
|
||||
|
|
Loading…
Reference in New Issue