Fix replica authentication failure when masterauth is below replicaof in the config file

Former-commit-id: c64ce7aa9c7783425430e08831f1c41346e315a9
This commit is contained in:
John Sully 2019-04-15 22:31:02 -04:00
parent fe552e3e39
commit 0798be97eb
3 changed files with 22 additions and 0 deletions

View File

@ -399,6 +399,8 @@ void loadServerConfigFromString(char *config) {
} else if (!strcasecmp(argv[0],"masterauth") && argc == 2) {
zfree(server.default_masterauth);
server.default_masterauth = argv[1][0] ? zstrdup(argv[1]) : NULL;
// Loop through all existing master infos and update them (in case this came after the replicaof config)
updateMasterAuth();
} else if ((!strcasecmp(argv[0],"slave-serve-stale-data") ||
!strcasecmp(argv[0],"replica-serve-stale-data"))
&& argc == 2)

View File

@ -3194,4 +3194,23 @@ void replicaReplayCommand(client *c)
// call() will not propogate this for us, so we do so here
alsoPropagate(server.rreplayCommand,c->db->id,c->argv,c->argc,PROPAGATE_AOF|PROPAGATE_REPL);
return;
}
void updateMasterAuth()
{
listIter li;
listNode *ln;
listRewind(server.masters, &li);
while ((ln = listNext(&li)))
{
redisMaster *mi = (redisMaster*)listNodeValue(ln);
zfree(mi->masterauth); mi->masterauth = nullptr;
zfree(mi->masteruser); mi->masteruser = nullptr;
if (server.default_masterauth)
mi->masterauth = zstrdup(server.default_masterauth);
if (server.default_masteruser)
mi->masteruser = zstrdup(server.default_masteruser);
}
}

View File

@ -1824,6 +1824,7 @@ void clearReplicationId2(void);
void chopReplicationBacklog(void);
void replicationCacheMasterUsingMyself(struct redisMaster *mi);
void feedReplicationBacklog(const void *ptr, size_t len);
void updateMasterAuth();
/* Generic persistence functions */
void startLoading(FILE *fp);