MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / ACLGetCommandID

Function ACLGetCommandID

src/acl.cpp:1137–1163  ·  view source on GitHub ↗

For ACL purposes, every user has a bitmap with the commands that such * user is allowed to execute. In order to populate the bitmap, every command * should have an assigned ID (that is used to index the bitmap). This function * creates such an ID: it uses sequential IDs, reusing the same ID for the same * command name, so that a command retains the same ID in case of modules that * are unload

Source from the content-addressed store, hash-verified

1135 * command name, so that a command retains the same ID in case of modules that
1136 * are unloaded and later reloaded. */
1137unsigned long ACLGetCommandID(const char *cmdname) {
1138
1139 sds lowername = sdsnew(cmdname);
1140 sdstolower(lowername);
1141 if (commandId == NULL) commandId = raxNew();
1142 void *id = raxFind(commandId,(unsigned char*)lowername,sdslen(lowername));
1143 if (id != raxNotFound) {
1144 sdsfree(lowername);
1145 return (unsigned long)id;
1146 }
1147 raxInsert(commandId,(unsigned char*)lowername,strlen(lowername),
1148 (void*)nextid,NULL);
1149 sdsfree(lowername);
1150 unsigned long thisid = nextid;
1151 nextid++;
1152
1153 /* We never assign the last bit in the user commands bitmap structure,
1154 * this way we can later check if this bit is set, understanding if the
1155 * current ACL for the user was created starting with a +@all to add all
1156 * the possible commands and just subtracting other single commands or
1157 * categories, or if, instead, the ACL was created just adding commands
1158 * and command categories from scratch, not allowing future commands by
1159 * default (loaded via modules). This is useful when rewriting the ACLs
1160 * with ACL SAVE. */
1161 if (nextid == USER_COMMAND_BITS_COUNT-1) nextid++;
1162 return thisid;
1163}
1164
1165/* Clear command id table and reset nextid to 0. */
1166void ACLClearCommandID(void) {

Callers 4

populateCommandTableFunction · 0.85
RM_CreateCommandFunction · 0.85
initSentinelFunction · 0.85
ACLSetUserFunction · 0.85

Calls 7

sdsnewFunction · 0.85
sdstolowerFunction · 0.85
raxNewFunction · 0.85
raxFindFunction · 0.85
sdslenFunction · 0.85
sdsfreeFunction · 0.85
raxInsertFunction · 0.85

Tested by

no test coverage detected