summaryrefslogtreecommitdiff
path: root/src/acl.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2019-02-25 16:33:36 +0100
committerantirez <antirez@gmail.com>2019-02-25 16:33:38 +0100
commit87594a7470063ad095a58f32c04594533ebd485f (patch)
tree11892fab5e524725118f419b7e2c31732fdba3ad /src/acl.c
parent07473feaebd9af228baddd6c28ded0da42dab255 (diff)
downloadredis-87594a7470063ad095a58f32c04594533ebd485f.tar.gz
ACL: move AUTH implementation in acl.c.
Diffstat (limited to 'src/acl.c')
-rw-r--r--src/acl.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/acl.c b/src/acl.c
index 43db19898..2351fc7f4 100644
--- a/src/acl.c
+++ b/src/acl.c
@@ -1572,3 +1572,49 @@ void addReplyCommandCategories(client *c, struct redisCommand *cmd) {
}
setDeferredSetLen(c, flaglen, flagcount);
}
+
+/* AUTH <passowrd>
+ * AUTH <username> <password> (Redis >= 6.0 form)
+ *
+ * When the user is omitted it means that we are trying to authenticate
+ * against the default user. */
+void authCommand(client *c) {
+ /* Only two or three argument forms are allowed. */
+ if (c->argc > 3) {
+ addReply(c,shared.syntaxerr);
+ return;
+ }
+
+ /* Handle the two different forms here. The form with two arguments
+ * will just use "default" as username. */
+ robj *username, *password;
+ if (c->argc == 2) {
+ /* Mimic the old behavior of giving an error for the two commands
+ * from if no password is configured. */
+ if (DefaultUser->flags & USER_FLAG_NOPASS) {
+ addReplyError(c,"AUTH <password> called without any password "
+ "configured for the default user. Are you sure "
+ "your configuration is correct?");
+ return;
+ }
+
+ username = createStringObject("default",7);
+ password = c->argv[1];
+ } else {
+ username = c->argv[1];
+ password = c->argv[2];
+ }
+
+ if (ACLCheckUserCredentials(username,password) == C_OK) {
+ c->authenticated = 1;
+ c->user = ACLGetUserByName(username->ptr,sdslen(username->ptr));
+ addReply(c,shared.ok);
+ } else {
+ addReplyError(c,"-WRONGPASS invalid username-password pair");
+ }
+
+ /* Free the "default" string object we created for the two
+ * arguments form. */
+ if (c->argc == 2) decrRefCount(username);
+}
+