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

Function ACLSetUser

src/acl.cpp:834–1023  ·  view source on GitHub ↗

Set user properties according to the string "op". The following * is a description of what different strings will do: * * on Enable the user: it is possible to authenticate as this user. * off Disable the user: it's no longer possible to authenticate * with this user, however the already authenticated connections * will still work. * +

Source from the content-addressed store, hash-verified

832 * EBADMSG: The hash you are trying to add is not a valid hash.
833 */
834int ACLSetUser(user *u, const char *op, ssize_t oplen) {
835 if (oplen == -1) oplen = strlen(op);
836 if (oplen == 0) return C_OK; /* Empty string is a no-operation. */
837 if (!strcasecmp(op,"on")) {
838 u->flags |= USER_FLAG_ENABLED;
839 u->flags &= ~USER_FLAG_DISABLED;
840 } else if (!strcasecmp(op,"off")) {
841 u->flags |= USER_FLAG_DISABLED;
842 u->flags &= ~USER_FLAG_ENABLED;
843 } else if (!strcasecmp(op,"skip-sanitize-payload")) {
844 u->flags |= USER_FLAG_SANITIZE_PAYLOAD_SKIP;
845 u->flags &= ~USER_FLAG_SANITIZE_PAYLOAD;
846 } else if (!strcasecmp(op,"sanitize-payload")) {
847 u->flags &= ~USER_FLAG_SANITIZE_PAYLOAD_SKIP;
848 u->flags |= USER_FLAG_SANITIZE_PAYLOAD;
849 } else if (!strcasecmp(op,"allkeys") ||
850 !strcasecmp(op,"~*"))
851 {
852 u->flags |= USER_FLAG_ALLKEYS;
853 listEmpty(u->patterns);
854 } else if (!strcasecmp(op,"resetkeys")) {
855 u->flags &= ~USER_FLAG_ALLKEYS;
856 listEmpty(u->patterns);
857 } else if (!strcasecmp(op,"allchannels") ||
858 !strcasecmp(op,"&*"))
859 {
860 u->flags |= USER_FLAG_ALLCHANNELS;
861 listEmpty(u->channels);
862 } else if (!strcasecmp(op,"resetchannels")) {
863 u->flags &= ~USER_FLAG_ALLCHANNELS;
864 listEmpty(u->channels);
865 } else if (!strcasecmp(op,"allcommands") ||
866 !strcasecmp(op,"+@all"))
867 {
868 memset(u->allowed_commands,255,sizeof(u->allowed_commands));
869 u->flags |= USER_FLAG_ALLCOMMANDS;
870 ACLResetSubcommands(u);
871 } else if (!strcasecmp(op,"nocommands") ||
872 !strcasecmp(op,"-@all"))
873 {
874 memset(u->allowed_commands,0,sizeof(u->allowed_commands));
875 u->flags &= ~USER_FLAG_ALLCOMMANDS;
876 ACLResetSubcommands(u);
877 } else if (!strcasecmp(op,"nopass")) {
878 u->flags |= USER_FLAG_NOPASS;
879 listEmpty(u->passwords);
880 } else if (!strcasecmp(op,"resetpass")) {
881 u->flags &= ~USER_FLAG_NOPASS;
882 listEmpty(u->passwords);
883 } else if (op[0] == '>' || op[0] == '#') {
884 sds newpass;
885 if (op[0] == '>') {
886 newpass = ACLHashPassword((unsigned char*)op+1,oplen-1);
887 } else {
888 if (ACLCheckPasswordHash((unsigned char*)op+1,oplen-1) == C_ERR) {
889 errno = EBADMSG;
890 return C_ERR;
891 }

Callers 8

RM_SetModuleUserACLFunction · 0.85
ACLInitDefaultUserFunction · 0.85
ACLAppendUserForLoadingFunction · 0.85
ACLLoadConfiguredUsersFunction · 0.85
ACLLoadFromFileFunction · 0.85
aclCommandFunction · 0.85

Calls 15

listEmptyFunction · 0.85
ACLResetSubcommandsFunction · 0.85
ACLHashPasswordFunction · 0.85
ACLCheckPasswordHashFunction · 0.85
sdsnewlenFunction · 0.85
listSearchKeyFunction · 0.85
listAddNodeTailFunction · 0.85
sdsfreeFunction · 0.85
listDelNodeFunction · 0.85
ACLStringHasSpacesFunction · 0.85
ACLLookupCommandFunction · 0.85
ACLGetCommandIDFunction · 0.85

Tested by

no test coverage detected