diff options
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-handshake.c')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-handshake.c | 69 |
1 files changed, 48 insertions, 21 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handshake.c b/xlators/mgmt/glusterd/src/glusterd-handshake.c index 04e5fae7b..dd41330b6 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handshake.c +++ b/xlators/mgmt/glusterd/src/glusterd-handshake.c @@ -40,11 +40,13 @@ extern struct rpc_clnt_program gd_peer_prog; extern struct rpc_clnt_program gd_mgmt_prog; +#define TRUSTED_PREFIX "trusted-" + typedef ssize_t (*gfs_serialize_t) (struct iovec outmsg, void *data); static size_t build_volfile_path (const char *volname, char *path, - size_t path_len) + size_t path_len, char *trusted_str) { struct stat stbuf = {0,}; int32_t ret = -1; @@ -61,7 +63,7 @@ build_volfile_path (const char *volname, char *path, if (strstr (volname, "gluster/")) { server = strchr (volname, '/') + 1; glusterd_get_nodesvc_volfile (server, priv->workdir, - path, path_len); + path, path_len); ret = 1; goto out; } else if (volname[0] != '/') { @@ -86,20 +88,24 @@ build_volfile_path (const char *volname, char *path, if (ret) goto out; } + ret = snprintf (path, path_len, "%s/vols/%s/%s.vol", priv->workdir, volinfo->volname, volname); if (ret == -1) goto out; ret = stat (path, &stbuf); + if ((ret == -1) && (errno == ENOENT)) { - ret = snprintf (path, path_len, "%s/vols/%s/%s-fuse.vol", - priv->workdir, volinfo->volname, volname); + snprintf (path, path_len, "%s/vols/%s/%s%s-fuse.vol", + priv->workdir, volinfo->volname, + (trusted_str ? trusted_str : ""), dup_volname); ret = stat (path, &stbuf); } + if ((ret == -1) && (errno == ENOENT)) { - ret = snprintf (path, path_len, "%s/vols/%s/%s-tcp.vol", - priv->workdir, volinfo->volname, volname); + snprintf (path, path_len, "%s/vols/%s/%s-tcp.vol", + priv->workdir, volinfo->volname, volname); } ret = 1; @@ -112,20 +118,23 @@ out: int server_getspec (rpcsvc_request_t *req) { - int32_t ret = -1; - int32_t op_errno = 0; - int32_t spec_fd = -1; - size_t file_len = 0; - char filename[ZR_PATH_MAX] = {0,}; - struct stat stbuf = {0,}; - char *volume = NULL; - int cookie = 0; - - gf_getspec_req args = {0,}; - gf_getspec_rsp rsp = {0,}; - - - if (!xdr_to_generic (req->msg[0], &args, (xdrproc_t)xdr_gf_getspec_req)) { + int32_t ret = -1; + int32_t op_errno = 0; + int32_t spec_fd = -1; + size_t file_len = 0; + char filename[ZR_PATH_MAX] = {0,}; + struct stat stbuf = {0,}; + char *volume = NULL; + char *tmp = NULL; + int cookie = 0; + rpc_transport_t *trans = NULL; + gf_getspec_req args = {0,}; + gf_getspec_rsp rsp = {0,}; + char addrstr[RPCSVC_PEER_STRLEN] = {0}; + + + if (!xdr_to_generic (req->msg[0], &args, + (xdrproc_t)xdr_gf_getspec_req)) { //failed to decode msg; req->rpc_err = GARBAGE_ARGS; goto fail; @@ -133,7 +142,25 @@ server_getspec (rpcsvc_request_t *req) volume = args.key; - ret = build_volfile_path (volume, filename, sizeof (filename)); + trans = req->trans; + ret = rpcsvc_transport_peername (trans, (char *)&addrstr, + sizeof (addrstr)); + if (ret) + goto fail; + + tmp = strrchr (addrstr, ':'); + *tmp = '\0'; + + /* we trust the local admin */ + if (!glusterd_is_local_addr (addrstr)) { + + ret = build_volfile_path (volume, filename, + sizeof (filename), + TRUSTED_PREFIX); + } else { + ret = build_volfile_path (volume, filename, + sizeof (filename), NULL); + } if (ret > 0) { /* to allocate the proper buffer to hold the file data */ |