From: Sebastian Harl Date: Wed, 5 Feb 2014 21:07:46 +0000 (+0100) Subject: frontend/session: Store authenticated user information. X-Git-Tag: sysdb-0.1.0~220 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=be7975aabb4cba23235e460beba549e190175d92;p=sysdb.git frontend/session: Store authenticated user information. Also, for now, reject access in case no username is provided. --- diff --git a/src/frontend/session.c b/src/frontend/session.c index 6403469..a64931e 100644 --- a/src/frontend/session.c +++ b/src/frontend/session.c @@ -29,6 +29,8 @@ #include "frontend/connection-private.h" +#include + /* * public API */ @@ -36,13 +38,26 @@ int sdb_fe_session_start(sdb_conn_t *conn) { + const char *username; + if ((! conn) || (conn->username)) return -1; if (conn->cmd != CONNECTION_STARTUP) return -1; + username = sdb_strbuf_string(conn->buf); + if ((! username) || (! conn->cmd_len) || (! *username)) { + sdb_strbuf_sprintf(conn->errbuf, "Invalid empty username"); + return -1; + } + /* XXX: for now, simply accept all connections */ + conn->username = strndup(username, conn->cmd_len); + if (! conn->username) { + sdb_strbuf_sprintf(conn->errbuf, "Authentication failed"); + return -1; + } sdb_connection_send(conn, CONNECTION_OK, 0, NULL); return 0; } /* sdb_fe_session_start */