From f67feebcc2a7d169336102d0ec906fe2425191c4 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Sat, 6 Mar 2021 17:37:30 +0800 Subject: [PATCH] protocol: fix auth token check --- src/protocol.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/protocol.c b/src/protocol.c index 94e4d01..02eb95d 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -284,16 +284,17 @@ int callback_tty(struct lws *wsi, enum lws_callback_reasons reason, void *user, if (pss->process != NULL) break; uint16_t columns = 0; uint16_t rows = 0; - char *token = NULL; json_object *obj = parse_window_size(pss->buffer, pss->len, &columns, &rows); if (server->credential != NULL) { struct json_object *o = NULL; if (json_object_object_get_ex(obj, "AuthToken", &o)) { const char *token = json_object_get_string(o); - pss->authenticated = token != NULL && !strcmp(token, server->credential); + if (token != NULL && !strcmp(token, server->credential)) + pss->authenticated = true; + else + lwsl_warn("WS authentication failed with token: %s\n", token); } if (!pss->authenticated) { - lwsl_warn("WS authentication failed with token: %s\n", token); json_object_put(obj); lws_close_reason(wsi, LWS_CLOSE_STATUS_POLICY_VIOLATION, NULL, 0); return -1; -- 2.43.4