mirror of
https://github.com/yarrick/iodine.git
synced 2024-09-07 03:27:00 +00:00
Added daemonizing, less debug
This commit is contained in:
parent
ab2584d42d
commit
b1dbcc664b
4
dns.c
4
dns.c
|
@ -85,11 +85,13 @@ open_dns(const char *host, const char *domain)
|
|||
}
|
||||
|
||||
printf("Opened UDP socket\n");
|
||||
printf("Sending queries for %s to %s\n", domain, host);
|
||||
|
||||
// Init dns target struct
|
||||
h = gethostbyname(host);
|
||||
if (!h) {
|
||||
perror("gethostbyname");
|
||||
printf("Could not resolve name %s, exiting\n", host);
|
||||
exit(9);
|
||||
}
|
||||
bzero(&peer, sizeof(peer));
|
||||
peer.sin_family = AF_INET;
|
||||
|
|
20
iodine.c
20
iodine.c
|
@ -81,7 +81,6 @@ tunnel(int tun_fd, int dns_fd)
|
|||
if(FD_ISSET(tun_fd, &fds)) {
|
||||
read = read_tun(tun_fd, frame, FRAMESIZE);
|
||||
if (read > 0) {
|
||||
printf("Got data on tun! %d bytes\n", read);
|
||||
buflen = sizeof(buf);
|
||||
compress2(buf, &buflen, frame->data, read - 4, 9);
|
||||
dns_handle_tun(dns_fd, buf, buflen);
|
||||
|
@ -93,8 +92,6 @@ tunnel(int tun_fd, int dns_fd)
|
|||
buflen = 64*1024-4;
|
||||
uncompress(frame->data, &buflen, buf, read);
|
||||
|
||||
printf("Got data on dns! %d bytes\n", read);
|
||||
|
||||
frame->flags = htons(0x0000);
|
||||
#ifdef LINUX
|
||||
frame->proto = htons(0x0800); // Linux wants ETH_P_IP
|
||||
|
@ -121,6 +118,8 @@ extern char *__progname;
|
|||
static void
|
||||
usage() {
|
||||
printf("Usage: %s [-u user] nameserver topdomain\n", __progname);
|
||||
printf("-f is to keep running in foreground\n");
|
||||
printf("-u name to drop privileges and run as user 'name'\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
|
@ -132,16 +131,21 @@ main(int argc, char **argv)
|
|||
int choice;
|
||||
char *username;
|
||||
struct passwd *pw;
|
||||
int foreground;
|
||||
|
||||
username = NULL;
|
||||
foreground = 0;
|
||||
|
||||
if (geteuid() != 0) {
|
||||
printf("Run as root and you'll be happy.\n");
|
||||
usage();
|
||||
}
|
||||
|
||||
while ((choice = getopt(argc, argv, "u:")) != -1) {
|
||||
while ((choice = getopt(argc, argv, "fu:")) != -1) {
|
||||
switch(choice) {
|
||||
case 'f':
|
||||
foreground = 1;
|
||||
break;
|
||||
case 'u':
|
||||
username = optarg;
|
||||
break;
|
||||
|
@ -166,13 +170,17 @@ main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
tun_fd = open_tun();
|
||||
dns_fd = open_dns(argv[0], argv[1]);
|
||||
printf("Sending queries for %s to %s\n", argv[1], argv[0]);
|
||||
|
||||
signal(SIGINT, sigint);
|
||||
|
||||
if (!foreground) {
|
||||
daemon(0, 0);
|
||||
umask(0);
|
||||
alarm(0);
|
||||
}
|
||||
|
||||
if (username) {
|
||||
if (setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0) {
|
||||
printf("Could not switch to user %s!\n", username);
|
||||
|
|
19
iodined.c
19
iodined.c
|
@ -116,7 +116,9 @@ extern char *__progname;
|
|||
|
||||
static void
|
||||
usage() {
|
||||
printf("Usage: %s [-u user] topdomain\n", __progname);
|
||||
printf("Usage: %s [-f] [-u user] topdomain\n", __progname);
|
||||
printf("-f is to keep running in foreground\n");
|
||||
printf("-u name to drop privileges and run as user 'name'\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
|
@ -128,16 +130,21 @@ main(int argc, char **argv)
|
|||
int choice;
|
||||
char *username;
|
||||
struct passwd *pw;
|
||||
int foreground;
|
||||
|
||||
username = NULL;
|
||||
foreground = 0;
|
||||
|
||||
if (geteuid() != 0) {
|
||||
printf("Run as root and you'll be happy.\n");
|
||||
usage();
|
||||
}
|
||||
|
||||
while ((choice = getopt(argc, argv, "u:")) != -1) {
|
||||
while ((choice = getopt(argc, argv, "fu:")) != -1) {
|
||||
switch(choice) {
|
||||
case 'f':
|
||||
foreground = 1;
|
||||
break;
|
||||
case 'u':
|
||||
username = optarg;
|
||||
break;
|
||||
|
@ -166,6 +173,12 @@ main(int argc, char **argv)
|
|||
dnsd_fd = open_dnsd(argv[0]);
|
||||
printf("Listening to dns for domain %s\n", argv[0]);
|
||||
|
||||
if (!foreground) {
|
||||
daemon(0, 0);
|
||||
umask(0);
|
||||
alarm(0);
|
||||
}
|
||||
|
||||
signal(SIGINT, sigint);
|
||||
if (username) {
|
||||
if (setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0) {
|
||||
|
@ -177,8 +190,6 @@ main(int argc, char **argv)
|
|||
|
||||
tunnel(tun_fd, dnsd_fd);
|
||||
|
||||
printf("Closing tunnel\n");
|
||||
|
||||
close_dnsd(dnsd_fd);
|
||||
close_tun(tun_fd);
|
||||
|
||||
|
|
Loading…
Reference in a new issue