60 #define PRINT(t,n,y) {if (t) {t->Beg(n); std::cerr <<y; t->End();}}
61 #define DEBUG(d,t,n,y) {if (d && t) {t->Beg(n); std::cerr <<y; t->End();}}
85 return (match) ? 1 : 0;
96 if (gm && gm->
isValid())
return gm;
104 : valid(0), mf_mtime(-1), notafter(-1), timeout(600), elogger(
eDest), tracer(0), dbg(0)
113 if (pp.length() > 0) {
115 while ((from = pp.tokenize(p, from,
'|')) != -1) {
117 if (p ==
"debug" || p ==
"dbg") {
124 PRINT(tracer,
"OucGMap",
"timeout value badly formatted ("<<p<<
"); ignoring");
132 if (timeout > 0) notafter = time(0) + (time_t) timeout;
137 if (mf_name.
length() <= 0) {
138 mf_name = getenv(
"GRIDMAP");
139 if (mf_name.
length() <= 0)
140 mf_name =
"/etc/grid-security/grid-mapfile";
145 PRINT(tracer,
"OucGMap",
"cannot access grid map file '"<< mf_name
146 <<
"' in read mode; " <<
XrdSysE2T(errno));
152 if (load(mf_name.
c_str()) != 0) {
153 PRINT(tracer,
"OucGMap",
"unable to load file "<<mf_name<<
" - aborting");
163 int XrdOucGMap::load(
const char *mf,
bool force)
174 PRINT(tracer,
"OucGMap::load",
"cannot access grid map file '"
177 if (errno == ENOENT) mappings.
Purge();
181 #if defined(__APPLE__)
182 if (mf_mtime > 0 && (mf_mtime >= st.st_mtimespec.tv_sec) && !force) {
184 if (mf_mtime > 0 && (mf_mtime >= st.st_mtim.tv_sec) && !force) {
186 DEBUG(dbg, tracer,
"OucGMap::load",
"map information up-to-date: no need to load");
198 const char *inst = getenv(
"XRDINSTANCE") ? getenv(
"XRDINSTANCE") :
"gmap config instance";
202 if ( (fD =
open(mf_name.
c_str(), O_RDONLY, 0)) < 0) {
203 PRINT(tracer,
"OucGMap::load",
"map file '"<<mf_name
204 <<
"' could not be open; " <<
XrdSysE2T(errno));
213 while ((var = mapf.GetLine())) {
214 int len = strlen(var);
215 if (len < 2)
continue;
216 if (var[0] ==
'#')
continue;
233 char stype[20] = {
"matching"};
240 strcpy(stype,
"beginning with");
242 if (p[l0-1] ==
'$') {
246 strcpy(stype,
"ending with");
247 }
else if (p[l0-1] ==
'+') {
251 strcpy(stype,
"containing");
260 if (usr.length() > 0) {
262 DEBUG(dbg, tracer,
"XrdOucGMap::load",
"mapping DN: '"<<udn<<
"' to user: '"<< usr <<
"' (type:'"<< stype <<
"')");
264 PRINT(tracer,
"OucGMap::load",
"ERROR: incomplete line found in file '"
265 <<mf_name <<
"': "<<var<<
" - skipping");
270 if ((rc = mapf.LastError())) {
271 PRINT(tracer,
"OucGMap::load",
"ERROR: reading file '"<<mf_name<<
"'; "
279 #if defined(__APPLE__)
280 mf_mtime = st.st_mtimespec.tv_sec;
282 mf_mtime = st.st_mtim.tv_sec;
298 if (user && ulen > 0) {
299 memset(user,
'\0', ulen);
301 PRINT(tracer,
"OucGMap::dn2user",
302 "buffer for the user name is undefined or has undefined length");
309 if (now <= 0) now = time(0);
310 if (notafter < now) {
312 if (load(mf_name.
c_str()) != 0) {
313 PRINT(tracer,
"OucGMap::dn2user",
314 "problems loading file "<<mf_name);
317 if (timeout > 0) notafter = now + (time_t) timeout;
329 if ((mc = mappings.
Find(dn))) {
340 if (mc->user.length() > 0) {
342 strncpy(user, mc->user.c_str(), ul);
349 DEBUG(dbg, tracer,
"XrdOucGMap::dn2user",
"mapping DN '"<<dn<<
"' to '"<<user<<
"'");
351 DEBUG(dbg, tracer,
"XrdOucGMap::dn2user",
"no valid match found for DN '"<<dn<<
"'");
static XrdSysError eDest(0,"crypto_")
#define DEBUG(d, t, n, y)
static int FindMatchingCondition(const char *, XrdSecGMapEntry_t *mc, void *xmp)
XrdOucGMap * XrdOucgetGMap(XrdOucGMapArgs)
int stat(const char *path, struct stat *buf)
int open(const char *path, int oflag,...)
int access(const char *path, int amode)
const char * XrdSysE2T(int errcode)
XrdOucGMap(XrdOucGMapArgs)
bool isValid() const
Validity checker.
virtual int dn2user(const char *dn, char *user, int ulen, time_t now=0)
T * Apply(int(*func)(const char *, T *, void *), void *Arg)
T * Add(const char *KeyVal, T *KeyData, const int LifeTime=0, XrdOucHash_Options opt=Hash_default)
T * Find(const char *KeyVal, time_t *KeyTime=0)
const char * c_str() const
int erasefromstart(int sz=0)
int matches(const char *s, char wch=' *')
int find(const char c, int start=0, bool forward=1)
bool isdigit(int from=0, int to=-1)
long atoi(int from=0, int to=-1)
void Lock(const XrdSysXS_Type usage)
void UnLock(const XrdSysXS_Type usage=xs_None)