Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
f891b64a
Commit
f891b64a
authored
Dec 17, 2019
by
Madelyn Olson
Browse files
Tweaking the documentation
parent
67aa527b
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
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
, i
t is expected to completely clean up
it's
state
* the same
. I
t 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
authenticat
ion
. */
* resources associated with
clients it has
authenticat
ed
. */
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 obtai
ned from the AuthenticateClientWithUser and
* The client ID
is retur
ned 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. */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment