Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Xrootd HTTP] Allow redirect to local filesystem when using HTTP #1242

Merged
merged 3 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/XrdCms/XrdCmsRedirLocal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ int XrdCmsRedirLocal::Locate(XrdOucErrInfo &Resp, const char *path, int flags,
int rcode = 0;
if (nativeCmsFinder) {
string dialect = EnvInfo->secEnv()->addrInfo->Dialect();
const string httpDialects = "https";
// get regular target host
rcode = nativeCmsFinder->Locate(Resp, path, flags, EnvInfo);

// check if http redirect to local filesystem is allowed
if (httpDialects.find(dialect) != string::npos && !httpRedirect)
if (strncmp(dialect.c_str(), "http", 4) == 0 && !httpRedirect)
return rcode;

// define target host from locate result
Expand All @@ -132,12 +132,12 @@ int XrdCmsRedirLocal::Locate(XrdOucErrInfo &Resp, const char *path, int flags,
return rcode;

// as we can't rely on the flags from http clients, we do not perform the below
if (httpDialects.find(dialect) == string::npos)
if (strncmp(dialect.c_str(), "http", 4) != 0)
{
// get client url redirect capability
int urlRedirSupport = Resp.getUCap();
urlRedirSupport &= XrdOucEI::uUrlOK;
if (!urlRedirSupport && httpDialects.find(dialect) == string::npos)
if (!urlRedirSupport)
return rcode;

// get client localredirect capability
Expand All @@ -149,7 +149,7 @@ int XrdCmsRedirLocal::Locate(XrdOucErrInfo &Resp, const char *path, int flags,

// http gets SFS_O_STAT flag when opening to read, instead of SFS_O_RDONLY
// in case of http dialect and stat, we do not perform the checks below
if (!(httpDialects.find(dialect) != string::npos && flags == 0x20000000))
if (!(strncmp(dialect.c_str(), "http", 4) == 0 && flags == 0x20000000))
{
// only allow simple (but most prominent) operations to avoid complications
// RDONLY, WRONLY, RDWR, CREAT, TRUNC are allowed
Expand All @@ -168,10 +168,10 @@ int XrdCmsRedirLocal::Locate(XrdOucErrInfo &Resp, const char *path, int flags,
char *buff = new char[maxPathLength];
// prepend oss.localroot
const char *ppath = ("file://" + string(theSS->Lfn2Pfn(path, buff, maxPathLength, rc))).c_str();
if (httpDialects.find(dialect) != string::npos)
if (strncmp(dialect.c_str(), "http", 4) == 0)
{
// set info which will be sent to client
// eliminate the resource name so we it is not doubled in XrdHttpReq::Redir.
// eliminate the resource name so it is not doubled in XrdHttpReq::Redir.
Resp.setErrInfo(-1, string(ppath).substr(0, string(ppath).find(path)).c_str());
}
else{
Expand Down
2 changes: 1 addition & 1 deletion src/XrdHttp/XrdHttpReq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ bool XrdHttpReq::Redir(XrdXrootd::Bridge::Context &info, //!< the result context
// port < 0 signals switch to full URL
if (port < 0)
{
if (string(hname).find("file://") != string::npos)
if (strncmp(hname, "file://", 7) == 0)
{
TRACE(REQ, " XrdHttpReq::Redir Switching to file:// ");
redirdest = "Location: "; // "file://" already contained in hname
Expand Down