XRootD
Loading...
Searching...
No Matches
XrdCmsBlackList Class Reference

#include <XrdCmsBlackList.hh>

+ Inheritance diagram for XrdCmsBlackList:
+ Collaboration diagram for XrdCmsBlackList:

Public Member Functions

 XrdCmsBlackList ()
 Constructor and Destructor.
 
 ~XrdCmsBlackList ()
 
void DoIt ()
 Time driven method for checking black list file.
 
- Public Member Functions inherited from XrdJob
 XrdJob (const char *desc="")
 
virtual ~XrdJob ()
 
virtual void DoIt ()=0
 

Static Public Member Functions

static void Init (XrdScheduler *sP, XrdCmsCluster *cP, const char *blfn, int chkt=600)
 
static int Present (const char *hName, XrdOucTList *bList=0, char *rbuff=0, int rblen=0)
 

Additional Inherited Members

- Public Attributes inherited from XrdJob
const char * Comment
 
XrdJobNextJob
 

Detailed Description

Definition at line 41 of file XrdCmsBlackList.hh.

Constructor & Destructor Documentation

◆ XrdCmsBlackList()

XrdCmsBlackList::XrdCmsBlackList ( )
inline

Constructor and Destructor.

Definition at line 91 of file XrdCmsBlackList.hh.

91: XrdJob("Black List Check") {}

◆ ~XrdCmsBlackList()

XrdCmsBlackList::~XrdCmsBlackList ( )
inline

Definition at line 92 of file XrdCmsBlackList.hh.

92{}

Member Function Documentation

◆ DoIt()

void XrdCmsBlackList::DoIt ( )
virtual

Time driven method for checking black list file.

Implements XrdJob.

Definition at line 295 of file XrdCmsBlackList.cc.

296{
297 struct stat Stat;
298 XrdOucTList **blOldRedr = 0, **blNewRedr = 0, *blNewReal = 0, *tP = 0, *nP;
299 int rc, blOldRcnt = 0, blNewRcnt;
300 bool doUpdt = false, doPrt = false;
301
302// Check if the black list file was modified
303//
304 rc = stat(blFN, &Stat);
305 if ((!rc && blTime != Stat.st_mtime) || (rc && blTime && errno == ENOENT))
306 {blTime = (rc ? 0 : Stat.st_mtime);
307 if (GetBL(blNewReal, blNewRedr, blNewRcnt))
308 {blMutex.Lock();
309 tP = blReal; blReal = blNewReal;
310 blOldRedr = blRedr; blRedr = blNewRedr;
311 blOldRcnt = blRcnt; blRcnt = blNewRcnt;
312 blMutex.UnLock();
313 if (!blReal && tP) doPrt = !isWList;
314 else blMN.Ring();
315 doUpdt = true;
316 }
317 }
318
319// Delete any list we need to release
320//
321 while(tP)
322 {if (doPrt) Say.Say("Config ", tP->text, " removed from blacklist.");
323 nP = tP->next; delete tP; tP = nP;
324 }
325
326// Delete the old redirect array
327//
328 if (blOldRedr)
329 {for (int i = 0; i < blOldRcnt; i++) delete blOldRedr[i];
330 delete [] blOldRedr;
331 }
332
333// Do real-time update if need be
334//
335 if (doUpdt) blCluster->BlackList(blReal);
336
337// Reschedule this to check any modifications
338//
339 blSched->Schedule((XrdJob *)&BlackList, time(0) + blChk);
340}
struct stat Stat
Definition XrdCks.cc:49
#define stat(a, b)
Definition XrdPosix.hh:96
virtual void BlackList(XrdOucTList *blP)
void Ring()
This method gets called at midnight.
void Schedule(XrdJob *jp)
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)
XrdCmsBlackList BlackList
XrdSysError Say
XrdCmsCluster * blCluster
XrdOucTList * blReal
XrdOucTList ** blRedr
time_t blTime
XrdSysMutex blMutex
MidNightTask blMN
XrdScheduler * blSched

References XrdCms::BlackList, XrdCmsCluster::BlackList(), XrdCms::blChk, XrdCms::blCluster, XrdCms::blFN, XrdCms::blMN, XrdCms::blMutex, XrdCms::blRcnt, XrdCms::blReal, XrdCms::blRedr, XrdCms::blSched, XrdCms::blTime, XrdCms::isWList, XrdSysMutex::Lock(), XrdCms::MidNightTask::Ring(), XrdCms::Say, XrdSysError::Say(), XrdScheduler::Schedule(), Stat, stat, and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

◆ Init()

void XrdCmsBlackList::Init ( XrdScheduler sP,
XrdCmsCluster cP,
const char *  blfn,
int  chkt = 600 
)
static

Initialize the black list

Parameters
sPPointer to the scheduler object.
cPPointer to the cluster object.
blfnThe path to the black list file or null.
chktSeconds between checks for blacklist changes. If the value is negative, the blacklist is treated as a whitelist.

Definition at line 467 of file XrdCmsBlackList.cc.

469{
470 struct stat Stat;
471 const char *cfn;
472
473// Copy out the scheduler and cluster pointers
474//
475 blSched = sP;
476 blCluster = cP;
477
478// Determine if this is a black or white list
479//
480 if (chkt < 0) {isWList = true; chkt = -chkt;}
481
482// Copy the file path (this is a one time call during config)
483//
484 if (blfn) blFN = strdup(blfn);
485 else if (!(cfn = getenv("XRDCONFIGFN"))) return;
486 else {char pBuff[2048], *Slash;
487 strcpy(pBuff, cfn);
488 if (!(Slash = rindex(pBuff, '/'))) return;
489 strcpy(Slash+1, (isWList ? "cms.whitelist" : "cms.blacklist"));
490 blFN = strdup(pBuff);
491 }
492
493// Check if the black list file exists, it might not. If it does, process it
494//
495 if (!stat(blFN, &Stat))
496 {blTime = Stat.st_mtime;
497 GetBL(blReal, blRedr, blRcnt, /* isInit = */ true);
498 if (blReal) blMN.Ring();
499 }
500
501// Schedule this to recheck any modifications
502//
503 blChk = chkt;
504 blSched->Schedule((XrdJob *)&BlackList, time(0) + chkt);
505
506// Add ourselves to the midnight run list
507//
509}
XrdSysLogger * logger(XrdSysLogger *lp=0)
void AtMidnight(Task *mnTask)

References XrdSysLogger::AtMidnight(), XrdCms::BlackList, XrdCms::blChk, XrdCms::blCluster, XrdCms::blFN, XrdCms::blMN, XrdCms::blRcnt, XrdCms::blReal, XrdCms::blRedr, XrdCms::blSched, XrdCms::blTime, XrdCms::isWList, XrdSysError::logger(), XrdCms::MidNightTask::Ring(), XrdCms::Say, XrdScheduler::Schedule(), Stat, and stat.

+ Here is the call graph for this function:

◆ Present()

int XrdCmsBlackList::Present ( const char *  hName,
XrdOucTList bList = 0,
char *  rbuff = 0,
int  rblen = 0 
)
static

Check if host is in the black list and how it should be managed.

Parameters
hNamePointer to the host name or address.
bListOptional pointer to a private black list.
rbuffPointer to the buffer to contain the redirect response. If nil, the host is not redirected.
rblenThe size of rbuff. If zero or insufficiently large the host is not redirected.
Returns
< -1 Host is in the black list and would be redirected; but either rbuff was nil or the buffer was too small. The abs(returned value) is the size the buffer should have been.
= -1 Host is in the black list and should not be redirected.
= 0 Host not in the black list.
> 0 Host is in the black list and should be redirected. The return value is the size of the redirect response placed in the supplied buffer.

Definition at line 515 of file XrdCmsBlackList.cc.

517{
518 BL_Info Hdr;
519 int hLen, retval;
520 bool doUnLk;
521
522// Check if we really have a name here
523//
524 if (!hName || !blSched) return 0;
525
526// Check if we need to supply our list
527//
528 if (bList) doUnLk = false;
529 else {doUnLk = true;
530 blMutex.Lock();
531 bList = blReal;
532 }
533
534// By definition, if there is no list at all then everybody is allowed
535//
536 if (!bList)
537 {if (doUnLk) blMutex.UnLock();
538 return 0;
539 }
540
541// Run through the list and try to compare
542//
543 hLen = strlen(hName);
544 while(bList)
545 {Hdr.info = bList->dval;
546 if (Hdr.v.flags & BL_Info::exact)
547 {if (!strcmp(hName, bList->text)) break;}
548 else if (hLen >= Hdr.v.totLen)
549 {if (!Hdr.v.pfxLen
550 || !strncmp(bList->text, hName, Hdr.v.pfxLen))
551 {if (!Hdr.v.sfxLen
552 || !strncmp(bList->text+Hdr.v.pfxLen+1,
553 hName + (hLen - Hdr.v.sfxLen),
554 Hdr.v.sfxLen)) break;
555 }
556 }
557 bList = bList->next;
558 }
559
560// If we have a black list check if we should redirect
561//
562 if (bList)
563 {if (!(Hdr.v.flags & BL_Info::redir)) retval = (isWList ? 0 : -1);
564 else {XrdOucTList *rP = blRedr[Hdr.v.flags & BL_Info::rmask];
565 if (rP)
566 {retval = rP->sval[1];
567 if (!rBuff || retval > rBLen) retval = -retval;
568 else {memcpy(rBuff, &(rP->sval[2]), sizeof(short));
569 memcpy(rBuff+sizeof(short), rP->text, rP->sval[0]);
570 }
571 } else retval = -1;
572 }
573 } else retval = (isWList ? -1 : 0);
574
575// Unlock ourselves if need be and return result
576//
577 if (doUnLk) blMutex.UnLock();
578 return retval;
579}
XrdOucTList * next
struct BL_Info::@79 v
long long info

References XrdCms::blMutex, XrdCms::blReal, XrdCms::blRedr, XrdCms::blSched, BL_Info::exact, BL_Info::info, XrdCms::isWList, XrdSysMutex::Lock(), XrdOucTList::next, BL_Info::redir, BL_Info::rmask, XrdOucTList::text, XrdSysMutex::UnLock(), and BL_Info::v.

Referenced by XrdCmsLogin::Admit(), and XrdCmsCluster::BlackList().

+ 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: