32#include "XrdVersion.hh"
181 XrdXrootdProtocol::ProtStack(
"ProtStack",
182 "xroot protocol anchor");
201 const char *txt =
"completed.";
205 pi->
eDest->
Say(
"Copr. 2012 Stanford University, xroot protocol "
207 pi->
eDest->
Say(
"++++++ xroot protocol initialization started.");
213 else txt =
"failed.";
214 pi->
eDest->
Say(
"------ xroot protocol initialization ", txt);
238 if (pi->
Port < 0)
return 1094;
272 static unsigned int Sid = 1;
295static struct hs_response
310 {
if (dlen <= 0) lp->
setEtext(
"handshake not received");
328 rc = lp->
Send((
char *)&hsresp,
sizeof(hsresp));
339 if (lp->
Recv(hsbuff, hsSZ) != hsSZ)
364#define TRACELINK Link
375 else if ((rc = (*this.*
Resume)()) != 0)
return rc;
376 else {
Resume = 0;
return 0;}
385 reqID = ntohs(
Request.header.requestid);
393 Request.header.requestid = reqID;
397 <<
" dlen=" <<
Request.header.dlen);
404 return Link->setEtext(
"protocol data length error");
442 {
const char *eText =
"Request not signed";
446 <<
" verification failed; " <<eText);
447 SI->Bump(
SI->badSCnt);
448 return Link->setEtext(eText);
450 SI->Bump(
SI->aokSCnt);
456 <<
" unneeded signature discarded.");
458 {
eDest.Emsg(
"Protocol",
"Client is needlessly signing requests.");
461 SI->Bump(
SI->ignSCnt);
469 switch(
Request.header.requestid)
474 "Invalid request; user not logged in");
475 return Link->setEtext(
"request without login");
484 switch(
Request.header.requestid)
501 if (!
Request.header.dlen)
return do_Truncate();
511 switch(
Request.header.requestid)
523 "Invalid request; user not authenticated");
536 switch(
Request.header.requestid)
553 if (
Link->AddrInfo()->isPrivate())
rdType = 1;
561 {doRdr =
true;
break;}
573 switch(
Request.header.requestid)
581 SI->Bump(
SI->miscCnt);
585 switch(
Request.header.requestid)
591 case kXR_mv:
return do_Mv();
594 case kXR_rm:
return do_Rm();
630 return Link->setEtext(
"signature data length error");
656#define TRACELINK Link
673 if (reason && strcmp(reason,
"hangup"))
674 {snprintf(buff,
sizeof(buff),
"%s (%s)", ctbuff, reason);
676 }
else sfxp = ctbuff;
736 if (
Response.isOurs()) ProtStack.Push(&ProtLink);
743int XrdXrootdProtocol::StatGen(
struct stat &buf,
char *xxBuff,
int xxLen,
746 const mode_t isReadable = (S_IRUSR | S_IRGRP | S_IROTH);
747 const mode_t isWritable = (S_IWUSR | S_IWGRP | S_IWOTH);
748 const mode_t isExecable = (S_IXUSR | S_IXGRP | S_IXOTH);
751 union {
long long uuid;
struct {
int hi;
int lo;} id;} Dev;
762 Dev.id.lo = buf.st_ino;
763 Dev.id.hi = buf.st_dev;
767 if (buf.st_mode & isReadable
768 &&((buf.st_mode & S_IRUSR && theuid == buf.st_uid)
769 || (buf.st_mode & S_IRGRP && thegid == buf.st_gid)
774 if (buf.st_mode & isWritable
775 &&((buf.st_mode & S_IWUSR && theuid == buf.st_uid)
776 || (buf.st_mode & S_IWGRP && thegid == buf.st_gid)
781 if (buf.st_mode & isExecable
782 &&((buf.st_mode & S_IXUSR && theuid == buf.st_uid)
783 || (buf.st_mode & S_IXGRP && thegid == buf.st_gid)
784 || buf.st_mode & S_IXOTH)) flags |=
kXR_xset;
789 if (S_ISDIR(buf.st_mode)) flags |=
kXR_isDir;
790 else if (!S_ISREG(buf.st_mode)) flags |=
kXR_other;
799 fsz =
static_cast<long long>(buf.st_size);
803 m = snprintf(xxBuff, xxLen,
"%lld %lld %d %lld",
804 Dev.uuid, fsz, flags, (
long long) buf.st_mtime);
810 char *origP = xxBuff;
811 char *nullP = xxBuff + m++;
812 xxBuff += m; xxLen -= m;
813 n = snprintf(xxBuff, xxLen,
"%lld %lld %04o ",
814 (
long long) buf.st_ctime, (
long long) buf.st_atime,
816 if (n >= xxLen)
return m;
817 xxBuff += n; xxLen -= n;
821 if (buf.st_uid ==
myUID)
822 {
if (
myUNLen >= xxLen)
return m;
834 if (buf.st_gid ==
myGID)
835 {
if (
myGNLen >= xxLen)
return m;
846 return xxBuff - origP;
858 {
SI->statsMutex.Lock();
876 SI->statsMutex.UnLock();
881 return SI->Stats(buff, blen, do_sync);
896 {
if (bsz) *bsz = xbP->
bsize;
913 if (minasz >=
argp->bsize || datasz >=
argp->bsize/2)
return Swap(buff);
955 else if (buff !=
argp->buff) errno = EINVAL;
961 if (
argp)
return oldBP;
1006int XrdXrootdProtocol::CheckSum(
XrdOucStream *Stream,
char **argv,
int argc)
1013 {
Stream->PutLine(
"Internal error; not enough checksum args!");
1020 XrdOucErrInfo myInfo(argv[3], &myEnv);
1024 if (argc > 4 && *argv[4]) myEnv.
Put(
"request.name", argv[4]);
1032 Stream->PutLine(myInfo.getErrText(ecode));
1033 if (rc) {
SI->errorCnt++;
1034 if (ecode) rc = ecode;
1043void XrdXrootdProtocol::Cleanup()
1059 {
Stream[i]->Stream[0] = 0;
1061 Stream[i]->Recycle(0, 0, 0);
1099 SI->statsMutex.Lock();
1101 SI->statsMutex.UnLock();
1134 {
if (rlen != -ENOMSG)
return Link->setEtext(
"link read error");
1139 TRACEP(REQ, dtype <<
" timeout; read " <<rlen <<
" of " <<blen <<
" bytes");
1148 const char *dtype,
char *buff,
int blen)
1155 gdCtl.BuffLen = blen;
1156 gdCtl.Buffer = buff;
1157 gdCtl.CallBack= cbP;
1158 gdCtl.ioDType = dtype;
1165 {
gdCtl.useCB =
true;
1168 return getDataCont();
1172namespace {
int consumed = 0;}
1175 const char *dtype,
struct iovec *
iov,
int iovn)
1182 gdCtl.iovNum = iovn;
1184 gdCtl.CallBack= cbP;
1185 gdCtl.ioDType = dtype;
1192 {
gdCtl.useCB =
true;
1196 return getDataIovCont();
1203int XrdXrootdProtocol::getDataCont()
1210 return -EINPROGRESS;
1216 gdCtl.Buffer += rlen;
1217 gdCtl.BuffLen -= rlen;
1227 rlen =
gdCtl.CallBack->gdDone();
1228 if (rlen < 0)
break;
1241 if (
gdCtl.BuffLen < 0)
1242 {rlen =
Link->setEtext(
"link excessive read length error");
1250 Resume = &XrdXrootdProtocol::getDataCont;
1258 TRACEP(REQ,
gdCtl.ioDType <<
" timeout; read " <<rlen <<
" bytes "
1259 <<
gdCtl.BuffLen <<
" remaining");
1266 if (rlen != -ENOMSG)
return Link->setEtext(
"link read error");
1272 gdCtl.CallBack->gdFail();
1282int XrdXrootdProtocol::getDataIovCont()
1289 return -EINPROGRESS;
1294do{
struct iovec *ioV =
gdCtl.iovVec;
1295 int i, rlen, iovN =
gdCtl.iovNum, iNow =
gdCtl.iovNow;
1302 {
if (rlen != -ENOMSG)
Link->setEtext(
"link read error");
1304 {ioV[iNow].iov_base = ((
char *)ioV[iNow].iov_base) -
gdCtl.iovAdj;
1305 ioV[iNow].iov_len +=
gdCtl.iovAdj;
1314 for (i = iNow; i < iovN && (int)ioV[i].iov_len <= rlen; i++)
1315 rlen -= ioV[i].iov_len;
1319 if (i != iNow &&
gdCtl.iovAdj)
1320 {ioV[iNow].iov_base = ((
char *)ioV[iNow].iov_base) -
gdCtl.iovAdj;
1321 ioV[iNow].iov_len +=
gdCtl.iovAdj;
1335 rc =
gdCtl.CallBack->gdDone();
1345 rc =
Link->setEtext(
"link iov read length error");
1355 gdCtl.iovAdj += rlen;
1356 ioV[i].iov_base = ((
char *)ioV[i].iov_base) + rlen;
1357 ioV[i].iov_len -= rlen;
1363 Resume = &XrdXrootdProtocol::getDataIovCont;
1371 TRACEP(REQ,
gdCtl.ioDType<<
" read timeout; "<<iovN-i<<
" of "
1372 <<
gdCtl.iovNum <<
" iov elements left");
1381 gdCtl.CallBack->gdFail();
1398 gdCtl.DumpLen = dlen;
1399 gdCtl.ioDType = dtype;
1405 return (inCB ? 1 : getDumpCont());
1412int XrdXrootdProtocol::getDumpCont()
1414 int rlen = 0, rwant;
1421 while(
gdCtl.DumpLen > 0)
1422 {
if (
gdCtl.DumpLen <= (
int)
sizeof(buff)) rwant =
gdCtl.DumpLen;
1423 else rwant =
sizeof(buff);
1425 gdCtl.DumpLen -= rlen;
1430 if (rlen < 0 ||
gdCtl.DumpLen < 0)
1431 {
if (
gdCtl.DumpLen < 0)
Link->setEtext(
"link read overrun error");
1432 else if (rlen != -ENOMSG)
Link->setEtext(
"link read error");
1439 if (
gdCtl.DumpLen == 0)
1446 Resume = &XrdXrootdProtocol::getDumpCont;
1450 <<
" bytes left to discard");
1458void XrdXrootdProtocol::Reset()
1472 memset(&
IO, 0,
sizeof(
IO));
#define kXR_PROTOCOLVSTRING
#define kXR_PROTOCOLVERSION
XrdProtocol * XrdgetProtocol(const char *pname, char *parms, XrdProtocol_Config *pi)
int XrdgetProtocolPort(const char *pname, char *parms, XrdProtocol_Config *pi)
#define NEED2SECURE(protP)
This class implements the XRootD protocol security protection.
static const dev_t XRDSFS_HASBKUP
static const dev_t XRDSFS_RDVMASK
static const dev_t XRDSFS_OFFLINE
class XrdBuffer * XrdSfsXioHandle
XrdSys::RAtomic< int > RAtomic_int
const kXR_char XROOTD_MON_BOUNDP
const kXR_char XROOTD_MON_FORCED
XrdVERSIONINFO(XrdgetProtocol, xrootd)
XrdProtocol * XrdgetProtocol(const char *pname, char *parms, XrdProtocol_Config *pi)
XrdSysTrace XrdXrootdTrace("Xrootd")
int XrdgetProtocolPort(const char *pname, char *parms, XrdProtocol_Config *pi)
static const char * reqName(kXR_unt16 reqCode)
int setEtext(const char *text)
int Peek(char *buff, int blen, int timeout=-1)
int Recv(char *buff, int blen)
XrdNetAddrInfo * AddrInfo()
char * ID
Pointer to the client's link identity.
int Send(const char *buff, int blen)
const char * Host() const
static bool InDomain(XrdNetAddrInfo *epaddr)
void Put(const char *varname, const char *value)
static int GidName(gid_t gID, char *gName, int gNsz, time_t keepT=0)
static int UidName(uid_t uID, char *uName, int uNsz, time_t keepT=0)
XrdProtocol(const char *jname)
XrdNetAddrInfo * addrInfo
Entity's connection details.
char prot[XrdSecPROTOIDSIZE]
Auth protocol used (e.g. krb5)
char * host
Entity's host name dnr dependent.
XrdSfsXio(XrdSfsXioImpl &xioimpl)
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)
static char * s2hms(int sec, char *buff, int blen)
static void ClearErrorQueue()
Clear the SSL error queue for the calling thread.
static void Disc(unsigned int usrID)
static XrdXrootdStats * SI
static const char * myInst
XrdXrootdProtocol * VerifyStream(int &rc, int pID, bool lok=true)
static XrdSfsFileSystem * digFS
XrdNetPMark::Handle * pmHandle
static XrdNetPMark * PMark
XrdXrootdProtocol * Stream[maxStreams]
static short as_okstutter
static XrdXrootdXPath RPList
static XrdNetSocket * AdminSock
XrdProtocol * Match(XrdLink *lp) override
struct XrdXrootdProtocol::GetDataCtl gdCtl
static void Reclaim(XrdSfsXioHandle h)
XrdXrootdFileTable * FTab
static XrdXrootdJob * JobCKS
static XrdSysError & eDest
static unsigned int getSID()
XrdSecProtocol * AuthProt
int getData(gdCallBack *gdcbP, const char *dtype, char *buff, int blen)
XrdSfsXioHandle Claim(const char *buff, int datasz, int minasz=0) override
XrdXrootdMonitor::User Monitor
static const char * myCName
XrdSfsXioHandle Swap(const char *buff, XrdSfsXioHandle h=0) override
static XrdXrootdFileLock * Locker
int(XrdXrootdProtocol::* Resume)()
static XrdTlsContext * tlsCtx
static XrdXrootdXPath XPList
static XrdScheduler * Sched
static struct XrdXrootdProtocol::RC_Table RouteClient
int Process(XrdLink *lp) override
void Recycle(XrdLink *lp, int consec, const char *reason) override
static char * Buffer(XrdSfsXioHandle h, int *bsz)
static const char * myUName
XrdXrootdResponse Response
int(XrdXrootdProtocol::* ResumePio)()
static const char * TraceID
static int Configure(char *parms, XrdProtocol_Config *pi)
int Stats(char *buff, int blen, int do_sync=0) override
static const int maxStreams
int getDump(const char *dtype, int dlen)
static XrdOucTList * JobCKTLST
static XrdXrootdXPath RQList
static struct XrdXrootdProtocol::RD_Table Route[RD_Num]
static XrdSecProtector * DHS
static XrdBuffManager * BPool
static XrdSecService * CIA
static RAtomic_int srvrAioOps
static const char * myGName
static uint64_t fsFeatures
static XrdOucReqID * PrepID
static XrdSfsFileSystem * osFS
static const uint64_t hasCACH
Feature: Implements a data cache.
static const int Terminate
static const int inCallBk
static const int inDataIov