diff options
author | Madelyn Olson <matolson@amazon.com> | 2019-12-17 07:15:04 +0000 |
---|---|---|
committer | Madelyn Olson <matolson@amazon.com> | 2019-12-17 07:15:04 +0000 |
commit | 67aa527b222a9bd72f7c6f1d58abb3d30776aea5 (patch) | |
tree | 3dc0c28e67b5d3b2f7e364f6807f0342f7b88227 | |
parent | 034dcf185cfaa844154e422d26a9ec7afa314189 (diff) | |
download | redis-67aa527b222a9bd72f7c6f1d58abb3d30776aea5.tar.gz |
Added some documentation and fixed a test
-rw-r--r-- | src/modules/helloacl.c | 10 | ||||
-rw-r--r-- | src/server.h | 13 | ||||
-rw-r--r-- | tests/modules/auth.c | 10 |
3 files changed, 18 insertions, 15 deletions
diff --git a/src/modules/helloacl.c b/src/modules/helloacl.c index a6cc68a04..6766c0a58 100644 --- a/src/modules/helloacl.c +++ b/src/modules/helloacl.c @@ -1,4 +1,5 @@ -/* ACL API example - An example of performing custom password authentication +/* ACL API example - An example for performing custom synchronous and + * asynchronous password authentication. * * ----------------------------------------------------------------------------- * @@ -32,11 +33,6 @@ #define REDISMODULE_EXPERIMENTAL_API #include "../redismodule.h" -#include <stdio.h> -#include <stdlib.h> -#include <ctype.h> -#include <string.h> -#include <strings.h> #include <pthread.h> #include <unistd.h> @@ -51,7 +47,7 @@ int RevokeCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, in REDISMODULE_NOT_USED(argc); if (global_auth_client_id) { - RedisModule_DisconnectClient(ctx, global_auth_client_id); + RedisModule_DeauthenticateAndCloseClient(ctx, global_auth_client_id); return RedisModule_ReplyWithSimpleString(ctx, "OK"); } else { return RedisModule_ReplyWithError(ctx, "Global user currently not used"); diff --git a/src/server.h b/src/server.h index 9c25a7ef5..d7e07a016 100644 --- a/src/server.h +++ b/src/server.h @@ -481,7 +481,8 @@ typedef void (*moduleTypeDigestFunc)(struct RedisModuleDigest *digest, void *val typedef size_t (*moduleTypeMemUsageFunc)(const void *value); typedef void (*moduleTypeFreeFunc)(void *value); -/* TODO */ +/* A callback that is called when the client authentication changes. This + * needs to be exposed since you can't cast a function pointer to (void *) */ typedef void (*RedisModuleUserChangedFunc) (uint64_t client_id, void *privdata); @@ -803,13 +804,15 @@ typedef struct client { list *pubsub_patterns; /* patterns a client is interested in (SUBSCRIBE) */ sds peerid; /* Cached peer ID. */ listNode *client_list_node; /* list node in client list */ - RedisModuleUserChangedFunc auth_callback; /* Callback to execute when the - * authentication changes */ + RedisModuleUserChangedFunc auth_callback; /* Module callback to execute + * when the authenticated user + * changes. */ void *auth_callback_privdata; /* Private data that is passed when the auth - * callback is executed */ + * changed callback is executed. Opaque for + * Redis Core. */ void *auth_module; /* The module that owns the callback, which is used * to disconnect the client if the module is - * unloaded to allow for cleanup. */ + * unloaded for cleanup. Opaque for Redis Core.*/ /* If this client is in tracking mode and this field is non zero, * invalidation messages for keys fetched by this client will be send to diff --git a/tests/modules/auth.c b/tests/modules/auth.c index ad4366e47..52b5da169 100644 --- a/tests/modules/auth.c +++ b/tests/modules/auth.c @@ -34,7 +34,7 @@ #include "redismodule.h" // A simple global user -static RedisModuleUser *global; +static RedisModuleUser *global = NULL; static long long client_change_delta = 0; void UserChangedCallback(uint64_t client_id, void *privdata) { @@ -44,6 +44,8 @@ void UserChangedCallback(uint64_t client_id, void *privdata) { } int Auth_CreateModuleUser(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { + REDISMODULE_NOT_USED(argv); + REDISMODULE_NOT_USED(argc); if (global) { RedisModule_FreeModuleUser(global); @@ -58,6 +60,8 @@ int Auth_CreateModuleUser(RedisModuleCtx *ctx, RedisModuleString **argv, int arg } int Auth_AuthModuleUser(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { + REDISMODULE_NOT_USED(argv); + REDISMODULE_NOT_USED(argc); uint64_t client_id; RedisModule_AuthenticateClientWithUser(ctx, global, UserChangedCallback, NULL, &client_id); @@ -82,6 +86,8 @@ int Auth_AuthRealUser(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { } int Auth_ChangeCount(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { + REDISMODULE_NOT_USED(argv); + REDISMODULE_NOT_USED(argc); long long result = client_change_delta; client_change_delta = 0; return RedisModule_ReplyWithLongLong(ctx, result); @@ -112,7 +118,5 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) Auth_ChangeCount,"",0,0,0) == REDISMODULE_ERR) return REDISMODULE_ERR; - client_change_delta = 0; - return REDISMODULE_OK; } |