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;
260 ProtLink(this), Entity(0), AppName(0)
272 static unsigned int Sid = 1;
295 static 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;}
442 {
const char *eText =
"Request not signed";
446 <<
" verification failed; " <<eText);
456 <<
" unneeded signature discarded.");
458 {
eDest.
Emsg(
"Protocol",
"Client is needlessly signing requests.");
474 "Invalid request; user not logged in");
523 "Invalid request; user not authenticated");
561 {doRdr =
true;
break;}
591 case kXR_mv:
return do_Mv();
594 case kXR_rm:
return do_Rm();
656 #define TRACELINK Link
673 if (reason && strcmp(reason,
"hangup"))
674 {snprintf(buff,
sizeof(buff),
"%s (%s)", ctbuff, reason);
676 }
else sfxp = ctbuff;
743 int 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;
797 fsz =
static_cast<long long>(buf.st_size);
801 m = snprintf(xxBuff, xxLen,
"%lld %lld %d %lld",
802 Dev.uuid, fsz, flags, (
long long) buf.st_mtime);
808 char *origP = xxBuff;
809 char *nullP = xxBuff + m++;
810 xxBuff += m; xxLen -= m;
811 n = snprintf(xxBuff, xxLen,
"%lld %lld %04o ",
812 (
long long) buf.st_ctime, (
long long) buf.st_atime,
814 if (n >= xxLen)
return m;
815 xxBuff += n; xxLen -= n;
819 if (buf.st_uid ==
myUID)
820 {
if (
myUNLen >= xxLen)
return m;
832 if (buf.st_gid ==
myGID)
833 {
if (
myGNLen >= xxLen)
return m;
844 return xxBuff - origP;
879 return SI->
Stats(buff, blen, do_sync);
894 {
if (bsz) *bsz = xbP->
bsize;
953 else if (buff !=
argp->
buff) errno = EINVAL;
959 if (
argp)
return oldBP;
1004 int XrdXrootdProtocol::CheckSum(
XrdOucStream *Stream,
char **argv,
int argc)
1011 {
Stream->PutLine(
"Internal error; not enough checksum args!");
1022 if (argc > 4 && *argv[4]) myEnv.
Put(
"request.name", argv[4]);
1030 Stream->PutLine(myInfo.getErrText(ecode));
1032 if (ecode) rc = ecode;
1041 void XrdXrootdProtocol::Cleanup()
1132 {
if (rlen != -ENOMSG)
return Link->
setEtext(
"link read error");
1137 TRACEP(REQ, dtype <<
" timeout; read " <<rlen <<
" of " <<blen <<
" bytes");
1146 const char *dtype,
char *buff,
int blen)
1153 gdCtl.BuffLen = blen;
1154 gdCtl.Buffer = buff;
1166 return getDataCont();
1170 namespace {
int consumed = 0;}
1173 const char *dtype,
struct iovec *
iov,
int iovn)
1194 return getDataIovCont();
1201 int XrdXrootdProtocol::getDataCont()
1208 return -EINPROGRESS;
1214 gdCtl.Buffer += rlen;
1215 gdCtl.BuffLen -= rlen;
1226 if (rlen < 0)
break;
1239 if (
gdCtl.BuffLen < 0)
1240 {rlen =
Link->
setEtext(
"link excessive read length error");
1248 Resume = &XrdXrootdProtocol::getDataCont;
1257 <<
gdCtl.BuffLen <<
" remaining");
1264 if (rlen != -ENOMSG)
return Link->
setEtext(
"link read error");
1280 int XrdXrootdProtocol::getDataIovCont()
1287 return -EINPROGRESS;
1292 do{
struct iovec *ioV =
gdCtl.iovVec;
1300 {
if (rlen != -ENOMSG)
Link->
setEtext(
"link read error");
1302 {ioV[iNow].iov_base = ((
char *)ioV[iNow].iov_base) -
gdCtl.iovAdj;
1303 ioV[iNow].iov_len +=
gdCtl.iovAdj;
1312 for (i = iNow; i < iovN && (int)ioV[i].iov_len <= rlen; i++)
1313 rlen -= ioV[i].iov_len;
1317 if (i != iNow &&
gdCtl.iovAdj)
1318 {ioV[iNow].iov_base = ((
char *)ioV[iNow].iov_base) -
gdCtl.iovAdj;
1319 ioV[iNow].iov_len +=
gdCtl.iovAdj;
1353 gdCtl.iovAdj += rlen;
1354 ioV[i].iov_base = ((
char *)ioV[i].iov_base) + rlen;
1355 ioV[i].iov_len -= rlen;
1361 Resume = &XrdXrootdProtocol::getDataIovCont;
1396 gdCtl.DumpLen = dlen;
1403 return (inCB ? 1 : getDumpCont());
1410 int XrdXrootdProtocol::getDumpCont()
1412 int rlen = 0, rwant;
1419 while(
gdCtl.DumpLen > 0)
1420 {
if (
gdCtl.DumpLen <= (
int)
sizeof(buff)) rwant =
gdCtl.DumpLen;
1421 else rwant =
sizeof(buff);
1423 gdCtl.DumpLen -= rlen;
1428 if (rlen < 0 ||
gdCtl.DumpLen < 0)
1430 else if (rlen != -ENOMSG)
Link->
setEtext(
"link read error");
1437 if (
gdCtl.DumpLen == 0)
1444 Resume = &XrdXrootdProtocol::getDumpCont;
1448 <<
" bytes left to discard");
1456 void XrdXrootdProtocol::Reset()
1470 memset(&
IO, 0,
sizeof(
IO));
struct ClientRequestHdr header
struct ClientRequestHdr header
#define kXR_PROTOCOLVSTRING
#define kXR_PROTOCOLVERSION
int stat(const char *path, struct stat *buf)
#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
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)
void Release(XrdBuffer *bp)
XrdBuffer * Obtain(int bsz)
int setEtext(const char *text)
int Peek(char *buff, int blen, int timeout=-1)
int Recv(char *buff, int blen)
const char * Host() const
int Close(bool defer=false)
XrdNetAddrInfo * AddrInfo()
char * ID
Pointer to the client's link identity.
int Send(const char *buff, int blen)
static bool InDomain(XrdNetAddrInfo *epaddr)
void Push(XrdObject< T > *Node)
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)
XrdNetAddrInfo * addrInfo
Entity's connection details.
char prot[XrdSecPROTOIDSIZE]
Auth protocol used (e.g. krb5)
gid_t gid
Unix gid or 0 if none.
void Reset(const char *spV=0)
uid_t uid
Unix uid or 0 if none.
char * moninfo
Information for monitoring.
char * host
Entity's host name dnr dependent.
virtual const char * Verify(SecurityRequest &secreq, ClientRequest &thereq, const char *thedata)
virtual void Delete()
Delete this object. Use this method as opposed to operator delete.
virtual void Delete()=0
Delete the protocol object. DO NOT use C++ delete() on this object.
virtual void Disc(const XrdSecEntity *client=0)
virtual int chksum(csFunc Func, const char *csName, const char *path, XrdOucErrInfo &eInfo, const XrdSecEntity *client=0, const char *opaque=0)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
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)
void Log(int mask, const char *esfx, const char *text1, const char *text2=0, const char *text3=0)
static char * s2hms(int sec, char *buff, int blen)
T fetch_and(T v) noexcept
static void ClearErrorQueue()
Clear the SSL error queue for the calling thread.
void Recycle(XrdXrootdMonitor *monP)
static void Disc(unsigned int usrID)
void Disc(kXR_unt32 dictid, int csec, char Flags=0)
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 XrdSecProtector * DHS
static XrdBuffManager * BPool
static XrdSecService * CIA
static RAtomic_int srvrAioOps
static const char * myGName
static uint64_t fsFeatures
static XrdOucReqID * PrepID
static struct XrdXrootdProtocol::RD_Table Route[RD_Num]
static XrdSfsFileSystem * osFS
void setID(unsigned long long id)
int Stats(char *buff, int blen, int do_sync=0)
XrdXrootd::gdCallBack * CallBack
static const int Terminate
static const int inCallBk
static const int inDataIov