Merge branch 'protect-options' of https://github.com/Masaq-/iodine into protect_opts

This commit is contained in:
Erik Ekman 2017-10-22 11:59:38 +02:00
commit 72bdf7f20e
3 changed files with 19 additions and 3 deletions

View File

@ -254,6 +254,18 @@ static int check_authenticated_user_and_ip(int userid, struct query *q)
return 0; return 0;
} }
static int check_authenticated_user_and_ip_and_options(int userid, struct query *q)
{
int res = check_authenticated_user_and_ip(userid, q);
if (res || check_ip)
return res;
if (users[userid].options_locked)
return 1;
return 0;
}
static void send_raw(int fd, char *buf, int buflen, int user, int cmd, struct query *q) static void send_raw(int fd, char *buf, int buflen, int user, int cmd, struct query *q)
{ {
char packet[4096]; char packet[4096];
@ -955,7 +967,7 @@ handle_null_request(int tun_fd, int dns_fd, struct dnsfd *dns_fds, struct query
userid = b32_8to5(in[1]); userid = b32_8to5(in[1]);
if (check_authenticated_user_and_ip(userid, q) != 0) { if (check_authenticated_user_and_ip_and_options(userid, q) != 0) {
write_dns(dns_fd, q, "BADIP", 5, 'T'); write_dns(dns_fd, q, "BADIP", 5, 'T');
return; /* illegal id */ return; /* illegal id */
} }
@ -996,7 +1008,7 @@ handle_null_request(int tun_fd, int dns_fd, struct dnsfd *dns_fds, struct query
userid = b32_8to5(in[1]); userid = b32_8to5(in[1]);
if (check_authenticated_user_and_ip(userid, q) != 0) { if (check_authenticated_user_and_ip_and_options(userid, q) != 0) {
write_dns(dns_fd, q, "BADIP", 5, 'T'); write_dns(dns_fd, q, "BADIP", 5, 'T');
return; /* illegal id */ return; /* illegal id */
} }
@ -1159,7 +1171,7 @@ handle_null_request(int tun_fd, int dns_fd, struct dnsfd *dns_fds, struct query
/* Downstream fragsize packet */ /* Downstream fragsize packet */
userid = unpacked[0]; userid = unpacked[0];
if (check_authenticated_user_and_ip(userid, q) != 0) { if (check_authenticated_user_and_ip_and_options(userid, q) != 0) {
write_dns(dns_fd, q, "BADIP", 5, 'T'); write_dns(dns_fd, q, "BADIP", 5, 'T');
return; /* illegal id */ return; /* illegal id */
} }
@ -1169,6 +1181,7 @@ handle_null_request(int tun_fd, int dns_fd, struct dnsfd *dns_fds, struct query
write_dns(dns_fd, q, "BADFRAG", 7, users[userid].downenc); write_dns(dns_fd, q, "BADFRAG", 7, users[userid].downenc);
} else { } else {
users[userid].fragsize = max_frag_size; users[userid].fragsize = max_frag_size;
users[userid].options_locked = 1;
write_dns(dns_fd, q, &unpacked[1], 2, users[userid].downenc); write_dns(dns_fd, q, &unpacked[1], 2, users[userid].downenc);
} }
return; return;

View File

@ -76,6 +76,7 @@ int init_users(in_addr_t my_ip, int netbits)
users[i].disabled = 0; users[i].disabled = 0;
users[i].authenticated = 0; users[i].authenticated = 0;
users[i].authenticated_raw = 0; users[i].authenticated_raw = 0;
users[i].options_locked = 0;
users[i].active = 0; users[i].active = 0;
/* Rest is reset on login ('V' packet) */ /* Rest is reset on login ('V' packet) */
} }
@ -151,6 +152,7 @@ int find_available_user(void)
users[i].active = 1; users[i].active = 1;
users[i].authenticated = 0; users[i].authenticated = 0;
users[i].authenticated_raw = 0; users[i].authenticated_raw = 0;
users[i].options_locked = 0;
users[i].last_pkt = time(NULL); users[i].last_pkt = time(NULL);
users[i].fragsize = 4096; users[i].fragsize = 4096;
users[i].conn = CONN_DNS_NULL; users[i].conn = CONN_DNS_NULL;

View File

@ -39,6 +39,7 @@ struct tun_user {
int active; int active;
int authenticated; int authenticated;
int authenticated_raw; int authenticated_raw;
int options_locked;
int disabled; int disabled;
time_t last_pkt; time_t last_pkt;
int seed; int seed;