mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-02-10 08:46:58 +08:00
Store User-Agent information and send to occtl.
This commit is contained in:
@@ -93,4 +93,5 @@ message session_info_msg
|
||||
{
|
||||
required string tls_ciphersuite = 1;
|
||||
required string dtls_ciphersuite = 2;
|
||||
required string user_agent = 3;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ typedef struct {
|
||||
#define ENTRY(name, iface, desc, func) \
|
||||
{name, sizeof(name)-1, iface, sizeof(iface)-1, desc, sizeof(desc)-1, func}
|
||||
|
||||
#define LIST_USERS_SIG "(ussssssssussss)"
|
||||
#define LIST_USERS_SIG "(ussssssssusssss)"
|
||||
|
||||
#define DESC_LIST \
|
||||
" <method name=\"list\">\n" \
|
||||
@@ -496,6 +496,12 @@ static int append_user_info(DBusMessageIter * subs, struct proc_st *ctmp)
|
||||
return -1;
|
||||
}
|
||||
|
||||
strtmp = ctmp->user_agent;
|
||||
if (dbus_message_iter_append_basic
|
||||
(subs, DBUS_TYPE_STRING, &strtmp) == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ctmp->auth_status == PS_AUTH_COMPLETED)
|
||||
strtmp = "connected";
|
||||
else if (ctmp->auth_status == PS_AUTH_INIT)
|
||||
|
||||
@@ -432,6 +432,8 @@ int handle_commands(main_server_st *s, struct proc_st* proc)
|
||||
snprintf(proc->tls_ciphersuite, sizeof(proc->tls_ciphersuite), "%s", tmsg->tls_ciphersuite);
|
||||
if (tmsg->dtls_ciphersuite)
|
||||
snprintf(proc->dtls_ciphersuite, sizeof(proc->dtls_ciphersuite), "%s", tmsg->dtls_ciphersuite);
|
||||
if (tmsg->user_agent)
|
||||
snprintf(proc->user_agent, sizeof(proc->user_agent), "%s", tmsg->user_agent);
|
||||
|
||||
session_info_msg__free_unpacked(tmsg, NULL);
|
||||
|
||||
|
||||
@@ -100,6 +100,7 @@ struct proc_st {
|
||||
char hostname[MAX_HOSTNAME_SIZE]; /* the requested hostname */
|
||||
uint8_t cookie[COOKIE_SIZE]; /* the cookie associated with the session */
|
||||
|
||||
char user_agent[MAX_AGENT_SIZE];
|
||||
char tls_ciphersuite[MAX_CIPHERSUITE_NAME];
|
||||
char dtls_ciphersuite[MAX_DTLS_CIPHERSUITE_NAME];
|
||||
|
||||
|
||||
23
src/occtl.c
23
src/occtl.c
@@ -534,6 +534,7 @@ int handle_list_users_cmd(DBusConnection * conn, const char *arg)
|
||||
char *vpn_ipv4 = "", *vpn_ptp_ipv4 = "";
|
||||
char *vpn_ipv6 = "", *vpn_ptp_ipv6 = "";
|
||||
char *hostname = "", *auth = "", *device = "";
|
||||
char *user_agent = "";
|
||||
char str_since[64];
|
||||
const char *vpn_ip;
|
||||
struct tm *tm;
|
||||
@@ -641,6 +642,13 @@ int handle_list_users_cmd(DBusConnection * conn, const char *arg)
|
||||
goto error_parse;
|
||||
dbus_message_iter_get_basic(&subs, &hostname);
|
||||
|
||||
if (!dbus_message_iter_next(&subs))
|
||||
goto error_recv;
|
||||
|
||||
if (dbus_message_iter_get_arg_type(&subs) != DBUS_TYPE_STRING)
|
||||
goto error_parse;
|
||||
dbus_message_iter_get_basic(&subs, &user_agent);
|
||||
|
||||
if (!dbus_message_iter_next(&subs))
|
||||
goto error_recv;
|
||||
|
||||
@@ -724,6 +732,7 @@ int common_info_cmd(DBusMessageIter * args)
|
||||
char *vpn_ipv4 = "", *vpn_ptp_ipv4 = "";
|
||||
char *vpn_ipv6 = "", *vpn_ptp_ipv6 = "";
|
||||
char *hostname = "", *auth = "", *device = "";
|
||||
char *user_agent = "";
|
||||
char str_since[64];
|
||||
struct tm *tm;
|
||||
time_t t;
|
||||
@@ -826,6 +835,13 @@ int common_info_cmd(DBusMessageIter * args)
|
||||
goto error_parse;
|
||||
dbus_message_iter_get_basic(&subs, &hostname);
|
||||
|
||||
if (!dbus_message_iter_next(&subs))
|
||||
goto error_recv;
|
||||
|
||||
if (dbus_message_iter_get_arg_type(&subs) != DBUS_TYPE_STRING)
|
||||
goto error_parse;
|
||||
dbus_message_iter_get_basic(&subs, &user_agent);
|
||||
|
||||
if (!dbus_message_iter_next(&subs))
|
||||
goto error_recv;
|
||||
|
||||
@@ -868,11 +884,14 @@ int common_info_cmd(DBusMessageIter * args)
|
||||
}
|
||||
fprintf(out, "\tDevice: %s ", device);
|
||||
|
||||
if (hostname != NULL && hostname[0] != 0)
|
||||
fprintf(out, "Hostname: %s\n", hostname);
|
||||
if (user_agent != NULL && user_agent[0] != 0)
|
||||
fprintf(out, "User-Agent: %s\n", user_agent);
|
||||
else
|
||||
fprintf(out, "\n");
|
||||
|
||||
if (hostname != NULL && hostname[0] != 0)
|
||||
fprintf(out, "\tHostname: %s\n", hostname);
|
||||
|
||||
fprintf(out, "\tConnected at: %s (", str_since);
|
||||
print_time_ival7(t, out);
|
||||
fprintf(out, ")\n");
|
||||
|
||||
@@ -227,6 +227,7 @@ struct main_server_st;
|
||||
|
||||
#define MAX_BANNER_SIZE 256
|
||||
#define MAX_USERNAME_SIZE 64
|
||||
#define MAX_AGENT_SIZE 32
|
||||
#define MAX_PASSWORD_SIZE 64
|
||||
#define TLS_MASTER_SIZE 48
|
||||
#define MAX_HOSTNAME_SIZE MAX_USERNAME_SIZE
|
||||
|
||||
@@ -169,6 +169,7 @@ int url_cb(http_parser * parser, const char *at, size_t length)
|
||||
}
|
||||
|
||||
#define STR_HDR_COOKIE "Cookie"
|
||||
#define STR_HDR_USER_AGENT "User-Agent"
|
||||
#define STR_HDR_CONNECTION "Connection"
|
||||
#define STR_HDR_MS "X-DTLS-Master-Secret"
|
||||
#define STR_HDR_CS "X-DTLS-CipherSuite"
|
||||
@@ -220,6 +221,14 @@ static void value_check(struct worker_st *ws, struct http_req_st *req)
|
||||
memcpy(req->hostname, req->value.data, req->value.length);
|
||||
req->hostname[req->value.length] = 0;
|
||||
break;
|
||||
case HEADER_USER_AGENT:
|
||||
if (req->value.length + 1 > MAX_AGENT_SIZE) {
|
||||
req->user_agent[0] = 0;
|
||||
return;
|
||||
}
|
||||
memcpy(req->user_agent, req->value.data, req->value.length);
|
||||
req->user_agent[req->value.length] = 0;
|
||||
break;
|
||||
|
||||
case HEADER_DTLS_CIPHERSUITE:
|
||||
str = (char *)req->value.data;
|
||||
@@ -395,6 +404,10 @@ static void header_check(struct http_req_st *req)
|
||||
strncmp((char *)req->header.data, STR_HDR_CONNECTION,
|
||||
req->header.length) == 0) {
|
||||
req->next_header = HEADER_CONNECTION;
|
||||
} else if (req->header.length == sizeof(STR_HDR_USER_AGENT) - 1 &&
|
||||
strncmp((char *)req->header.data, STR_HDR_USER_AGENT,
|
||||
req->header.length) == 0) {
|
||||
req->next_header = HEADER_USER_AGENT;
|
||||
} else {
|
||||
req->next_header = 0;
|
||||
}
|
||||
@@ -764,6 +777,10 @@ void session_info_send(worker_st * ws)
|
||||
msg.dtls_ciphersuite = ws->req.selected_ciphersuite;
|
||||
}
|
||||
|
||||
if (ws->req.user_agent[0] != 0) {
|
||||
msg.user_agent = ws->req.user_agent;
|
||||
}
|
||||
|
||||
send_msg_to_main(ws, CMD_SESSION_INFO, &msg,
|
||||
(pack_size_func) session_info_msg__get_packed_size,
|
||||
(pack_func) session_info_msg__pack);
|
||||
|
||||
@@ -51,6 +51,7 @@ enum {
|
||||
HEADER_DTLS_MTU,
|
||||
HEADER_DTLS_CIPHERSUITE,
|
||||
HEADER_CONNECTION,
|
||||
HEADER_USER_AGENT,
|
||||
};
|
||||
|
||||
enum {
|
||||
@@ -74,6 +75,7 @@ struct http_req_st {
|
||||
unsigned int header_state;
|
||||
|
||||
char hostname[MAX_HOSTNAME_SIZE];
|
||||
char user_agent[MAX_AGENT_SIZE];
|
||||
unsigned int next_header;
|
||||
unsigned char cookie[COOKIE_SIZE];
|
||||
unsigned int cookie_set;
|
||||
|
||||
Reference in New Issue
Block a user