diff options
Diffstat (limited to 'src/server.h')
-rw-r--r-- | src/server.h | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/src/server.h b/src/server.h index 4b6e776c5..b911697a1 100644 --- a/src/server.h +++ b/src/server.h @@ -233,6 +233,9 @@ extern int configOOMScoreAdjValuesDefaults[CONFIG_OOM_COUNT]; #define CMD_CATEGORY_TRANSACTION (1ULL<<38) #define CMD_CATEGORY_SCRIPTING (1ULL<<39) +#define CMD_SENTINEL (1ULL<<40) /* "sentinel" flag */ +#define CMD_ONLY_SENTINEL (1ULL<<41) /* "only-sentinel" flag */ + /* AOF states */ #define AOF_OFF 0 /* AOF is off */ #define AOF_ON 1 /* AOF is on */ @@ -886,20 +889,29 @@ typedef struct { uint64_t flags; /* See USER_FLAG_* */ /* The bit in allowed_commands is set if this user has the right to - * execute this command. In commands having subcommands, if this bit is - * set, then all the subcommands are also available. + * execute this command. * * If the bit for a given command is NOT set and the command has - * subcommands, Redis will also check allowed_subcommands in order to + * allowed first-args, Redis will also check allowed_firstargs in order to * understand if the command can be executed. */ uint64_t allowed_commands[USER_COMMAND_BITS_COUNT/64]; - /* This array points, for each command ID (corresponding to the command + /* NOTE: allowed_firstargs is a transformation of the old mechanism for allowing + * subcommands (now, subcommands are actually commands, with their own + * ACL ID) + * We had to keep allowed_firstargs (previously called allowed_subcommands) + * in order to support the widespread abuse of ACL rules to block a command + * with a specific argv[1] (which is not a subcommand at all). + * For example, a user can use the rule "-select +select|0" to block all + * SELECT commands, except "SELECT 0". + * It can also be applied for subcommands: "+config -config|set +config|set|loglevel" + * + * This array points, for each command ID (corresponding to the command * bit set in allowed_commands), to an array of SDS strings, terminated by - * a NULL pointer, with all the sub commands that can be executed for - * this command. When no subcommands matching is used, the field is just + * a NULL pointer, with all the first-args that are allowed for + * this command. When no first-arg matching is used, the field is just * set to NULL to avoid allocating USER_COMMAND_BITS_COUNT pointers. */ - sds **allowed_subcommands; + sds **allowed_firstargs; list *passwords; /* A list of SDS valid passwords for this user. */ list *patterns; /* A list of allowed key patterns. If this field is NULL the user cannot mention any key in a command, unless @@ -1824,8 +1836,10 @@ struct redisCommand { char *sflags; /* Flags as string representation, one char per flag. */ keySpec key_specs_static[STATIC_KEY_SPECS_NUM]; /* Use a function to determine keys arguments in a command line. - * Used for Redis Cluster redirect. */ + * Used for Redis Cluster redirect (may be NULL) */ redisGetKeysProc *getkeys_proc; + /* Array of subcommands (may be NULL) */ + struct redisCommand *subcommands; /* Runtime data */ uint64_t flags; /* The actual flags, obtained from the 'sflags' field. */ @@ -1844,6 +1858,8 @@ struct redisCommand { int key_specs_num; int key_specs_max; int movablekeys; /* See populateCommandMovableKeys */ + dict *subcommands_dict; + struct redisCommand *parent; }; struct redisError { @@ -1980,6 +1996,8 @@ robj *moduleTypeDupOrReply(client *c, robj *fromkey, robj *tokey, int todb, robj int moduleDefragValue(robj *key, robj *obj, long *defragged, int dbid); int moduleLateDefrag(robj *key, robj *value, unsigned long *cursor, long long endtime, long long *defragged, int dbid); long moduleDefragGlobals(void); +void *moduleGetHandleByName(char *modulename); +int moduleIsModuleCommand(void *module_handle, struct redisCommand *cmd); /* Utils */ long long ustime(void); @@ -2420,9 +2438,12 @@ void removeSignalHandlers(void); int createSocketAcceptHandler(socketFds *sfd, aeFileProc *accept_handler); int changeListenPort(int port, socketFds *sfd, aeFileProc *accept_handler); int changeBindAddr(sds *addrlist, int addrlist_len); -struct redisCommand *lookupCommand(sds name); +struct redisCommand *lookupCommand(robj **argv ,int argc); +struct redisCommand *lookupCommandBySdsLogic(dict *commands, sds s); +struct redisCommand *lookupCommandBySds(sds s); +struct redisCommand *lookupCommandByCStringLogic(dict *commands, const char *s); struct redisCommand *lookupCommandByCString(const char *s); -struct redisCommand *lookupCommandOrOriginal(sds name); +struct redisCommand *lookupCommandOrOriginal(robj **argv ,int argc); void call(client *c, int flags); void propagate(int dbid, robj **argv, int argc, int flags); void alsoPropagate(int dbid, robj **argv, int argc, int target); @@ -2448,7 +2469,7 @@ void usage(void); void updateDictResizePolicy(void); int htNeedsResize(dict *dict); void populateCommandTable(void); -void resetCommandTableStats(void); +void resetCommandTableStats(dict* commands); void resetErrorTableStats(void); void adjustOpenFilesLimit(void); void incrementErrorCount(const char *fullerr, size_t namelen); @@ -2606,7 +2627,6 @@ int sortGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult * int migrateGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result); int georadiusGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result); int xreadGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result); -int memoryGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result); int lcsGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result); int lmpopGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result); int blmpopGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result); @@ -2624,6 +2644,10 @@ void queueSentinelConfig(sds *argv, int argc, int linenum, sds line); void loadSentinelConfigFromQueue(void); void sentinelIsRunning(void); void sentinelCheckConfigFile(void); +void sentinelCommand(client *c); +void sentinelInfoCommand(client *c); +void sentinelPublishCommand(client *c); +void sentinelRoleCommand(client *c); /* redis-check-rdb & aof */ int redis_check_rdb(char *rdbfilename, FILE *fp); @@ -2694,6 +2718,11 @@ void authCommand(client *c); void pingCommand(client *c); void echoCommand(client *c); void commandCommand(client *c); +void commandCountCommand(client *c); +void commandListCommand(client *c); +void commandInfoCommand(client *c); +void commandGetKeysCommand(client *c); +void commandHelpCommand(client *c); void setCommand(client *c); void setnxCommand(client *c); void setexCommand(client *c); @@ -2846,7 +2875,11 @@ void hgetallCommand(client *c); void hexistsCommand(client *c); void hscanCommand(client *c); void hrandfieldCommand(client *c); -void configCommand(client *c); +void configSetCommand(client *c); +void configGetCommand(client *c); +void configResetStatCommand(client *c); +void configRewriteCommand(client *c); +void configHelpCommand(client *c); void hincrbyCommand(client *c); void hincrbyfloatCommand(client *c); void subscribeCommand(client *c); @@ -2937,6 +2970,7 @@ void _serverPanic(const char *file, int line, const char *msg, ...); #endif void serverLogObjectDebugInfo(const robj *o); void sigsegvHandler(int sig, siginfo_t *info, void *secret); +sds getFullCommandName(struct redisCommand *cmd); const char *getSafeInfoString(const char *s, size_t len, char **tmp); sds genRedisInfoString(const char *section); sds genModulesInfoString(sds info); @@ -2948,6 +2982,7 @@ int memtest_preserving_test(unsigned long *m, size_t bytes, int passes); void mixDigest(unsigned char *digest, void *ptr, size_t len); void xorDigest(unsigned char *digest, void *ptr, size_t len); int populateSingleCommand(struct redisCommand *c, char *strflags); +void commandAddSubcommand(struct redisCommand *parent, struct redisCommand *subcommand); void populateCommandMovableKeys(struct redisCommand *cmd); void debugDelay(int usec); void killIOThreads(void); |