Check ip address of incoming packet

This commit is contained in:
Erik Ekman 2006-11-18 16:19:39 +00:00
parent 1c7f63e97a
commit cf3ca7e5d0

View File

@ -150,6 +150,11 @@ tunnel(int tun_fd, int dns_fd)
dnsd_send(dns_fd, &q, out, 8); dnsd_send(dns_fd, &q, out, 8);
} }
} else if(in[0] == 'L' || in[0] == 'l') { } else if(in[0] == 'L' || in[0] == 'l') {
// Check sending ip number
if (q.fromlen != u.addrlen ||
memcmp(&(u.host), &(q.from), q.fromlen) != 0) {
dnsd_send(dns_fd, &q, "BADIP", 5);
} else {
// Login phase, handle auth // Login phase, handle auth
login_calculate(logindata, 16, password, seed); login_calculate(logindata, 16, password, seed);
if (read >= 17 && (memcmp(logindata, in+1, 16) == 0)) { if (read >= 17 && (memcmp(logindata, in+1, 16) == 0)) {
@ -171,6 +176,7 @@ tunnel(int tun_fd, int dns_fd)
} else { } else {
dnsd_send(dns_fd, &q, "LNAK", 4); dnsd_send(dns_fd, &q, "LNAK", 4);
} }
}
} else if((in[0] >= '0' && in[0] <= '9') } else if((in[0] >= '0' && in[0] <= '9')
|| (in[0] >= 'a' && in[0] <= 'f') || (in[0] >= 'a' && in[0] <= 'f')
|| (in[0] >= 'A' && in[0] <= 'F')) { || (in[0] >= 'A' && in[0] <= 'F')) {
@ -181,6 +187,11 @@ tunnel(int tun_fd, int dns_fd)
if ((in[0] >= 'A' && in[0] <= 'F')) if ((in[0] >= 'A' && in[0] <= 'F'))
code = in[0] - 'A' + 10; code = in[0] - 'A' + 10;
// Check sending ip number
if (q.fromlen != u.addrlen ||
memcmp(&(u.host), &(q.from), q.fromlen) != 0) {
dnsd_send(dns_fd, &q, "BADIP", 5);
} else {
memcpy(packetbuf.data + packetbuf.offset, in + 1, read - 1); memcpy(packetbuf.data + packetbuf.offset, in + 1, read - 1);
packetbuf.len += read - 1; packetbuf.len += read - 1;
packetbuf.offset += read - 1; packetbuf.offset += read - 1;
@ -194,7 +205,11 @@ tunnel(int tun_fd, int dns_fd)
packetbuf.len = packetbuf.offset = 0; packetbuf.len = packetbuf.offset = 0;
} }
} }
if (outpacket.len > 0) { }
if (q.fromlen == u.addrlen &&
memcmp(&(u.host), &(q.from), q.fromlen) == 0 &&
outpacket.len > 0) {
dnsd_send(dns_fd, &q, outpacket.data, outpacket.len); dnsd_send(dns_fd, &q, outpacket.data, outpacket.len);
outpacket.len = 0; outpacket.len = 0;
q.id = 0; q.id = 0;