summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSalvatore Sanfilippo <antirez@gmail.com>2019-02-12 10:27:59 +0100
committerGitHub <noreply@github.com>2019-02-12 10:27:59 +0100
commita22815b4e9cfaf607378596d1ed715f71d6762c2 (patch)
treed201f15a3ae05900d29b3305b19472a05c4ef0df
parentd5e4a7f43976d14241c56dd65754189fd8569087 (diff)
parentea9d3aefec76f5798510e09c9b2c8046e7eb2b8f (diff)
downloadredis-a22815b4e9cfaf607378596d1ed715f71d6762c2.tar.gz
Merge pull request #5833 from soloestoy/masteruser
ACL: add masteruser configuration for replication
-rw-r--r--src/config.c8
-rw-r--r--src/replication.c8
-rw-r--r--src/server.h1
3 files changed, 16 insertions, 1 deletions
diff --git a/src/config.c b/src/config.c
index fc9160d26..68a2ea227 100644
--- a/src/config.c
+++ b/src/config.c
@@ -395,6 +395,9 @@ void loadServerConfigFromString(char *config) {
err = "repl-backlog-ttl can't be negative ";
goto loaderr;
}
+ } else if (!strcasecmp(argv[0],"masteruser") && argc == 2) {
+ zfree(server.masteruser);
+ server.masteruser = argv[1][0] ? zstrdup(argv[1]) : NULL;
} else if (!strcasecmp(argv[0],"masterauth") && argc == 2) {
zfree(server.masterauth);
server.masterauth = argv[1][0] ? zstrdup(argv[1]) : NULL;
@@ -943,6 +946,9 @@ void configSetCommand(client *c) {
sds aclop = sdscatprintf(sdsempty(),">%s",(char*)o->ptr);
ACLSetUser(DefaultUser,aclop,sdslen(aclop));
sdsfree(aclop);
+ } config_set_special_field("masteruser") {
+ zfree(server.masteruser);
+ server.masteruser = ((char*)o->ptr)[0] ? zstrdup(o->ptr) : NULL;
} config_set_special_field("masterauth") {
zfree(server.masterauth);
server.masterauth = ((char*)o->ptr)[0] ? zstrdup(o->ptr) : NULL;
@@ -1354,6 +1360,7 @@ void configGetCommand(client *c) {
/* String values */
config_get_string_field("dbfilename",server.rdb_filename);
+ config_get_string_field("masteruser",server.masteruser);
config_get_string_field("masterauth",server.masterauth);
config_get_string_field("cluster-announce-ip",server.cluster_announce_ip);
config_get_string_field("unixsocket",server.unixsocket);
@@ -2232,6 +2239,7 @@ int rewriteConfig(char *path) {
rewriteConfigDirOption(state);
rewriteConfigSlaveofOption(state,"replicaof");
rewriteConfigStringOption(state,"replica-announce-ip",server.slave_announce_ip,CONFIG_DEFAULT_SLAVE_ANNOUNCE_IP);
+ rewriteConfigStringOption(state,"masteruser",server.masteruser,NULL);
rewriteConfigStringOption(state,"masterauth",server.masterauth,NULL);
rewriteConfigStringOption(state,"cluster-announce-ip",server.cluster_announce_ip,NULL);
rewriteConfigYesNoOption(state,"replica-serve-stale-data",server.repl_serve_stale_data,CONFIG_DEFAULT_SLAVE_SERVE_STALE_DATA);
diff --git a/src/replication.c b/src/replication.c
index 3bc42d62a..9175bb420 100644
--- a/src/replication.c
+++ b/src/replication.c
@@ -1661,7 +1661,13 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {
/* AUTH with the master if required. */
if (server.repl_state == REPL_STATE_SEND_AUTH) {
- if (server.masterauth) {
+ if (server.masteruser && server.masterauth) {
+ err = sendSynchronousCommand(SYNC_CMD_WRITE,fd,"AUTH",
+ server.masteruser,server.masterauth,NULL);
+ if (err) goto write_error;
+ server.repl_state = REPL_STATE_RECEIVE_AUTH;
+ return;
+ } else if (server.masterauth) {
err = sendSynchronousCommand(SYNC_CMD_WRITE,fd,"AUTH",server.masterauth,NULL);
if (err) goto write_error;
server.repl_state = REPL_STATE_RECEIVE_AUTH;
diff --git a/src/server.h b/src/server.h
index 59f7cbe10..a396e1cf7 100644
--- a/src/server.h
+++ b/src/server.h
@@ -1217,6 +1217,7 @@ struct redisServer {
int repl_diskless_sync; /* Send RDB to slaves sockets directly. */
int repl_diskless_sync_delay; /* Delay to start a diskless repl BGSAVE. */
/* Replication (slave) */
+ char *masteruser; /* AUTH with this user and masterauth with master */
char *masterauth; /* AUTH with this password with master */
char *masterhost; /* Hostname of master */
int masterport; /* Port of master */