Logo ROOT  
Reference Guide
XrdProofdProtocol.h
Go to the documentation of this file.
1// @(#)root/proofd:$Id$
2// Author: G. Ganis June 2005
3
4/*************************************************************************
5 * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_XrdProofdProtocol
13#define ROOT_XrdProofdProtocol
14
15//////////////////////////////////////////////////////////////////////////
16// //
17// XrdProofdProtocol //
18// //
19// Authors: G. Ganis, CERN, 2005 //
20// //
21// XrdProtocol implementation to coordinate 'proofserv' applications. //
22// //
23//////////////////////////////////////////////////////////////////////////
24
25#include <vector>
26
27// Version index: start from 1001 (0x3E9) to distinguish from 'proofd'
28// To be increment when non-backward compatible changes are introduced
29// 1001 (0x3E9) -> 1002 (0x3EA) : support for flexible env setting
30// 1002 (0x3EA) -> 1003 (0x3EB) : many new features
31// 1003 (0x3EB) -> 1004 (0x3EC) : restructuring
32// 1004 (0x3EC) -> 1005 (0x3ED) : deeper restructuring
33// 1005 (0x3ED) -> 1006 (0x3EE) : support for ls,rm,stat,md5sum, getfile, ...
34// 1006 (0x3EE) -> 1007 (0x3EF) : introduce kQueryMssUrl
35#define XPROOFD_VERSBIN 0x000003EF
36#define XPROOFD_VERSION "0.7"
37
38#include "XpdSysPthread.h"
39
40#include "Xrd/XrdLink.hh"
41#include "Xrd/XrdProtocol.hh"
42#include "XrdOuc/XrdOucString.hh"
43#include "XrdSec/XrdSecInterface.hh"
44#include "XpdObject.h"
45#include "XProofProtocol.h"
46
47class XrdBuffer;
48class XrdProofdClient;
52class XrdSrvBuffer;
53
55
56public:
57 XrdProofdProtocol(XrdProtocol_Config *pi = 0);
58 virtual ~XrdProofdProtocol() {} // Never gets destroyed
59
60 void DoIt() {}
61 XrdProtocol *Match(XrdLink *lp);
62 int Process(XrdLink *lp);
63 void Recycle(XrdLink *lp, int x, const char *y);
64 int Stats(char *buff, int blen, int do_sync);
65
66 static int Configure(char *parms, XrdProtocol_Config *pi);
67
68 // Buffer / Data handlers
69 int GetData(const char *dtype, char *buff, int blen);
70 static XrdBuffer *GetBuff(int quantum, XrdBuffer *argp = 0);
71 static void ReleaseBuff(XrdBuffer *argp);
72 static int MaxBuffsz() { return fgMaxBuffsz; } // Maximum buffer size we can have
73
74 // Getters
75 inline kXR_int32 CID() const { return fCID; }
76 inline XrdProofdClient *Client() const { return fPClient; }
77 inline const char *GroupIn() const { return fGroupIn.c_str(); }
78 inline const char *UserIn() const { return fUserIn.c_str(); }
79 inline int ConnType() const { return fConnType; }
80 inline const char *TraceID() const { return fTraceID.c_str(); }
81 inline bool Internal() { return (fConnType == kXPD_Internal) ? 1 : 0; }
83 bool rc = fIsCtrlC; fIsCtrlC = 0; return rc; }
84 inline int Pid() const { return fPid; }
85 inline void ResetCtrlC() { XrdSysMutexHelper mhp(fCtrlcMutex); fIsCtrlC = 0; }
86 inline char Status() const { return fStatus; }
87 inline short int ProofProtocol() const { return fProofProtocol; }
88 inline bool SuperUser() const { return fSuperUser; }
89
90 XrdProofdResponse *Response(kXR_unt16 rid);
91 inline XPClientRequest *Request() const { return (XPClientRequest *)&fRequest; }
92 inline XrdBuffer *Argp() const { return fArgp; }
93 inline XrdLink *Link() const { return fLink; }
94 inline XrdSecProtocol *AuthProt() const { return fAuthProt; }
95
96 // Setters
97 inline void SetAdminPath(const char *p) { XrdSysMutexHelper mhp(fMutex); fAdminPath = p; }
98 inline void SetAuthEntity(XrdSecEntity *se = 0) { fSecEntity.tident = fLink->ID;
99 fSecClient = (se) ? se : &fSecEntity; }
100 inline void SetAuthProt(XrdSecProtocol *p) { fAuthProt = p; }
101 inline void SetClient(XrdProofdClient *c) { fPClient = c; }
102 inline void SetClntCapVer(unsigned char c) { fClntCapVer = c; }
103 inline void SetCID(kXR_int32 cid) { fCID = cid; }
104 inline void SetConnType(int ct) { fConnType = ct; }
105 inline void SetGroupIn(const char *gin) { fGroupIn = gin; }
106 inline void SetTraceID() { if (fLink) XPDFORM(fTraceID, "%s: ", fLink->ID); }
107 inline void SetPid(int pid) { fPid = pid; }
108 inline void SetProofProtocol(short int pp) { fProofProtocol = pp; }
109 inline void SetStatus(char s) { fStatus = s; }
110 inline void SetSuperUser(bool su = 1) { fSuperUser = su; }
111 inline void SetUserIn(const char *uin) { fUserIn = uin; }
112
113 static XrdProofdManager *Mgr() { return fgMgr; }
114 static int EUidAtStartup() { return fgEUidAtStartup; }
115
116 private:
117
118 XrdProofdResponse *GetNewResponse(kXR_unt16 rid);
119 int Interrupt();
120 int Ping();
121 int Process2();
122 void Reset();
123 int SendData(XrdProofdProofServ *xps, kXR_int32 sid = -1, XrdSrvBuffer **buf = 0, bool sb = 0);
124 int SendDataN(XrdProofdProofServ *xps, XrdSrvBuffer **buf = 0, bool sb = 0);
125 int SendMsg();
126 int CtrlC();
127 void TouchAdminPath();
128 int Urgent();
129
130 //
131 // Protocol variables
132
134 XrdBuffer *fArgp;
135
136 XrdLink *fLink;
137 int fPid; // Remote ID of the connected process
138
140
141 unsigned char fClntCapVer;
142 short int fProofProtocol; // PROOF protocol version run by client
143
144 bool fSuperUser; // TRUE for privileged clients (admins)
145
146 XrdOucString fUserIn; // Incoming user name (can be different from the fPClient one)
147 XrdOucString fGroupIn; // Explicit group request from incoming user
148 XrdProofdClient *fPClient; // Our reference XrdProofdClient
149 XrdOucString fAdminPath; // Admin path for this client
150
151 XrdOucString fTraceID; // Tracing ID
152
153 XrdSecEntity *fSecClient;
154 XrdSecProtocol *fAuthProt;
155 XrdSecEntity fSecEntity;
156
157 kXR_int32 fConnType; // Type of connection: Clnt-Mst, Mst-Mst, Mst-Wrk
158
159 kXR_int32 fCID; // Reference ID of this client
160
161 XrdSysRecMutex fMutex; // Local mutex
163
164 bool fIsCtrlC; // True is CtrlC was raised;
165
167
168 //
169 // These depend on the logical connection
170 XPClientRequest fRequest; // handle client requests
171 std::vector<XrdProofdResponse *> fResponses; // One per each logical connection
172
173 //
174 // Static area: general protocol managing section
175 //
176 static bool fgConfigDone;
177 static int fgCount;
179 static XrdBuffManager *fgBPool; // Buffer manager
180 static int fgMaxBuffsz; // Maximum buffer size we can have
181 static XrdSysRecMutex fgBMutex; // Buffer management mutex
182
183 static XrdSysError fgEDest; // Error message handler
184 static XrdSysLogger *fgLogger; // Error logger
185
186 static int fgEUidAtStartup; // Effective uid at startup
187
188 //
189 // Static area: protocol configuration section
190 static int fgReadWait;
191 static XrdProofdManager *fgMgr; // Cluster manager
192
193 static void PostSession(int on, const char *u, const char *g,
194 XrdProofdProofServ *xps);
195};
196
197#define XPD_SETRESP(p, x) \
198 kXR_unt16 rid; \
199 memcpy((void *)&rid, (const void *)&(p->Request()->header.streamid[0]), 2); \
200 XrdProofdResponse *response = p->Response(rid); \
201 if (!response) { \
202 TRACEP(p, XERR, x << ": could not get Response instance for requid:"<< rid); \
203 return rc; \
204 }
205
206#define XPD_SETRESPV(p, x) \
207 kXR_unt16 rid; \
208 memcpy((void *)&rid, (const void *)&(p->Request()->header.streamid[0]), 2); \
209 XrdProofdResponse *response = p->Response(rid); \
210 if (!response) { \
211 TRACEP(p, XERR, x << ": could not get Response instance for requid:"<< rid); \
212 return; \
213 }
214
215#define XPD_CLNT_VERSION_OK(p,v) (v < 0 || (p && p->ProofProtocol() >= v))
216
217#endif
#define c(i)
Definition: RSha256.hxx:101
#define g(i)
Definition: RSha256.hxx:105
#define kXPD_Internal
#define XrdSysError
Definition: XpdSysError.h:8
#define XrdSysLogger
Definition: XpdSysLogger.h:8
#define XPDFORM
Definition: XrdProofdAux.h:378
#define XrdSysMutexHelper
Definition: XrdSysToOuc.h:17
#define XrdSysRecMutex
Definition: XrdSysToOuc.h:18
static int Configure(char *parms, XrdProtocol_Config *pi)
Protocol configuration tool Function: Establish configuration at load time.
void Recycle(XrdLink *lp, int x, const char *y)
Recycle call. Release the instance and give it back to the stack.
int SendMsg()
Handle a request to forward a message to another process.
const char * GroupIn() const
int SendData(XrdProofdProofServ *xps, kXR_int32 sid=-1, XrdSrvBuffer **buf=0, bool sb=0)
Send data over the open link. Segmentation is done here, if required.
XrdProofdResponse * Response(kXR_unt16 rid)
Get response instance corresponding to stream ID 'sid'.
XrdSecEntity fSecEntity
static int MaxBuffsz()
XrdProofdResponse * GetNewResponse(kXR_unt16 rid)
Create new response instance for stream ID 'sid'.
XrdLink * Link() const
static bool fgConfigDone
static XrdSysRecMutex fgBMutex
static void PostSession(int on, const char *u, const char *g, XrdProofdProofServ *xps)
Post change of session status.
static XrdSysError fgEDest
short int ProofProtocol() const
void SetPid(int pid)
XrdProofdClient * fPClient
void SetSuperUser(bool su=1)
void SetUserIn(const char *uin)
int SendDataN(XrdProofdProofServ *xps, XrdSrvBuffer **buf=0, bool sb=0)
Send data over the open client links of session 'xps'.
static int EUidAtStartup()
static XpdObjectQ fgProtStack
XrdProtocol * Match(XrdLink *lp)
Check whether the request matches this protocol.
XrdProofdProtocol(XrdProtocol_Config *pi=0)
Protocol constructor.
static XrdProofdManager * fgMgr
XrdProofdClient * Client() const
void SetClient(XrdProofdClient *c)
int Process2()
Local processing method: here the request is dispatched to the appropriate method.
void SetGroupIn(const char *gin)
int CtrlC()
Set and propagate a Ctrl-C request.
void SetAuthProt(XrdSecProtocol *p)
int Stats(char *buff, int blen, int do_sync)
Return statistics info about the protocol.
XrdSecProtocol * AuthProt() const
static XrdBuffManager * fgBPool
void SetProofProtocol(short int pp)
kXR_int32 CID() const
const char * UserIn() const
XrdBuffer * Argp() const
std::vector< XrdProofdResponse * > fResponses
XrdSysRecMutex fCtrlcMutex
static XrdProofdManager * Mgr()
XrdSecProtocol * fAuthProt
XrdOucString fAdminPath
void Reset()
Reset static and local vars.
int Process(XrdLink *lp)
Process the information received on the active link.
void SetConnType(int ct)
void SetStatus(char s)
virtual ~XrdProofdProtocol()
static XrdSysLogger * fgLogger
int Interrupt()
Handle an interrupt request.
static XrdBuffer * GetBuff(int quantum, XrdBuffer *argp=0)
Allocate a buffer to handle quantum bytes; if argp points to an existing buffer, its size is checked ...
XPClientRequest * Request() const
void TouchAdminPath()
Recording time of the last request on this instance.
int Urgent()
Handle generic request of a urgent message to be forwarded to the server.
XPClientRequest fRequest
static int fgEUidAtStartup
const char * TraceID() const
XrdSecEntity * fSecClient
void SetAuthEntity(XrdSecEntity *se=0)
void SetAdminPath(const char *p)
unsigned char fClntCapVer
void SetClntCapVer(unsigned char c)
void SetCID(kXR_int32 cid)
XrdSysRecMutex fMutex
int GetData(const char *dtype, char *buff, int blen)
Get data from the open link.
static void ReleaseBuff(XrdBuffer *argp)
Release a buffer previously allocated via GetBuff.
int Ping()
Handle a ping request.
bool SuperUser() const
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
static constexpr double s
static constexpr double pi