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