ROOT  6.06/09
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 
47 class XrdBuffer;
48 class XrdProofdClient;
49 class XrdProofdManager;
50 class XrdProofdResponse;
51 class XrdProofdProofServ;
52 class XrdSrvBuffer;
53 
54 class XrdProofdProtocol : XrdProtocol {
55 
56 public:
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; }
82  inline bool IsCtrlC() { XrdSysMutexHelper mhp(fCtrlcMutex);
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  int StartRootd(XrdLink *lp, XrdOucString &emsg);
128  void TouchAdminPath();
129  int Urgent();
130 
131  //
132  // Protocol variables
133 
135  XrdBuffer *fArgp;
136 
137  XrdLink *fLink;
138  int fPid; // Remote ID of the connected process
139 
140  char fStatus;
141 
142  unsigned char fClntCapVer;
143  short int fProofProtocol; // PROOF protocol version run by client
144 
145  bool fSuperUser; // TRUE for privileged clients (admins)
146 
147  XrdOucString fUserIn; // Incoming user name (can be different from the fPClient one)
148  XrdOucString fGroupIn; // Explicit group request from incoming user
149  XrdProofdClient *fPClient; // Our reference XrdProofdClient
150  XrdOucString fAdminPath; // Admin path for this client
151 
152  XrdOucString fTraceID; // Tracing ID
153 
154  XrdSecEntity *fSecClient;
155  XrdSecProtocol *fAuthProt;
156  XrdSecEntity fSecEntity;
157 
158  kXR_int32 fConnType; // Type of connection: Clnt-Mst, Mst-Mst, Mst-Wrk
159 
160  kXR_int32 fCID; // Reference ID of this client
161 
162  XrdSysRecMutex fMutex; // Local mutex
163  XrdSysRecMutex fCtrlcMutex; // CtrlC mutex
164 
165  bool fIsCtrlC; // True is CtrlC was raised;
166 
168 
169  //
170  // These depend on the logical connection
171  XPClientRequest fRequest; // handle client requests
172  std::vector<XrdProofdResponse *> fResponses; // One per each logical connection
173 
174  //
175  // Static area: general protocol managing section
176  //
177  static bool fgConfigDone;
178  static int fgCount;
180  static XrdBuffManager *fgBPool; // Buffer manager
181  static int fgMaxBuffsz; // Maximum buffer size we can have
182  static XrdSysRecMutex fgBMutex; // Buffer management mutex
183 
184  static XrdSysError fgEDest; // Error message handler
185  static XrdSysLogger *fgLogger; // Error logger
186 
187  static int fgEUidAtStartup; // Effective uid at startup
188 
189  //
190  // Static area: protocol configuration section
191  static int fgReadWait;
192  static XrdProofdManager *fgMgr; // Cluster manager
193 
194  static void PostSession(int on, const char *u, const char *g,
195  XrdProofdProofServ *xps);
196 };
197 
198 #define XPD_SETRESP(p, x) \
199  kXR_unt16 rid; \
200  memcpy((void *)&rid, (const void *)&(p->Request()->header.streamid[0]), 2); \
201  XrdProofdResponse *response = p->Response(rid); \
202  if (!response) { \
203  TRACEP(p, XERR, x << ": could not get Response instance for requid:"<< rid); \
204  return rc; \
205  }
206 
207 #define XPD_SETRESPV(p, x) \
208  kXR_unt16 rid; \
209  memcpy((void *)&rid, (const void *)&(p->Request()->header.streamid[0]), 2); \
210  XrdProofdResponse *response = p->Response(rid); \
211  if (!response) { \
212  TRACEP(p, XERR, x << ": could not get Response instance for requid:"<< rid); \
213  return; \
214  }
215 
216 #define XPD_CLNT_VERSION_OK(p,v) (v < 0 || (p && p->ProofProtocol() >= v))
217 
218 #endif
static void PostSession(int on, const char *u, const char *g, XrdProofdProofServ *xps)
Post change of session status.
#define XrdSysLogger
Definition: XpdSysLogger.h:8
static XpdObjectQ fgProtStack
static int MaxBuffsz()
static XrdSysLogger * fgLogger
XrdSecEntity * fSecClient
const double pi
XrdProtocol * Match(XrdLink *lp)
Check whether the request matches this protocol.
#define XrdSysRecMutex
Definition: XrdSysToOuc.h:18
const char * TraceID() const
virtual ~XrdProofdProtocol()
kXR_int32 CID() const
XrdSysRecMutex fMutex
void SetAuthProt(XrdSecProtocol *p)
static XrdSysError fgEDest
void SetAdminPath(const char *p)
XPClientRequest fRequest
static XrdSysRecMutex fgBMutex
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 ...
const char * UserIn() const
char Status() const
Double_t x[n]
Definition: legend1.C:17
void SetConnType(int ct)
void SetCID(kXR_int32 cid)
static int Configure(char *parms, XrdProtocol_Config *pi)
Protocol configuration tool Function: Establish configuration at load time.
XrdSecEntity fSecEntity
void SetUserIn(const char *uin)
short int ProofProtocol() const
static XrdBuffManager * fgBPool
static XrdProofdManager * fgMgr
std::vector< XrdProofdResponse * > fResponses
bool SuperUser() const
void SetPid(int pid)
void Reset()
Reset static and local vars.
static int EUidAtStartup()
XrdProofdClient * fPClient
XrdSecProtocol * fAuthProt
const char * GroupIn() const
int ConnType() const
unsigned char fClntCapVer
XPClientRequest * Request() const
XrdProofdResponse * Response(kXR_unt16 rid)
Get response instance corresponding to stream ID 'sid'.
#define XrdSysMutexHelper
Definition: XrdSysToOuc.h:17
void Recycle(XrdLink *lp, int x, const char *y)
Recycle call. Release the instance and give it back to the stack.
#define XrdSysError
Definition: XpdSysError.h:8
void SetProofProtocol(short int pp)
XrdSecProtocol * AuthProt() const
void SetClntCapVer(unsigned char c)
void SetAuthEntity(XrdSecEntity *se=0)
int GetData(const char *dtype, char *buff, int blen)
Get data from the open link.
#define kXPD_Internal
XrdProofdProtocol(XrdProtocol_Config *pi=0)
Protocol constructor.
#define XPDFORM
Definition: XrdProofdAux.h:381
void SetClient(XrdProofdClient *c)
void TouchAdminPath()
Recording time of the last request on this instance.
XrdBuffer * Argp() const
int Process2()
Local processing method: here the request is dispatched to the appropriate method.
void SetSuperUser(bool su=1)
XrdSysRecMutex fCtrlcMutex
Double_t y[n]
Definition: legend1.C:17
XrdProofdResponse * GetNewResponse(kXR_unt16 rid)
Create new response instance for stream ID 'sid'.
int Ping()
Handle a ping request.
static int fgEUidAtStartup
int Process(XrdLink *lp)
Process the information received on the active link.
int StartRootd(XrdLink *lp, XrdOucString &emsg)
Transfer the connection to a rootd daemon to serve a file access request Return 0 on success...
int Urgent()
Handle generic request of a urgent message to be forwarded to the server.
static void ReleaseBuff(XrdBuffer *argp)
Release a buffer previously allocated via GetBuff.
int Stats(char *buff, int blen, int do_sync)
Return statistics info about the protocol.
int Interrupt()
Handle an interrupt request.
int SendDataN(XrdProofdProofServ *xps, XrdSrvBuffer **buf=0, bool sb=0)
Send data over the open client links of session 'xps'.
int SendMsg()
Handle a request to forward a message to another process.
static XrdProofdManager * Mgr()
int CtrlC()
Set and propagate a Ctrl-C request.
XrdLink * Link() const
XrdOucString fAdminPath
void SetStatus(char s)
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.
XrdProofdClient * Client() const
static bool fgConfigDone
void SetGroupIn(const char *gin)