HELLO [ [AUTH ] [SETNAME ] ] */
| 3609 | |
| 3610 | /* HELLO [<protocol-version> [AUTH <user> <password>] [SETNAME <name>] ] */ |
| 3611 | void helloCommand(client *c) { |
| 3612 | long long ver = 0; |
| 3613 | int next_arg = 1; |
| 3614 | |
| 3615 | if (c->argc >= 2) { |
| 3616 | if (getLongLongFromObjectOrReply(c, c->argv[next_arg++], &ver, |
| 3617 | "Protocol version is not an integer or out of range") != C_OK) { |
| 3618 | return; |
| 3619 | } |
| 3620 | |
| 3621 | if (ver < 2 || ver > 3) { |
| 3622 | addReplyError(c,"-NOPROTO unsupported protocol version"); |
| 3623 | return; |
| 3624 | } |
| 3625 | } |
| 3626 | |
| 3627 | for (int j = next_arg; j < c->argc; j++) { |
| 3628 | int moreargs = (c->argc-1) - j; |
| 3629 | const char *opt = (const char*)ptrFromObj(c->argv[j]); |
| 3630 | if (!strcasecmp(opt,"AUTH") && moreargs >= 2) { |
| 3631 | redactClientCommandArgument(c, j+1); |
| 3632 | redactClientCommandArgument(c, j+2); |
| 3633 | if (ACLAuthenticateUser(c, c->argv[j+1], c->argv[j+2]) == C_ERR) { |
| 3634 | addReplyError(c,"-WRONGPASS invalid username-password pair or user is disabled."); |
| 3635 | return; |
| 3636 | } |
| 3637 | j += 2; |
| 3638 | } else if (!strcasecmp(opt,"SETNAME") && moreargs) { |
| 3639 | if (clientSetNameOrReply(c, c->argv[j+1]) == C_ERR) return; |
| 3640 | j++; |
| 3641 | } else { |
| 3642 | addReplyErrorFormat(c,"Syntax error in HELLO option '%s'",opt); |
| 3643 | return; |
| 3644 | } |
| 3645 | } |
| 3646 | |
| 3647 | /* At this point we need to be authenticated to continue. */ |
| 3648 | if (!c->authenticated) { |
| 3649 | addReplyError(c,"-NOAUTH HELLO must be called with the client already " |
| 3650 | "authenticated, otherwise the HELLO AUTH <user> <pass> " |
| 3651 | "option can be used to authenticate the client and " |
| 3652 | "select the RESP protocol version at the same time"); |
| 3653 | return; |
| 3654 | } |
| 3655 | |
| 3656 | /* Let's switch to the specified RESP mode. */ |
| 3657 | if (ver) c->resp = ver; |
| 3658 | addReplyMapLen(c,6 + !g_pserver->sentinel_mode); |
| 3659 | |
| 3660 | addReplyBulkCString(c,"server"); |
| 3661 | addReplyBulkCString(c,"redis"); |
| 3662 | |
| 3663 | addReplyBulkCString(c,"version"); |
| 3664 | addReplyBulkCString(c,KEYDB_SET_VERSION); |
| 3665 | |
| 3666 | addReplyBulkCString(c,"proto"); |
| 3667 | addReplyLongLong(c,c->resp); |
| 3668 |
nothing calls this directly
no test coverage detected