This commit is contained in:
Bjorn Andersson 2007-02-06 16:01:09 +00:00
parent c58df44dc6
commit 0d08be747f
2 changed files with 40 additions and 38 deletions

View file

@ -101,9 +101,9 @@ read_dns(int fd, char *buf, int buflen)
int r; int r;
addrlen = sizeof(struct sockaddr); addrlen = sizeof(struct sockaddr);
r = recvfrom(fd, packet, sizeof(packet), 0, (struct sockaddr*)&from, &addrlen); if ((r = recvfrom(fd, packet, sizeof(packet), 0,
if(r == -1) { (struct sockaddr*)&from, &addrlen)) == -1) {
perror("recvfrom"); warn("recvfrom");
return 0; return 0;
} }
@ -129,14 +129,15 @@ read_dns(int fd, char *buf, int buflen)
static int static int
tunnel_tun(int tun_fd, int dns_fd) tunnel_tun(int tun_fd, int dns_fd)
{ {
char out[64*1024];
char in[64*1024];
unsigned long outlen; unsigned long outlen;
unsigned long inlen; unsigned long inlen;
char out[64*1024];
char in[64*1024];
size_t read; size_t read;
read = read_tun(tun_fd, in, sizeof(in)); if ((read = read_tun(tun_fd, in, sizeof(in))) <= 0)
if(read > 0) { return -1;
outlen = sizeof(out); outlen = sizeof(out);
inlen = read; inlen = read;
compress2(out, &outlen, in, inlen, 9); compress2(out, &outlen, in, inlen, 9);
@ -147,7 +148,6 @@ tunnel_tun(int tun_fd, int dns_fd)
packetlen = outlen; packetlen = outlen;
send_chunk(dns_fd); send_chunk(dns_fd);
}
return read; return read;
} }
@ -155,14 +155,15 @@ tunnel_tun(int tun_fd, int dns_fd)
static int static int
tunnel_dns(int tun_fd, int dns_fd) tunnel_dns(int tun_fd, int dns_fd)
{ {
char out[64*1024];
char in[64*1024];
unsigned long outlen; unsigned long outlen;
unsigned long inlen; unsigned long inlen;
char out[64*1024];
char in[64*1024];
size_t read; size_t read;
read = read_dns(dns_fd, in, sizeof(in)); if ((read = read_dns(dns_fd, in, sizeof(in))) <= 0)
if (read > 0) { return -1;
outlen = sizeof(out); outlen = sizeof(out);
inlen = read; inlen = read;
uncompress(out, &outlen, in, inlen); uncompress(out, &outlen, in, inlen);
@ -170,7 +171,6 @@ tunnel_dns(int tun_fd, int dns_fd)
write_tun(tun_fd, out, outlen); write_tun(tun_fd, out, outlen);
if (!is_sending()) if (!is_sending())
send_ping(dns_fd); send_ping(dns_fd);
}
return read; return read;
} }
@ -408,7 +408,7 @@ handshake(int dns_fd)
return 1; return 1;
} }
int static void
set_target(const char *host) set_target(const char *host)
{ {
struct hostent *h; struct hostent *h;
@ -420,11 +420,8 @@ set_target(const char *host)
peer.sin_family = AF_INET; peer.sin_family = AF_INET;
peer.sin_port = htons(53); peer.sin_port = htons(53);
peer.sin_addr = *((struct in_addr *) h->h_addr); peer.sin_addr = *((struct in_addr *) h->h_addr);
return 0;
} }
static void static void
usage() { usage() {
extern char *__progname; extern char *__progname;
@ -449,14 +446,19 @@ help() {
printf(" -d device to set tunnel device name\n"); printf(" -d device to set tunnel device name\n");
printf("nameserver is the IP number of the relaying nameserver\n"); printf("nameserver is the IP number of the relaying nameserver\n");
printf("topdomain is the FQDN that is delegated to the tunnel endpoint.\n"); printf("topdomain is the FQDN that is delegated to the tunnel endpoint.\n");
exit(0); exit(0);
} }
static void static void
version() { version() {
char *svnver = "$Rev$ from $Date$"; char *svnver;
svnver = "$Rev$ from $Date$";
printf("iodine IP over DNS tunneling client\n"); printf("iodine IP over DNS tunneling client\n");
printf("SVN version: %s\n", svnver); printf("SVN version: %s\n", svnver);
exit(0); exit(0);
} }
@ -472,12 +474,12 @@ main(int argc, char **argv)
int tun_fd; int tun_fd;
int dns_fd; int dns_fd;
username = NULL;
memset(password, 0, 33); memset(password, 0, 33);
username = NULL;
foreground = 0; foreground = 0;
chunkid = 0;
newroot = NULL; newroot = NULL;
device = NULL; device = NULL;
chunkid = 0;
while ((choice = getopt(argc, argv, "vfhu:t:d:P:")) != -1) { while ((choice = getopt(argc, argv, "vfhu:t:d:P:")) != -1) {
switch(choice) { switch(choice) {
@ -540,8 +542,7 @@ main(int argc, char **argv)
goto cleanup1; goto cleanup1;
if ((dns_fd = open_dns(0, INADDR_ANY)) == -1) if ((dns_fd = open_dns(0, INADDR_ANY)) == -1)
goto cleanup2; goto cleanup2;
if (set_target(argv[0]) == -1) set_target(argv[0]);
goto cleanup2;
signal(SIGINT, sighandler); signal(SIGINT, sighandler);
signal(SIGTERM, sighandler); signal(SIGTERM, sighandler);
@ -554,6 +555,7 @@ main(int argc, char **argv)
if (newroot) { if (newroot) {
if (chroot(newroot) != 0 || chdir("/") != 0) if (chroot(newroot) != 0 || chdir("/") != 0)
err(1, "%s", newroot); err(1, "%s", newroot);
seteuid(geteuid()); seteuid(geteuid());
setuid(getuid()); setuid(getuid());
} }

View file

@ -88,10 +88,10 @@ tunnel_dns(int tun_fd, int dns_fd)
{ {
struct in_addr clientip; struct in_addr clientip;
struct in_addr myip; struct in_addr myip;
char logindata[16];
char out[64*1024]; char out[64*1024];
char in[64*1024]; char in[64*1024];
char *tmp[2]; char *tmp[2];
char logindata[16];
long outlen; long outlen;
int read; int read;
int code; int code;