XRootD
XrdOucUtils Class Reference

#include <XrdOucUtils.hh>

+ Collaboration diagram for XrdOucUtils:

Public Member Functions

 XrdOucUtils ()
 
 ~XrdOucUtils ()
 

Static Public Member Functions

static int argList (char *args, char **argV, int argC)
 
static char * bin2hex (char *inbuff, int dlen, char *buff, int blen, bool sep=true)
 
static int doIf (XrdSysError *eDest, XrdOucStream &Config, const char *what, const char *hname, const char *nname, const char *pname)
 
static bool endsWith (const char *text, const char *ending, int endlen)
 
static char * eText (int rc, char *eBuff, int eBlen)
 
static bool findPgm (const char *pgm, XrdOucString &path)
 
static int fmtBytes (long long val, char *buff, int bsz)
 
static int genPath (char *buff, int blen, const char *path, const char *psfx=0)
 
static char * genPath (const char *path, const char *inst, const char *psfx=0)
 
static char * getFile (const char *path, int &rc, int maxsz=10240, bool notempty=true)
 
static bool getGID (const char *gName, gid_t &gID)
 
static int getModificationTime (const char *path, time_t &modificationTime)
 
static bool getUID (const char *uName, uid_t &uID, gid_t *gID=0)
 
static int GidName (gid_t gID, char *gName, int gNsz, time_t keepT=0)
 
static int GroupName (gid_t gID, char *gName, int gNsz)
 
static const char * i2bstr (char *buff, int blen, int val, bool pad=false)
 
static char * Ident (long long &mySID, char *iBuff, int iBlen, const char *iHost, const char *iProg, const char *iName, int Port)
 
static const char * InstName (const char *name, int Fillit=1)
 
static const char * InstName (int TranOpt=0)
 
static int is1of (char *val, const char **clist)
 
static int isFWD (const char *path, int *port=0, char *hBuff=0, int hBLen=0, bool pTrim=false)
 
static int Log10 (unsigned long long n)
 
static int Log2 (unsigned long long n)
 
static void makeHome (XrdSysError &eDest, const char *inst)
 
static bool makeHome (XrdSysError &eDest, const char *inst, const char *path, mode_t mode)
 
static int makePath (char *path, mode_t mode, bool reset=false)
 
static bool mode2mask (const char *mode, mode_t &mask)
 
static char * parseHome (XrdSysError &eDest, XrdOucStream &Config, int &mode)
 
static bool parseLib (XrdSysError &eDest, XrdOucStream &Config, const char *libName, char *&path, char **libparm)
 
static bool PidFile (XrdSysError &eDest, const char *path)
 
static int ReLink (const char *path, const char *target, mode_t mode=0)
 
static void Sanitize (char *instr, char subc='_')
 
static char * subLogfn (XrdSysError &eDest, const char *inst, char *logfn)
 
static int Token (const char **str, char delim, char *buff, int bsz)
 
static void toLower (char *str)
 
static void trim (std::string &str)
 
static int UidName (uid_t uID, char *uName, int uNsz, time_t keepT=0)
 
static void Undercover (XrdSysError &eDest, int noLog, int *pipeFD=0)
 
static int UserName (uid_t uID, char *uName, int uNsz)
 
static const char * ValPath (const char *path, mode_t allow, bool isdir)
 

Static Public Attributes

static const mode_t pathMode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH
 

Detailed Description

Definition at line 44 of file XrdOucUtils.hh.

Constructor & Destructor Documentation

◆ XrdOucUtils()

XrdOucUtils::XrdOucUtils ( )
inline

Definition at line 139 of file XrdOucUtils.hh.

139 {}

◆ ~XrdOucUtils()

XrdOucUtils::~XrdOucUtils ( )
inline

Definition at line 140 of file XrdOucUtils.hh.

140 {}

Member Function Documentation

◆ argList()

int XrdOucUtils::argList ( char *  args,
char **  argV,
int  argC 
)
static

Definition at line 135 of file XrdOucUtils.cc.

136 {
137  char *aP = args;
138  int j;
139 
140 // Construct the argv array based on passed command line.
141 //
142 for (j = 0; j < argC; j++)
143  {while(*aP == ' ') aP++;
144  if (!(*aP)) break;
145 
146  if (*aP == '"' || *aP == '\'')
147  {argV[j] = aP+1;
148  aP = index(aP+1, *aP);
149  if (!aP || (*(aP+1) != ' ' && *(aP+1)))
150  {if (!j) argV[0] = 0; return -EINVAL;}
151  *aP++ = '\0';
152  } else {
153  argV[j] = aP;
154  if ((aP = index(aP+1, ' '))) *aP++ = '\0';
155  else {j++; break;}
156  }
157 
158  }
159 
160 // Make sure we did not overflow the vector
161 //
162  if (j > argC-1) return -E2BIG;
163 
164 // End list with a null pointer and return the actual number of arguments
165 //
166  argV[j] = 0;
167  return j;
168 }

Referenced by XrdOucProg::Setup().

+ Here is the caller graph for this function:

◆ bin2hex()

char * XrdOucUtils::bin2hex ( char *  inbuff,
int  dlen,
char *  buff,
int  blen,
bool  sep = true 
)
static

Definition at line 174 of file XrdOucUtils.cc.

176 {
177  static char hv[] = "0123456789abcdef";
178  char *outbuff = buff;
179  for (int i = 0; i < dlen && blen > 2; i++) {
180  *outbuff++ = hv[(inbuff[i] >> 4) & 0x0f];
181  *outbuff++ = hv[ inbuff[i] & 0x0f];
182  blen -= 2;
183  if (sep && blen > 1 && ((i & 0x03) == 0x03 || i+1 == dlen))
184  {*outbuff++ = ' '; blen--;}
185  }
186  *outbuff = '\0';
187  return buff;
188 }

Referenced by XrdOssMio::Map().

+ Here is the caller graph for this function:

◆ doIf()

int XrdOucUtils::doIf ( XrdSysError eDest,
XrdOucStream Config,
const char *  what,
const char *  hname,
const char *  nname,
const char *  pname 
)
static

Definition at line 242 of file XrdOucUtils.cc.

245 {
246  static const char *brk[] = {"defined", "exec", "named", 0};
247  XrdOucEnv *theEnv = 0;
248  char *val;
249  int hostok, isDef;
250 
251 // Make sure that at least one thing appears after the if
252 //
253  if (!(val = Config.GetWord()))
254  {if (eDest) eDest->Emsg("Config","Host name missing after 'if' in", what);
255  return -1;
256  }
257 
258 // Check if we are one of the listed hosts
259 //
260  if (!is1of(val, brk))
261  {do {hostok = XrdNetUtils::Match(hname, val);
262  val = Config.GetWord();
263  } while(!hostok && val && !is1of(val, brk));
264  if (hostok)
265  { while(val && !is1of(val, brk)) val = Config.GetWord();
266  // No more directives
267  if (!val) return 1;
268  } else return 0;
269  }
270 
271 // Check if this is a defined test
272 //
273  while(!strcmp(val, "defined"))
274  {if (!(val = Config.GetWord()) || *val != '?')
275  {if (eDest)
276  {eDest->Emsg("Config","'?var' missing after 'defined' in",what);}
277  return -1;
278  }
279  // Get environment if we have none
280  //
281  if (!theEnv && (theEnv = Config.SetEnv(0))) Config.SetEnv(theEnv);
282  if (!theEnv && *(val+1) != '~') return 0;
283 
284  // Check if any listed variable is defined.
285  //
286  isDef = 0;
287  while(val && *val == '?')
288  {if (*(val+1) == '~' ? getenv(val+2) : theEnv->Get(val+1)) isDef=1;
289  val = Config.GetWord();
290  }
291  if (!val || !isDef) return isDef;
292  if (strcmp(val, "&&"))
293  {if (eDest)
294  {eDest->Emsg("Config",val,"is invalid for defined test in",what);}
295  return -1;
296  } else {
297  if (!(val = Config.GetWord()))
298  {if (eDest)
299  {eDest->Emsg("Config","missing keyword after '&&' in",what);}
300  return -1;
301  }
302  }
303  if (!is1of(val, brk))
304  {if (eDest)
305  {eDest->Emsg("Config",val,"is invalid after '&&' in",what);}
306  return -1;
307  }
308  }
309 
310 // Check if we need to compare program names (we are here only if we either
311 // passed the hostlist test or there was no hostlist present)
312 //
313  if (!strcmp(val, "exec"))
314  {if (!(val = Config.GetWord()) || !strcmp(val, "&&"))
315  {if (eDest)
316  {eDest->Emsg("Config","Program name missing after 'if exec' in",what);}
317  return -1;
318  }
319 
320  // Check if we are one of the programs.
321  //
322  if (!pname) return 0;
323  while(val && strcmp(val, pname))
324  if (!strcmp(val, "&&")) return 0;
325  else val = Config.GetWord();
326  if (!val) return 0;
327  while(val && strcmp(val, "&&")) val = Config.GetWord();
328  if (!val) return 1;
329 
330  if (!(val = Config.GetWord()))
331  {if (eDest)
332  {eDest->Emsg("Config","Keyword missing after '&&' in",what);}
333  return -1;
334  }
335  if (strcmp(val, "named"))
336  {if (eDest)
337  {eDest->Emsg("Config",val,"is invalid after '&&' in",what);}
338  return -1;
339  }
340  }
341 
342 // Check if we need to compare net names (we are here only if we either
343 // passed the hostlist test or there was no hostlist present)
344 //
345  if (!(val = Config.GetWord()))
346  {if (eDest)
347  {eDest->Emsg("Config","Instance name missing after 'if named' in", what);}
348  return -1;
349  }
350 
351 // Check if we are one of the names
352 //
353  if (!nname) return 0;
354  while(val && strcmp(val, nname)) val = Config.GetWord();
355 
356 // All done
357 //
358  return (val != 0);
359 }
static XrdSysError eDest(0,"crypto_")
static bool Match(const char *hName, const char *pattern)
Definition: XrdNetUtils.cc:623
char * Get(const char *varname)
Definition: XrdOucEnv.hh:69
static int is1of(char *val, const char **clist)
Definition: XrdOucUtils.cc:769
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95
XrdCmsConfig Config
XrdOucEnv theEnv

References XrdCms::Config, eDest, XrdSysError::Emsg(), XrdOucEnv::Get(), is1of(), XrdNetUtils::Match(), and XrdCms::theEnv.

Referenced by main().

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

◆ endsWith()

bool XrdOucUtils::endsWith ( const char *  text,
const char *  ending,
int  endlen 
)
static

Definition at line 194 of file XrdOucUtils.cc.

195 {
196  int tlen = strlen(text);
197 
198  return (tlen >= endlen && !strcmp(text+(tlen-endlen), ending));
199 }

Referenced by XrdBwmFile::open().

+ Here is the caller graph for this function:

◆ eText()

char * XrdOucUtils::eText ( int  rc,
char *  eBuff,
int  eBlen 
)
static

Definition at line 208 of file XrdOucUtils.cc.

209 {
210  const char *etP;
211 
212 // Get error text
213 //
214  etP = XrdSysE2T(rc);
215 
216 // Copy the text and lower case the first letter
217 //
218  strlcpy(eBuff, etP, eBlen);
219 
220 // All done
221 //
222  return eBuff;
223 }
const char * XrdSysE2T(int errcode)
Definition: XrdSysE2T.cc:99
size_t strlcpy(char *dst, const char *src, size_t sz)

References strlcpy(), and XrdSysE2T().

+ Here is the call graph for this function:

◆ findPgm()

bool XrdOucUtils::findPgm ( const char *  pgm,
XrdOucString path 
)
static

Definition at line 365 of file XrdOucUtils.cc.

366 {
367  struct stat Stat;
368 
369 // Check if only executable bit needs to be checked
370 //
371  if (*pgm == '/')
372  {if (stat(pgm, &Stat) || !(Stat.st_mode & S_IXOTH)) return false;
373  path = pgm;
374  return true;
375  }
376 
377 // Make sure we have the paths to check
378 //
379  const char *pEnv = getenv("PATH");
380  if (!pEnv) return false;
381 
382 // Setup to find th executable
383 //
384  XrdOucString prog, pList(pEnv);
385  int from = 0;;
386  prog += '/'; prog += pgm;
387 
388 // Find it!
389 //
390  while((from = pList.tokenize(path, from, ':')) != -1)
391  {path += prog;
392  if (!stat(path.c_str(), &Stat) && Stat.st_mode & S_IXOTH) return true;
393  }
394  return false;
395 }
struct stat Stat
Definition: XrdCks.cc:49
int stat(const char *path, struct stat *buf)
const char * c_str() const

References XrdOucString::c_str(), Stat, stat(), and XrdOucString::tokenize().

Referenced by XrdNetPMarkCfg::Parse().

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

◆ fmtBytes()

int XrdOucUtils::fmtBytes ( long long  val,
char *  buff,
int  bsz 
)
static

Definition at line 401 of file XrdOucUtils.cc.

402 {
403  static const long long Kval = 1024LL;
404  static const long long Mval = 1024LL*1024LL;
405  static const long long Gval = 1024LL*1024LL*1024LL;
406  static const long long Tval = 1024LL*1024LL*1024LL*1024LL;
407  char sName = ' ';
408  int resid;
409 
410 // Get correct scaling
411 //
412  if (val < 1024) return snprintf(buff, bsz, "%lld", val);
413  if (val < Mval) {val = val*10/Kval; sName = 'K';}
414  else if (val < Gval) {val = val*10/Mval; sName = 'M';}
415  else if (val < Tval) {val = val*10/Gval; sName = 'G';}
416  else {val = val*10/Tval; sName = 'T';}
417  resid = val%10LL; val = val/10LL;
418 
419 // Format it
420 //
421  return snprintf(buff, bsz, "%lld.%d%c", val, resid, sName);
422 }

Referenced by XrdFrmPurge::Display().

+ Here is the caller graph for this function:

◆ genPath() [1/2]

int XrdOucUtils::genPath ( char *  buff,
int  blen,
const char *  path,
const char *  psfx = 0 
)
static

Definition at line 446 of file XrdOucUtils.cc.

447 {
448  int i, j;
449 
450  i = strlen(path);
451  j = (psfx ? strlen(psfx) : 0);
452  if (i+j+3 > blen) return -ENAMETOOLONG;
453 
454  strcpy(buff, path);
455  if (psfx)
456  {if (buff[i-1] != '/') buff[i++] = '/';
457  strcpy(&buff[i], psfx);
458  if (psfx[j-1] != '/') strcat(buff, "/");
459  }
460  return 0;
461 }

◆ genPath() [2/2]

char * XrdOucUtils::genPath ( const char *  path,
const char *  inst,
const char *  psfx = 0 
)
static

Definition at line 428 of file XrdOucUtils.cc.

430 {
431  char buff[2048];
432  int i = strlcpy(buff, p_path, sizeof(buff));
433 
434  if (buff[i-1] != '/') {buff[i++] = '/'; buff[i] = '\0';}
435  if (inst) {strcpy(buff+i, inst); strcat(buff, "/");}
436  if (s_path) strcat(buff, s_path);
437 
438  i = strlen(buff);
439  if (buff[i-1] != '/') {buff[i++] = '/'; buff[i] = '\0';}
440 
441  return strdup(buff);
442 }

References strlcpy().

Referenced by XrdNetCmsNotify::XrdNetCmsNotify(), XrdXrootdProtocol::Configure(), XrdCmsClientConfig::Configure(), XrdCmsConfig::Configure0(), XrdCmsConfig::Configure2(), XrdOfsConfigCP::Init(), and XrdFrcUtils::makePath().

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

◆ getFile()

char * XrdOucUtils::getFile ( const char *  path,
int &  rc,
int  maxsz = 10240,
bool  notempty = true 
)
static

Definition at line 467 of file XrdOucUtils.cc.

468 {
469  struct stat Stat;
470  struct fdHelper
471  {int fd = -1;
472  fdHelper() {}
473  ~fdHelper() {if (fd >= 0) close(fd);}
474  } file;
475  char *buff;
476  int flen;
477 
478 // Preset RC
479 //
480  rc = 0;
481 
482 // Open the file in read mode
483 //
484  if ((file.fd = open(path, O_RDONLY)) < 0) {rc = errno; return 0;}
485 
486 // Get the size of the file
487 //
488  if (fstat(file.fd, &Stat)) {rc = errno; return 0;}
489 
490 // Check if the size exceeds the maximum allowed
491 //
492  if (Stat.st_size > maxsz) {rc = EFBIG; return 0;}
493 
494 // Make sure the file is not empty if empty files are disallowed
495 //
496  if (Stat.st_size == 0 && notempty) {rc = ENODATA; return 0;}
497 
498 // Allocate a buffer
499 //
500  if ((buff = (char *)malloc(Stat.st_size+1)) == 0)
501  {rc = errno; return 0;}
502 
503 // Read the contents of the file into the buffer
504 //
505  if (Stat.st_size)
506  {if ((flen = read(file.fd, buff, Stat.st_size)) < 0)
507  {rc = errno; free(buff); return 0;}
508  } else flen = 0;
509 
510 // Add null byte. recall the buffer is bigger by one byte
511 //
512  buff[flen] = 0;
513 
514 // Return the size aand the buffer
515 //
516  rc = flen;
517  return buff;
518 }
#define ENODATA
Definition: XrdOucUtils.cc:63
int open(const char *path, int oflag,...)
int fstat(int fildes, struct stat *buf)
ssize_t read(int fildes, void *buf, size_t nbyte)
#define close(a)
Definition: XrdPosix.hh:43

References close, ENODATA, fstat(), open(), read(), Stat, and stat().

+ Here is the call graph for this function:

◆ getGID()

bool XrdOucUtils::getGID ( const char *  gName,
gid_t &  gID 
)
static

Definition at line 524 of file XrdOucUtils.cc.

525 {
526  struct group Grp, *result;
527  char buff[65536];
528 
529  getgrnam_r(gName, &Grp, buff, sizeof(buff), &result);
530  if (!result) return false;
531 
532  gID = Grp.gr_gid;
533  return true;
534 }

Referenced by XrdSecProtocolsss::Authenticate().

+ Here is the caller graph for this function:

◆ getModificationTime()

int XrdOucUtils::getModificationTime ( const char *  path,
time_t &  modificationTime 
)
static

Definition at line 1412 of file XrdOucUtils.cc.

1412  {
1413  struct stat buf;
1414  int statRet = ::stat(path,&buf);
1415  if(!statRet) {
1416  modificationTime = buf.st_mtime;
1417  }
1418  return statRet;
1419 }

References stat().

Referenced by XrdTlsContext::XrdTlsContext(), and XrdTlsContext::newHostCertificateDetected().

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

◆ getUID()

bool XrdOucUtils::getUID ( const char *  uName,
uid_t &  uID,
gid_t *  gID = 0 
)
static

Definition at line 540 of file XrdOucUtils.cc.

541 {
542  struct passwd pwd, *result;
543  char buff[16384];
544 
545  getpwnam_r(uName, &pwd, buff, sizeof(buff), &result);
546  if (!result) return false;
547 
548  uID = pwd.pw_uid;
549  if (gID) *gID = pwd.pw_gid;
550 
551  return true;
552 }

Referenced by XrdSecProtocolsss::Authenticate().

+ Here is the caller graph for this function:

◆ GidName()

int XrdOucUtils::GidName ( gid_t  gID,
char *  gName,
int  gNsz,
time_t  keepT = 0 
)
static

Definition at line 558 of file XrdOucUtils.cc.

559 {
560  static const int maxgBsz = 256*1024;
561  static const int addGsz = 4096;
562  struct group *gEnt, gStruct;
563  char gBuff[1024], *gBp = gBuff;
564  int glen = 0, gBsz = sizeof(gBuff), aOK = 1;
565  int n, retVal = 0;
566 
567 // Get ID from cache, if allowed
568 //
569  if (keepT)
570  {int n = LookUp(gidMap, static_cast<unsigned int>(gID),gName,gNsz);
571  if (n > 0) return (n < gNsz ? n : 0);
572  }
573 
574 // Get the the group struct. If we don't have a large enough buffer, get a
575 // larger one and try again up to the maximum buffer we will tolerate.
576 //
577  while(( retVal = getgrgid_r(gID, &gStruct, gBp, gBsz, &gEnt) ) == ERANGE)
578  {if (gBsz >= maxgBsz) {aOK = 0; break;}
579  if (gBsz > addGsz) free(gBp);
580  gBsz += addGsz;
581  if (!(gBp = (char *)malloc(gBsz))) {aOK = 0; break;}
582  }
583 
584 // Return a group name if all went well
585 //
586  if (aOK && retVal == 0 && gEnt != NULL)
587  {if (keepT)
588  AddID(gidMap, static_cast<unsigned int>(gID), gEnt->gr_name, keepT);
589  glen = strlen(gEnt->gr_name);
590  if (glen >= gNsz) glen = 0;
591  else strcpy(gName, gEnt->gr_name);
592  } else {
593  n = snprintf(gName, gNsz, "%ud", static_cast<unsigned int>(gID));
594  if (n >= gNsz) glen = 0;
595  }
596 
597 // Free any allocated buffer and return result
598 //
599  if (gBsz > addGsz && gBp) free(gBp);
600  return glen;
601 }

◆ GroupName()

int XrdOucUtils::GroupName ( gid_t  gID,
char *  gName,
int  gNsz 
)
static

Definition at line 607 of file XrdOucUtils.cc.

608 {
609  static const int maxgBsz = 256*1024;
610  static const int addGsz = 4096;
611  struct group *gEnt, gStruct;
612  char gBuff[1024], *gBp = gBuff;
613  int glen, gBsz = sizeof(gBuff), aOK = 1;
614  int retVal = 0;
615 
616 // Get the the group struct. If we don't have a large enough buffer, get a
617 // larger one and try again up to the maximum buffer we will tolerate.
618 //
619  while(( retVal = getgrgid_r(gID, &gStruct, gBp, gBsz, &gEnt) ) == ERANGE)
620  {if (gBsz >= maxgBsz) {aOK = 0; break;}
621  if (gBsz > addGsz) free(gBp);
622  gBsz += addGsz;
623  if (!(gBp = (char *)malloc(gBsz))) {aOK = 0; break;}
624  }
625 
626 // Return a group name if all went well
627 //
628  if (aOK && retVal == 0 && gEnt != NULL)
629  {glen = strlen(gEnt->gr_name);
630  if (glen >= gNsz) glen = 0;
631  else strcpy(gName, gEnt->gr_name);
632  } else glen = 0;
633 
634 // Free any allocated buffer and return result
635 //
636  if (gBsz > addGsz && gBp) free(gBp);
637  return glen;
638 }

Referenced by XrdSecProtocolunix::getCredentials().

+ Here is the caller graph for this function:

◆ i2bstr()

const char * XrdOucUtils::i2bstr ( char *  buff,
int  blen,
int  val,
bool  pad = false 
)
static

Definition at line 644 of file XrdOucUtils.cc.

645 {
646  char zo[2] = {'0', '1'};
647 
648  if (blen < 2) return "";
649 
650  buff[--blen] = 0;
651  if (!val) buff[blen--] = '0';
652  else while(val && blen >= 0)
653  {buff[blen--] = zo[val & 0x01];
654  val >>= 1;
655  }
656 
657  if (blen >= 0 && pad) while(blen >= 0) buff[blen--] = '0';
658 
659  return &buff[blen+1];
660 }

◆ Ident()

char * XrdOucUtils::Ident ( long long &  mySID,
char *  iBuff,
int  iBlen,
const char *  iHost,
const char *  iProg,
const char *  iName,
int  Port 
)
static

Definition at line 713 of file XrdOucUtils.cc.

716 {
717  static char *theSIN;
718  static long long theSID = genSID(theSIN, iHost, iPort, iName, iProg);
719  const char *sP = getenv("XRDSITE");
720  char uName[256];
721  int myPid = static_cast<int>(getpid());
722 
723 // Get our username
724 //
725  if (UserName(getuid(), uName, sizeof(uName)))
726  sprintf(uName, "%d", static_cast<int>(getuid()));
727 
728 // Create identification record
729 //
730  snprintf(iBuff,iBlen,"%s.%d:%s@%s\n&site=%s&port=%d&inst=%s&pgm=%s",
731  uName, myPid, theSIN, iHost, (sP ? sP : ""), iPort, iName, iProg);
732 
733 // Return a copy of the sid key
734 //
735  h2nll(theSID, mySID);
736  return strdup(theSIN);
737 }
static int UserName(uid_t uID, char *uName, int uNsz)

References XrdXrootdMonInfo::mySID, and UserName().

Referenced by XrdFrmMonitor::Init(), and XrdXrootdMonitor::Init().

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

◆ InstName() [1/2]

const char * XrdOucUtils::InstName ( const char *  name,
int  Fillit = 1 
)
static

Definition at line 760 of file XrdOucUtils.cc.

761 { return (Fillit ? name && *name ? name : "anon"
762  : name && strcmp(name,"anon") && *name ? name : 0);
763 }

◆ InstName() [2/2]

const char * XrdOucUtils::InstName ( int  TranOpt = 0)
static

Definition at line 743 of file XrdOucUtils.cc.

744 {
745  const char *iName = getenv("XRDNAME");
746 
747 // If tran is zero, return what we have
748 //
749  if (!TranOpt) return iName;
750 
751 // If trans is positive then make sure iName has a value. Otherwise, make sure
752 // iName has no value if it's actually "anon".
753 //
754  if (TranOpt > 0) {if (!iName || !*iName) iName = "anon";}
755  else if (iName && !strcmp(iName, "anon")) iName = 0;
756  return iName;
757 }

Referenced by XrdFrcProxy::XrdFrcProxy(), XrdFrmConfig::XrdFrmConfig(), XrdNetCmsNotify::XrdNetCmsNotify(), XrdSsiSfsConfig::XrdSsiSfsConfig(), XrdOssSys::ConfigStage(), XrdCmsClientConfig::Configure(), XrdConfig::Configure(), XrdFrmConfig::Configure(), XrdCmsConfig::Configure0(), XrdCmsConfig::Configure1(), XrdOfsConfigCP::Init(), XrdOssSpace::Init(), main(), and XrdFrcReqAgent::Start().

+ Here is the caller graph for this function:

◆ is1of()

int XrdOucUtils::is1of ( char *  val,
const char **  clist 
)
static

Definition at line 769 of file XrdOucUtils.cc.

770 {
771  int i = 0;
772  while(clist[i]) if (!strcmp(val, clist[i])) return 1;
773  else i++;
774  return 0;
775 }

Referenced by doIf().

+ Here is the caller graph for this function:

◆ isFWD()

int XrdOucUtils::isFWD ( const char *  path,
int *  port = 0,
char *  hBuff = 0,
int  hBLen = 0,
bool  pTrim = false 
)
static

Definition at line 781 of file XrdOucUtils.cc.

783 {
784  const char *hName, *hNend, *hPort, *hPend, *hP = path;
785  char *eP;
786  int n;
787 
788  if (*path == '/') hP++; // Note: It's assumed an objectid if no slash
789  if (*hP == 'x') hP++;
790  if (strncmp("root:/", hP, 6)) return 0;
791  if (hBuff == 0 || hBLen <= 0) return (hP - path) + 6;
792  hP += 6;
793 
794  if (!XrdNetUtils::Parse(hP, &hName, &hNend, &hPort, &hPend)) return 0;
795  if (*hNend == ']') hNend++;
796  else {if (!(*hNend) && !(hNend = index(hName, '/'))) return 0;
797  if (!(*hPend)) hPend = hNend;
798  }
799 
800  if (pTrim || !(*hPort)) n = hNend - hP;
801  else n = hPend - hP;
802  if (n >= hBLen) return 0;
803  strncpy(hBuff, hP, n);
804  hBuff[n] = 0;
805 
806  if (port)
807  {if (*hNend != ':') *port = 0;
808  else {*port = strtol(hPort, &eP, 10);
809  if (*port < 0 || *port > 65535 || eP != hPend) return 0;
810  }
811  }
812 
813  return hPend-path;
814 }
static bool Parse(const char *hSpec, const char **hName, const char **hNend, const char **hPort, const char **hPend)
Definition: XrdNetUtils.cc:745

References XrdNetUtils::Parse().

+ Here is the call graph for this function:

◆ Log10()

int XrdOucUtils::Log10 ( unsigned long long  n)
static

Definition at line 844 of file XrdOucUtils.cc.

845 {
846  int i = 0;
847 
848  #define SHFT(k, m) if (n >= m) { i += k; n /= m; }
849 
850  SHFT(16,10000000000000000ULL); SHFT(8,100000000ULL);
851  SHFT(4,10000ULL); SHFT(2,100ULL); SHFT(1,10ULL);
852  return i;
853 
854  #undef SHFT
855 }
#define SHFT(k)

References SHFT.

◆ Log2()

int XrdOucUtils::Log2 ( unsigned long long  n)
static

Definition at line 829 of file XrdOucUtils.cc.

830 {
831  int i = 0;
832 
833  #define SHFT(k) if (n >= (1ULL << k)) { i += k; n >>= k; }
834 
835  SHFT(32); SHFT(16); SHFT(8); SHFT(4); SHFT(2); SHFT(1); return i;
836 
837  #undef SHFT
838 }

References SHFT.

Referenced by XrdBuffXL::Init(), XrdBuffManager::Obtain(), XrdBuffXL::Obtain(), XrdBuffManager::Recalc(), and XrdBuffXL::Recalc().

+ Here is the caller graph for this function:

◆ makeHome() [1/2]

void XrdOucUtils::makeHome ( XrdSysError eDest,
const char *  inst 
)
static

Definition at line 861 of file XrdOucUtils.cc.

862 {
863  char buff[2048];
864 
865  if (!inst || !getcwd(buff, sizeof(buff))) return;
866 
867  strcat(buff, "/"); strcat(buff, inst);
868  if (MAKEDIR(buff, pathMode) && errno != EEXIST)
869  {eDest.Emsg("Config", errno, "create home directory", buff);
870  return;
871  }
872 
873  if (chdir(buff) < 0)
874  eDest.Emsg("Config", errno, "chdir to home directory", buff);
875 }
int chdir(const char *path)
#define MAKEDIR(path, mode)
static const mode_t pathMode
Definition: XrdOucUtils.hh:48

References chdir(), eDest, XrdSysError::Emsg(), MAKEDIR, and pathMode.

Referenced by XrdConfig::Configure(), XrdFrmConfig::Configure(), and makeHome().

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

◆ makeHome() [2/2]

bool XrdOucUtils::makeHome ( XrdSysError eDest,
const char *  inst,
const char *  path,
mode_t  mode 
)
static

Definition at line 879 of file XrdOucUtils.cc.

881 {
882  char cwDir[2048];
883  const char *slash = "", *slash2 = "";
884  int n, rc;
885 
886 // Provide backward compatibility for instance name qualification
887 //
888 
889  if (!path || !(n = strlen(path)))
890  {if (inst) makeHome(eDest, inst);
891  return true;
892  }
893 
894 // Augment the path with instance name, if need be
895 //
896  if (path[n-1] != '/') slash = "/";
897  if (!inst || !(n = strlen(inst))) inst = "";
898  else slash2 = "/";
899  n = snprintf(cwDir, sizeof(cwDir), "%s%s%s%s", path, slash, inst, slash2);
900  if (n >= (int)sizeof(cwDir))
901  {eDest.Emsg("Config", ENAMETOOLONG, "create home directory", cwDir);
902  return false;
903  }
904 
905 // Create the path if it doesn't exist
906 //
907  if ((rc = makePath(cwDir, mode, true)))
908  {eDest.Emsg("Config", rc, "create home directory", cwDir);
909  return false;
910  }
911 
912 // Switch to this directory
913 //
914  if (chdir(cwDir) < 0)
915  {eDest.Emsg("Config", errno, "chdir to home directory", cwDir);
916  return false;
917  }
918 
919 // All done
920 //
921  return true;
922 }
static int makePath(char *path, mode_t mode, bool reset=false)
Definition: XrdOucUtils.cc:928
static void makeHome(XrdSysError &eDest, const char *inst)
Definition: XrdOucUtils.cc:861

References chdir(), eDest, XrdSysError::Emsg(), makeHome(), and makePath().

+ Here is the call graph for this function:

◆ makePath()

int XrdOucUtils::makePath ( char *  path,
mode_t  mode,
bool  reset = false 
)
static

Definition at line 928 of file XrdOucUtils.cc.

929 {
930  char *next_path = path+1;
931  struct stat buf;
932  bool dochmod = false; // The 1st component stays as is
933 
934 // Typically, the path exists. So, do a quick check before launching into it
935 //
936  if (!reset && !stat(path, &buf)) return 0;
937 
938 // Start creating directories starting with the root
939 //
940  while((next_path = index(next_path, int('/'))))
941  {*next_path = '\0';
942  if (MAKEDIR(path, mode))
943  if (errno != EEXIST) return -errno;
944  if (dochmod) CHMOD(path, mode);
945  dochmod = reset;
946  *next_path = '/';
947  next_path = next_path+1;
948  }
949 
950 // All done
951 //
952  return 0;
953 }
#define CHMOD(path, mode)

References CHMOD, MAKEDIR, and stat().

Referenced by XrdOssSys::Create(), XrdOfsConfigCP::Init(), makeHome(), XrdFrcUtils::makePath(), XrdFrcUtils::makeQDir(), ReLink(), XrdOssSys::Reloc(), XrdOssSys::Rename(), XrdSecsssKT::Rewrite(), XrdNetSocket::socketPath(), and subLogfn().

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

◆ mode2mask()

bool XrdOucUtils::mode2mask ( const char *  mode,
mode_t &  mask 
)
static

Definition at line 959 of file XrdOucUtils.cc.

960 {
961  mode_t mval[3] = {0}, mbit[3] = {0x04, 0x02, 0x01};
962  const char *mok = "rwx";
963  char mlet;
964 
965 // Accept octal mode
966 //
967  if (isdigit(*mode))
968  {char *eP;
969  mask = strtol(mode, &eP, 8);
970  return *eP == 0;
971  }
972 
973 // Make sure we have the correct number of characters
974 //
975  int n = strlen(mode);
976  if (!n || n > 9 || n/3*3 != n) return false;
977 
978 // Convert groups of three
979 //
980  int k = 0;
981  do {for (int i = 0; i < 3; i++)
982  {mlet = *mode++;
983  if (mlet != '-')
984  {if (mlet != mok[i]) return false;
985  mval[k] |= mbit[i];
986  }
987  }
988  } while(++k < 3 && *mode);
989 
990 // Combine the modes and return success
991 //
992  mask = mval[0]<<6 | mval[1]<<3 | mval[2];
993  return true;
994 }

◆ parseHome()

char * XrdOucUtils::parseHome ( XrdSysError eDest,
XrdOucStream Config,
int &  mode 
)
static

Definition at line 1050 of file XrdOucUtils.cc.

1051 {
1052  char *pval, *val, *HomePath = 0;
1053 
1054 // Get the path
1055 //
1056  pval = Config.GetWord();
1057  if (!pval || !pval[0])
1058  {eDest.Emsg("Config", "home path not specified"); return 0;}
1059 
1060 // Make sure it's an absolute path
1061 //
1062  if (*pval != '/')
1063  {eDest.Emsg("Config", "home path not absolute"); return 0;}
1064 
1065 // Record the path
1066 //
1067  HomePath = strdup(pval);
1068 
1069 // Get the optional access rights
1070 //
1071  mode = S_IRWXU;
1072  if ((val = Config.GetWord()) && val[0])
1073  {if (!strcmp("group", val)) mode |= (S_IRGRP | S_IXGRP);
1074  else {eDest.Emsg("Config", "invalid home path modifier -", val);
1075  free(HomePath);
1076  return 0;
1077  }
1078  }
1079  return HomePath;
1080 }

References XrdCms::Config, eDest, and XrdSysError::Emsg().

+ Here is the call graph for this function:

◆ parseLib()

bool XrdOucUtils::parseLib ( XrdSysError eDest,
XrdOucStream Config,
const char *  libName,
char *&  path,
char **  libparm 
)
static

Definition at line 1000 of file XrdOucUtils.cc.

1002 {
1003  char *val, parms[2048];
1004 
1005 // Get the next token
1006 //
1007  val = Config.GetWord();
1008 
1009 // We do not support stacking as the caller does not support stacking
1010 //
1011  if (val && !strcmp("++", val))
1012  {eDest.Say("Config warning: stacked plugins are not supported in "
1013  "this context; directive ignored!");
1014  return true;
1015  }
1016 
1017 // Now skip over any options
1018 //
1019  while(val && *val && *val == '+') val = Config.GetWord();
1020 
1021 // Check if we actually have a path
1022 //
1023  if (!val || !val[0])
1024  {eDest.Emsg("Config", libName, "not specified"); return false;}
1025 
1026 // Record the path
1027 //
1028  if (libPath) free(libPath);
1029  libPath = strdup(val);
1030 
1031 // Handle optional parameter
1032 //
1033  if (!libParm) return true;
1034  if (*libParm) free(*libParm);
1035  *libParm = 0;
1036 
1037 // Record any parms
1038 //
1039  *parms = 0;
1040  if (!Config.GetRest(parms, sizeof(parms)))
1041  {eDest.Emsg("Config", libName, "parameters too long"); return false;}
1042  if (*parms) *libParm = strdup(parms);
1043  return true;
1044 }
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)
Definition: XrdSysError.cc:141

References XrdCms::Config, eDest, XrdSysError::Emsg(), and XrdSysError::Say().

+ Here is the call graph for this function:

◆ PidFile()

bool XrdOucUtils::PidFile ( XrdSysError eDest,
const char *  path 
)
static

Definition at line 1387 of file XrdOucUtils.cc.

1388 {
1389  char buff[32];
1390  int fd;
1391 
1392  if( (fd = open( path, O_WRONLY|O_CREAT|O_TRUNC, 0644 )) < 0 )
1393  {
1394  eDest.Emsg( "Config", errno, "create pidfile" );
1395  return false;
1396  }
1397 
1398  if( write( fd, buff, snprintf( buff, sizeof(buff), "%d",
1399  static_cast<int>(getpid()) ) ) < 0 )
1400  {
1401  eDest.Emsg( "Config", errno, "write to pidfile" );
1402  close(fd);
1403  return false;
1404  }
1405 
1406  close(fd);
1407  return true;
1408 }
ssize_t write(int fildes, const void *buf, size_t nbyte)

References close, eDest, XrdSysError::Emsg(), open(), and write().

Referenced by XrdFrmConfig::Configure().

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

◆ ReLink()

int XrdOucUtils::ReLink ( const char *  path,
const char *  target,
mode_t  mode = 0 
)
static

Definition at line 1086 of file XrdOucUtils.cc.

1087 {
1088  const mode_t AMode = S_IRWXU; // Only us as a default
1089  char pbuff[MAXPATHLEN+64];
1090  int n;
1091 
1092 // Copy the path
1093 //
1094  n = strlen(path);
1095  if (n >= (int)sizeof(pbuff)) return ENAMETOOLONG;
1096  strcpy(pbuff, path);
1097 
1098 // Unlink the target, make the path, and create the symlink
1099 //
1100  unlink(path);
1101  makePath(pbuff, (mode ? mode : AMode));
1102  if (symlink(target, path)) return errno;
1103  return 0;
1104 }
int unlink(const char *path)

References makePath(), and unlink().

+ Here is the call graph for this function:

◆ Sanitize()

void XrdOucUtils::Sanitize ( char *  instr,
char  subc = '_' 
)
static

Definition at line 1110 of file XrdOucUtils.cc.

1111 {
1112 
1113 // Sanitize string according to POSIX.1-2008 stanadard using only the
1114 // Portable Filename Character Set: a-z A-Z 0-9 ._- with 1st char not being -
1115 //
1116  if (*str)
1117  {if (*str == '-') *str = subc;
1118  else if (*str == ' ') *str = subc;
1119  char *blank = rindex(str, ' ');
1120  if (blank) while(*blank == ' ') *blank-- = 0;
1121  while(*str)
1122  {if (!isalnum(*str) && index("_-.", *str) == 0) *str = subc;
1123  str++;
1124  }
1125  }
1126 }

◆ subLogfn()

char * XrdOucUtils::subLogfn ( XrdSysError eDest,
const char *  inst,
char *  logfn 
)
static

Definition at line 1132 of file XrdOucUtils.cc.

1133 {
1134  const mode_t lfm = S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH;
1135  char buff[2048], *sp;
1136  int rc;
1137 
1138  if (!inst || !*inst) return logfn;
1139  if (!(sp = rindex(logfn, '/'))) strcpy(buff, "./");
1140  else {*sp = '\0'; strcpy(buff, logfn); strcat(buff, "/");}
1141 
1142  strcat(buff, inst); strcat(buff, "/");
1143 
1144  if ((rc = XrdOucUtils::makePath(buff, lfm)))
1145  {eDest.Emsg("Config", rc, "create log file path", buff);
1146  return 0;
1147  }
1148 
1149  if (sp) {*sp = '/'; strcat(buff, sp+1);}
1150  else strcat(buff, logfn);
1151 
1152  free(logfn);
1153  return strdup(buff);
1154 }

References eDest, XrdSysError::Emsg(), and makePath().

Referenced by XrdOucLogging::configLog(), and XrdFrmConfig::Configure().

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

◆ Token()

int XrdOucUtils::Token ( const char **  str,
char  delim,
char *  buff,
int  bsz 
)
static

Definition at line 1173 of file XrdOucUtils.cc.

1174 {
1175  const char *eP, *bP = *str;
1176  int aLen, mLen;
1177 
1178 // Trim off the delimeters. Return zero if nothing left.
1179 //
1180  while(*bP && *bP == delim) bP++;
1181  if (*bP == 0) {*buff = 0; return 0;}
1182 
1183 // Find the next delimiter
1184 //
1185  eP = bP;
1186  while(*eP && *eP != delim) eP++;
1187 
1188 // If we ended at a null, make sure next call will return zero
1189 //
1190  if (*eP == 0) *str = eP;
1191  else *str = eP+1;
1192 
1193 // Calculate length and make sure we don't overrun the buffer
1194 //
1195  aLen = eP-bP;
1196  if (aLen >= bsz) mLen = bsz-1;
1197  else mLen = aLen;
1198 
1199 // Copy token into buffer and end with null byte
1200 //
1201  strncpy(buff, bP, mLen);
1202  buff[mLen] = 0;
1203 
1204 // Return actual length
1205 //
1206  return aLen;
1207 }

◆ toLower()

void XrdOucUtils::toLower ( char *  str)
static

Definition at line 1160 of file XrdOucUtils.cc.

1161 {
1162  unsigned char* ustr = (unsigned char*)str; // Avoid undefined behaviour
1163 
1164 // Change each character to lower case
1165 //
1166  while(*ustr) {*ustr = tolower(*ustr); ustr++;}
1167 }

Referenced by XrdCksManager::Config(), XrdOfsConfigPI::DefaultCS(), XrdNetUtils::NetConfig(), and XrdCksConfig::ParseLib().

+ Here is the caller graph for this function:

◆ trim()

void XrdOucUtils::trim ( std::string &  str)
static

Definition at line 1421 of file XrdOucUtils.cc.

1421  {
1422  // Trim leading non-letters
1423  while( str.size() && !isgraph(str[0]) ) str.erase(str.begin());
1424 
1425  // Trim trailing non-letters
1426 
1427  while( str.size() && !isgraph(str[str.size()-1]) )
1428  str.resize (str.size () - 1);
1429 }

Referenced by XrdHttpReadRangeHandler::Configure(), and trim().

+ Here is the caller graph for this function:

◆ UidName()

int XrdOucUtils::UidName ( uid_t  uID,
char *  uName,
int  uNsz,
time_t  keepT = 0 
)
static

Definition at line 1291 of file XrdOucUtils.cc.

1292 {
1293  struct passwd *pEnt, pStruct;
1294  char pBuff[1024];
1295  int n, rc;
1296 
1297 // Get ID from cache, if allowed
1298 //
1299  if (keepT)
1300  {int n = LookUp(uidMap, static_cast<unsigned int>(uID),uName,uNsz);
1301  if (n > 0) return (n < uNsz ? n : 0);
1302  }
1303 
1304 // Try to obtain the username. We use this form to make sure we are using
1305 // the standards conforming version (compilation error otherwise).
1306 //
1307  rc = getpwuid_r(uID, &pStruct, pBuff, sizeof(pBuff), &pEnt);
1308  if (rc || !pEnt)
1309  {n = snprintf(uName, uNsz, "%ud", static_cast<unsigned int>(uID));
1310  return (n >= uNsz ? 0 : n);
1311  }
1312 
1313 // Add entry to the cache if need be
1314 //
1315  if (keepT)
1316  AddID(uidMap, static_cast<unsigned int>(uID), pEnt->pw_name, keepT);
1317 
1318 // Return length of username or zero if it is too big
1319 //
1320  n = strlen(pEnt->pw_name);
1321  if (uNsz <= (int)strlen(pEnt->pw_name)) return 0;
1322  strcpy(uName, pEnt->pw_name);
1323  return n;
1324 }

◆ Undercover()

void XrdOucUtils::Undercover ( XrdSysError eDest,
int  noLog,
int *  pipeFD = 0 
)
static

Definition at line 1217 of file XrdOucUtils.cc.

1218 {
1219  static const int maxFiles = 256;
1220  pid_t mypid;
1221  int myfd, logFD = eDest.baseFD();
1222 
1223 // Issue warning if there is no logfile attached
1224 //
1225  if (noLog) eDest.Emsg("Config", "Warning! No log file specified; "
1226  "backgrounding disables all logging!");
1227 
1228 // Fork so that we are not tied to a shell
1229 //
1230  if ((mypid = fork()) < 0)
1231  {eDest.Emsg("Config", errno, "fork process 1 for backgrounding");
1232  return;
1233  }
1234  else if (mypid)
1235  {
1236  // we have been given a pair of pipe descriptors to be able to read the
1237  // status of the child process
1238  if( pipeFD )
1239  {
1240  int status = 1;
1241  close( pipeFD[1] );
1242  // read will wait untill the status is communicated by the
1243  // child process, if the child process dies before being able
1244  // to comunicate the status then read will see EOF
1245  if( read( pipeFD[0], &status, sizeof(status) ) != sizeof(status) )
1246  _exit(1);
1247  _exit(status);
1248  }
1249  // no pipes given, return success
1250  else _exit(0);
1251  }
1252 
1253  if( pipeFD )
1254  close( pipeFD[0] );
1255 
1256 // Become the process group leader
1257 //
1258  if (setsid() < 0)
1259  {eDest.Emsg("Config", errno, "doing setsid() for backgrounding");
1260  return;
1261  }
1262 
1263 // Fork to that we are cannot get a controlling terminal
1264 //
1265  if ((mypid = fork()) < 0)
1266  {eDest.Emsg("Config", errno, "fork process 2 for backgrounding");
1267  return;
1268  }
1269  else if (mypid) _exit(0);
1270 
1271 // Switch stdin, stdout, and stderr to /dev/null (we can't use /dev/console
1272 // unless we are root which is unlikely).
1273 //
1274  if ((myfd = open("/dev/null", O_RDWR)) < 0)
1275  {eDest.Emsg("Config", errno, "open /dev/null for backgrounding");
1276  return;
1277  }
1278  dup2(myfd, 0); dup2(myfd, 1); dup2(myfd, 2); dup2(myfd, logFD);
1279 
1280 // Close any open file descriptors left open by the parent process
1281 // but the communication pipe and the logger's shadow file descriptor.
1282 //
1283  for (myfd = 3; myfd < maxFiles; myfd++)
1284  if( (!pipeFD || myfd != pipeFD[1]) && myfd != logFD ) close(myfd);
1285 }
int baseFD()
Definition: XrdSysError.cc:73

References XrdSysError::baseFD(), close, eDest, XrdSysError::Emsg(), XrdOfsPrepGPIReal::maxFiles, open(), and read().

Referenced by XrdConfig::Configure(), and XrdFrmConfig::Configure().

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

◆ UserName()

int XrdOucUtils::UserName ( uid_t  uID,
char *  uName,
int  uNsz 
)
static

Definition at line 1330 of file XrdOucUtils.cc.

1331 {
1332  struct passwd *pEnt, pStruct;
1333  char pBuff[1024];
1334  int rc;
1335 
1336 // Try to obtain the username. We use this form to make sure we are using
1337 // the standards conforming version (compilation error otherwise).
1338 //
1339  rc = getpwuid_r(uID, &pStruct, pBuff, sizeof(pBuff), &pEnt);
1340  if (rc) return rc;
1341  if (!pEnt) return ESRCH;
1342 
1343 // Return length of username or zero if it is too big
1344 //
1345  if (uNsz <= (int)strlen(pEnt->pw_name)) return ENAMETOOLONG;
1346  strcpy(uName, pEnt->pw_name);
1347  return 0;
1348 }

Referenced by XrdPfc::Cache::Config(), XrdSecProtocolunix::getCredentials(), and Ident().

+ Here is the caller graph for this function:

◆ ValPath()

const char * XrdOucUtils::ValPath ( const char *  path,
mode_t  allow,
bool  isdir 
)
static

Definition at line 1354 of file XrdOucUtils.cc.

1355 {
1356  static const mode_t mMask = S_IRWXU | S_IRWXG | S_IRWXO;
1357  struct stat buf;
1358 
1359 // Check if this really exists
1360 //
1361  if (stat(path, &buf))
1362  {if (errno == ENOENT) return "does not exist.";
1363  return XrdSysE2T(errno);
1364  }
1365 
1366 // Verify that this is the correct type of file
1367 //
1368  if (isdir)
1369  {if (!S_ISDIR(buf.st_mode)) return "is not a directory.";
1370  } else {
1371  if (!S_ISREG(buf.st_mode)) return "is not a file.";
1372  }
1373 
1374 // Verify that the does not have excessive privileges
1375 //
1376  if ((buf.st_mode & mMask) & ~allow) return "has excessive access rights.";
1377 
1378 // All went well
1379 //
1380  return 0;
1381 }

References stat(), and XrdSysE2T().

Referenced by XrdCl::InitTLS().

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

Member Data Documentation

◆ pathMode

const mode_t XrdOucUtils::pathMode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH
static

Definition at line 48 of file XrdOucUtils.hh.

Referenced by makeHome().


The documentation for this class was generated from the following files: