35 #include <sys/types.h>
38 #include "XrdVersion.hh"
57 #define DEBUG(x) {if (DebugON) std::cerr <<"sec_PM: " <<x <<std::endl;}
78 protargs = (parg ? strdup(parg): (
char *)
"");
114 if ((plp = Lookup(pid)))
135 if ((pl = Lookup(pname)))
136 {
DEBUG(
"Using " <<pname <<
" protocol, args='"
138 return pl->
ep(
's', hname, endPoint, 0, erp);
144 msgv[1] =
" security protocol is not supported.";
154 char secbuff[4096], *nscan, *pname, *pargs, *bp = secbuff;
171 if (!fwdCreds) eri = 0;
174 if (!eri || (
envP = eri->
getEnv()) == 0) wp = 0;
175 else wp =
envP->
Get(
"xrd.wantprot");
180 const char *wantProt = wp ? (
const char *)wp : getenv(
"XrdSecPROTOCOL");
181 erp = (eri) ? eri : &ei;
190 {i = strlen(wantProt);
191 compProt = (
char *)malloc(i+3);
193 strcpy(compProt+1, wantProt);
194 compProt[i+1] =
','; compProt[i+2] = 0; *pcomp =
',';
200 if (secparm.
size < (
int)
sizeof(secbuff)) i = secparm.
size;
201 else i =
sizeof(secbuff)-1;
202 strncpy(secbuff, secparm.
buffer, i);
208 {
if (*bp !=
'&') {bp++;
continue;}
209 else if (!*(++bp) || *bp !=
'P' || !*(++bp) || *bp !=
'=')
continue;
210 bp++; pname = bp; pargs = 0;
211 while(*bp && *bp !=
',' && *bp !=
'&') bp++;
213 else {
if (*bp ==
'&') {*bp =
'\0'; pargs = 0; nscan = bp;}
214 else {*bp =
'\0'; pargs = ++bp;
215 while (*bp && *bp !=
'&') bp++;
216 if (*bp) {*bp =
'\0'; nscan = bp;}
225 if (!wantProt || strstr(compProt, pcomp))
227 if ((pl = Lookup(pname)) || (pl = ldPO(erp,
'c', pname)))
228 {
DEBUG(
"Using " <<pname <<
" protocol, args='"
229 <<(pargs ? pargs :
"") <<
"'");
230 if ((pp = pl->
ep(
'c', hname, endPoint, pargs, erp)))
231 {
if (nscan) {i = nscan - secbuff;
233 }
else secparm.
size = -1;
234 if (compProt) free(compProt);
239 }
else {
DEBUG(
"Skipping " <<pname <<
" only want " <<wantProt);}
241 *nscan =
'&'; bp = nscan;
244 if (compProt) free(compProt);
265 {
eMsg->setErrInfo(-1,
"XrdSec: Too many protocols defined.");
271 if (parg && !strncmp(parg,
"TLS:",4))
274 strcpy(pBuff+1, pid);
275 if (!tlsProt) tlsProt = strdup(pBuff);
276 else {std::string tmp(tlsProt);
279 tlsProt = strdup(tmp.c_str());
290 if (Last) {Last->
Next = plp; Last = plp;}
291 else First = Last = plp;
293 if (protnum & 0x40000000) protnum = 0;
294 else protnum = protnum<<1;
306 #define INITPARMS const char, const char *, XrdOucErrInfo *
317 XrdVersionInfo *myVer = (pmode ==
'c' ? &clVer : &srVer);
321 const char *sep, *libloc;
322 char poname[80], libpath[2048], *newargs, *bP;
335 snprintf(poname,
sizeof(poname),
"libXrdSec%s.so", pid);
336 i = (spath ? strlen(spath) : 0);
337 if (!i) {spath =
""; sep =
"";}
338 else sep = (spath[i-1] ==
'/' ?
"" :
"/");
339 snprintf(libpath,
sizeof(libpath),
"%s%s%s", spath, sep, poname);
344 if (errP) secLib =
new XrdOucPinLoader(errP, myVer,
"sec.protocol", libloc);
345 else {bP =
eMsg->getMsgBuff(i);
352 snprintf(poname,
sizeof(poname),
"XrdSecProtocol%sObject", pid);
354 {secLib->
Unload(
true);
return 0;}
358 sprintf(poname,
"XrdSecProtocol%sInit", pid);
360 {secLib->
Unload(
true);
return 0;}
364 libloc = secLib->
Path();
365 DEBUG(
"Loaded " <<pid <<
" protocol object from " <<libpath);
369 if (!(newargs = ip(pmode, (pmode ==
'c' ? 0 : parg),
eMsg)))
370 {
if (!*(
eMsg->getErrText()))
371 {
const char *eTxt[] = {
"XrdSec: ", pid,
372 " initialization failed in sec.protocol ", libloc};
373 eMsg->setErrInfo(-1, eTxt,
sizeof(eTxt));
382 return Add(
eMsg, pid, ep, newargs);
402 while(plp && strcmp(plp->
protid, pid)) plp = plp->
Next;
XrdSecProtocol * XrdSecGetProtocol(const char *hostname, XrdNetAddrInfo &endPoint, XrdSecParameters &parms, XrdOucErrInfo *einfo)
#define XrdSecPROTOIDSIZE
XrdVERSIONINFO(XrdSecGetProtocol, secprot)
XrdSecProtocol * XrdSecProtocolhostObject(const char who, const char *hostname, XrdNetAddrInfo &endPoint, const char *parms, XrdOucErrInfo *einfo)
XrdSecService * XrdSecgetService(XrdSysLogger *lp, const char *cfn)
static int Export(const char *Var, const char *Val)
char * Get(const char *varname)
const char * getErrText()
int setErrInfo(int code, const char *emsg)
void * Resolve(const char *symbl, int mcnt=1)
void Unload(bool dodel=false)
XrdSecPMask_t Find(const char *pid, char **parg=0)
XrdSecProtocol * Get(const char *hname, XrdNetAddrInfo &endPoint, const char *pname, XrdOucErrInfo *erp)
XrdSecProtocol *(* ep)(PROTPARMS)
char protid[XrdSecPROTOIDSIZE+1]
XrdSecProtList(const char *pid, const char *parg, bool tls)
XrdVERSIONINFODEF(myVersion, cmsclient, XrdVNUMBER, XrdVERSION)
Generic structure to pass security information back and forth.
char * buffer
Pointer to the buffer.
int size
Size of the buffer or length of data in the buffer.