diff options
author | laodc <github@laodc.com> | 2023-08-21 15:45:58 +0700 |
---|---|---|
committer | laodc <github@laodc.com> | 2023-08-21 15:45:58 +0700 |
commit | 75fdc829bacbdc767b20d3f0e40b91215fce14fe (patch) | |
tree | 209d8d53e71cd5a92deb69fcb740bb2649bb66ee /src/libstat/backends | |
parent | 1931487b17059d6c63adf2245c9632384657f89e (diff) | |
download | rspamd-75fdc829bacbdc767b20d3f0e40b91215fce14fe.tar.gz rspamd-75fdc829bacbdc767b20d3f0e40b91215fce14fe.zip |
Added support for Redis 6 ACL (username/password)
Diffstat (limited to 'src/libstat/backends')
-rw-r--r-- | src/libstat/backends/redis_backend.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/libstat/backends/redis_backend.c b/src/libstat/backends/redis_backend.c index a0d11bb0d..72ffd6c44 100644 --- a/src/libstat/backends/redis_backend.c +++ b/src/libstat/backends/redis_backend.c @@ -45,6 +45,7 @@ struct redis_stat_ctx { gint conf_ref; struct rspamd_stat_async_elt *stat_elt; const gchar *redis_object; + const gchar *username; const gchar *password; const gchar *dbname; gdouble timeout; @@ -363,7 +364,17 @@ gsize rspamd_redis_expand_object(const gchar *pattern, static void rspamd_redis_maybe_auth(struct redis_stat_ctx *ctx, redisAsyncContext *redis) { - if (ctx->password) { + if (ctx->username) { + if (ctx->password) { + redisAsyncCommand(redis, NULL, NULL, "AUTH %s %s", ctx->username, ctx->password); + } + else { + msg_err("Redis requires a password when username is supplied"); + redisAsyncFree(ctx); + return NULL; + } + } + else if (ctx->password) { redisAsyncCommand(redis, NULL, NULL, "AUTH %s", ctx->password); } if (ctx->dbname) { @@ -1603,6 +1614,14 @@ rspamd_redis_init(struct rspamd_stat_ctx *ctx, } lua_pop(L, 1); + lua_pushstring(L, "username"); + lua_gettable(L, -2); + if (lua_type(L, -1) == LUA_TSTRING) { + backend->username = rspamd_mempool_strdup(cfg->cfg_pool, + lua_tostring(L, -1)); + } + lua_pop(L, 1); + lua_pushstring(L, "password"); lua_gettable(L, -2); if (lua_type(L, -1) == LUA_TSTRING) { |