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 ()

## 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
XrdJob * | NextJob

## 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.

: XrdJob("Black List Check") {}
XrdJob::XrdJob
XrdJob(const char *desc="")
Definition XrdJob.hh:51

References XrdJob::XrdJob().

Here is the call graph for this function:

## ~XrdCmsBlackList()

XrdCmsBlackList::~XrdCmsBlackList | ( |  | ) |

inline

Definition at line 92 of file XrdCmsBlackList.hh.

{}

## 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.

{
struct stat Stat;
XrdOucTList **blOldRedr = 0, **blNewRedr = 0, *blNewReal = 0, *tP = 0, *nP;
int rc, blOldRcnt = 0, blNewRcnt;
bool doUpdt = false, doPrt = false;
// Check if the black list file was modified
//
rc = stat(blFN, &Stat);
if ((!rc && blTime != Stat.st_mtime) || (rc && blTime && errno == ENOENT))
{blTime = (rc ? 0 : Stat.st_mtime);
if (GetBL(blNewReal, blNewRedr, blNewRcnt))
{blMutex.Lock();
tP = blReal; blReal = blNewReal;
blOldRedr = blRedr; blRedr = blNewRedr;
blOldRcnt = blRcnt; blRcnt = blNewRcnt;
blMutex.UnLock();
if (!blReal && tP) doPrt = !isWList;
else blMN.Ring();
doUpdt = true;
}
}
// Delete any list we need to release
//
while(tP)
{if (doPrt) Say.Say("Config ", tP->text, " removed from blacklist.");
nP = tP->next; delete tP; tP = nP;
}
// Delete the old redirect array
//
if (blOldRedr)
{for (int i = 0; i < blOldRcnt; i++) delete blOldRedr[i];
delete [] blOldRedr;
}
// Do real-time update if need be
//
if (doUpdt) blCluster->BlackList(blReal);
// Reschedule this to check any modifications
//
blSched->Schedule((XrdJob *)&BlackList, time(0) + blChk);
}
Stat
struct stat Stat
Definition XrdCks.cc:49
stat
#define stat(a, b)
Definition XrdPosix.hh:101
XrdCmsCluster::BlackList
virtual void BlackList(XrdOucTList *blP)
Definition XrdCmsCluster.cc:330
XrdCms::MidNightTask::Ring
void Ring()
This method gets called at midnight.
Definition XrdCmsBlackList.cc:585
XrdScheduler::Schedule
void Schedule(XrdJob *jp)
Definition XrdScheduler.cc:373
XrdSysError::Say
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)
Definition XrdSysError.cc:141
XrdSysMutex::Lock
void Lock()
Definition XrdSysPthread.hh:222
XrdSysMutex::UnLock
void UnLock()
Definition XrdSysPthread.hh:224
XrdCms::isWList
bool isWList
Definition XrdCmsBlackList.cc:153
XrdCms::BlackList
XrdCmsBlackList BlackList
Definition XrdCmsBlackList.cc:140
XrdCms::blFN
char * blFN
Definition XrdCmsBlackList.cc:147
XrdCms::blRcnt
int blRcnt
Definition XrdCmsBlackList.cc:152
XrdCms::Say
XrdSysError Say
Definition XrdCmsManager.cc:62
XrdCms::blCluster
XrdCmsCluster * blCluster
Definition XrdCmsBlackList.cc:130
XrdCms::blChk
int blChk
Definition XrdCmsBlackList.cc:151
XrdCms::blReal
XrdOucTList * blReal
Definition XrdCmsBlackList.cc:144
XrdCms::blRedr
XrdOucTList ** blRedr
Definition XrdCmsBlackList.cc:145
XrdCms::blTime
time_t blTime
Definition XrdCmsBlackList.cc:149
XrdCms::blMutex
XrdSysMutex blMutex
Definition XrdCmsBlackList.cc:142
XrdCms::blMN
MidNightTask blMN
Definition XrdCmsBlackList.cc:138
XrdCms::blSched
XrdScheduler * blSched
Definition XrdCmsBlackList.cc:128

References XrdJob::XrdJob(), XrdCms::BlackList, XrdCms::blChk, XrdCms::blCluster, XrdCms::blFN, XrdCms::blMN, XrdCms::blMutex, XrdCms::blRcnt, XrdCms::blReal, XrdCms::blRedr, XrdCms::blSched, XrdCms::blTime, XrdCms::isWList, XrdCms::Say, Stat, and stat.

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

  sP | Pointer to the scheduler object.
  cP | Pointer to the cluster object.
  blfn | The path to the black list file or null.
  chkt | Seconds 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.

{
struct stat Stat;
const char *cfn;
// Copy out the scheduler and cluster pointers
//
blSched = sP;
blCluster = cP;
// Determine if this is a black or white list
//
if (chkt < 0) {isWList = true; chkt = -chkt;}
// Copy the file path (this is a one time call during config)
//
if (blfn) blFN = strdup(blfn);
else if (!(cfn = getenv("XRDCONFIGFN"))) return;
else {char pBuff[2048], *Slash;
strcpy(pBuff, cfn);
if (!(Slash = rindex(pBuff, '/'))) return;
strcpy(Slash+1, (isWList ? "cms.whitelist" : "cms.blacklist"));
blFN = strdup(pBuff);
}
// Check if the black list file exists, it might not. If it does, process it
//
if (!stat(blFN, &Stat))
{blTime = Stat.st_mtime;
GetBL(blReal, blRedr, blRcnt, /* isInit = */ true);
if (blReal) blMN.Ring();
}
// Schedule this to recheck any modifications
//
blChk = chkt;
blSched->Schedule((XrdJob *)&BlackList, time(0) + chkt);
// Add ourselves to the midnight run list
//
Say.logger()->AtMidnight(&blMN);
}
XrdSysError::logger
XrdSysLogger * logger(XrdSysLogger *lp=0)
Definition XrdSysError.hh:141
XrdSysLogger::AtMidnight
void AtMidnight(Task *mnTask)
Definition XrdSysLogger.cc:202

References XrdJob::XrdJob(), XrdCms::BlackList, XrdCms::blChk, XrdCms::blCluster, XrdCms::blFN, XrdCms::blMN, XrdCms::blRcnt, XrdCms::blReal, XrdCms::blRedr, XrdCms::blSched, XrdCms::blTime, XrdCms::isWList, XrdCms::Say, Stat, stat, and XrdJob::XrdScheduler.

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

  hName | Pointer to the host name or address.
  bList | Optional pointer to a private black list.
  rbuff | Pointer to the buffer to contain the redirect response. If nil, the host is not redirected.
  rblen | The 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.

{
BL_Info Hdr;
int hLen, retval;
bool doUnLk;
// Check if we really have a name here
//
if (!hName || !blSched) return 0;
// Check if we need to supply our list
//
if (bList) doUnLk = false;
else {doUnLk = true;
blMutex.Lock();
bList = blReal;
}
// By definition, if there is no list at all then everybody is allowed
//
if (!bList)
{if (doUnLk) blMutex.UnLock();
return 0;
}
// Run through the list and try to compare
//
hLen = strlen(hName);
while(bList)
{Hdr.info = bList->dval;
if (Hdr.v.flags & BL_Info::exact)
{if (!strcmp(hName, bList->text)) break;}
else if (hLen >= Hdr.v.totLen)
{if (!Hdr.v.pfxLen
|| !strncmp(bList->text, hName, Hdr.v.pfxLen))
{if (!Hdr.v.sfxLen
|| !strncmp(bList->text+Hdr.v.pfxLen+1,
hName + (hLen - Hdr.v.sfxLen),
Hdr.v.sfxLen)) break;
}
}
bList = bList->next;
}
// If we have a black list check if we should redirect
//
if (bList)
{if (!(Hdr.v.flags & BL_Info::redir)) retval = (isWList ? 0 : -1);
else {XrdOucTList *rP = blRedr[Hdr.v.flags & BL_Info::rmask];
if (rP)
{retval = rP->sval[1];
if (!rBuff || retval > rBLen) retval = -retval;
else {memcpy(rBuff, &(rP->sval[2]), sizeof(short));
memcpy(rBuff+sizeof(short), rP->text, rP->sval[0]);
}
} else retval = -1;
}
} else retval = (isWList ? -1 : 0);
// Unlock ourselves if need be and return result
//
if (doUnLk) blMutex.UnLock();
return retval;
}
XrdOucTList::next
XrdOucTList * next
Definition XrdOucTList.hh:45
XrdOucTList::text
char * text
Definition XrdOucTList.hh:46
BL_Info::v
struct BL_Info::@243254232005125207266263157042265104236176317146 v
BL_Info::redir
@ redir
Definition XrdCmsBlackList.cc:117
BL_Info::exact
@ exact
Definition XrdCmsBlackList.cc:116
BL_Info::rmask
@ rmask
Definition XrdCmsBlackList.cc:118
BL_Info::info
long long info
Definition XrdCmsBlackList.cc:110

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

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

Here is the caller graph for this function:

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

- XrdCmsBlackList.hh
- XrdCmsBlackList.cc