XRootD
XrdOfsTPCAuth Class Reference

#include <XrdOfsTPCAuth.hh>

+ Inheritance diagram for XrdOfsTPCAuth:
+ Collaboration diagram for XrdOfsTPCAuth:

Public Member Functions

 XrdOfsTPCAuth (int vTTL)
 
 ~XrdOfsTPCAuth ()
 
int Add (Facts &Args)
 
void Del ()
 
int Expired ()
 
int Expired (const char *Dst, int cnt=1)
 

Static Public Member Functions

static int Get (Facts &Args, XrdOfsTPCAuth **theTPC)
 
static int RunTTL (int Init)
 

Detailed Description

Definition at line 39 of file XrdOfsTPCAuth.hh.

Constructor & Destructor Documentation

◆ XrdOfsTPCAuth()

XrdOfsTPCAuth::XrdOfsTPCAuth ( int  vTTL)
inline

Definition at line 55 of file XrdOfsTPCAuth.hh.

55 : expT(vTTL+time(0)) {}

◆ ~XrdOfsTPCAuth()

XrdOfsTPCAuth::~XrdOfsTPCAuth ( )
inline

Definition at line 57 of file XrdOfsTPCAuth.hh.

57 {}

Member Function Documentation

◆ Add()

int XrdOfsTPCAuth::Add ( XrdOfsTPC::Facts Args)

Definition at line 77 of file XrdOfsTPCAuth.cc.

78 {
79  XrdOfsTPCAuth *aP;
80  const char *eMsg;
81  char Buff[512];
82 
83 // Generate the origin information
84 //
85  if (!genOrg(Args.Usr, Buff, sizeof(Buff))) return Fatal(Args, Buff, EINVAL);
86  Args.Org = Buff;
87 
88 // Check if there is a matching authorization in the queue. If this is for a
89 // pending authorization, indicated that we now have one. Otherwise, consider
90 // this a potential security breach and cancel both autorizations.
91 //
92  authMutex.Lock();
93  if ((aP = Find(Args)))
94  {if (aP->Info.cbP)
95  {aP->expT = expT;
96  aP->Next = authQ; authQ = aP;
97  aP->Info.Reply(SFS_OK, 0, "", &authMutex);
98  return 1;
99  } else {
100  authMutex.UnLock();
101  return Fatal(Args, "duplicate athorization", EPROTO);
102  }
103  }
104 
105 // Set the copy authorization information
106 //
107  if ((eMsg = Info.Set(Args.Key, Buff, Args.Lfn, Args.Dst)))
108  {
109  authMutex.UnLock();
110  return Fatal(Args, eMsg, EINVAL);
111  }
112 
113 // Add this to queue
114 //
115  Next = authQ; authQ = this; inQ = 1;
116 
117 // All done
118 //
119  authMutex.UnLock();
120  return 1;
121 }
#define eMsg(x)
#define SFS_OK
const char * Set(const char *cKey, const char *cOrg, const char *xLfn, const char *xDst, const char *xCks=0)
static int Fatal(Facts &Args, const char *eMsg, int eCode, int nomsg=0)
Definition: XrdOfsTPC.cc:334
XrdOfsTPCInfo Info
Definition: XrdOfsTPC.hh:109
char inQ
Definition: XrdOfsTPC.hh:130
static int genOrg(const XrdSecEntity *client, char *Buff, int Blen)
Definition: XrdOfsTPC.cc:359
const XrdSecEntity * Usr
Definition: XrdOfsTPC.hh:57
const char * Key
Definition: XrdOfsTPC.hh:52
const char * Org
Definition: XrdOfsTPC.hh:55
const char * Lfn
Definition: XrdOfsTPC.hh:53
const char * Dst
Definition: XrdOfsTPC.hh:56

References XrdOfsTPC::Facts::Dst, eMsg, Fatal(), Info, XrdOfsTPC::Facts::Key, XrdOfsTPC::Facts::Lfn, XrdOfsTPC::Facts::Org, SFS_OK, and XrdOfsTPC::Facts::Usr.

Referenced by XrdOfsTPC::Authorize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Del()

void XrdOfsTPCAuth::Del ( )
virtual

Reimplemented from XrdOfsTPC.

Definition at line 127 of file XrdOfsTPCAuth.cc.

128 {
129  XrdOfsTPCAuth *pP;
130 
131 // Remove from queue if we are still in the queue
132 //
133  authMutex.Lock();
134  if (inQ)
135  {if (this == authQ) authQ = Next;
136  else {pP = authQ;
137  while(pP && pP->Next != this) pP = pP->Next;
138  if (pP) pP->Next = Next;
139  }
140  inQ = 0;
141  }
142 
143 // Delete the element if possible
144 //
145  if (Refs <= 1) delete this;
146  else Refs--;
147  authMutex.UnLock();
148 }
char Refs
Definition: XrdOfsTPC.hh:129

Referenced by XrdOfsTPC::Authorize().

+ Here is the caller graph for this function:

◆ Expired() [1/2]

int XrdOfsTPCAuth::Expired ( )
inline

Definition at line 47 of file XrdOfsTPCAuth.hh.

47 {return (time(0) >= expT);}

Referenced by XrdOfsTPC::Authorize(), and RunTTL().

+ Here is the caller graph for this function:

◆ Expired() [2/2]

int XrdOfsTPCAuth::Expired ( const char *  Dst,
int  cnt = 1 
)

Definition at line 154 of file XrdOfsTPCAuth.cc.

155 {
156  char Buff[1024];
157 
158 // If there is a callback, tell the client they are no longer wanted
159 //
160  if (Info.cbP) Info.Reply(SFS_ERROR, EACCES, "tpc authorization expired");
161 
162 // Log this event
163 //
164  snprintf(Buff, sizeof(Buff), "tpc grant by %s expired for", Info.Org);
165  Buff[sizeof(Buff)-1] = 0;
166  OfsEroute.Emsg("TPC", Dst, Buff, Info.Lfn);
167 
168 // Count stats and return
169 //
170  if (cnt) OfsStats.Add(OfsStats.Data.numTPCexpr);
171  return 0;
172 }
XrdOfsStats OfsStats
Definition: XrdOfs.cc:113
XrdSysError OfsEroute
#define SFS_ERROR
struct XrdOfsStats::StatsData Data
void Add(int &Cntr)
Definition: XrdOfsStats.hh:62
XrdOucCallBack * cbP
void Reply(int rC, int eC, const char *eMsg, XrdSysMutex *mP=0)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95

References XrdOfsStats::Add(), XrdOfsStats::Data, XrdSysError::Emsg(), Info, XrdOfsStats::StatsData::numTPCexpr, OfsEroute, OfsStats, and SFS_ERROR.

+ Here is the call graph for this function:

◆ Get()

int XrdOfsTPCAuth::Get ( XrdOfsTPC::Facts Args,
XrdOfsTPCAuth **  theTPC 
)
static

Definition at line 204 of file XrdOfsTPCAuth.cc.

205 {
206  XrdSysMutexHelper authMon(&authMutex);
207  XrdOfsTPCAuth *aP;
208  const char *eMsg;
209 
210 // Check if there is a matching authorization in the queue. If this is for a
211 // pending authorization, then consider this a potential security breach and
212 // cancel both requests. Otherwise, indicate that authorization is present.
213 //
214  if ((aP = Find(Args)))
215  {if (aP->Info.cbP)
216  {aP->Info.Reply(SFS_ERROR, EPROTO, "duplicate tpc auth request");
217  return Fatal(Args, "duplicate tpc auth request", EPROTO);
218  } else {
219  aP->Refs++;
220  *theTPC = aP;
221  return SFS_OK;
222  }
223  }
224 
225 // Add this request as a pending authorization to the queue
226 //
227  if (!(aP = new XrdOfsTPCAuth(Cfg.maxTTL)))
228  return Fatal(Args, "insufficient memory", ENOMEM);
229 
230 // Set the copy authorization information
231 //
232  if ((eMsg = aP->Info.Set(Args.Key, Args.Org, Args.Lfn, Args.Dst)))
233  {delete aP;
234  return Fatal(Args, eMsg, EINVAL);
235  }
236 
237 // Create a callback
238 //
239  if (aP->Info.SetCB(Args.eRR)) {delete aP; return SFS_ERROR;}
240 
241 // Add it to the queue
242 //
243  aP->Next = authQ; authQ = aP;
244 
245 // Return result
246 //
247  *theTPC = aP;
248  aP->Refs = 0;
249  aP->Info.Engage();
250  return SFS_STARTED;
251 }
#define SFS_STARTED
XrdOfsTPCAuth(int vTTL)
XrdOucErrInfo * eRR
Definition: XrdOfsTPC.hh:58

References XrdOfsTPCParms::Cfg, XrdOfsTPC::Facts::Dst, eMsg, XrdOfsTPC::Facts::eRR, Fatal(), XrdOfsTPC::Facts::Key, XrdOfsTPC::Facts::Lfn, XrdOfsTPCConfig::maxTTL, XrdOfsTPC::Facts::Org, SFS_ERROR, SFS_OK, and SFS_STARTED.

Referenced by XrdOfsTPC::Authorize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RunTTL()

int XrdOfsTPCAuth::RunTTL ( int  Init)
static

Definition at line 257 of file XrdOfsTPCAuth.cc.

258 {
259  XrdOfsTPCAuth *cP, *pP, *nP;
260  time_t eNow;
261  int eWait, eDiff, numExp;
262 
263 // Start the expiration thread
264 //
265  if (Init)
266  {pthread_t tid;
267  int rc;
268  if ((rc = XrdSysThread::Run(&tid,XrdOfsTPCAuthttl,0,0,"TPC ttl runner")))
269  OfsEroute.Emsg("TPC", rc, "create tpc ttl runner thread");
270  return (rc ? 0 : 1);
271  }
272 
273 // Find all expired entries and remove them
274 //
275 do{authMutex.Lock();
276  cP = authQ; pP = 0;
277  eNow = time(0); eWait = Cfg.maxTTL; numExp = 0;
278  while(cP)
279  {if (eNow < cP->expT)
280  {eDiff = cP->expT - eNow;
281  if (eDiff < eWait) eWait = eDiff;
282  pP = cP; cP = cP->Next;
283  }
284  else {if (pP) pP->Next = cP->Next;
285  else authQ = cP->Next;
286  cP->Expired("localhost", 0); numExp++;
287  nP = cP->Next;
288  if (cP->Refs < 1) delete cP;
289  cP = nP;
290  }
291  }
292  authMutex.UnLock();
293 
294 // Add number of expirations to statistics
295 //
296  if (numExp)
297  {OfsStats.sdMutex.Lock();
298  OfsStats.Data.numTPCexpr += numExp;
300  }
301 
302 // Wait as long as possible for a recan
303 //
304  XrdSysTimer::Snooze(eWait);
305  } while(1);
306 }
void * XrdOfsTPCAuthttl(void *pp)
XrdSysMutex sdMutex
Definition: XrdOfsStats.hh:60
static void Init()
Definition: XrdOfsTPC.cc:414
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)
static void Snooze(int seconds)
Definition: XrdSysTimer.cc:168

References XrdOfsTPCParms::Cfg, XrdOfsStats::Data, XrdSysError::Emsg(), Expired(), XrdSysMutex::Lock(), XrdOfsTPCConfig::maxTTL, XrdOfsStats::StatsData::numTPCexpr, OfsEroute, OfsStats, XrdSysThread::Run(), XrdOfsStats::sdMutex, XrdSysTimer::Snooze(), XrdSysMutex::UnLock(), and XrdOfsTPCAuthttl().

Referenced by XrdOfsTPC::Start(), and XrdOfsTPCAuthttl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: