Skip to content

Commit 71306a4

Browse files
committed
MGM: Transform input path to its canonical form also when there is no opaque info
1 parent 77fc48c commit 71306a4

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

mgm/http/HttpServer.cc

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,13 @@ HttpServer::Handler(void* cls,
130130

131131
// Authenticate the client
132132
std::unique_ptr<eos::common::VirtualIdentity> vid = Authenticate(headers);
133+
133134
if (!vid) {
134135
eos_static_info("msg=\"could not build VirtualIdentity based on headers\" "
135136
"method=%s", method);
136137
return MHD_NO;
137138
}
139+
138140
eos_static_info("request=%s client-real-ip=%s client-real-host=%s vid.uid=%s vid.gid=%s vid.host=%s vid.tident=%s\n",
139141
method, headers["client-real-ip"].c_str(), headers["client-real-host"].c_str(),
140142
vid->uid_string.c_str(), vid->gid_string.c_str(), vid->host.c_str(),
@@ -399,18 +401,18 @@ HttpServer::XrdHttpHandler(std::string& method,
399401
headers["client-real-ip"] = "NOIPLOOKUP";
400402
headers["client-real-host"] = client.host;
401403
headers["x-real-ip"] = client.host;
402-
403404
auto it = headers.find("xrd-http-fullresource");
404405

405406
if (it != headers.end()) {
406-
extractOpaqueWithoutAuthz(it->second,query);
407+
extractOpaqueWithoutAuthz(it->second, query);
407408
}
408409

409410
if (client.moninfo && strlen(client.moninfo)) {
410411
headers["ssl_client_s_dn"] = client.moninfo;
411412
}
412413

413414
vid = Authenticate(headers);
415+
414416
if (!vid) {
415417
eos_static_info("msg=\"could not build VirtualIdentity based on headers\" "
416418
"method=%s", method.c_str());
@@ -446,8 +448,8 @@ HttpServer::XrdHttpHandler(std::string& method,
446448
// Retrieve the protocol handler stored in *ptr
447449
std::unique_ptr<eos::common::HttpRequest> request {
448450
new eos::common::HttpRequest(headers, method, uri,
449-
(query.c_str() ? query : ""),
450-
body, &bodySize, cookies)};
451+
(query.c_str() ? query : ""),
452+
body, &bodySize, cookies)};
451453
eos_static_debug("\n\n%s\n%s\n", request->ToString().c_str(),
452454
request->GetBody().c_str());
453455
handler->HandleRequest(request.get());
@@ -478,8 +480,7 @@ HttpServer::BuildPathAndEnvOpaque
478480
}
479481

480482
std::string opaque;
481-
extractPathAndOpaque(it->second,path,opaque);
482-
483+
extractPathAndOpaque(it->second, path, opaque);
483484
// Check if there is an explicit authorization header
484485
std::string http_authz;
485486
it = normalized_headers.find("authorization");
@@ -520,35 +521,39 @@ HttpServer::BuildPathAndEnvOpaque
520521
}
521522

522523
// Append eos.app tag
523-
eos::common::AddEosApp(opaque,"http");
524-
524+
eos::common::AddEosApp(opaque, "http");
525525
env_opaque = std::make_unique<XrdOucEnv>(opaque.c_str(), opaque.length());
526526
return true;
527527
}
528528

529-
void HttpServer::extractPathAndOpaque(const std::string & fullpath, std::string & path, std::string & opaque)
529+
void HttpServer::extractPathAndOpaque(const std::string& fullpath,
530+
std::string& path, std::string& opaque)
530531
{
531532
path = fullpath;
532-
533533
size_t pos = fullpath.find('?');
534+
534535
if ((pos != std::string::npos) && (pos != fullpath.length())) {
535536
opaque = path.substr(pos + 1);
536537
path = path.substr(0, pos);
537-
eos::common::Path canonical_path(path);
538-
path = canonical_path.GetFullPath().c_str();
539538
}
540539

540+
eos::common::Path canonical_path(path);
541+
path = canonical_path.GetFullPath().c_str();
541542
}
542543

543-
void HttpServer::extractOpaqueWithoutAuthz(const std::string & fullpath, std::string & opaque) {
544+
void HttpServer::extractOpaqueWithoutAuthz(const std::string& fullpath,
545+
std::string& opaque)
546+
{
544547
std::string path;
545548
opaque.clear();
546-
extractPathAndOpaque(fullpath,path,opaque);
547-
if(opaque.size()) {
549+
extractPathAndOpaque(fullpath, path, opaque);
550+
551+
if (opaque.size()) {
548552
auto env_opaque = std::make_unique<XrdOucEnv>(opaque.c_str(), opaque.length());
549553
int envTidyLen;
550-
char * envTidy = env_opaque->EnvTidy(envTidyLen);
551-
if(envTidyLen > 1) {
554+
char* envTidy = env_opaque->EnvTidy(envTidyLen);
555+
556+
if (envTidyLen > 1) {
552557
// Seen during unit tests, EnvTidy puts an ampersand at the beginning of the resulting string
553558
opaque.assign(envTidy + 1, envTidyLen - 1);
554559
}

0 commit comments

Comments
 (0)