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
| 1135 | * command name, so that a command retains the same ID in case of modules that |
| 1136 | * are unloaded and later reloaded. */ |
| 1137 | unsigned 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. */ |
| 1166 | void ACLClearCommandID(void) { |
no test coverage detected