Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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  void TouchAdminPath();
128  int Urgent();
129 
130  //
131  // Protocol variables
132 
133  XpdObject fProtLink;
134  XrdBuffer *fArgp;
135 
136  XrdLink *fLink;
137  int fPid; // Remote ID of the connected process
138 
139  char fStatus;
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
162  XrdSysRecMutex fCtrlcMutex; // CtrlC mutex
163 
164  bool fIsCtrlC; // True is CtrlC was raised;
165 
166  int fStdErrFD;
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;
178  static XpdObjectQ fgProtStack;
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