XRootD
Loading...
Searching...
No Matches
XrdSecgsiGMAPFunDN.cc File Reference
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cerrno>
#include "XrdVersion.hh"
#include "XrdOuc/XrdOucHash.hh"
#include "XrdOuc/XrdOucString.hh"
#include "XrdOuc/XrdOucTrace.hh"
#include "XrdSys/XrdSysError.hh"
#include "XrdSys/XrdSysLogger.hh"
+ Include dependency graph for XrdSecgsiGMAPFunDN.cc:

Go to the source code of this file.

Classes

class  XrdSecgsiMapEntry_t
 

Macros

#define DEBUG(y)   if (dnTrace && (dnTrace->What & TRACE_Authen)) PRINT(y)
 
#define EPNAME(x)   static const char *epname = x;
 
#define PRINT(y)   {if (dnTrace) {dnTrace->Beg(epname); std::cerr <<y; dnTrace->End();}}
 
#define TRACE_Authen   0x0002
 

Enumerations

enum  XrdSecgsi_Match {
  kFull = 0 ,
  kBegins = 1 ,
  kEnds = 2 ,
  kContains = 4
}
 

Functions

static int FindMatchingCondition (const char *, XrdSecgsiMapEntry_t *mc, void *xmp)
 
char * XrdSecgsiGMAPFun (const char *dn, int now)
 
int XrdSecgsiGMAPInit (const char *cfg)
 
 XrdVERSIONINFO (XrdSecgsiGMAPFun, secgsigmap)
 

Variables

static XrdSysError dnDest (0, "gmapdn_")
 
static XrdSysLogger dnLogger
 
static XrdOucTracednTrace = 0
 
static XrdOucHash< XrdSecgsiMapEntry_tgMappings
 

Macro Definition Documentation

◆ DEBUG

#define DEBUG (   y)    if (dnTrace && (dnTrace->What & TRACE_Authen)) PRINT(y)

Definition at line 55 of file XrdSecgsiGMAPFunDN.cc.

◆ EPNAME

#define EPNAME (   x)    static const char *epname = x;

Definition at line 53 of file XrdSecgsiGMAPFunDN.cc.

◆ PRINT

#define PRINT (   y)    {if (dnTrace) {dnTrace->Beg(epname); std::cerr <<y; dnTrace->End();}}

Definition at line 54 of file XrdSecgsiGMAPFunDN.cc.

◆ TRACE_Authen

#define TRACE_Authen   0x0002

Definition at line 52 of file XrdSecgsiGMAPFunDN.cc.

Enumeration Type Documentation

◆ XrdSecgsi_Match

Enumerator
kFull 
kBegins 
kEnds 
kContains 

Definition at line 68 of file XrdSecgsiGMAPFunDN.cc.

68 {kFull = 0,
69 kBegins = 1,
70 kEnds = 2,
71 kContains = 4
72 };
@ kContains

Function Documentation

◆ FindMatchingCondition()

static int FindMatchingCondition ( const char *  ,
XrdSecgsiMapEntry_t mc,
void *  xmp 
)
static

Definition at line 91 of file XrdSecgsiGMAPFunDN.cc.

92{
93 // Print content of entry 'ui' and go to next
94
96
97 bool match = 0;
98 if (mc && mpe) {
99 if (mc->type == kContains) {
100 if (mpe->val.find(mc->val) != STR_NPOS) match = 1;
101 } else if (mc->type == kBegins) {
102 if (mpe->val.beginswith(mc->val)) match = 1;
103 } else if (mc->type == kEnds) {
104 if (mpe->val.endswith(mc->val)) match = 1;
105 } else {
106 if (mpe->val.matches(mc->val.c_str())) match = 1;
107 }
108 if (match) mpe->user = mc->user;
109 }
110
111 // We stop if matched, otherwise we continue
112 return (match) ? 1 : 0;
113}
#define STR_NPOS
bool endswith(char c)
bool beginswith(char c)
int matches(const char *s, char wch=' *')
int find(const char c, int start=0, bool forward=1)
const char * c_str() const

References XrdOucString::beginswith(), XrdOucString::c_str(), XrdOucString::endswith(), XrdOucString::find(), kBegins, kContains, kEnds, XrdOucString::matches(), STR_NPOS, XrdSecgsiMapEntry_t::type, XrdSecgsiMapEntry_t::user, and XrdSecgsiMapEntry_t::val.

Referenced by XrdSecgsiGMAPFun().

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

◆ XrdSecgsiGMAPFun()

char * XrdSecgsiGMAPFun ( const char *  dn,
int  now 
)

Definition at line 123 of file XrdSecgsiGMAPFunDN.cc.

124{
125 // Implementation of XrdSecgsiGMAPFun extracting the information from the
126 // distinguished name 'dn'
127 EPNAME("GMAPFunDN");
128
129 // Init the relevant fields (only once)
130 if (now <= 0) {
131 if (XrdSecgsiGMAPInit(dn) != 0)
132 return (char *)-1;
133 return (char *)0;
134 }
135
136 // Output
137 char *name = 0;
138
139 XrdSecgsiMapEntry_t *mc = 0;
140 // Try the full match first
141 if ((mc = gMappings.Find(dn))) {
142 // Get the associated user
143 name = new char[mc->val.length() + 1];
144 strcpy(name, mc->val.c_str());
145 } else {
146 // Else scan the available mappings
147 mc = new XrdSecgsiMapEntry_t(dn, "", kFull);
148 gMappings.Apply(FindMatchingCondition, (void *)mc);
149 if (mc->user.length() > 0) {
150 name = new char[mc->user.length() + 1];
151 strcpy(name, mc->user.c_str());
152 }
153 }
154 if (name) {
155 DEBUG("mapping DN '"<<dn<<"' to '"<<name<<"'");
156 } else {
157 DEBUG("no valid match found for DN '"<<dn<<"'");
158 }
159
160 // Done
161 return name;
162}}
#define EPNAME(x)
static int FindMatchingCondition(const char *, XrdSecgsiMapEntry_t *mc, void *xmp)
int XrdSecgsiGMAPInit(const char *cfg)
static XrdOucHash< XrdSecgsiMapEntry_t > gMappings
#define DEBUG(y)
int length() const

References XrdOucString::c_str(), DEBUG, EPNAME, FindMatchingCondition(), gMappings, kFull, XrdOucString::length(), XrdSecgsiMapEntry_t::val, and XrdSecgsiGMAPInit().

+ Here is the call graph for this function:

◆ XrdSecgsiGMAPInit()

int XrdSecgsiGMAPInit ( const char *  cfg)

Definition at line 167 of file XrdSecgsiGMAPFunDN.cc.

168{
169 // Initialize the relevant parameters
170 // parms = "[cfg]|[d|dbg|debug]"
171 // The config file 'cfg' can also be defined by XRDGSIGMAPDNCF.
172 // The flag 'd|dbg|debug' enables some verbosity.
173 // Return 0 on success, -1 otherwise
174 EPNAME("GMAPInitDN");
175
176 bool debug = 0;
177 XrdOucString pps(parms), p, cfg;
178 int from = 0;
179 while ((from = pps.tokenize(p, from, '|')) != -1) {
180 if (p.length() > 0) {
181 if (p == "d" || p == "dbg" || p == "debug") {
182 debug = 1;
183 } else {
184 cfg = p;
185 }
186 }
187 }
188 // Initiate error logging and tracing
190 dnTrace = new XrdOucTrace(&dnDest);
191 if (debug) dnTrace->What |= TRACE_Authen;
192
193 if (cfg.length() <= 0) cfg = getenv("XRDGSIGMAPDNCF");
194 if (cfg.length() <= 0) {
195 PRINT("ERROR: undefined config file path");
196 return -1;
197 }
198
199 FILE *fcf = fopen(cfg.c_str(), "r");
200 if (fcf) {
201 char l[4096], val[4096], usr[256];
202 while (fgets(l, sizeof(l), fcf)) {
203 int len = strlen(l);
204 if (len < 2) continue;
205 if (l[0] == '#') continue;
206 if (l[len-1] == '\n') l[len-1] = '\0';
207 if (sscanf(l, "%4095s %255s", val, usr) >= 2) {
208 XrdOucString stype = "matching";
209 char *p = &val[0];
210 int type = kFull;
211 if (val[0] == '^') {
212 // Starts-with
213 type = kBegins;
214 p = &val[1];
215 stype = "beginning with";
216 } else {
217 int vlen = strlen(val);
218 if (val[vlen-1] == '$') {
219 // Ends-with
220 type = kEnds;
221 val[vlen-1] = '\0';
222 stype = "ending with";
223 } else if (val[vlen-1] == '+') {
224 // Contains
225 type = kContains;
226 val[vlen-1] = '\0';
227 stype = "containing";
228 }
229 }
230 // Register
231 gMappings.Add(p, new XrdSecgsiMapEntry_t(p, usr, type));
232 //
233 DEBUG("mapping DNs "<<stype<<" '"<<p<<"' to '"<<usr<<"'");
234 }
235 }
236 fclose(fcf);
237 } else {
238 PRINT("ERROR: config file '"<<cfg<<"' could not be open (errno: "<<errno<<")");
239 return -1;
240 }
241 // Done
242 return 0;
243}
int fclose(FILE *stream)
#define fopen(a, b)
Definition XrdPosix.hh:54
#define PRINT(y)
#define TRACE_Authen
static XrdSysError dnDest(0, "gmapdn_")
static XrdSysLogger dnLogger
static XrdOucTrace * dnTrace
XrdSysLogger * logger(XrdSysLogger *lp=0)

References XrdOucString::c_str(), DEBUG, dnDest, dnLogger, dnTrace, EPNAME, fclose(), fopen, gMappings, kBegins, kContains, kEnds, kFull, XrdOucString::length(), XrdSysError::logger(), PRINT, TRACE_Authen, and XrdOucTrace::What.

Referenced by XrdSecgsiGMAPFun().

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

◆ XrdVERSIONINFO()

XrdVERSIONINFO ( XrdSecgsiGMAPFun  ,
secgsigmap   
)

Variable Documentation

◆ dnDest

XrdSysError dnDest(0, "gmapdn_") ( ,
"gmapdn_"   
)
static

Referenced by XrdSecgsiGMAPInit().

◆ dnLogger

XrdSysLogger dnLogger
static

Definition at line 49 of file XrdSecgsiGMAPFunDN.cc.

Referenced by XrdSecgsiGMAPInit().

◆ dnTrace

XrdOucTrace* dnTrace = 0
static

Definition at line 50 of file XrdSecgsiGMAPFunDN.cc.

Referenced by XrdSecgsiGMAPInit().

◆ gMappings

XrdOucHash<XrdSecgsiMapEntry_t> gMappings
static

Definition at line 84 of file XrdSecgsiGMAPFunDN.cc.

Referenced by XrdSecgsiGMAPFun(), and XrdSecgsiGMAPInit().