summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f36bfd9)
raw | patch | inline | side by side (parent: f36bfd9)
author | Sebastian Harl <sh@tokkee.org> | |
Wed, 5 Feb 2014 21:07:46 +0000 (22:07 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Wed, 5 Feb 2014 21:07:46 +0000 (22:07 +0100) |
Also, for now, reject access in case no username is provided.
src/frontend/session.c | patch | blob | history |
diff --git a/src/frontend/session.c b/src/frontend/session.c
index 6403469a1e2d15020a939f130a54ed20c8711704..a64931eeca6f795075b09322cea6ac4c8b5bd1ff 100644 (file)
--- a/src/frontend/session.c
+++ b/src/frontend/session.c
#include "frontend/connection-private.h"
+#include <string.h>
+
/*
* public API
*/
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 */