mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-26 10:09:19 +02:00
Switch to IPv6-ready storage of user IP address
This commit is contained in:
parent
5233d1e858
commit
778d29825d
|
@ -178,8 +178,6 @@ syslog(int a, const char *str, ...)
|
||||||
static int
|
static int
|
||||||
check_user_and_ip(int userid, struct query *q)
|
check_user_and_ip(int userid, struct query *q)
|
||||||
{
|
{
|
||||||
struct sockaddr_in *tempin;
|
|
||||||
|
|
||||||
/* Note: duplicate in handle_raw_login() except IP-address check */
|
/* Note: duplicate in handle_raw_login() except IP-address check */
|
||||||
|
|
||||||
if (userid < 0 || userid >= created_users ) {
|
if (userid < 0 || userid >= created_users ) {
|
||||||
|
@ -197,8 +195,19 @@ check_user_and_ip(int userid, struct query *q)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
tempin = (struct sockaddr_in *) &(q->from);
|
if (q->from.ss_family != users[userid].host.ss_family) {
|
||||||
return memcmp(&(users[userid].host), &(tempin->sin_addr), sizeof(struct in_addr));
|
return 1;
|
||||||
|
}
|
||||||
|
/* Check IPv4 */
|
||||||
|
if (q->from.ss_family == AF_INET) {
|
||||||
|
struct sockaddr_in *expected, *received;
|
||||||
|
|
||||||
|
expected = (struct sockaddr_in *) &(users[userid].host);
|
||||||
|
received = (struct sockaddr_in *) &(q->from);
|
||||||
|
return memcmp(&(expected->sin_addr), &(received->sin_addr), sizeof(struct in_addr));
|
||||||
|
}
|
||||||
|
/* Unknown address family */
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This checks that user has passed normal (non-raw) login challenge */
|
/* This checks that user has passed normal (non-raw) login challenge */
|
||||||
|
@ -769,12 +778,11 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
|
||||||
userid = find_available_user();
|
userid = find_available_user();
|
||||||
if (userid >= 0) {
|
if (userid >= 0) {
|
||||||
int i;
|
int i;
|
||||||
struct sockaddr_in *tempin;
|
|
||||||
|
|
||||||
users[userid].seed = rand();
|
users[userid].seed = rand();
|
||||||
/* Store remote IP number */
|
/* Store remote IP number */
|
||||||
tempin = (struct sockaddr_in *) &(q->from);
|
memcpy(&(users[userid].host), &(q->from), q->fromlen);
|
||||||
memcpy(&(users[userid].host), &(tempin->sin_addr), sizeof(struct in_addr));
|
users[userid].hostlen = q->fromlen;
|
||||||
|
|
||||||
memcpy(&(users[userid].q), q, sizeof(struct query));
|
memcpy(&(users[userid].q), q, sizeof(struct query));
|
||||||
users[userid].encoder = get_base32_encoder();
|
users[userid].encoder = get_base32_encoder();
|
||||||
|
@ -1879,15 +1887,13 @@ handle_raw_login(char *packet, int len, struct query *q, int fd, int userid)
|
||||||
/* User sends hash of seed + 1 */
|
/* User sends hash of seed + 1 */
|
||||||
login_calculate(myhash, 16, password, users[userid].seed + 1);
|
login_calculate(myhash, 16, password, users[userid].seed + 1);
|
||||||
if (memcmp(packet, myhash, 16) == 0) {
|
if (memcmp(packet, myhash, 16) == 0) {
|
||||||
struct sockaddr_in *tempin;
|
|
||||||
|
|
||||||
/* Update query and time info for user */
|
/* Update query and time info for user */
|
||||||
users[userid].last_pkt = time(NULL);
|
users[userid].last_pkt = time(NULL);
|
||||||
memcpy(&(users[userid].q), q, sizeof(struct query));
|
memcpy(&(users[userid].q), q, sizeof(struct query));
|
||||||
|
|
||||||
/* Store remote IP number */
|
/* Store remote IP number */
|
||||||
tempin = (struct sockaddr_in *) &(q->from);
|
memcpy(&(users[userid].host), &(q->from), q->fromlen);
|
||||||
memcpy(&(users[userid].host), &(tempin->sin_addr), sizeof(struct in_addr));
|
users[userid].hostlen = q->fromlen;
|
||||||
|
|
||||||
/* Correct hash, reply with hash of seed - 1 */
|
/* Correct hash, reply with hash of seed - 1 */
|
||||||
user_set_conn_type(userid, CONN_RAW_UDP);
|
user_set_conn_type(userid, CONN_RAW_UDP);
|
||||||
|
|
|
@ -43,7 +43,8 @@ struct tun_user {
|
||||||
time_t last_pkt;
|
time_t last_pkt;
|
||||||
int seed;
|
int seed;
|
||||||
in_addr_t tun_ip;
|
in_addr_t tun_ip;
|
||||||
struct in_addr host;
|
struct sockaddr_storage host;
|
||||||
|
socklen_t hostlen;
|
||||||
struct query q;
|
struct query q;
|
||||||
struct query q_sendrealsoon;
|
struct query q_sendrealsoon;
|
||||||
int q_sendrealsoon_new;
|
int q_sendrealsoon_new;
|
||||||
|
|
Loading…
Reference in New Issue