51#include "XrdVersion.hh"
81#define ENOATTR ENODATA
88#define isNOSTAGE(_x_) !(XRDEXP_STAGE & XrdPssSys::XPList.Find(_x_))
90#define isREADONLY(_x_) (XRDEXP_NOTRW & XrdPssSys::XPList.Find(_x_))
192 eDest.Say(
"Copr. 2019, Stanford University, Pss Version " XrdVSTRING);
196 tmp = ((NoGo = Configure(cFN,
envP)) ?
"failed." :
"completed.");
197 eDest.Say(
"------ Proxy storage system initialization ", tmp);
243 if (idMapper && client)
244 {
const char *fmt = (client->
ueid & 0xf0000000 ?
"%x" :
"U%x");
246 snprintf(uName,
sizeof(uName), fmt, client->
ueid);
248 idMapper->Register(uName, client,
deferID);
292 if (idMapper && client)
293 {
const char *fmt = (client->
ueid & 0xf0000000 ?
"%x" :
"U%x");
295 snprintf(uName,
sizeof(uName), fmt, client->
ueid);
296 DEBUG(client->
tident,
"Unregistering as ID "<<uName);
297 idMapper->Register(uName, 0);
339 std::string thePath(args, alen);
363 {
int n = theResp.size() + 1;
365 strcpy(*resp, theResp.c_str());
389 if (theN2N)
return -(theN2N->lfn2pfn(oldp, newp, blen));
390 if ((
int)strlen(oldp) >= blen)
return -ENAMETOOLONG;
397 if (!theN2N) {rc = 0;
return oldp;}
398 if ((rc = -(theN2N->lfn2pfn(oldp, newp, blen))))
return 0;
461 const char *Cgi =
"";
532 DEBUG(uInfoOld.
Tident(),
"old url="<<oldNameObf <<
" new url=" <<newNameObf);
562 const char *Cgi =
"";
672 const char *Cgi =
"";
731 if (*dir_path !=
'/')
return -ENOTSUP;
785 {dirent *entP, myEnt;
791 if (!entP) *buff = 0;
792 else strlcpy(buff, myEnt.d_name, blen);
831 if ((theDir = myDir))
854 if (lastEtrc <= 0 || lastEtext.empty())
return false;
882 const char *Cgi =
"";
885 bool tpcMode = (Oflag & O_NOFOLLOW) != 0;
886 bool rwMode = (Oflag & O_ACCMODE) != O_RDONLY;
916 char *envcgi = (
char *)Env.
Env(elen);
918 if (envcgi && strstr(envcgi,
"only-if-cached"))
922 myData.
Arg1 =
"cached";
925 const char *myArgs[1];
927 myData.ArgP = myArgs;
943 {Oflag &= ~O_NOFOLLOW;
946 {tpcPath = strdup(path);
948 {
const char *rPath = Env.
Get(
"tpc.reproxy");
949 if (!rPath || *rPath !=
'/')
return -
ENOATTR;
950 if (!(rPath = rindex(rPath,
'/')) || *(rPath+1) == 0)
952 rpInfo =
new tprInfo(rPath+1);
995 {Env.
Put(
"FileURL", Info.cacheURL);
996 return -EDESTADDRREQ;
1027 if (retsz) *retsz = 0;
1056 if (lastEtrc <= 0 || lastEtext.empty())
return false;
1087 std::vector<uint32_t> vecCS;
1109 if (vecCS.size() && csvec)
1110 memcpy(csvec, vecCS.data(), vecCS.size()*
sizeof(uint32_t));
1143 std::vector<uint32_t> vecCS;
1157 {lastEtext =
"pgWrite checksum verification failed.";
1167 if (csvec) memcpy(csvec, vecCS.data(), vecCS.size()*
sizeof(uint32_t));
1172 memcpy(vecCS.data(), csvec, n*
sizeof(uint32_t));
1268 return (ssize_t)retval;;
1289 return Read(buff, offset, blen);
1318 return (ssize_t)retval;
1346 std::string theArgs(args, alen);
1347 std::string theResp;
1361 {
int n = theResp.size() + 1;
1362 *resp =
new char[n];
1363 strcpy(*resp, theResp.c_str());
1401 return XrdProxySS.Stat(tpcPath, buff, 0, &fstatEnv);
1408 if (rpInfo->dstURL == 0
1409 || !fstatat(
rpFD, rpInfo->tprPath, &
Stat, AT_SYMLINK_NOFOLLOW))
1410 {
char lnkbuff[2048];
int lnklen;
1411 lnklen = readlinkat(
rpFD, rpInfo->tprPath, lnkbuff,
sizeof(lnkbuff)-1);
1414 if (lnklen < 0) {
if (errno != ENOENT) rc = -errno;}
1417 {unlinkat(
rpFD, rpInfo->tprPath, 0);
1421 unlinkat(
rpFD, rpInfo->tprPath, 0);
1422 lnkbuff[lnklen] = 0;
1423 if (rpInfo->dstURL) free(rpInfo->dstURL);
1424 rpInfo->dstURL = strdup(lnkbuff);
1426 DEBUG(
tident,rpInfo->tprPath<<
" maps "<<tpcPath<<
" -> "<<lnkbuff);
1435 {
if (!(rpInfo->fSize = buff->st_size)) rpInfo->fSize = 1;
1438 free(rpInfo->dstURL);
1445 {memset(buff, 0,
sizeof(
struct stat));
1446 buff->st_size = rpInfo->fSize;
1455 if (
XrdProxySS.Stat(tpcPath, buff, 0, &fstatEnv))
1456 memset(buff, 0,
sizeof(
struct stat));
1538 Slash = index(path,
'/');
1539 if (!Slash || (n = (Slash - path)) == 0) {retc = -EINVAL;
return 0;}
1540 if (n >= hBlen) {retc = -ENAMETOOLONG;
return 0;}
1541 strncpy(hBuff, path, n); hBuff[n] = 0;
1546 {retc = -EACCES;
return 0;}
1558{
const char *theID = uInfo.
getID();
1559 const char *pname, *path, *thePath;
1565 thePath = path = uInfo.
thePath();
1569 if (*path ==
'/') path++;
1571 else {
if (!
hdrLen)
return -ENOTSUP;
1572 n = snprintf(pbuff, pblen,
hdrData, theID, thePath);
1573 if (n >= pblen || !uInfo.
addCGI(pbuff, pbuff+n, pblen-n))
1574 return -ENAMETOOLONG;
1580 if (*thePath !=
'/')
1583 if (*path ==
'/') theID =
"";
1586 path+(*path ==
'/' ? 1:0)))
return 0;
1587 n = snprintf(pbuff, pblen,
"%s%s%s", pname, theID, path);
1588 if (n >= pblen || !uInfo.
addCGI(pbuff, pbuff+n, pblen-n))
1589 return -ENAMETOOLONG;
1597 if (!(n =
P2DST(retc, hBuff,
sizeof(hBuff),
PolPath, path)))
return 0;
1604 if (index(hBuff,
'@')) theID=
"";
1605 n = snprintf(pbuff,pblen,
"%s%s%s/%s",pname,theID,hBuff,path);
1609 if (n >= pblen || !uInfo.
addCGI(pbuff, pbuff+n, pblen-n))
1610 return -ENAMETOOLONG;
1630 const char *path = uInfo.
thePath();
1632 char Apath[MAXPATHLEN+1];
1642 {
if ((retc =
XrdProxySS.theN2N->lfn2pfn(path, Apath,
sizeof(Apath))))
1643 {
if (retc > 0)
return -retc;}
1651 else pfxLen = snprintf(pbuff, pblen,
hdrData, uInfo.
getID(), path);
1652 if (pfxLen >= pblen)
return -ENAMETOOLONG;
1657 {
if (!uInfo.
addCGI(pbuff, pbuff+pfxLen, pblen-pfxLen))
1658 return -ENAMETOOLONG;
XrdAccAuthorize * Authorize
static XrdSysLogger Logger
static XrdSysError eDest(0,"crypto_")
std::string obfuscateAuth(const std::string &input)
XrdOss * XrdOssGetStorageSystem2(XrdOss *native_oss, XrdSysLogger *Logger, const char *cFN, const char *parms, XrdOucEnv *envp)
XrdVERSIONINFO(XrdOssGetStorageSystem2, XrdPss)
static const uint64_t doCalc
pgw: Calculate checksums
static const uint64_t Verify
all: Verify checksums
static const int Fctl_QFinfo
const XrdSecEntity * secEnv() const
char * Get(const char *varname)
void Put(const char *varname, const char *value)
static void csCalc(const char *data, off_t offs, size_t count, uint32_t *csval)
static bool csVer(dataInfo &dInfo, off_t &bado, int &badc)
static int csNum(off_t offs, int count)
Compute the required size of a checksum vector based on offset & length.
static bool OpenFC(const char *path, int oflag, mode_t mode, XrdPosixInfo &Info)
static int Stats(const char *theID, char *buff, int blen)
static void EnvInfo(XrdOucEnv &theEnv)
static ssize_t Pread(int fildes, void *buf, size_t nbyte, off_t offset)
Pread() conforms to POSIX.1-2001 pread().
static int Closedir(DIR *dirp)
Closedir() conforms to POSIX.1-2001 closedir().
static int Stat(const char *path, struct stat *buf)
Stat() conforms to POSIX.1-2001 stat().
static int Mkdir(const char *path, mode_t mode)
Mkdir() conforms to POSIX.1-2001 mkdir().
static int Unlink(const char *path)
Unlink() conforms to POSIX.1-2001 unlink().
static int Rmdir(const char *path)
Rmdir() conforms to POSIX.1-2001 rmdir().
static void VRead(int fildes, const XrdOucIOVec *readV, int n, XrdPosixCallBackIO *cbp)
static int Rename(const char *oldpath, const char *newpath)
Rename() conforms to POSIX.1-2001 rename().
static int Close(int fildes)
Close() conforms to POSIX.1-2001 close().
static int Readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
static int QueryError(std::string &emsg, int fd=-1, bool reset=true)
static int Ftruncate(int fildes, off_t offset)
Ftruncate() conforms to POSIX.1-2001 ftruncate().
static DIR * Opendir(const char *path)
Opendir() conforms to POSIX.1-2001 opendir().
static int Fsync(int fildes)
Fsync() conforms to POSIX.1-2001 fsync().
static int StatRet(DIR *dirp, struct stat *buf)
static int Fstat(int fildes, struct stat *buf)
Fstat() conforms to POSIX.1-2001 fstat().
static int Open(const char *path, int oflag, mode_t mode=0, XrdPosixCallBack *cbP=0)
static ssize_t Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
Pwrite() conforms to POSIX.1-2001 pwrite().
static int Truncate(const char *path, off_t offset)
Telldir() conforms to POSIX.1-2001 telldir().
int Readdir(char *buff, int blen) override
int Close(long long *retsz=0) override
int Opendir(const char *, XrdOucEnv &) override
int StatRet(struct stat *buf) override
bool getErrMsg(std::string &eText) override
ssize_t Read(off_t, size_t) override
virtual int Open(const char *, int, mode_t, XrdOucEnv &) override
ssize_t pgWrite(void *buffer, off_t offset, size_t wrlen, uint32_t *csvec, uint64_t opts) override
ssize_t Write(const void *, off_t, size_t) override
virtual int Close(long long *retsz=0) override
int Fstat(struct stat *) override
ssize_t ReadV(XrdOucIOVec *readV, int n) override
int Ftruncate(unsigned long long) override
bool getErrMsg(std::string &eText) override
ssize_t pgRead(void *buffer, off_t offset, size_t rdlen, uint32_t *csvec, uint64_t opts) override
ssize_t ReadRaw(void *, off_t, size_t) override
int Fctl(int cmd, int alen, const char *args, char **resp=0) override
int Mkdir(const char *, mode_t mode, int mkpath=0, XrdOucEnv *eP=0) override
static int P2OUT(char *pbuff, int pblen, XrdPssUrlInfo &uInfo)
int Unlink(const char *, int Opts=0, XrdOucEnv *eP=0) override
virtual void Connect(XrdOucEnv &) override
int Truncate(const char *, unsigned long long, XrdOucEnv *eP=0) override
int Stats(char *bp, int bl) override
static const char * hdrData
int Stat(const char *, struct stat *, int opts=0, XrdOucEnv *eP=0) override
int Init(XrdSysLogger *, const char *) override
static int P2DST(int &retc, char *hBuff, int hBlen, PolAct pType, const char *path)
int Chmod(const char *, mode_t mode, XrdOucEnv *eP=0) override
void EnvInfo(XrdOucEnv *envP) override
static XrdNetSecurity * Police[PolNum]
static XrdOucPListAnchor XPList
static int P2URL(char *pbuff, int pblen, XrdPssUrlInfo &uInfo, bool doN2N=true)
int Remdir(const char *, int Opts=0, XrdOucEnv *eP=0) override
int Lfn2Pfn(const char *Path, char *buff, int blen) override
int FSctl(int cmd, int alen, const char *args, char **resp=0) override
virtual int Create(const char *, const char *, mode_t, XrdOucEnv &, int opts=0) override
virtual void Disc(XrdOucEnv &) override
int Rename(const char *, const char *, XrdOucEnv *eP1=0, XrdOucEnv *eP2=0) override
bool getErrMsg(std::string &eText) override
void setID(const char *tid=0)
bool addCGI(const char *prot, char *buff, int blen)
static const char * valProt(const char *pname, int &plen, int adj=0)
const char * tident
Trace identifier always preset.
unsigned int ueid
Unique ID of entity instance.
XrdOfsFSctl_PI * cacheFSctl
XrdSysTrace SysTrace("Pss", 0)
XrdSysError eDest(0, "pss_")
XrdOucECMsg ecMsg("[pss]")
static const char * osslclCGI
static XrdPssSys XrdProxySS
static const char * ofslclCGI
< SFS_FSCTL_PLUGIN/PLUGIO/PLUGXC/PLUGFS parms
const char * Arg1
PLUGFS, PLUGIN, PLUGIO, PLUGXC.
int Arg2Len
Length or -count of args in extension.