aboutsummaryrefslogtreecommitdiff
path: root/command.c
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-09-14 17:14:47 +0200
committerTom Smeding <tom.smeding@gmail.com>2020-09-14 17:15:15 +0200
commit535566cf29c045a954dc87f6072ccf90da778818 (patch)
tree76c400f35447fa900b2ad54c904d26f2a3e7580b /command.c
parent78b5312816498315acc921b05c8980a534dfecbb (diff)
server/protocol: Add 'change_password' command
Diffstat (limited to 'command.c')
-rw-r--r--command.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/command.c b/command.c
index ca70d76..39a50b7 100644
--- a/command.c
+++ b/command.c
@@ -98,6 +98,21 @@ static struct cmd_retval cmd_logout(struct conn_data *data,const char *tag,const
return RET_OK;
}
+static struct cmd_retval cmd_change_password(struct conn_data *data, const char *tag, const char **args) {
+ // TODO: use sodium_mlock correctly for the password
+
+ // Note: this function has exactly ONE return point, so that it is easier
+ // to see that we indeed return MEMZERO.
+
+ if (data->userid == -1) {
+ net_send_error(data->fd, tag, "Not logged in");
+ } else {
+ db_set_pass(data->userid, args[0]);
+ net_send_ok(data->fd, tag);
+ }
+ return RET_MEMZERO;
+}
+
static struct cmd_retval cmd_list_rooms(struct conn_data *data,const char *tag,const char **args){
(void)args;
if(data->userid==-1){
@@ -465,8 +480,8 @@ struct cmd_info{
// Use CommandHash.hs to re-generate this perfect hash function for a different
// list of commands.
-#define COMMAND_HASH_MODULUS 34
-#define COMMAND_HASH(cmd0, len) ((4 * cmd0 + 7 * len) % COMMAND_HASH_MODULUS)
+#define COMMAND_HASH_MODULUS 35
+#define COMMAND_HASH(cmd0, len) ((1 * cmd0 + 6 * len) % COMMAND_HASH_MODULUS)
#define COMMAND_ENTRY(cmd0, cmd, nargs, longlast, handler) \
[COMMAND_HASH(cmd0, strlen(cmd))] = {cmd, nargs, longlast, handler}
@@ -478,6 +493,7 @@ static const struct cmd_info commands[COMMAND_HASH_MODULUS] = {
COMMAND_ENTRY('r', "register", 2, true, cmd_register),
COMMAND_ENTRY('l', "login", 2, true, cmd_login),
COMMAND_ENTRY('l', "logout", 0, false, cmd_logout),
+ COMMAND_ENTRY('c', "change_password", 1, true, cmd_change_password),
COMMAND_ENTRY('l', "list_rooms", 0, false, cmd_list_rooms),
COMMAND_ENTRY('l', "list_members", 1, false, cmd_list_members),
COMMAND_ENTRY('c', "create_room", 0, false, cmd_create_room),