Send the AUTH command with the specified master password if needed. * Note that for slaves the password set for the master is used. * * In case this Sentinel requires a password as well, via the "requirepass" * configuration directive, we assume we should use the local password in * order to authenticate when connecting with the other Sentinels as well. * So basically all the Sentinels share
| 2351 | * to the instance as if it fails Sentinel will detect the instance down, |
| 2352 | * will disconnect and reconnect the link and so forth. */ |
| 2353 | void sentinelSendAuthIfNeeded(sentinelRedisInstance *ri, redisAsyncContext *c) { |
| 2354 | char *auth_pass = NULL; |
| 2355 | char *auth_user = NULL; |
| 2356 | |
| 2357 | if (ri->flags & SRI_MASTER) { |
| 2358 | auth_pass = ri->auth_pass; |
| 2359 | auth_user = ri->auth_user; |
| 2360 | } else if (ri->flags & SRI_SLAVE) { |
| 2361 | auth_pass = ri->master->auth_pass; |
| 2362 | auth_user = ri->master->auth_user; |
| 2363 | } else if (ri->flags & SRI_SENTINEL) { |
| 2364 | /* If sentinel_auth_user is NULL, AUTH will use default user |
| 2365 | with sentinel_auth_pass to authenticate */ |
| 2366 | if (sentinel.sentinel_auth_pass) { |
| 2367 | auth_pass = sentinel.sentinel_auth_pass; |
| 2368 | auth_user = sentinel.sentinel_auth_user; |
| 2369 | } else { |
| 2370 | /* Compatibility with old configs. requirepass is used |
| 2371 | * for both incoming and outgoing authentication. */ |
| 2372 | auth_pass = g_pserver->requirepass; |
| 2373 | auth_user = NULL; |
| 2374 | } |
| 2375 | } |
| 2376 | |
| 2377 | if (auth_pass && auth_user == NULL) { |
| 2378 | if (redisAsyncCommand(c, sentinelDiscardReplyCallback, ri, "%s %s", |
| 2379 | sentinelInstanceMapCommand(ri,"AUTH"), |
| 2380 | auth_pass) == C_OK) ri->link->pending_commands++; |
| 2381 | } else if (auth_pass && auth_user) { |
| 2382 | /* If we also have an username, use the ACL-style AUTH command |
| 2383 | * with two arguments, username and password. */ |
| 2384 | if (redisAsyncCommand(c, sentinelDiscardReplyCallback, ri, "%s %s %s", |
| 2385 | sentinelInstanceMapCommand(ri,"AUTH"), |
| 2386 | auth_user, auth_pass) == C_OK) ri->link->pending_commands++; |
| 2387 | } |
| 2388 | } |
| 2389 | |
| 2390 | /* Use CLIENT SETNAME to name the connection in the Redis instance as |
| 2391 | * sentinel-<first_8_chars_of_runid>-<connection_type> |
no test coverage detected