73 #include "XrdVersion.hh"
110 const int g_certificate_format = 1;
111 const int g_maxvolen = 255;
112 static char *g_valido = 0;
113 static char *g_vo2grp = 0;
114 static char *g_vo2usr = 0;
115 static int g_debug = 0;
116 static int g_cn2usr = 1;
124 #define PRINT(y) if (g_debug) {std::cerr << y << "\n";}
127 std::cerr <<inf_pfx <<"entity." #_x_ "='" <<(entity._x_ ? entity._x_ : "") <<"'.\n"
142 static const char* inf_pfx =
"INFO in AuthzFun: ";
144 const char *vtxt =
"", *etxt = 0;
145 char vbuff[(g_maxvolen+1)*2];
151 if (!entity.
vorg) etxt =
"missing";
152 else if ((n = strlen(entity.
vorg)) > g_maxvolen) etxt =
"too long";
155 strcpy(vbuff+1, entity.
vorg);
156 if (!strstr(g_valido, vbuff))
157 {vtxt = entity.
vorg; etxt =
" not allowed";}
163 {std::cerr <<
"AuthzVO: Invalid cert; vo " <<vtxt <<etxt <<std::endl;
170 {snprintf(vbuff,
sizeof(vbuff), g_vo2grp, entity.
vorg);
172 entity.
grps = strdup(vbuff);
178 {snprintf(vbuff,
sizeof(vbuff), g_vo2usr, entity.
vorg);
180 entity.
name = strdup(vbuff);
181 }
else if (g_cn2usr && entity.
name && (vtxt=strstr(entity.
name,
"/CN=")))
183 strncpy(vbuff, vtxt+4, g_maxvolen); vbuff[n] = 0;
184 while(*cP) {
if (*cP ==
' ') *cP =
'_'; cP++;}
185 for (i = n-1; i >= 0; i--) {
if (*cP ==
'_') *cP = 0;}
187 {
if (entity.
name) free(entity.
name);
188 entity.
name = strdup(vbuff);
215 static const char* err_pfx =
"ERR in AuthzKey: ";
216 static const char* inf_pfx =
"INFO in AuthzKey: ";
220 PRINT(err_pfx <<
"'key' is not defined!");
224 PRINT(inf_pfx <<
"Returning creds of len " << entity.
credslen <<
" as key.");
227 *key =
new char[entity.
credslen + 1];
228 strcpy(*key, entity.
creds);
244 static const char* inf_pfx =
"INFO in AuthzInit: ";
246 char cfgbuff[2048], *sP;
254 if (i >= (
int)
sizeof(cfgbuff)) i =
sizeof(cfgbuff)-1;
255 memcpy(cfgbuff, cfg, i);
257 if ((sP = index(cfgbuff,
' '))) *sP = 0;
259 if (!cfg || !(*cfg))
return g_certificate_format;
267 if ((sP =
envP->
Get(
"debug")) && *sP ==
'1') g_debug = 1;
271 if ((g_vo2grp =
envP->
Get(
"vo2grp"))) g_vo2grp = strdup(g_vo2grp);
272 if ((g_vo2usr =
envP->
Get(
"vo2usr")))
274 g_vo2usr = (!strcmp(g_vo2usr,
"*") ? 0 : strdup(g_vo2usr));
279 if ((sP =
envP->
Get(
"valido")))
281 g_valido = (
char *)malloc(i+2);
283 strcpy(g_valido+1, sP);
292 PRINT(inf_pfx <<
"cfg='"<< (cfg ? cfg :
"null") <<
"'.");
293 return g_certificate_format;
XrdVERSIONINFO(XrdSecgsiAuthzFun, secgsiauthz)
int XrdSecgsiAuthzKey(XrdSecEntity &entity, char **key)
int XrdSecgsiAuthzFun(XrdSecEntity &entity)
int XrdSecgsiAuthzInit(const char *cfg)
char * Get(const char *varname)
char * vorg
Entity's virtual organization(s)
int credslen
Length of the 'creds' data.
char * creds
Raw entity credentials or cert.
char * grps
Entity's group name(s)
char * name
Entity's name.