From 34eab81339a518a97e6cb8f9e3879c2441508609 Mon Sep 17 00:00:00 2001 From: Alan Jowett Date: Mon, 27 Jul 2020 11:02:31 -0600 Subject: [PATCH] Resolves: #326 Pass the hostname to ocserv-main after receiving the connect request. Signed-off-by: Alan Jowett --- src/ipc.proto | 13 +++++-------- src/main-auth.c | 3 +++ src/main-worker-cmd.c | 12 +----------- src/worker-auth.c | 2 ++ src/worker-vpn.c | 12 ------------ tests/connect-script | 10 ++++++---- 6 files changed, 17 insertions(+), 35 deletions(-) diff --git a/src/ipc.proto b/src/ipc.proto index dc8739d7..693c9b29 100644 --- a/src/ipc.proto +++ b/src/ipc.proto @@ -13,6 +13,7 @@ enum AUTH_REP { message auth_cookie_request_msg { required bytes cookie = 1; + optional string hostname = 2; } message fw_port_st @@ -183,18 +184,14 @@ message session_info_msg { required string tls_ciphersuite = 1; required string dtls_ciphersuite = 2; - required string user_agent = 3; - optional string cstp_compr = 4; - optional string dtls_compr = 5; + optional string cstp_compr = 3; + optional string dtls_compr = 4; /* these two are of type sockaddr_storage, * and contain the addresses we got from proxy * protocol (if any). */ - optional bytes our_addr = 6; - optional bytes remote_addr = 7; - - optional string hostname = 8; - optional string device_type = 9; + optional bytes our_addr = 5; + optional bytes remote_addr = 6; } /* WORKER_BAN_IP: sent from worker to main */ diff --git a/src/main-auth.c b/src/main-auth.c index 9021d224..9f3f7ba0 100644 --- a/src/main-auth.c +++ b/src/main-auth.c @@ -226,6 +226,9 @@ int handle_auth_cookie_req(main_server_st* s, struct proc_st* proc, /* this also hints to call session_close() */ proc->active_sid = 1; + if (req->hostname != NULL) + strlcpy(proc->hostname, req->hostname, sizeof(proc->hostname)); + /* add the links to proc hash */ if (proc_table_add(s, proc) < 0) { mslog(s, proc, LOG_ERR, "failed to add proc hashes"); diff --git a/src/main-worker-cmd.c b/src/main-worker-cmd.c index 3df02dc6..800a435b 100644 --- a/src/main-worker-cmd.c +++ b/src/main-worker-cmd.c @@ -383,17 +383,7 @@ int handle_worker_commands(main_server_st * s, struct proc_st *proc) strlcpy(proc->dtls_compr, tmsg->dtls_compr, sizeof(proc->dtls_compr)); - if (tmsg->user_agent && tmsg->device_type == NULL) - strlcpy(proc->user_agent, tmsg->user_agent, - sizeof(proc->user_agent)); - else if (tmsg->user_agent && tmsg->device_type) - snprintf(proc->user_agent, sizeof(proc->user_agent), "%s / %s", - tmsg->user_agent, tmsg->device_type); - - if (tmsg->hostname) { - strlcpy(proc->hostname, tmsg->hostname, - sizeof(proc->hostname)); - mslog(s, proc, LOG_DEBUG, "setting worker hostname to '%s'", proc->hostname); + if (proc->hostname[0] != 0) { user_hostname_update(s, proc); } diff --git a/src/worker-auth.c b/src/worker-auth.c index 40ea3a7e..de6a5f30 100644 --- a/src/worker-auth.c +++ b/src/worker-auth.c @@ -932,6 +932,8 @@ int auth_cookie(worker_st * ws, void *cookie, size_t cookie_size) msg.cookie.data = cookie; msg.cookie.len = cookie_size; + if (ws->req.hostname[0] != 0) + msg.hostname = ws->req.hostname; ret = send_msg_to_main(ws, AUTH_COOKIE_REQ, &msg, (pack_size_func) auth_cookie_request_msg__get_packed_size, diff --git a/src/worker-vpn.c b/src/worker-vpn.c index 55f4411a..cd998515 100644 --- a/src/worker-vpn.c +++ b/src/worker-vpn.c @@ -980,18 +980,6 @@ void session_info_send(worker_st * ws) msg.dtls_compr = (char*)ws->dtls_selected_comp->name; } - if (ws->req.user_agent[0] != 0) { - msg.user_agent = ws->req.user_agent; - } - - if (ws->req.devtype[0] != 0) { - msg.device_type = ws->req.devtype; - } - - if (ws->req.hostname[0] != 0) { - msg.hostname = ws->req.hostname; - } - if (WSCONFIG(ws)->listen_proxy_proto) { msg.our_addr.data = (uint8_t*)&ws->our_addr; msg.our_addr.len = ws->our_addr_len; diff --git a/tests/connect-script b/tests/connect-script index 94166938..16383f4f 100755 --- a/tests/connect-script +++ b/tests/connect-script @@ -10,16 +10,18 @@ verify_env_set() { fi } +# Verify the common environment variables verify_env_set "IP_REMOTE" verify_env_set "REASON" +verify_env_set "HOSTNAME" +verify_env_set "USERNAME" +verify_env_set "USER_AGENT" +verify_env_set "DEVICE_PLATFORM" +verify_env_set "DEVICE_TYPE" case "$REASON" in connect) - verify_env_set "USERNAME" - verify_env_set "USER_AGENT" verify_env_set "DEVICE" - verify_env_set "DEVICE_PLATFORM" - verify_env_set "DEVICE_TYPE" test "${OCSERV_DNS}" = "192.168.1.1 192.168.5.1 " && \ test "${OCSERV_DNS4}" = "192.168.1.1 192.168.5.1 " && \