From f22fea661d0755029173a21fa72f7c131ee884e7 Mon Sep 17 00:00:00 2001 From: Jorge Arellano Cid Date: Sun, 1 Nov 2009 16:31:59 -0300 Subject: Introduce basic shared-secret-based authentication --- dpi/file.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'dpi/file.c') diff --git a/dpi/file.c b/dpi/file.c index ce7dcee7..8f18c19b 100644 --- a/dpi/file.c +++ b/dpi/file.c @@ -844,14 +844,30 @@ static int File_num_clients(void) * Serve this client. * (this function runs on its own thread) */ -static void *File_serve_client(void *data) +static void File_serve_client(void *data) { - char *dpip_tag, *cmd = NULL, *url = NULL, *path; + char *dpip_tag = NULL, *cmd = NULL, *url = NULL, *path, *auth, *p; ClientInfo *Client = data; + /* Authenticate our client... */ + auth = sock_handler_read(Client->sh); + if ((p = strchr(auth, '<')) != NULL) { + /* auth and dpip's tag are in one chunk, separate them */ + dpip_tag = dStrdup(p); + *p = 0; + } + MSG("auth={%s}\n", auth); + if (a_Dpip_check_auth(auth) == -1) { + dFree(dpip_tag); + dFree(auth); + return; + } + dFree(auth); + /* Read the dpi command */ - dpip_tag = sock_handler_read(Client->sh); - _MSG("dpip_tag={%s}\n", dpip_tag); + if (!dpip_tag) + dpip_tag = sock_handler_read(Client->sh); + MSG("dpip_tag={%s}\n", dpip_tag); if (dpip_tag) { cmd = a_Dpip_get_attr(dpip_tag, "cmd"); @@ -864,8 +880,8 @@ static void *File_serve_client(void *data) MSG("file.dpi:: Failed to parse 'url'\n"); } } + dFree(cmd); } - dFree(cmd); dFree(dpip_tag); if (!DPIBYE && url) { @@ -886,8 +902,6 @@ static void *File_serve_client(void *data) /* flag the the transfer finished */ Client->done = 1; - - return NULL; } /* -- cgit v1.2.3