Skip to content

Commit

Permalink
[TPC] Make sure to include source CGI in a delegated transfer.
Browse files Browse the repository at this point in the history
  • Loading branch information
abh3 committed Sep 12, 2019
1 parent 4e9cfb8 commit 8024b36
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 10 deletions.
28 changes: 24 additions & 4 deletions src/XrdOfs/XrdOfsTPC.cc
Expand Up @@ -582,6 +582,7 @@ int XrdOfsTPC::Validate(XrdOfsTPC **theTPC, XrdOfsTPC::Facts &Args)
const char *tpcLfn = Args.Env->Get(XrdOucTPC::tpcLfn);
const char *tpcSrc = Args.Env->Get(XrdOucTPC::tpcSrc);
const char *tpcCks = Args.Env->Get(XrdOucTPC::tpcCks);
const char *tpcSgi = Args.Env->Get(XrdOucTPC::tpcSgi);
const char *tpcStr = Args.Env->Get(XrdOucTPC::tpcStr);
const char *tpcSpr = Args.Env->Get(XrdOucTPC::tpcSpr);
const char *tpcTpr = Args.Env->Get(XrdOucTPC::tpcTpr);
Expand Down Expand Up @@ -635,20 +636,39 @@ int XrdOfsTPC::Validate(XrdOfsTPC **theTPC, XrdOfsTPC::Facts &Args)

// Generate the origin id
//
if (!genOrg(Args.Usr, Buff, sizeof(Buff))) return Death(Args, Buff, EINVAL);
if (!enVar && !genOrg(Args.Usr, Buff, sizeof(Buff)))
return Death(Args, Buff, EINVAL);

// Construct the source url (it may be very big)
//
n = snprintf(myURL, myURLen, "xroot://%s/%s?", tpcSrc, tpcLfn);
if (n >= int(sizeof(myURL))) return Death(Args, "url too long", EINVAL);
char *cgiP = myURL+n;
int cgiL = myURLen-n;
if (cgiL < 3) return Death(Args, "url too long", EINVAL);

// Set lfn location in the URL but only if we need to do a rename
//
if (doRN) {lfnLoc[1] = strlen(tpcLfn); lfnLoc[0] = n - lfnLoc[1];}
else lfnLoc[1] = lfnLoc[0] = 0;

theCGI = XrdOucTPC::cgiD2Src(Args.Key, Buff, myURL+n, myURLen-n);
if (*theCGI == '!') return Death(Args, theCGI+1, EINVAL);
// Copy user specified CGI into the source URL (omit tpc tokens)
//
if (tpcSgi)
{if ((int)strlen(tpcSgi) >= cgiL)
return Death(Args, "url too long", EINVAL);
n = XrdOucTPC::copyCGI(tpcSgi, cgiP, cgiL);
cgiP += n;
cgiL -= n;
}

// Insert tpc toksns unless this is a delegated tpc which needs no tokens
//
if (!enVar)
{if (cgiL < 3) return Death(Args, "url too long", EINVAL);
*cgiP++ = '&'; cgiL--; *cgiP = 0;
theCGI = XrdOucTPC::cgiD2Src(Args.Key, Buff, cgiP, cgiL);
if (*theCGI == '!') return Death(Args, theCGI+1, EINVAL);
}

// Create a pseudo tpc object that will contain the information we need to
// actually peform this copy.
Expand Down
8 changes: 2 additions & 6 deletions src/XrdOfs/XrdOfsTPCProg.cc
Expand Up @@ -305,13 +305,9 @@ int XrdOfsTPCProg::Xeq()
eVec[i++] = sprBuff;
}

// Determine if credentials are being passed, If so, we don't need any cgi but
// we must set an envar to point to the file holding the credentials.
// Determine if credentials are being passed, If so, pass where it is.
//
if (cFile.Path)
{eVec[i++] = cFile.pEnv;
if (Quest) *Quest = 0;
}
if (cFile.Path) eVec[i++] = cFile.pEnv;
eVec[i] = 0;

// Start the job.
Expand Down
49 changes: 49 additions & 0 deletions src/XrdOuc/XrdOucTPC.cc
Expand Up @@ -28,6 +28,7 @@
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/

//#include <iostream>
#include <stdio.h>
#include <string.h>
#include <strings.h>
Expand All @@ -46,6 +47,7 @@ const char *XrdOucTPC::tpcKey = "tpc.key";
const char *XrdOucTPC::tpcLfn = "tpc.lfn";
const char *XrdOucTPC::tpcOrg = "tpc.org";
const char *XrdOucTPC::tpcPsh = "tpc.psh";
const char *XrdOucTPC::tpcSgi = "tpc.scgi";
const char *XrdOucTPC::tpcSrc = "tpc.src";
const char *XrdOucTPC::tpcSpr = "tpc.spr";
const char *XrdOucTPC::tpcStr = "tpc.str";
Expand Down Expand Up @@ -215,3 +217,50 @@ bool XrdOucTPC::cgiHost(tpcInfo &Info, const char *hSpec)
if ((hName = hAddr.Name())) Info.hName = strdup(hName);
return hName != 0;
}

/******************************************************************************/
/* c o p y C G I */
/******************************************************************************/

int XrdOucTPC::copyCGI(const char *cgi, char *Buff, int Blen)
{
const char *bgi;
char *bP = Buff;
int xlen;
bool eqs;

// Skip over initial ampersands
//
while(*cgi == '&' && *cgi) cgi++;

// Check if there is anything here
//
if (!cgi || *cgi == 0) {*Buff = 0; return 0;}
Blen--;

// Copy all keys except system oriented ones.
//
//std::cerr <<"TPC cgi IN: " <<cgi <<'\n' <<std::flush;
do{bgi = cgi; eqs = false;
while(*cgi != '\t' && *cgi)
{if (*cgi == '=') eqs = true;
cgi++;
}
if (*bgi && eqs && strncmp(bgi, "tpc.", 4) && strncmp(bgi, "xrd.", 4)
&& strncmp(bgi, "xrdcl.", 4))
{xlen = cgi - bgi;
if (bP != Buff && Blen > 0) {*bP++ = '&'; Blen--;}
if (xlen > Blen) xlen = Blen;
strncpy(bP, bgi, xlen);
bP += xlen;
Blen -= xlen;
}
while(*cgi && *cgi == '\t') cgi++;
} while(*cgi && Blen > 2);

// Compute length and return
//
*bP = 0;
// std::cerr <<"TPC cgi OT: " <<Buff <<" len=" <<(bP-Buff) <<'\n' <<std::flush;
return bP - Buff;
}
3 changes: 3 additions & 0 deletions src/XrdOuc/XrdOucTPC.hh
Expand Up @@ -50,13 +50,16 @@ static
const char *cgiD2Src(const char *cKey, const char *cOrg,
char *Buff, int Blen);

static int copyCGI(const char *cgi, char *Buff, int Blen);

static const char *tpcCks;
static const char *tpcDlg;
static const char *tpcDst;
static const char *tpcKey;
static const char *tpcLfn;
static const char *tpcOrg;
static const char *tpcPsh;
static const char *tpcSgi;
static const char *tpcSpr;
static const char *tpcSrc;
static const char *tpcStr;
Expand Down

0 comments on commit 8024b36

Please sign in to comment.