add authmodule
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
LingZhaoHui 2022-05-10 23:05:43 +08:00
parent c60a267c36
commit e6fe5045cb
3 changed files with 81 additions and 6 deletions

View File

@ -1,12 +1,13 @@
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
WARN=-Wall -W -Wno-missing-field-initializers
# Compile flags for linux / osx
ifeq ($(uname_S),Linux)
SHOBJ_CFLAGS ?= -W -Wall -fno-common -g -ggdb -std=c99 -O2
SHOBJ_CFLAGS ?= -W -Wall -fno-common -g -ggdb -std=c11 -O2 $(WARN) $(OPTIMIZATION)
SHOBJ_LDFLAGS ?= -shared
else
SHOBJ_CFLAGS ?= -W -Wall -dynamic -fno-common -g -ggdb -std=c99 -O2
SHOBJ_CFLAGS ?= -W -Wall -dynamic -fno-common -g -ggdb -std=c11 -O2 $(WARN) $(OPTIMIZATION)
SHOBJ_LDFLAGS ?= -bundle -undefined dynamic_lookup
endif
@ -25,4 +26,4 @@ redis-acl.so: redis-acl.xo
$(LD) -o $@ $^ $(SHOBJ_LDFLAGS) $(LIBS) -lc
clean:
rm -rf *.xo *.so
rm -rf *.xo *.so *.o

View File

@ -1,7 +1,61 @@
#include <stdio.h>
#include "redis-acl.h"
#include "redismodule.h"
int main(){
printf("Hello world\n");
return 0;
static RedisModuleCommandFilter *filter;
void AuthFilter_CommandFilter(RedisModuleCommandFilter *filter) {
int log = 0;
int pos = 0;
RedisModule_Log(NULL, LOG_LEVL_NOTICE, "command filter");
while (pos < RedisModule_CommandFilterArgsCount(filter)) {
const RedisModuleString *arg = RedisModule_CommandFilterArgGet(filter, pos);
size_t arg_len;
const char *arg_str = RedisModule_StringPtrLen(arg, &arg_len);
RedisModule_Log(NULL, LOG_LEVL_NOTICE, "str=%s,len=%d", arg_str, arg_len);
// 解密
pos++;
}
RedisModuleUser *user = RedisModule_CreateModuleUser("default");
if (user == NULL) {
RedisModule_Log(NULL, LOG_LEVL_NOTICE, "user is null");
}
}
int AuthCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
return REDISMODULE_OK;
}
void create_users(RedisModuleCtx *ctx) {
RedisModuleUser *user = RedisModule_CreateModuleUser("default");
RedisModule_SetModuleUserACL(user, "allcommands");
RedisModule_SetModuleUserACL(user, "allkeys");
RedisModule_SetModuleUserACL(user, "on");
RedisModule_Log(ctx, LOG_LEVL_NOTICE, "init module user success!");
RedisModule_FreeModuleUser(user);
}
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
REDISMODULE_NOT_USED(argv);
REDISMODULE_NOT_USED(argc);
if (RedisModule_Init(ctx, "redis-auth", 1, REDISMODULE_APIVER_1) == REDISMODULE_ERR) {
RedisModule_Log(ctx, LOG_LEVL_NOTICE, "init redis-auth failed");
return REDISMODULE_ERR;
}
create_users(ctx);
filter = RedisModule_RegisterCommandFilter(ctx, AuthFilter_CommandFilter, 0);
if (filter == NULL) {
return REDISMODULE_ERR;
}
RedisModule_Log(ctx, LOG_LEVL_NOTICE, "init redis-auth success!");
return REDISMODULE_OK;
}

20
src/redis-acl.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef REDISAUTH_H
#include "redismodule.h"
/* Error status return values. */
#define REDISMODULE_OK 0
#define REDISMODULE_ERR 1
#define LOG_LEVL_NOTICE "notice"
/* *
* Redis Auth command
* */
int AuthCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
void AuthFilter_CommandFilter(RedisModuleCommandFilter *filter);
#endif // REDISAUTH_H