Added some documentation and fixed a test
This commit is contained in:
parent
034dcf185c
commit
67aa527b22
@ -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
|
#define REDISMODULE_EXPERIMENTAL_API
|
||||||
#include "../redismodule.h"
|
#include "../redismodule.h"
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <strings.h>
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@ -51,7 +47,7 @@ int RevokeCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, in
|
|||||||
REDISMODULE_NOT_USED(argc);
|
REDISMODULE_NOT_USED(argc);
|
||||||
|
|
||||||
if (global_auth_client_id) {
|
if (global_auth_client_id) {
|
||||||
RedisModule_DisconnectClient(ctx, global_auth_client_id);
|
RedisModule_DeauthenticateAndCloseClient(ctx, global_auth_client_id);
|
||||||
return RedisModule_ReplyWithSimpleString(ctx, "OK");
|
return RedisModule_ReplyWithSimpleString(ctx, "OK");
|
||||||
} else {
|
} else {
|
||||||
return RedisModule_ReplyWithError(ctx, "Global user currently not used");
|
return RedisModule_ReplyWithError(ctx, "Global user currently not used");
|
||||||
|
13
src/server.h
13
src/server.h
@ -481,7 +481,8 @@ typedef void (*moduleTypeDigestFunc)(struct RedisModuleDigest *digest, void *val
|
|||||||
typedef size_t (*moduleTypeMemUsageFunc)(const void *value);
|
typedef size_t (*moduleTypeMemUsageFunc)(const void *value);
|
||||||
typedef void (*moduleTypeFreeFunc)(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);
|
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) */
|
list *pubsub_patterns; /* patterns a client is interested in (SUBSCRIBE) */
|
||||||
sds peerid; /* Cached peer ID. */
|
sds peerid; /* Cached peer ID. */
|
||||||
listNode *client_list_node; /* list node in client list */
|
listNode *client_list_node; /* list node in client list */
|
||||||
RedisModuleUserChangedFunc auth_callback; /* Callback to execute when the
|
RedisModuleUserChangedFunc auth_callback; /* Module callback to execute
|
||||||
* authentication changes */
|
* when the authenticated user
|
||||||
|
* changes. */
|
||||||
void *auth_callback_privdata; /* Private data that is passed when the auth
|
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
|
void *auth_module; /* The module that owns the callback, which is used
|
||||||
* to disconnect the client if the module is
|
* 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,
|
/* 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
|
* invalidation messages for keys fetched by this client will be send to
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
#include "redismodule.h"
|
#include "redismodule.h"
|
||||||
|
|
||||||
// A simple global user
|
// A simple global user
|
||||||
static RedisModuleUser *global;
|
static RedisModuleUser *global = NULL;
|
||||||
static long long client_change_delta = 0;
|
static long long client_change_delta = 0;
|
||||||
|
|
||||||
void UserChangedCallback(uint64_t client_id, void *privdata) {
|
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) {
|
int Auth_CreateModuleUser(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||||
|
REDISMODULE_NOT_USED(argv);
|
||||||
|
REDISMODULE_NOT_USED(argc);
|
||||||
|
|
||||||
if (global) {
|
if (global) {
|
||||||
RedisModule_FreeModuleUser(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) {
|
int Auth_AuthModuleUser(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||||
|
REDISMODULE_NOT_USED(argv);
|
||||||
|
REDISMODULE_NOT_USED(argc);
|
||||||
uint64_t client_id;
|
uint64_t client_id;
|
||||||
RedisModule_AuthenticateClientWithUser(ctx, global, UserChangedCallback, NULL, &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) {
|
int Auth_ChangeCount(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||||
|
REDISMODULE_NOT_USED(argv);
|
||||||
|
REDISMODULE_NOT_USED(argc);
|
||||||
long long result = client_change_delta;
|
long long result = client_change_delta;
|
||||||
client_change_delta = 0;
|
client_change_delta = 0;
|
||||||
return RedisModule_ReplyWithLongLong(ctx, result);
|
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)
|
Auth_ChangeCount,"",0,0,0) == REDISMODULE_ERR)
|
||||||
return REDISMODULE_ERR;
|
return REDISMODULE_ERR;
|
||||||
|
|
||||||
client_change_delta = 0;
|
|
||||||
|
|
||||||
return REDISMODULE_OK;
|
return REDISMODULE_OK;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user