Loading...
Searching...
No Matches
XrdOucGMap Class Reference

`#include <XrdOucGMap.hh>`

Collaboration diagram for XrdOucGMap:

## Public Member Functions

| XrdOucGMap (XrdOucGMapArgs)
virtual | ~XrdOucGMap ()
| Destructor.
virtual int | dn2user (const char *dn, char *user, int ulen, time_t now=0)
bool | isValid () const
| Validity checker.

## Detailed Description

Definition at line 48 of file XrdOucGMap.hh.

## Constructor & Destructor Documentation

## XrdOucGMap()

XrdOucGMap::XrdOucGMap | ( | XrdOucGMapArgs |  | ) |

Definition at line 103 of file XrdOucGMap.cc.

: valid(0), mf_mtime(-1), notafter(-1), timeout(600), elogger(eDest), tracer(0), dbg(0)
{
// Set tracer
//
tracer = new XrdOucTrace(eDest);
// Parse parameters, if any
//
XrdOucString pp(parms), p;
if (pp.length() > 0) {
int from = 0;
while ((from = pp.tokenize(p, from, '|')) != -1) {
// Debug
if (p == "debug" || p == "dbg") {
dbg = 1;
} else if (p.beginswith("to=")) {
p.erasefromstart(3);
if (p.isdigit()) {
timeout = p.atoi();
} else {
PRINT(tracer, "OucGMap", "timeout value badly formatted ("<<p<<"); ignoring");
}
}
}
}
// Set notafter is timeout is active
//
if (timeout > 0) notafter = time(0) + (time_t) timeout;
// Set the file name
//
mf_name = mapfn;
if (mf_name.length() <= 0) {
mf_name = getenv("GRIDMAP");
if (mf_name.length() <= 0)
mf_name = "/etc/grid-security/grid-mapfile";
}
// Check if it can be read
//
if (access(mf_name.c_str(), R_OK) != 0) {
PRINT(tracer, "OucGMap", "cannot access grid map file '"<< mf_name
<<"' in read mode; " <<XrdSysE2T(errno));
return;
}
// Load the file
//
if (load(mf_name.c_str()) != 0) {
PRINT(tracer, "OucGMap", "unable to load file "<<mf_name<<" - aborting");
return;
}
// Done
valid = 1;
}
eDest
static XrdSysError eDest(0,"crypto_")
PRINT
#define PRINT(y)
Definition XrdCryptosslTrace.hh:39
access
#define access(a, b)
Definition XrdPosix.hh:44
XrdSysE2T
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:104
XrdOucString::erasefromstart
int erasefromstart(int sz=0)
Definition XrdOucString.hh:328
XrdOucString::beginswith
bool beginswith(char c)
Definition XrdOucString.hh:289
XrdOucString::isdigit
bool isdigit(int from=0, int to=-1)
Definition XrdOucString.cc:1270
XrdOucString::atoi
long atoi(int from=0, int to=-1)
Definition XrdOucString.cc:1295

References access, XrdOucString::atoi(), XrdOucString::beginswith(), eDest, XrdOucString::erasefromstart(), XrdOucString::isdigit(), PRINT, XrdOucGMapArgs, and XrdSysE2T().

Here is the call graph for this function:

## ~XrdOucGMap()

virtual XrdOucGMap::~XrdOucGMap | ( |  | ) |

inline virtual

Destructor.

Definition at line 98 of file XrdOucGMap.hh.

{}

## Member Function Documentation

## dn2user()

int XrdOucGMap::dn2user | ( | const char * | dn,
|  | char * | user,
|  | int | ulen,
|  | time_t | now = 0 )

virtual

Map a distinguished name (dn) to a user name.

Parameters

  dn | -> Distinguished name.
  user | -> Buffer where the user name is to be placed. It must end with a null byte.
  ulen | -> The length of the 'user' buffer.
  now | -> Current time (result of time(0)) or 0 if not available.

Returns
  Success: Zero. Failure: An errno number describing the failure; typically -EFAULT - No valid matching found. -errno - If problems reloading the file

Definition at line 292 of file XrdOucGMap.cc.

{
int rc = -1;
// Reset output
//
if (user && ulen > 0) {
memset(user, '\0', ulen);
} else {
PRINT(tracer, "OucGMap::dn2user",
"buffer for the user name is undefined or has undefined length");
return -(int)EINVAL;
}
// Check if we need to reload the information
//
if (notafter > 0) {
if (now <= 0) now = time(0);
if (notafter < now) {
// Reload the file
if (load(mf_name.c_str()) != 0) {
PRINT(tracer, "OucGMap::dn2user",
"problems loading file "<<mf_name);
return -(int)errno;
}
if (timeout > 0) notafter = now + (time_t) timeout;
}
}
// A shared lock is enough
xsl.Lock(xs_Shared);
// Search
//
XrdSecGMapEntry_t *mc = 0;
// Try the full match first
//
if ((mc = mappings.Find(dn))) {
// Save the associated user
int ul = mc->user.length();
strncpy(user, mc->user.c_str(), ul);
user[ul] = 0;
rc = 0;
} else {
// Else scan the available mappings
//
mc = new XrdSecGMapEntry_t(dn, "", kFull);
mappings.Apply(FindMatchingCondition, (void *)mc);
if (mc->user.length() > 0) {
int ul = mc->user.length();
strncpy(user, mc->user.c_str(), ul);
user[ul] = 0;
rc = 0;
}
if (mc) delete mc;
}
if (rc == 0) {
DEBUG(dbg, tracer, "XrdOucGMap::dn2user", "mapping DN '"<<dn<<"' to '"<<user<<"'");
} else {
DEBUG(dbg, tracer, "XrdOucGMap::dn2user", "no valid match found for DN '"<<dn<<"'");
rc = -(int)EFAULT;
}
// Done
xsl.UnLock();
return rc;
}
DEBUG
#define DEBUG(x)
Definition XrdBwmTrace.hh:54
kFull
@ kFull
Definition XrdOucGMap.cc:54
FindMatchingCondition
static int FindMatchingCondition(const char *, XrdSecGMapEntry_t *mc, void *xmp)
Definition XrdOucGMap.cc:64
xs_Shared
@ xs_Shared
Definition XrdSysXSLock.hh:38
XrdOucString::length
int length() const
Definition XrdOucString.hh:279
XrdOucString::c_str
const char * c_str() const
Definition XrdOucString.hh:278
XrdSecGMapEntry_t::user
XrdOucString user
Definition XrdOucGMap.hh:44

References XrdOucString::c_str(), DEBUG, FindMatchingCondition(), kFull, XrdOucString::length(), PRINT, XrdSecGMapEntry_t::user, and xs_Shared.

Here is the call graph for this function:

## isValid()

bool XrdOucGMap::isValid | ( |  | ) | const

inline

Validity checker.

Definition at line 104 of file XrdOucGMap.hh.

{ return valid; }

Referenced by XrdOucgetGMap().

Here is the caller graph for this function:

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

- XrdOucGMap.hh
- XrdOucGMap.cc