store hostname of the user, and pass it to scripts.

This commit is contained in:
Nikos Mavrogiannopoulos
2013-02-05 21:21:40 +01:00
parent 83a07083fd
commit 40c9a094a7
10 changed files with 20 additions and 7 deletions

View File

@@ -5,6 +5,7 @@
struct __attribute__ ((__packed__)) stored_cookie_st {
char username[MAX_USERNAME_SIZE];
char hostname[MAX_USERNAME_SIZE];
uint8_t session_id[GNUTLS_MAX_SESSION_ID];
time_t expiration;
};

View File

@@ -45,6 +45,7 @@ struct __attribute__ ((__packed__)) cmd_auth_req_st {
char pass[MAX_PASSWORD_SIZE];
uint8_t tls_auth_ok;
char cert_user[MAX_USERNAME_SIZE];
char hostname[MAX_HOSTNAME_SIZE];
};
/* AUTH_REP */

View File

@@ -139,6 +139,7 @@ struct stored_cookie_st sc;
sc.expiration = time(0) + s->config->cookie_validity;
memcpy(sc.username, proc->username, sizeof(sc.username));
memcpy(sc.hostname, proc->hostname, sizeof(sc.hostname));
memcpy(sc.session_id, proc->session_id, sizeof(sc.session_id));
ret = store_cookie(s->config, proc->cookie, sizeof(proc->cookie), &sc);
@@ -179,6 +180,9 @@ unsigned username_set = 0;
}
if (ret == 0) { /* open tun */
if (req->hostname[0] != 0)
memcpy(proc->hostname, req->hostname, MAX_HOSTNAME_SIZE);
ret = open_tun(s->config, s->tun, lease);
if (ret < 0)
ret = -1; /* sorry */

View File

@@ -79,7 +79,7 @@ int ret;
}
ret = execlp(s->config->disconnect_script, s->config->disconnect_script,
proc->username, proc->lease->name, real, local, remote, NULL);
proc->username, proc->hostname, proc->lease->name, real, local, remote, NULL);
if (ret == -1)
exit(1);
@@ -126,7 +126,7 @@ int ret, status;
}
ret = execlp(s->config->connect_script, s->config->connect_script,
proc->username, lease->name, real, local, remote, NULL);
proc->username, proc->hostname, lease->name, real, local, remote, NULL);
if (ret == -1)
exit(1);

View File

@@ -23,6 +23,7 @@ struct proc_list_st {
struct sockaddr_storage remote_addr; /* peer address */
socklen_t remote_addr_len;
char username[MAX_USERNAME_SIZE]; /* the owner */
char hostname[MAX_HOSTNAME_SIZE]; /* the requested hostname */
uint8_t cookie[COOKIE_SIZE]; /* the cookie associated with the session */
uint8_t session_id[GNUTLS_MAX_SESSION_ID];

View File

@@ -2,7 +2,7 @@
*
* DO NOT EDIT THIS FILE (ocserv-args.c)
*
* It has been AutoGen-ed February 5, 2013 at 09:03:24 PM by AutoGen 5.16
* It has been AutoGen-ed February 5, 2013 at 09:21:04 PM by AutoGen 5.16
* From the definitions ocserv-args.def
* and the template file options
*

View File

@@ -99,7 +99,8 @@ auth-timeout = 40
cookie-validity = 14400
# Script to call when a client connects and obtains an IP
# Parameters: username device IP-REAL IP-LOCAL IP-REMOTE
# Parameters: username hostname device IP-REAL IP-LOCAL IP-REMOTE
# hostname is the hostname selected by the client
# IP-REAL is the remote IP of the client,
# IP-LOCAL is the local IP in the P-t-P connection and IP-REMOTE
# is the VPN client IP.
@@ -129,7 +130,7 @@ ipv4-dns = local
# Leave empty to assign the default MTU of the device
# mtu =
route = 192.168.2.0/255.255.255.0
route = 192.168.1.0/255.255.255.0
route = 192.168.5.0/255.255.255.0
@end example

View File

@@ -2,7 +2,7 @@
*
* DO NOT EDIT THIS FILE (ocserv-args.h)
*
* It has been AutoGen-ed February 5, 2013 at 09:03:24 PM by AutoGen 5.16
* It has been AutoGen-ed February 5, 2013 at 09:21:04 PM by AutoGen 5.16
* From the definitions ocserv-args.def
* and the template file options
*

View File

@@ -59,7 +59,8 @@ run-as-group = nogroup
device = vpns
# Script to call when a client connects and obtains an IP
# Parameters: username device IP-REAL IP-LOCAL IP-REMOTE
# Parameters: username hostname device IP-REAL IP-LOCAL IP-REMOTE
# hostname is the hostname selected by the client
# IP-REAL is the remote IP of the client,
# IP-LOCAL is the local IP in the P-t-P connection and IP-REMOTE
# is the VPN client IP.

View File

@@ -343,6 +343,10 @@ struct cmd_auth_req_st areq;
snprintf(areq.user, sizeof(areq.user), "%s", username);
snprintf(areq.pass, sizeof(areq.pass), "%s", password);
}
if (req->hostname[0] != 0) {
memcpy(areq.hostname, req->hostname, sizeof(areq.hostname));
}
ret = auth_user(ws, &areq);
if (ret < 0) {