36 #include <sys/param.h>
37 #include <sys/types.h>
41 #include "XrdVersion.hh"
80 #define Duplicate(x,y) if (y) free(y); y = strdup(x)
82 #define TS_String(x,m) if (!strcmp(x,var)) {Duplicate(val,m); return 0;}
84 #define TS_Xeq(x,m) if (!strcmp(x,var)) return m(&eDest, Config);
86 #define TS_PSX(x,m) if (!strcmp(x,var)) \
87 return (psxConfig->m(&eDest, Config) ? 0 : 1);
89 #define TS_DBG(x,m) if (!strcmp(x,var)) {SysTrace.What |= m; return 0;}
150 std::vector<const char *> protVec;
173 myHost = getenv(
"XRDHOST");
187 if (getenv(
"XRDDEBUG"))
188 {psxConfig->traceLvl = 4;
210 if ((NoGo = ConfigProc(cfn)))
return NoGo;
214 if (!ManList && !
outProxy && !fileOrgn)
215 {
eDest.
Emsg(
"Config",
"Origin for proxy service not specified.");
221 if (sssMap && !ConfigMapID())
return 1;
225 if (LocalRoot) psxConfig->SetRoot(LocalRoot);
229 if (
outProxy && psxConfig->xLfn2Pfn)
231 if (!(psxConfig->xNameLib)) txt =
"localroot directive";
232 else if (psxConfig->xPfn2Lfn) txt =
"namelib -lfn2pfn option";
233 else txt =
"namelib directive";
234 eDest.
Say(
"Config warning: ignoring ",txt,
"; this is forwarding proxy!");
235 psxConfig->xLfn2Pfn =
false;
248 {
eDest.
Say(
"Config warning: ignoring 'pss.reproxy'; TPC is not enabled!");
252 rpFD = XrdSysFD_Open(rPath, O_DIRECTORY);
254 {
eDest.
Emsg(
"Config",
"to open reproxy directory", rPath);
262 if (!(psxConfig->ConfigSetup(
eDest)))
return 1;
270 if (psxConfig->xLfn2Pfn) xLfn2Pfn = (
theN2N = psxConfig->theN2N) != 0;
292 if (Streams)
sidP =
new XrdOucSid((Streams > 8192 ? 8192 : Streams));
303 {
eDest.
Emsg(
"Config",
"Unable to add origin protocol to protocol list.");
310 {
for (
int i = 0; i < (int)protVec.size(); i++)
312 {
eDest.
Emsg(
"Config",
"Unable to add", protVec[i],
313 "protocol to protocol list.");
322 const char *outeq = (
outProxy ?
"= " :
"");
323 if (ManList) sprintf(theRdr,
"%s%s:%d", outeq, ManList->text, ManList->val);
324 else if (fileOrgn) sprintf(theRdr,
"%s%s", outeq, fileOrgn);
325 else strcpy(theRdr, outeq);
332 {hdrLen = sprintf(theRdr,
"%s%%s%s:%d/%%s",
333 protName, ManList->text, ManList->val);
334 hdrData = strdup(theRdr);
341 {hdrLen = sprintf(theRdr,
"%s%s%%s", protName, fileOrgn);
342 hdrData = strdup(theRdr);
377 deferID = psxConfig->hasCache();
383 {
eDest.
Emsg(
"Config",
"Client personas are not supported for "
384 "caching proxy servers.");
394 {
eDest.
Emsg(
"Config",
"Client personas are not supported for "
395 "strictly forwarding proxy servers.");
398 eDest.
Say(
"Config warning: client personas only apply to "
399 "the origin server!");
412 {
eDest.
Emsg(
"Config",
"Unable to render persona; persona mapper failed!");
430 int XrdPssSys::ConfigProc(
const char *Cfn)
433 int cfgFD, retc, NoGo = 0;
440 {
eDest.
Emsg(
"Config",
"pss configuration file not specified.");
446 if ( (cfgFD =
open(Cfn, O_RDONLY, 0)) < 0)
447 {
eDest.
Emsg(
"Config", errno,
"open config file", Cfn);
451 static const char *cvec[] = {
"*** pss (oss) plugin config:", 0 };
456 while((var =
Config.GetMyFirstWord()))
457 {
if (!strncmp(var,
"pss.", 4)
458 || !strcmp(var,
"oss.defaults")
459 || !strcmp(var,
"all.export"))
460 if (ConfigXeq(var+4,
Config)) {
Config.Echo(); NoGo = 1;}
465 if ((retc =
Config.LastError()))
466 NoGo =
eDest.
Emsg(
"Config", retc,
"read config file", Cfn);
471 XPList.Set(DirFlags);
484 char myVar[80], *val;
488 TS_PSX(
"namelib", ParseNLib);
489 TS_PSX(
"memcache", ParseCache);
490 TS_PSX(
"cache", ParseCache);
491 TS_PSX(
"cachelib", ParseCLib);
492 TS_PSX(
"ccmlib", ParseMLib);
493 TS_PSX(
"ciosync", ParseCio);
499 TS_PSX(
"inetmode", ParseINet);
503 TS_PSX(
"setopt", ParseSet);
504 TS_PSX(
"trace", ParseTrace);
506 if (!strcmp(
"reproxy", var))
516 strlcpy(myVar, var,
sizeof(myVar)); var = myVar;
517 if (!(val =
Config.GetWord()))
518 {
eDest.
Emsg(
"Config",
"no value for directive", var);
528 eDest.
Say(
"Config warning: ignoring unknown directive '",var,
"'.");
552 struct Xtab {
const char *Key;
int *Val;} Xopts[] =
553 {{
"streams", &Streams},
554 {
"workers", &Workers}};
555 int i, numopts =
sizeof(Xopts)/
sizeof(
struct Xtab);
557 if (!(val =
Config.GetWord()))
558 {Eroute->
Emsg(
"Config",
"options argument not specified.");
return 1;}
560 do{
for (i = 0; i < numopts; i++)
if (!strcmp(Xopts[i].Key, val))
break;
563 Eroute->
Say(
"Config warning: ignoring unknown config option '",val,
"'.");
564 else {
if (!(val =
Config.GetWord()))
565 {Eroute->
Emsg(
"Config",
"config",Xopts[i].Key,
"value not specified.");
569 kval = strtol(val, &kvp, 10);
571 {Eroute->
Emsg(
"Config", Xopts[i].Key,
572 "config value is invalid -", val);
575 *(Xopts[i].Val) = kval;
578 }
while(val && *val);
600 static const int maxsz = 0x7fffffff;
611 while((val =
Config.GetWord()))
612 {
if (!strcmp(val,
"world")) dcaWorld =
true;
613 else if (!strcmp(val,
"group")) dcaWorld =
false;
614 else if (!strcmp(val,
"recheck"))
615 {
if (!strcmp(val,
"off")) dcaCTime = 0;
616 else {
if (!(val =
Config.GetWord()))
617 {errp->
Emsg(
"Config",
618 "dca recheck value not specified");
622 &dcaCTime,10,maxsz))
return 1;
625 else {errp->
Emsg(
"Config",
"invalid dca option -", val);
return 1;}
701 char *val, *colon, *slash, *mval = 0;
707 if (!(val =
Config.GetWord()))
708 {errp->
Emsg(
"Config",
"origin host name not specified");
return 1;}
715 {std::vector<char *> pVec;
716 char *pData = strdup(val+1);
720 {errp->
Emsg(
"Config",
"Malformed forwarding specification");
724 protVec.reserve(pVec.size());
725 for (
int i = 0; i < (int)pVec.size(); i++)
726 {
int n = strlen(pVec[i]);
728 {errp->
Emsg(
"Config",
"Unsupported forwarding protocol -",pVec[i]);
732 protVec.push_back(pName);
736 if (!(val =
Config.GetWord()))
return 0;
742 if (fileOrgn) {free(fileOrgn); fileOrgn = 0;}
747 {
char *vP = val +strlen(val) - 1;
748 while(*vP ==
'/'&& vP != val) {*vP-- = 0;}
749 if (ManList) {
delete ManList; ManList = 0;}
750 protName =
"file://";
751 fileOrgn = strdup(val);
758 if ((colon = index(val,
':')) && *(colon+1) ==
'/' && *(colon+2) ==
'/')
762 {errp->
Emsg(
"Config",
"Unsupported origin protocol -", val);
765 if (*val ==
'x') protName++;
768 if ((slash = index(val,
'/')))
770 {errp->
Emsg(
"Config",
"badly formed origin URL");
return 1;}
776 protName =
"root://";
784 if (!(val = index(mval,
':')) && !isURL) val =
Config.GetWord();
785 else if (val) {*val =
'\0'; val++;}
790 {errp->
Emsg(
"Config",
"origin host name not specified");
return 1;}
800 {errp->
Emsg(
"Config",
"unable to find tcp service", val);
806 port = *protName ==
'h' ? (strncmp(protName,
"https", 5) == 0 ? 443 : 80) : 1094;
811 errp->
Say(
"Config warning: origin port not specified, using port ",
812 std::to_string(port).c_str(),
" as default for ", protName);
817 if (!port) {free(mval);
return 1;}
821 if ((i = strlen(mval)) > 1 && mval[i-1] ==
'+') mval[i-1] = 0;
832 if (ManList)
delete ManList;
838 if (!index(mval,
'.')
840 && !strcmp(protName,
"http://") && !strcmp(protName,
"https://")))
865 bool pType[PolNum] = {
false,
false};
868 do {
if (!(val =
Config.GetWord()))
869 {Eroute->
Emsg(
"Config",
"permit target not specified");
return 1;}
870 if (!strcmp(val,
"/")) pType[PolPath] =
true;
871 else if (!strcmp(val,
"*")) pType[PolObj ] =
true;
875 if (!pType[PolPath] && !pType[PolObj])
876 pType[PolPath] = pType[PolObj] =
true;
878 for (i = 0; i < PolNum; i++)
881 Police[i]->AddHost(val);
910 bool isClient =
false, strict =
false;
915 if (!(val =
Config.GetWord()))
916 {Eroute->
Emsg(
"Config",
"persona not specified");
return 1;}
920 if (!strcmp(val,
"client")) isClient =
true;
921 else if (!strcmp(val,
"server")) isClient =
false;
922 else {Eroute->
Emsg(
"Config",
"Invalid persona - ", val);
return 1;}
926 while ((val =
Config.GetWord()))
927 {
if (!strcmp(val,
"strict" )) strict =
true;
928 else if (!strcmp(val,
"nonstrict" )) strict =
false;
929 else if (!strcmp(val,
"verify" )) doVer = 1;
930 else if (!strcmp(val,
"noverify" )) doVer = 0;
931 else {Eroute->
Emsg(
"Config",
"Invalid persona option - ", val);
939 {
idMapAll = (strict ? true :
false);
940 if (doVer < 0) doVer = 1;
int open(const char *path, int oflag,...)
static int ServPort(const char *sName, bool isUDP=false, const char **eText=0)
static int Export(const char *Var, const char *Val)
char * Get(const char *varname)
static unsigned long long ParseDefs(XrdOucStream &Config, XrdSysError &Eroute, unsigned long long Flags)
static XrdOucPList * ParsePath(XrdOucStream &Config, XrdSysError &Eroute, XrdOucPListAnchor &Export, unsigned long long Defopts)
static const char * InstName(int TranOpt=0)
static int a2i(XrdSysError &, const char *emsg, const char *item, int *val, int minv=-1, int maxv=-1)
static int a2tm(XrdSysError &, const char *emsg, const char *item, int *val, int minv=-1, int maxv=-1)
static void SetEnv(const char *kword, int kval)
static void setOids(bool isok)
static XrdSecsssCon * conTracker(bool debug=false)
static bool SetConfig(XrdOucPsx &parms)
static bool AddProto(const char *proto)
POSIX interface to XRootD with some extensions, as noted.
static const char * ConfigFN
static const char * hdrData
static XrdOucTList * ManList
static XrdNetSecurity * Police[PolNum]
static const char * myName
static XrdOucPListAnchor XPList
static const char * myHost
static const char * protName
static void setMapID(bool onoff)
static const char * getDomain(const char *hName)
static const char * valProt(const char *pname, int &plen, int adj=0)
static bool Vectorize(char *str, std::vector< char * > &vec, char sep)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)
XrdSysLogger * logger(XrdSysLogger *lp=0)
XrdSysTrace SysTrace("Pss", 0)
XrdSysError eDest(0, "pss_")
static XrdPosixXrootd * Xroot