Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
f891b64a
R
redis
项目概览
xindoo
/
redis
通知
2
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
f891b64a
编写于
12月 17, 2019
作者:
M
Madelyn Olson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tweaking the documentation
上级
67aa527b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
19 deletion
+17
-19
src/module.c
src/module.c
+17
-19
未找到文件。
src/module.c
浏览文件 @
f891b64a
...
@@ -5261,19 +5261,19 @@ int RM_GetTimerInfo(RedisModuleCtx *ctx, RedisModuleTimerID id, uint64_t *remain
...
@@ -5261,19 +5261,19 @@ int RM_GetTimerInfo(RedisModuleCtx *ctx, RedisModuleTimerID id, uint64_t *remain
* Implements a hook into the authentication and authorization within Redis.
* Implements a hook into the authentication and authorization within Redis.
* --------------------------------------------------------------------------*/
* --------------------------------------------------------------------------*/
/* This function is called when a client's user has changed and invoke
d a
/* This function is called when a client's user has changed and invoke
s the
*
a modules client
changed callback if it was set. This callback should
*
client's user
changed callback if it was set. This callback should
* cleanup any state the module was tracking about this client.
* cleanup any state the module was tracking about this client.
*
*
* A client's user can be changed through the AUTH command, module
* A client's user can be changed through the AUTH command, module
* authentication, and when
the
client is freed. */
* authentication, and when
a
client is freed. */
void
moduleNotifyUserChanged
(
client
*
c
)
{
void
moduleNotifyUserChanged
(
client
*
c
)
{
if
(
c
->
auth_callback
)
{
if
(
c
->
auth_callback
)
{
c
->
auth_callback
(
c
->
id
,
c
->
auth_callback_privdata
);
c
->
auth_callback
(
c
->
id
,
c
->
auth_callback_privdata
);
/* The callback will fire exactly once, even if the user remains
/* The callback will fire exactly once, even if the user remains
* the same
, it is expected to completely clean up it's
state
* the same
. It is expected to completely clean up the
state
* so all references are
removed
*/
* so all references are
cleared here.
*/
c
->
auth_callback
=
NULL
;
c
->
auth_callback
=
NULL
;
c
->
auth_callback_privdata
=
NULL
;
c
->
auth_callback_privdata
=
NULL
;
c
->
auth_module
=
NULL
;
c
->
auth_module
=
NULL
;
...
@@ -5281,8 +5281,11 @@ void moduleNotifyUserChanged(client *c) {
...
@@ -5281,8 +5281,11 @@ void moduleNotifyUserChanged(client *c) {
}
}
void
revokeClientAuthentication
(
client
*
c
)
{
void
revokeClientAuthentication
(
client
*
c
)
{
/* Fire the client changed handler now in case we are unloading the module
/* Freeing the client would result in moduleNotifyUserChanged() to be
* and need to cleanup. */
* called later, however since we use revokeClientAuthentication() also
* in moduleFreeAuthenticatedClients() to implement module unloading, we
* do this action ASAP: this way if the module is unloaded, when the client
* is eventually freed we don't rely on the module to still exist. */
moduleNotifyUserChanged
(
c
);
moduleNotifyUserChanged
(
c
);
c
->
user
=
DefaultUser
;
c
->
user
=
DefaultUser
;
...
@@ -5292,7 +5295,7 @@ void revokeClientAuthentication(client *c) {
...
@@ -5292,7 +5295,7 @@ void revokeClientAuthentication(client *c) {
/* Cleanup all clients that have been authenticated with this module. This
/* Cleanup all clients that have been authenticated with this module. This
* is called from onUnload() to give the module a chance to cleanup any
* is called from onUnload() to give the module a chance to cleanup any
* resources associated with
the authentication
. */
* resources associated with
clients it has authenticated
. */
static
void
moduleFreeAuthenticatedClients
(
RedisModule
*
module
)
{
static
void
moduleFreeAuthenticatedClients
(
RedisModule
*
module
)
{
listIter
li
;
listIter
li
;
listNode
*
ln
;
listNode
*
ln
;
...
@@ -5375,18 +5378,13 @@ int RM_SetModuleUserACL(RedisModuleUser *user, const char* acl) {
...
@@ -5375,18 +5378,13 @@ int RM_SetModuleUserACL(RedisModuleUser *user, const char* acl) {
* previously authenticated client if the authentication is no longer valid.
* previously authenticated client if the authentication is no longer valid.
*
*
* For expensive authentication operations, it is recommended to block the
* For expensive authentication operations, it is recommended to block the
* client and do the authentication in the background then attach the user
* client and do the authentication in the background
and
then attach the user
* to the client in a threadsafe context. */
* to the client in a threadsafe context. */
static
int
authenticateClientWithUser
(
RedisModuleCtx
*
ctx
,
user
*
user
,
RedisModuleUserChangedFunc
callback
,
void
*
privdata
,
uint64_t
*
client_id
)
{
static
int
authenticateClientWithUser
(
RedisModuleCtx
*
ctx
,
user
*
user
,
RedisModuleUserChangedFunc
callback
,
void
*
privdata
,
uint64_t
*
client_id
)
{
if
(
user
->
flags
&
USER_FLAG_DISABLED
)
{
if
(
user
->
flags
&
USER_FLAG_DISABLED
)
{
return
REDISMODULE_ERR
;
return
REDISMODULE_ERR
;
}
}
/* Freeing the client would result in moduleNotifyUserChanged() to be
* called later, however since we use revokeClientAuthentication() also
* in moduleFreeAuthenticatedClients() to implement module unloading, we
* do this action ASAP: this way if the module is unloaded, when the client
* is eventually freed we don't rely on the module to still exist. */
moduleNotifyUserChanged
(
ctx
->
client
);
moduleNotifyUserChanged
(
ctx
->
client
);
ctx
->
client
->
user
=
user
;
ctx
->
client
->
user
=
user
;
...
@@ -5409,7 +5407,7 @@ static int authenticateClientWithUser(RedisModuleCtx *ctx, user *user, RedisModu
...
@@ -5409,7 +5407,7 @@ static int authenticateClientWithUser(RedisModuleCtx *ctx, user *user, RedisModu
/* Authenticate the current context's user with the provided redis acl user.
/* Authenticate the current context's user with the provided redis acl user.
* Returns REDISMODULE_ERR if the user is disabled.
* Returns REDISMODULE_ERR if the user is disabled.
*
*
* See authenticateClientWithUser for information about callback
and
client_id,
* See authenticateClientWithUser for information about callback
,
client_id,
* and general usage for authentication. */
* and general usage for authentication. */
int
RM_AuthenticateClientWithUser
(
RedisModuleCtx
*
ctx
,
RedisModuleUser
*
module_user
,
RedisModuleUserChangedFunc
callback
,
void
*
privdata
,
uint64_t
*
client_id
)
{
int
RM_AuthenticateClientWithUser
(
RedisModuleCtx
*
ctx
,
RedisModuleUser
*
module_user
,
RedisModuleUserChangedFunc
callback
,
void
*
privdata
,
uint64_t
*
client_id
)
{
return
authenticateClientWithUser
(
ctx
,
module_user
->
user
,
callback
,
privdata
,
client_id
);
return
authenticateClientWithUser
(
ctx
,
module_user
->
user
,
callback
,
privdata
,
client_id
);
...
@@ -5418,7 +5416,7 @@ int RM_AuthenticateClientWithUser(RedisModuleCtx *ctx, RedisModuleUser *module_u
...
@@ -5418,7 +5416,7 @@ int RM_AuthenticateClientWithUser(RedisModuleCtx *ctx, RedisModuleUser *module_u
/* Authenticate the current context's user with the provided redis acl user.
/* Authenticate the current context's user with the provided redis acl user.
* Returns REDISMODULE_ERR if the user is disabled or the user does not exist.
* Returns REDISMODULE_ERR if the user is disabled or the user does not exist.
*
*
* See authenticateClientWithUser for information about callback
and
client_id,
* See authenticateClientWithUser for information about callback
,
client_id,
* and general usage for authentication. */
* and general usage for authentication. */
int
RM_AuthenticateClientWithACLUser
(
RedisModuleCtx
*
ctx
,
const
char
*
name
,
size_t
len
,
RedisModuleUserChangedFunc
callback
,
void
*
privdata
,
uint64_t
*
client_id
)
{
int
RM_AuthenticateClientWithACLUser
(
RedisModuleCtx
*
ctx
,
const
char
*
name
,
size_t
len
,
RedisModuleUserChangedFunc
callback
,
void
*
privdata
,
uint64_t
*
client_id
)
{
user
*
acl_user
=
ACLGetUserByName
(
name
,
len
);
user
*
acl_user
=
ACLGetUserByName
(
name
,
len
);
...
@@ -5435,9 +5433,9 @@ int RM_AuthenticateClientWithACLUser(RedisModuleCtx *ctx, const char *name, size
...
@@ -5435,9 +5433,9 @@ int RM_AuthenticateClientWithACLUser(RedisModuleCtx *ctx, const char *name, size
* handle users becomming deauthenticated. Returns REDISMODULE_ERR when the
* handle users becomming deauthenticated. Returns REDISMODULE_ERR when the
* client doesn't exist and REDISMODULE_OK when the operation was successful.
* client doesn't exist and REDISMODULE_OK when the operation was successful.
*
*
* The client ID
can be obtained from the
AuthenticateClientWithUser and
* The client ID
is returned from the RM_
AuthenticateClientWithUser and
*
AuthenticateClientWithACLUser APIs or through other APIs such as
*
RM_AuthenticateClientWithACLUser APIs, but can be obtained through
* server events.
*
the CLIENT api or through
server events.
*
*
* This function is not thread safe, and must be executed within the context
* This function is not thread safe, and must be executed within the context
* of a command or thread safe context. */
* of a command or thread safe context. */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录