From 71973f13ef759abc4c313fffa357da7f2c83d9dc Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Thu, 12 Jul 2007 15:22:32 +0000 Subject: [PATCH] #21: Reverted [538], reopening --- src/iodined.c | 31 +++++++++++-------------------- src/user.h | 3 ++- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/iodined.c b/src/iodined.c index 2241927..51083db 100644 --- a/src/iodined.c +++ b/src/iodined.c @@ -127,19 +127,10 @@ send_version_response(int fd, version_ack_t ack, uint32_t payload, struct user * write_dns(fd, &u->q, out, sizeof(out)); } -static int -cmp_remote_ip(int userid, struct query *q) { - struct sockaddr_in *tempin; - - tempin = (struct sockaddr_in *) &(q->from); - return memcmp(&(users[userid].host), &(tempin->sin_addr), sizeof(struct in_addr)); -} - static int tunnel_dns(int tun_fd, int dns_fd) { struct in_addr tempip; - struct sockaddr_in *tempin; struct user dummy; struct ip *hdr; unsigned long outlen; @@ -173,10 +164,9 @@ tunnel_dns(int tun_fd, int dns_fd) userid = find_available_user(); if (userid >= 0) { users[userid].seed = rand(); - /* Store remote IP number */ - tempin = (struct sockaddr_in *) &(dummy.q.from); - memcpy(&(users[userid].host), &(tempin->sin_addr), sizeof(struct in_addr)); + memcpy(&(users[userid].host), &(dummy.q.from), dummy.q.fromlen); memcpy(&(users[userid].q), &(dummy.q), sizeof(struct query)); + users[userid].addrlen = dummy.q.fromlen; users[userid].encoder = get_base32_encoder(); send_version_response(dns_fd, VERSION_ACK, users[userid].seed, &users[userid]); users[userid].q.id = 0; @@ -198,7 +188,8 @@ tunnel_dns(int tun_fd, int dns_fd) users[userid].last_pkt = time(NULL); login_calculate(logindata, 16, password, users[userid].seed); - if (cmp_remote_ip(userid, &(dummy.q)) != 0) { + if (dummy.q.fromlen != users[userid].addrlen || + memcmp(&(users[userid].host), &(dummy.q.from), dummy.q.fromlen) != 0) { write_dns(dns_fd, &(dummy.q), "BADIP", 5); } else { if (read >= 18 && (memcmp(logindata, unpacked+1, 16) == 0)) { @@ -229,10 +220,8 @@ tunnel_dns(int tun_fd, int dns_fd) write_dns(dns_fd, &(dummy.q), "BADIP", 5); return 0; /* illegal id */ } - if (cmp_remote_ip(userid, &(dummy.q)) != 0) { - memcpy(&(users[userid].q), &(dummy.q), sizeof(struct query)); - users[userid].last_pkt = time(NULL); - } + memcpy(&(users[userid].q), &(dummy.q), sizeof(struct query)); + users[userid].last_pkt = time(NULL); } else if(in[0] == 'Z' || in[0] == 'z') { /* Case conservation check */ @@ -256,7 +245,8 @@ tunnel_dns(int tun_fd, int dns_fd) } /* Check sending ip number */ - if (cmp_remote_ip(userid, &(dummy.q)) != 0) { + if (dummy.q.fromlen != users[userid].addrlen || + memcmp(&(users[userid].host), &(dummy.q.from), dummy.q.fromlen) != 0) { write_dns(dns_fd, &(dummy.q), "BADIP", 5); } else { /* decode with this users encoding */ @@ -265,6 +255,7 @@ tunnel_dns(int tun_fd, int dns_fd) users[userid].last_pkt = time(NULL); memcpy(&(users[userid].q), &(dummy.q), sizeof(struct query)); + users[userid].addrlen = dummy.q.fromlen; memcpy(users[userid].inpacket.data + users[userid].inpacket.offset, unpacked, read); users[userid].inpacket.len += read; users[userid].inpacket.offset += read; @@ -293,8 +284,8 @@ tunnel_dns(int tun_fd, int dns_fd) } } /* userid must be set for a reply to be sent */ - if (userid >= 0 && userid < USERS && - cmp_remote_ip(userid, &(dummy.q)) != 0 && + if (userid >= 0 && userid < USERS && dummy.q.fromlen == users[userid].addrlen && + memcmp(&(users[userid].host), &(dummy.q.from), dummy.q.fromlen) == 0 && users[userid].outpacket.len > 0) { write_dns(dns_fd, &(dummy.q), users[userid].outpacket.data, users[userid].outpacket.len); diff --git a/src/user.h b/src/user.h index b333bcb..2d0d2ad 100644 --- a/src/user.h +++ b/src/user.h @@ -25,7 +25,8 @@ struct user { time_t last_pkt; int seed; in_addr_t tun_ip; - struct in_addr host; + struct sockaddr host; + int addrlen; struct query q; struct packet inpacket; struct packet outpacket;