HELLO [ [AUTH ] [SETNAME ] ] */
| 2974 | |
| 2975 | /* HELLO [<protocol-version> [AUTH <user> <password>] [SETNAME <name>] ] */ |
| 2976 | void helloCommand(client *c) { |
| 2977 | long long ver = 0; |
| 2978 | int next_arg = 1; |
| 2979 | |
| 2980 | if (c->argc >= 2) { |
| 2981 | if (getLongLongFromObjectOrReply(c, c->argv[next_arg++], &ver, |
| 2982 | "Protocol version is not an integer or out of range") != C_OK) { |
| 2983 | return; |
| 2984 | } |
| 2985 | |
| 2986 | if (ver < 2 || ver > 3) { |
| 2987 | addReplyError(c,"-NOPROTO unsupported protocol version"); |
| 2988 | return; |
| 2989 | } |
| 2990 | } |
| 2991 | |
| 2992 | for (int j = next_arg; j < c->argc; j++) { |
| 2993 | int moreargs = (c->argc-1) - j; |
| 2994 | const char *opt = c->argv[j]->ptr; |
| 2995 | if (!strcasecmp(opt,"AUTH") && moreargs >= 2) { |
| 2996 | redactClientCommandArgument(c, j+1); |
| 2997 | redactClientCommandArgument(c, j+2); |
| 2998 | if (ACLAuthenticateUser(c, c->argv[j+1], c->argv[j+2]) == C_ERR) { |
| 2999 | addReplyError(c,"-WRONGPASS invalid username-password pair or user is disabled."); |
| 3000 | return; |
| 3001 | } |
| 3002 | j += 2; |
| 3003 | } else if (!strcasecmp(opt,"SETNAME") && moreargs) { |
| 3004 | if (clientSetNameOrReply(c, c->argv[j+1]) == C_ERR) return; |
| 3005 | j++; |
| 3006 | } else { |
| 3007 | addReplyErrorFormat(c,"Syntax error in HELLO option '%s'",opt); |
| 3008 | return; |
| 3009 | } |
| 3010 | } |
| 3011 | |
| 3012 | /* At this point we need to be authenticated to continue. */ |
| 3013 | if (!c->authenticated) { |
| 3014 | addReplyError(c,"-NOAUTH HELLO must be called with the client already " |
| 3015 | "authenticated, otherwise the HELLO AUTH <user> <pass> " |
| 3016 | "option can be used to authenticate the client and " |
| 3017 | "select the RESP protocol version at the same time"); |
| 3018 | return; |
| 3019 | } |
| 3020 | |
| 3021 | /* Let's switch to the specified RESP mode. */ |
| 3022 | if (ver) c->resp = ver; |
| 3023 | addReplyMapLen(c,6 + !server.sentinel_mode); |
| 3024 | |
| 3025 | addReplyBulkCString(c,"server"); |
| 3026 | addReplyBulkCString(c,"redis"); |
| 3027 | |
| 3028 | addReplyBulkCString(c,"version"); |
| 3029 | addReplyBulkCString(c,REDIS_VERSION); |
| 3030 | |
| 3031 | addReplyBulkCString(c,"proto"); |
| 3032 | addReplyLongLong(c,c->resp); |
| 3033 |
nothing calls this directly
no test coverage detected