summaryrefslogtreecommitdiff
path: root/src/networking.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2020-04-30 09:58:06 +0200
committerantirez <antirez@gmail.com>2020-04-30 13:02:59 +0200
commite1ee1a49d62b8637b6ba27362a15cc8b03d66d1c (patch)
treeda9829e749fddd6fffa8d2609556f53c0cf6468e /src/networking.c
parentd56f058c089dc255b31e698c3f4f08ca3a8cb627 (diff)
downloadredis-e1ee1a49d62b8637b6ba27362a15cc8b03d66d1c.tar.gz
CLIENT KILL USER <username>.
Diffstat (limited to 'src/networking.c')
-rw-r--r--src/networking.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/networking.c b/src/networking.c
index 7ffa99eb1..767206ab9 100644
--- a/src/networking.c
+++ b/src/networking.c
@@ -2101,6 +2101,7 @@ void clientCommand(client *c) {
"KILL <option> <value> [option value ...] -- Kill connections. Options are:",
" ADDR <ip:port> -- Kill connection made from <ip:port>",
" TYPE (normal|master|replica|pubsub) -- Kill connections by type.",
+" USER <username> -- Kill connections authenticated with such user.",
" SKIPME (yes|no) -- Skip killing current connection (default: yes).",
"LIST [options ...] -- Return information about client connections. Options:",
" TYPE (normal|master|replica|pubsub) -- Return clients of specified type.",
@@ -2151,6 +2152,7 @@ NULL
/* CLIENT KILL <ip:port>
* CLIENT KILL <option> [value] ... <option> [value] */
char *addr = NULL;
+ user *user = NULL;
int type = -1;
uint64_t id = 0;
int skipme = 1;
@@ -2182,6 +2184,14 @@ NULL
}
} else if (!strcasecmp(c->argv[i]->ptr,"addr") && moreargs) {
addr = c->argv[i+1]->ptr;
+ } else if (!strcasecmp(c->argv[i]->ptr,"user") && moreargs) {
+ user = ACLGetUserByName(c->argv[i+1]->ptr,
+ sdslen(c->argv[i+1]->ptr));
+ if (user == NULL) {
+ addReplyErrorFormat(c,"No such user '%s'",
+ (char*) c->argv[i+1]->ptr);
+ return;
+ }
} else if (!strcasecmp(c->argv[i]->ptr,"skipme") && moreargs) {
if (!strcasecmp(c->argv[i+1]->ptr,"yes")) {
skipme = 1;
@@ -2209,6 +2219,7 @@ NULL
if (addr && strcmp(getClientPeerId(client),addr) != 0) continue;
if (type != -1 && getClientType(client) != type) continue;
if (id != 0 && client->id != id) continue;
+ if (user && client->user != user) continue;
if (c == client && skipme) continue;
/* Kill it. */