36#include <unordered_set>
44#include "XrdSys/XrdWin32.hh"
68#define ENODATA ENOATTR
81 idInfo(
const char *name, time_t keep)
82 : Expr(time(0)+keep), Name(strdup(name)) {}
83 ~idInfo() {free(Name);}
86typedef std::map<unsigned int, struct idInfo*> idMap_t;
92void AddID(idMap_t &idMap,
unsigned int id,
const char *name, time_t keepT)
94 std::pair<idMap_t::iterator,bool> ret;
95 idInfo *infoP =
new idInfo(name, keepT);
98 ret = idMap.insert(std::pair<unsigned int, struct idInfo*>(
id, infoP));
99 if (ret.second ==
false)
delete infoP;
103int LookUp(idMap_t &idMap,
unsigned int id,
char *buff,
int blen)
105 idMap_t::iterator it;
110 if (it != idMap.end())
111 {
if (it->second->Expr <= time(0))
115 if (blen > 0) luRet = snprintf(buff, blen,
"%s", it->second->Name);
134for (j = 0; j < argC; j++)
135 {
while(*aP ==
' ') aP++;
138 if (*aP ==
'"' || *aP ==
'\'')
140 aP = index(aP+1, *aP);
141 if (!aP || (*(aP+1) !=
' ' && *(aP+1)))
142 {
if (!j) argV[0] = 0;
return -EINVAL;}
146 if ((aP = index(aP+1,
' '))) *aP++ =
'\0';
154 if (j > argC-1)
return -E2BIG;
169 static const char hv[] =
"0123456789abcdef";
170 char *outbuff = buff;
171 for (
int i = 0; i < dlen && blen > 2; i++) {
172 *outbuff++ = hv[(inbuff[i] >> 4) & 0x0f];
173 *outbuff++ = hv[ inbuff[i] & 0x0f];
175 if (sep && blen > 1 && ((i & 0x03) == 0x03 || i+1 == dlen))
176 {*outbuff++ =
' '; blen--;}
188 int len = 0, lo = -1, hi = -1;
190 while (
int c = *hex++) {
191 if (c ==
' ' || c ==
'\n')
219 bin[len++] = (hi << 4) | lo;
222 if (hi >= 0 || lo >= 0 || len == 0)
233 int tlen = strlen(text);
235 return (tlen >= endlen && !strcmp(text+(tlen-endlen), ending));
280 const char *what,
const char *hname,
281 const char *nname,
const char *pname)
283 static const char *brk[] = {
"defined",
"exec",
"named", 0};
290 if (!(val = Config.GetWord()))
291 {
if (
eDest)
eDest->Emsg(
"Config",
"Host name missing after 'if' in", what);
297 if (!
is1of(val, brk))
299 val = Config.GetWord();
300 }
while(!hostok && val && !
is1of(val, brk));
302 {
while(val && !
is1of(val, brk)) val = Config.GetWord();
310 while(!strcmp(val,
"defined"))
311 {
if (!(val = Config.GetWord()) || *val !=
'?')
313 {
eDest->Emsg(
"Config",
"'?var' missing after 'defined' in",what);}
318 if (!theEnv && (theEnv = Config.SetEnv(0))) Config.SetEnv(theEnv);
319 if (!theEnv && *(val+1) !=
'~')
return 0;
324 while(val && *val ==
'?')
325 {
if (*(val+1) ==
'~' ? getenv(val+2) : theEnv->
Get(val+1)) isDef=1;
326 val = Config.GetWord();
328 if (!val || !isDef)
return isDef;
329 if (strcmp(val,
"&&"))
331 {
eDest->Emsg(
"Config",val,
"is invalid for defined test in",what);}
334 if (!(val = Config.GetWord()))
336 {
eDest->Emsg(
"Config",
"missing keyword after '&&' in",what);}
340 if (!
is1of(val, brk))
342 {
eDest->Emsg(
"Config",val,
"is invalid after '&&' in",what);}
350 if (!strcmp(val,
"exec"))
351 {
if (!(val = Config.GetWord()) || !strcmp(val,
"&&"))
353 {
eDest->Emsg(
"Config",
"Program name missing after 'if exec' in",what);}
359 if (!pname)
return 0;
360 while(val && strcmp(val, pname))
361 if (!strcmp(val,
"&&"))
return 0;
362 else val = Config.GetWord();
364 while(val && strcmp(val,
"&&")) val = Config.GetWord();
367 if (!(val = Config.GetWord()))
369 {
eDest->Emsg(
"Config",
"Keyword missing after '&&' in",what);}
372 if (strcmp(val,
"named"))
374 {
eDest->Emsg(
"Config",val,
"is invalid after '&&' in",what);}
382 if (!(val = Config.GetWord()))
384 {
eDest->Emsg(
"Config",
"Instance name missing after 'if named' in", what);}
390 if (!nname)
return 0;
391 while(val && strcmp(val, nname)) val = Config.GetWord();
409 {
if (
stat(pgm, &
Stat) || !(
Stat.st_mode & S_IXOTH))
return false;
416 const char *pEnv = getenv(
"PATH");
417 if (!pEnv)
return false;
423 prog +=
'/'; prog += pgm;
427 while((from = pList.
tokenize(path, from,
':')) != -1)
440 static const long long Kval = 1024LL;
441 static const long long Mval = 1024LL*1024LL;
442 static const long long Gval = 1024LL*1024LL*1024LL;
443 static const long long Tval = 1024LL*1024LL*1024LL*1024LL;
449 if (val < 1024)
return snprintf(buff, bsz,
"%lld", val);
450 if (val < Mval) {val = val*10/Kval; sName =
'K';}
451 else if (val < Gval) {val = val*10/Mval; sName =
'M';}
452 else if (val < Tval) {val = val*10/Gval; sName =
'G';}
453 else {val = val*10/Tval; sName =
'T';}
454 resid = val%10LL; val = val/10LL;
458 return snprintf(buff, bsz,
"%lld.%d%c", val, resid, sName);
462 static const char* units[] = {
"",
"K",
"M",
"G",
"T",
"P",
"E"};
463 const int maxUnit = 6;
465 double value =
static_cast<double>(size);
468 while (value >=
static_cast<double>(base) && unitIndex < maxUnit) {
469 value /=
static_cast<double>(base);
473 auto ceil_to = [](
double x,
int decimals) {
474 if (x == 0.0)
return 0.0;
475 const double p = std::pow(10.0, decimals);
477 return std::ceil(x * p - 1e-12) / p;
480 auto decimals_for = [](
double x,
int u) {
481 return (u > 0 && x < 10.0) ? 1 : 0;
484 int prec = decimals_for(value, unitIndex);
485 double shown = ceil_to(value, prec);
488 if (shown >=
static_cast<double>(base) && unitIndex < maxUnit) {
489 shown /=
static_cast<double>(base);
492 prec = decimals_for(shown, unitIndex);
493 shown = ceil_to(shown, prec);
496 std::ostringstream out;
497 out << std::fixed << std::setprecision(prec) << shown << units[unitIndex];
509 int i =
strlcpy(buff, p_path,
sizeof(buff));
511 if (buff[i-1] !=
'/') {buff[i++] =
'/'; buff[i] =
'\0';}
512 if (inst) {strcpy(buff+i, inst); strcat(buff,
"/");}
513 if (s_path) strcat(buff, s_path);
516 if (buff[i-1] !=
'/') {buff[i++] =
'/'; buff[i] =
'\0';}
528 j = (psfx ? strlen(psfx) : 0);
529 if (i+j+3 > blen)
return -ENAMETOOLONG;
533 {
if (buff[i-1] !=
'/') buff[i++] =
'/';
534 strcpy(&buff[i], psfx);
535 if (psfx[j-1] !=
'/') strcat(buff,
"/");
550 ~fdHelper() {
if (fd >= 0)
close(fd);}
561 if ((file.fd =
open(path, O_RDONLY)) < 0) {rc = errno;
return 0;}
565 if (
fstat(file.fd, &
Stat)) {rc = errno;
return 0;}
569 if (
Stat.st_size > maxsz) {rc = EFBIG;
return 0;}
573 if (
Stat.st_size == 0 && notempty) {rc =
ENODATA;
return 0;}
577 if ((buff = (
char *)malloc(
Stat.st_size+1)) == 0)
578 {rc = errno;
return 0;}
583 {
if ((flen =
read(file.fd, buff,
Stat.st_size)) < 0)
584 {rc = errno; free(buff);
return 0;}
603 struct group Grp, *result;
606 getgrnam_r(gName, &Grp, buff,
sizeof(buff), &result);
607 if (!result)
return false;
619 struct passwd pwd, *result;
622 getpwnam_r(uName, &pwd, buff,
sizeof(buff), &result);
623 if (!result)
return false;
626 if (gID) *gID = pwd.pw_gid;
637 static const int maxgBsz = 256*1024;
638 static const int addGsz = 4096;
639 struct group *gEnt, gStruct;
640 char gBuff[1024], *gBp = gBuff;
641 int glen = 0, gBsz =
sizeof(gBuff), aOK = 1;
647 {
int n = LookUp(gidMap,
static_cast<unsigned int>(gID),gName,gNsz);
648 if (n > 0)
return (n < gNsz ? n : 0);
654 while(( retVal = getgrgid_r(gID, &gStruct, gBp, gBsz, &gEnt) ) == ERANGE)
655 {
if (gBsz >= maxgBsz) {aOK = 0;
break;}
656 if (gBsz > addGsz) free(gBp);
658 if (!(gBp = (
char *)malloc(gBsz))) {aOK = 0;
break;}
663 if (aOK && retVal == 0 && gEnt != NULL)
665 AddID(gidMap,
static_cast<unsigned int>(gID), gEnt->gr_name, keepT);
666 glen = strlen(gEnt->gr_name);
667 if (glen >= gNsz) glen = 0;
668 else strcpy(gName, gEnt->gr_name);
670 n = snprintf(gName, gNsz,
"%ud",
static_cast<unsigned int>(gID));
671 if (n >= gNsz) glen = 0;
676 if (gBsz > addGsz && gBp) free(gBp);
686 static const int maxgBsz = 256*1024;
687 static const int addGsz = 4096;
688 struct group *gEnt, gStruct;
689 char gBuff[1024], *gBp = gBuff;
690 int glen, gBsz =
sizeof(gBuff), aOK = 1;
696 while(( retVal = getgrgid_r(gID, &gStruct, gBp, gBsz, &gEnt) ) == ERANGE)
697 {
if (gBsz >= maxgBsz) {aOK = 0;
break;}
698 if (gBsz > addGsz) free(gBp);
700 if (!(gBp = (
char *)malloc(gBsz))) {aOK = 0;
break;}
705 if (aOK && retVal == 0 && gEnt != NULL)
706 {glen = strlen(gEnt->gr_name);
707 if (glen >= gNsz) glen = 0;
708 else strcpy(gName, gEnt->gr_name);
713 if (gBsz > addGsz && gBp) free(gBp);
727 {snprintf(buff, bsz,
"%zu", bytes);
733 const char *suffix =
" KMGTPEYZ";
734 double dBytes =
static_cast<double>(bytes);
736do{dBytes /= 1024.0; suffix++;
737 }
while(dBytes >= 1024.0 && *(suffix+1));
742 double whole, frac = modf(dBytes, &whole);
743 if (frac >= .005) snprintf(buff, bsz,
"%.02lf%c", dBytes, *suffix);
744 else snprintf(buff, bsz,
"%g%c", whole, *suffix);
754 char zo[2] = {
'0',
'1'};
756 if (blen < 2)
return "";
759 if (!val) buff[blen--] =
'0';
760 else while(val && blen >= 0)
761 {buff[blen--] = zo[val & 0x01];
765 if (blen >= 0 && pad)
while(blen >= 0) buff[blen--] =
'0';
767 return &buff[blen+1];
776long long genSID(
char *&urSID,
const char *iHost,
int iPort,
777 const char *iName,
const char *iProg)
780 static const uint32_t fpOffs = 2, fpSize = 6;
782 const char *iSite = getenv(
"XRDSITE");
783 unsigned char mDigest[mdLen];
785 union {uint64_t mdLL;
unsigned char mdUC[8];};
789 if (iSite) myID = iSite;
792 if (iName) myID += iName;
797 memset(mDigest, 0,
sizeof(mDigest));
807 uint64_t fpPos =
crc32c % (((uint32_t)mdLen) - fpSize);
809 memcpy(mdUC+fpOffs, mDigest+fpPos, fpSize);
810 long long fpVal =
static_cast<long long>(ntohll(mdLL));
815 snprintf(fpBuff,
sizeof(fpBuff),
"%lld", fpVal);
816 urSID = strdup(fpBuff);
822 const char *iHost,
const char *iProg,
823 const char *iName,
int iPort)
826 static long long theSID = genSID(theSIN, iHost, iPort, iName, iProg);
827 const char *sP = getenv(
"XRDSITE");
829 int myPid =
static_cast<int>(getpid());
833 if (
UserName(getuid(), uName,
sizeof(uName)))
834 sprintf(uName,
"%d",
static_cast<int>(getuid()));
838 snprintf(iBuff,iBlen,
"%s.%d:%s@%s\n&site=%s&port=%d&inst=%s&pgm=%s",
839 uName, myPid, theSIN, iHost, (sP ? sP :
""), iPort, iName, iProg);
843 h2nll(theSID, mySID);
844 return strdup(theSIN);
853 const char *iName = getenv(
"XRDNAME");
857 if (!TranOpt)
return iName;
862 if (TranOpt > 0) {
if (!iName || !*iName) iName =
"anon";}
863 else if (iName && !strcmp(iName,
"anon")) iName = 0;
869{
return (Fillit ? name && *name ? name :
"anon"
870 : name && strcmp(name,
"anon") && *name ? name : 0);
880 while(clist[i])
if (!strcmp(val, clist[i]))
return 1;
892 const char *hName, *hNend, *hPort, *hPend, *hP = path;
896 if (*path ==
'/') hP++;
897 if (*hP ==
'x') hP++;
898 if (strncmp(
"root:/", hP, 6))
return 0;
899 if (hBuff == 0 || hBLen <= 0)
return (hP - path) + 6;
903 if (*hNend ==
']') hNend++;
904 else {
if (!(*hNend) && !(hNend = index(hName,
'/')))
return 0;
905 if (!(*hPend)) hPend = hNend;
908 if (pTrim || !(*hPort)) n = hNend - hP;
910 if (n >= hBLen)
return 0;
911 strncpy(hBuff, hP, n);
915 {
if (*hNend !=
':') *port = 0;
916 else {*port = strtol(hPort, &eP, 10);
917 if (*port < 0 || *port > 65535 || eP != hPend)
return 0;
941 #define SHFT(k) if (n >= (1ULL << k)) { i += k; n >>= k; }
956 #define SHFT(k, m) if (n >= m) { i += k; n /= m; }
958 SHFT(16,10000000000000000ULL);
SHFT(8,100000000ULL);
973 if (!inst || !getcwd(buff,
sizeof(buff)))
return;
975 strcat(buff,
"/"); strcat(buff, inst);
977 {
eDest.Emsg(
"Config", errno,
"create home directory", buff);
982 eDest.Emsg(
"Config", errno,
"chdir to home directory", buff);
988 const char *path, mode_t mode)
991 const char *slash =
"", *slash2 =
"";
997 if (!path || !(n = strlen(path)))
1004 if (path[n-1] !=
'/') slash =
"/";
1005 if (!inst || !(n = strlen(inst))) inst =
"";
1007 n = snprintf(cwDir,
sizeof(cwDir),
"%s%s%s%s", path, slash, inst, slash2);
1008 if (n >= (
int)
sizeof(cwDir))
1009 {
eDest.Emsg(
"Config", ENAMETOOLONG,
"create home directory", cwDir);
1015 if ((rc =
makePath(cwDir, mode,
true)))
1016 {
eDest.Emsg(
"Config", rc,
"create home directory", cwDir);
1022 if (
chdir(cwDir) < 0)
1023 {
eDest.Emsg(
"Config", errno,
"chdir to home directory", cwDir);
1038 char *next_path = path+1;
1040 bool dochmod =
false;
1044 if (!reset && !
stat(path, &buf))
return 0;
1048 while((next_path = index(next_path,
int(
'/'))))
1051 if (errno != EEXIST)
return -errno;
1052 if (dochmod)
CHMOD(path, mode);
1055 next_path = next_path+1;
1069 mode_t mval[3] = {0}, mbit[3] = {0x04, 0x02, 0x01};
1070 const char *mok =
"rwx";
1077 mask = strtol(mode, &eP, 8);
1083 int n = strlen(mode);
1084 if (!n || n > 9 || n/3*3 != n)
return false;
1089 do {
for (
int i = 0; i < 3; i++)
1092 {
if (mlet != mok[i])
return false;
1096 }
while(++k < 3 && *mode);
1100 mask = mval[0]<<6 | mval[1]<<3 | mval[2];
1109 const char *libName,
char *&libPath,
char **libParm)
1111 char *val, parms[2048];
1115 val = Config.GetWord();
1119 if (val && !strcmp(
"++", val))
1120 {
eDest.Say(
"Config warning: stacked plugins are not supported in "
1121 "this context; directive ignored!");
1127 while(val && *val && *val ==
'+') val = Config.GetWord();
1131 if (!val || !val[0])
1132 {
eDest.Emsg(
"Config", libName,
"not specified");
return false;}
1136 if (libPath) free(libPath);
1137 libPath = strdup(val);
1141 if (!libParm)
return true;
1142 if (*libParm) free(*libParm);
1148 if (!Config.GetRest(parms,
sizeof(parms)))
1149 {
eDest.Emsg(
"Config", libName,
"parameters too long");
return false;}
1150 if (*parms) *libParm = strdup(parms);
1160 char *pval, *val, *HomePath = 0;
1164 pval = Config.GetWord();
1165 if (!pval || !pval[0])
1166 {
eDest.Emsg(
"Config",
"home path not specified");
return 0;}
1171 {
eDest.Emsg(
"Config",
"home path not absolute");
return 0;}
1175 HomePath = strdup(pval);
1180 if ((val = Config.GetWord()) && val[0])
1181 {
if (!strcmp(
"group", val)) mode |= (S_IRGRP | S_IXGRP);
1182 else {
eDest.Emsg(
"Config",
"invalid home path modifier -", val);
1196 const mode_t AMode = S_IRWXU;
1197 char pbuff[MAXPATHLEN+64];
1203 if (n >= (
int)
sizeof(pbuff))
return ENAMETOOLONG;
1204 strcpy(pbuff, path);
1209 makePath(pbuff, (mode ? mode : AMode));
1210 if (symlink(target, path))
return errno;
1225 {
if (*str ==
'-') *str = subc;
1226 else if (*str ==
' ') *str = subc;
1227 char *blank = rindex(str,
' ');
1228 if (blank)
while(*blank ==
' ') *blank-- = 0;
1230 {
if (!isalnum(*str) && index(
"_-.", *str) == 0) *str = subc;
1242 const mode_t lfm = S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH;
1243 char buff[2048], *sp;
1246 if (!inst || !*inst)
return logfn;
1247 if (!(sp = rindex(logfn,
'/'))) strcpy(buff,
"./");
1248 else {*sp =
'\0'; strcpy(buff, logfn); strcat(buff,
"/");}
1250 strcat(buff, inst); strcat(buff,
"/");
1253 {
eDest.Emsg(
"Config", rc,
"create log file path", buff);
1257 if (sp) {*sp =
'/'; strcat(buff, sp+1);}
1258 else strcat(buff, logfn);
1261 return strdup(buff);
1270 unsigned char* ustr = (
unsigned char*)str;
1274 while(*ustr) {*ustr = tolower(*ustr); ustr++;}
1283 const char *eP, *bP = *str;
1288 while(*bP && *bP == delim) bP++;
1289 if (*bP == 0) {*buff = 0;
return 0;}
1294 while(*eP && *eP != delim) eP++;
1298 if (*eP == 0) *str = eP;
1304 if (aLen >= bsz) mLen = bsz-1;
1309 strncpy(buff, bP, mLen);
1327 static const int maxFiles = 256;
1329 int myfd, logFD =
eDest.baseFD();
1333 if (noLog)
eDest.Emsg(
"Config",
"Warning! No log file specified; "
1334 "backgrounding disables all logging!");
1338 if ((mypid = fork()) < 0)
1339 {
eDest.Emsg(
"Config", errno,
"fork process 1 for backgrounding");
1353 if(
read( pipeFD[0], &status,
sizeof(status) ) !=
sizeof(status) )
1367 {
eDest.Emsg(
"Config", errno,
"doing setsid() for backgrounding");
1373 if ((mypid = fork()) < 0)
1374 {
eDest.Emsg(
"Config", errno,
"fork process 2 for backgrounding");
1377 else if (mypid) _exit(0);
1382 if ((myfd =
open(
"/dev/null", O_RDWR)) < 0)
1383 {
eDest.Emsg(
"Config", errno,
"open /dev/null for backgrounding");
1386 dup2(myfd, 0); dup2(myfd, 1); dup2(myfd, 2); dup2(myfd, logFD);
1391 for (myfd = 3; myfd < maxFiles; myfd++)
1392 if( (!pipeFD || myfd != pipeFD[1]) && myfd != logFD )
close(myfd);
1401 struct passwd *pEnt, pStruct;
1408 {
int n = LookUp(uidMap,
static_cast<unsigned int>(uID),uName,uNsz);
1409 if (n > 0)
return (n < uNsz ? n : 0);
1415 rc = getpwuid_r(uID, &pStruct, pBuff,
sizeof(pBuff), &pEnt);
1417 {n = snprintf(uName, uNsz,
"%ud",
static_cast<unsigned int>(uID));
1418 return (n >= uNsz ? 0 : n);
1424 AddID(uidMap,
static_cast<unsigned int>(uID), pEnt->pw_name, keepT);
1428 n = strlen(pEnt->pw_name);
1429 if (uNsz <= (
int)strlen(pEnt->pw_name))
return 0;
1430 strcpy(uName, pEnt->pw_name);
1440 struct passwd *pEnt, pStruct;
1447 rc = getpwuid_r(uID, &pStruct, pBuff,
sizeof(pBuff), &pEnt);
1449 if (!pEnt)
return ESRCH;
1453 if (uNsz <= (
int)strlen(pEnt->pw_name))
return ENAMETOOLONG;
1454 strcpy(uName, pEnt->pw_name);
1464 static const mode_t mMask = S_IRWXU | S_IRWXG | S_IRWXO;
1469 if (
stat(path, &buf))
1470 {
if (errno == ENOENT)
return "does not exist.";
1477 {
if (!S_ISDIR(buf.st_mode))
return "is not a directory.";
1479 if (!S_ISREG(buf.st_mode))
return "is not a file.";
1484 if ((buf.st_mode & mMask) & ~allow)
return "has excessive access rights.";
1500 if( (fd =
open( path, O_WRONLY|O_CREAT|O_TRUNC, 0644 )) < 0 )
1502 eDest.Emsg(
"Config", errno,
"create pidfile" );
1506 if(
write( fd, buff, snprintf( buff,
sizeof(buff),
"%d",
1507 static_cast<int>(getpid()) ) ) < 0 )
1509 eDest.Emsg(
"Config", errno,
"write to pidfile" );
1522 int statRet =
::stat(path,&buf);
1524 modificationTime = buf.st_mtime;
1531 while( str.size() && !isgraph(str[0]) ) str.erase(str.begin());
1535 while( str.size() && !isgraph(str[str.size()-1]) )
1536 str.resize (str.size () - 1);
1540 const auto toTrim = [](
char c) {
return !isgraph(c); };
1542 size_t end = sv.size();
1544 while (start < end && toTrim(sv[start])) ++start;
1545 while (end > start && toTrim(sv[end - 1])) --end;
1547 sv = sv.substr(start, end - start);
1552 auto [ptr,
ec] = std::from_chars(sv.data(), sv.data() + sv.size(), temp);
1554 if (
ec == std::errc::invalid_argument) {
1555 throw std::invalid_argument(
"Invalid number format");
1557 if (
ec == std::errc::result_out_of_range || temp > std::numeric_limits<uint8_t>::max()) {
1558 throw std::out_of_range(
"Value out of range for unsigned short");
1561 return static_cast<unsigned short>(temp);
1574 static constexpr char token_chars[] =
"-._~+/=:%";
1576 for (
char ch : token_chars)
1593 static const regex_t auth_regex = []() {
1594 constexpr char re[] =
1595 "(authz=|(transferheader)?(www-|proxy-)?auth(orization|enticate)[[:space:]]*:[[:space:]]*)"
1596 "(Bearer([[:space:]]|%20)?(token([[:space:]]|%20)?)?)?";
1600 if (regcomp(®ex, re, REG_EXTENDED | REG_ICASE) != 0)
1601 throw std::runtime_error(
"Failed to compile regular expression");
1608 std::string redacted;
1609 const char *
const text = input.c_str();
1611 while (regexec(&auth_regex, text + offset, 1, &match, 0) == 0) {
1612 redacted.append(text + offset, match.rm_eo).append(
"REDACTED");
1614 offset += match.rm_eo;
1620 return redacted.append(text + offset);
1625 return std::isalnum(c) || c ==
'-' || c ==
'_' || c ==
'.' || c ==
'~';
1637 static const char hex[] =
"0123456789ABCDEF";
1640 out.reserve(input.size() * 3);
1642 for (
unsigned char c: input) {
1647 out.push_back(hex[c >> 4]);
1648 out.push_back(hex[c & 0x0f]);
1656 if (c >=
'0' && c <=
'9')
return c -
'0';
1657 if (c >=
'A' && c <=
'F')
return c -
'A' + 10;
1658 if (c >=
'a' && c <=
'f')
return c -
'a' + 10;
1672 out.reserve(input.size());
1674 for (
size_t i = 0; i < input.size(); ++i) {
1675 if (input[i] ==
'%' && i + 2 < input.size() &&
1676 std::isxdigit(input[i + 1]) &&
1677 std::isxdigit(input[i + 2])) {
1678 const int hi =
from_hex(input[i + 1]);
1679 const int lo =
from_hex(input[i + 2]);
1680 out.push_back(
static_cast<char>((hi << 4) | lo));
1682 }
else if (input[i] ==
'+') {
1685 out.push_back(input[i]);
1698void stripCgi(std::string& url,
const std::unordered_set<std::string> &cgiKeys)
1700 for (
const auto &key : cgiKeys) {
1704 const std::string needle = key +
"=";
1705 size_t spos = 0, epos = 0;
1707 while ((spos = url.find(needle, spos)) != std::string::npos) {
1711 url.erase(spos, epos - spos);
1717 if ((spos = url.find(
"?&")) != std::string::npos)
1718 url.erase(spos + 1, 1);
1721 if (!url.empty() && url.back() ==
'?')
1727 std::string tmp = url.
c_str();
static XrdSysError eDest(0,"crypto_")
uint32_t crc32c(uint32_t crc, void const *buf, size_t len)
void stripCgi(std::string &url, const std::unordered_set< std::string > &cgiKeys)
static bool is_token_character(int c)
static int from_hex(char c)
static bool is_rfc3986_unreserved(unsigned char c)
std::string obfuscateAuth(const std::string &input)
const char * XrdSysE2T(int errcode)
static bool Match(const char *hName, const char *pattern)
static bool Parse(const char *hSpec, const char **hName, const char **hNend, const char **hPort, const char **hPend)
static uint32_t Calc32C(const void *data, size_t count, uint32_t prevcs=0)
char * Get(const char *varname)
MDLen
SHA3 digest lengths (bits to bytes).
static void * Calc(const void *in, size_t inlen, void *md, MDLen mdlen)
int tokenize(XrdOucString &tok, int from, char del=':')
const char * c_str() const
static char * parseHome(XrdSysError &eDest, XrdOucStream &Config, int &mode)
static void Sanitize(char *instr, char subc='_')
static bool getGID(const char *gName, gid_t &gID)
static const mode_t pathMode
static const char * HSize(size_t bytes, char *buff, int bsz)
static int isFWD(const char *path, int *port=0, char *hBuff=0, int hBLen=0, bool pTrim=false)
static int UserName(uid_t uID, char *uName, int uNsz)
static char * Ident(long long &mySID, char *iBuff, int iBlen, const char *iHost, const char *iProg, const char *iName, int Port)
static bool getUID(const char *uName, uid_t &uID, gid_t *gID=0)
static int getModificationTime(const char *path, time_t &modificationTime)
static const char * ValPath(const char *path, mode_t allow, bool isdir)
static char * genPath(const char *path, const char *inst, const char *psfx=0)
static uint8_t touint8_t(const std::string_view sv)
static int Token(const char **str, char delim, char *buff, int bsz)
static int ReLink(const char *path, const char *target, mode_t mode=0)
static bool parseLib(XrdSysError &eDest, XrdOucStream &Config, const char *libName, char *&path, char **libparm)
static int hex2bin(const char *hex, char *bin, int size)
static int is1of(char *val, const char **clist)
static std::string UrlDecode(const std::string &input)
static const char * InstName(int TranOpt=0)
static std::string UrlEncode(const std::string &input)
static char * eText(int rc, char *eBuff, int eBlen)
static int argList(char *args, char **argV, int argC)
static bool mode2mask(const char *mode, mode_t &mask)
static std::string genHumanSize(size_t size, uint64_t base)
static int GidName(gid_t gID, char *gName, int gNsz, time_t keepT=0)
static int UidName(uid_t uID, char *uName, int uNsz, time_t keepT=0)
static char * bin2hex(char *inbuff, int dlen, char *buff, int blen, bool sep=true)
static int Log10(unsigned long long n)
static int doIf(XrdSysError *eDest, XrdOucStream &Config, const char *what, const char *hname, const char *nname, const char *pname)
static int makePath(char *path, mode_t mode, bool reset=false)
static int GroupName(gid_t gID, char *gName, int gNsz)
static void trim(std::string &str)
static bool findPgm(const char *pgm, XrdOucString &path)
static bool PidFile(XrdSysError &eDest, const char *path)
static const char * i2bstr(char *buff, int blen, int val, bool pad=false)
static void toLower(char *str)
static int fmtBytes(long long val, char *buff, int bsz)
static int Log2(unsigned long long n)
static void makeHome(XrdSysError &eDest, const char *inst)
static bool endsWith(const char *text, const char *ending, int endlen)
static void Undercover(XrdSysError &eDest, int noLog, int *pipeFD=0)
static char * getFile(const char *path, int &rc, int maxsz=10240, bool notempty=true)
static char * subLogfn(XrdSysError &eDest, const char *inst, char *logfn)