XRootD
XrdOucUtils.hh
Go to the documentation of this file.
1 #ifndef __XRDOUCUTILS_HH__
2 #define __XRDOUCUTILS_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d O u c U t i l s . h h */
6 /* */
7 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <string>
36 #include <unordered_set>
37 #include <vector>
38 
39 class XrdSysError;
40 class XrdOucString;
41 class XrdOucStream;
42 
44 {
45 public:
46 
47 static const mode_t pathMode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
48 
49 static int argList(char *args, char **argV, int argC);
50 
51 static char *bin2hex(char *inbuff, int dlen, char *buff, int blen, bool sep=true);
52 
53 static int hex2bin(const char *hex, char *bin, int size);
54 
55 static bool endsWith(const char *text, const char *ending, int endlen);
56 
57 static char *eText(int rc, char *eBuff, int eBlen);
58 
60  const char *what, const char *hname,
61  const char *nname, const char *pname);
62 
63 static bool findPgm(const char *pgm, XrdOucString& path);
64 
65 static int fmtBytes(long long val, char *buff, int bsz);
66 
67 static char *genPath(const char *path, const char *inst, const char *psfx=0);
68 
69 static int genPath(char *buff, int blen, const char *path, const char *psfx=0);
70 
71 static char *getFile(const char *path, int &rc, int maxsz=10240,
72  bool notempty=true);
73 
74 static bool getGID(const char *gName, gid_t &gID);
75 
76 static bool getUID(const char *uName, uid_t &uID, gid_t *gID=0);
77 
78 static int GidName(gid_t gID, char *gName, int gNsz, time_t keepT=0);
79 
80 static int GroupName(gid_t gID, char *gName, int gNsz);
81 
82 static const char *i2bstr(char *buff, int blen, int val, bool pad=false);
83 
84 static const char *HSize(size_t bytes, char* buff, int bsz);
85 
86 static char *Ident(long long &mySID, char *iBuff, int iBlen,
87  const char *iHost, const char *iProg, const char *iName,
88  int Port);
89 
90 static const char *InstName(int TranOpt=0);
91 
92 static const char *InstName(const char *name, int Fillit=1);
93 
94 static int is1of(char *val, const char **clist);
95 
96 static int isFWD(const char *path, int *port=0, char *hBuff=0, int hBLen=0,
97  bool pTrim=false);
98 
99 static int Log2(unsigned long long n);
100 
101 static int Log10(unsigned long long n);
102 
103 static void makeHome(XrdSysError &eDest, const char *inst);
104 
105 static bool makeHome(XrdSysError &eDest, const char *inst,
106  const char *path, mode_t mode);
107 
108 static int makePath(char *path, mode_t mode, bool reset=false);
109 
110 static bool mode2mask(const char *mode, mode_t &mask);
111 
113  const char *libName, char *&path, char **libparm);
114 
115 static char *parseHome(XrdSysError &eDest, XrdOucStream &Config, int &mode);
116 
117 static int ReLink(const char *path, const char *target, mode_t mode=0);
118 
119 static void Sanitize(char *instr, char subc='_');
120 
121 static char *subLogfn(XrdSysError &eDest, const char *inst, char *logfn);
122 
123 static void toLower(char *str);
124 
125 static int Token(const char **str, char delim, char *buff, int bsz);
126 
127 static void Undercover(XrdSysError &eDest, int noLog, int *pipeFD = 0);
128 
129 static int UidName(uid_t uID, char *uName, int uNsz, time_t keepT=0);
130 
131 static int UserName(uid_t uID, char *uName, int uNsz);
132 
133 static
134 const char *ValPath(const char *path, mode_t allow, bool isdir);
135 
136 static bool PidFile(XrdSysError &eDest, const char *path);
137 
138 static int getModificationTime(const char * path, time_t & modificationTime);
139 
140 static void trim(std::string & str);
141 
142 static void trim(std::string_view & sv);
143 
146 
147 };
148 #endif
static XrdSysError eDest(0,"crypto_")
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)
Definition: XrdOucUtils.cc:559
static const mode_t pathMode
Definition: XrdOucUtils.hh:47
static const char * HSize(size_t bytes, char *buff, int bsz)
Definition: XrdOucUtils.cc:679
static int isFWD(const char *path, int *port=0, char *hBuff=0, int hBLen=0, bool pTrim=false)
Definition: XrdOucUtils.cc:847
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)
Definition: XrdOucUtils.cc:779
static bool getUID(const char *uName, uid_t &uID, gid_t *gID=0)
Definition: XrdOucUtils.cc:575
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)
Definition: XrdOucUtils.cc:463
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)
Definition: XrdOucUtils.cc:184
static int is1of(char *val, const char **clist)
Definition: XrdOucUtils.cc:835
static const char * InstName(int TranOpt=0)
Definition: XrdOucUtils.cc:809
static char * eText(int rc, char *eBuff, int eBlen)
Definition: XrdOucUtils.cc:243
static int argList(char *args, char **argV, int argC)
Definition: XrdOucUtils.cc:125
static bool mode2mask(const char *mode, mode_t &mask)
static int GidName(gid_t gID, char *gName, int gNsz, time_t keepT=0)
Definition: XrdOucUtils.cc:593
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)
Definition: XrdOucUtils.cc:164
static int Log10(unsigned long long n)
Definition: XrdOucUtils.cc:910
static int doIf(XrdSysError *eDest, XrdOucStream &Config, const char *what, const char *hname, const char *nname, const char *pname)
Definition: XrdOucUtils.cc:277
static int makePath(char *path, mode_t mode, bool reset=false)
Definition: XrdOucUtils.cc:994
static int GroupName(gid_t gID, char *gName, int gNsz)
Definition: XrdOucUtils.cc:642
static void trim(std::string &str)
static bool findPgm(const char *pgm, XrdOucString &path)
Definition: XrdOucUtils.cc:400
static bool PidFile(XrdSysError &eDest, const char *path)
static const char * i2bstr(char *buff, int blen, int val, bool pad=false)
Definition: XrdOucUtils.cc:710
static void toLower(char *str)
static int fmtBytes(long long val, char *buff, int bsz)
Definition: XrdOucUtils.cc:436
static int Log2(unsigned long long n)
Definition: XrdOucUtils.cc:895
static void makeHome(XrdSysError &eDest, const char *inst)
Definition: XrdOucUtils.cc:927
static bool endsWith(const char *text, const char *ending, int endlen)
Definition: XrdOucUtils.cc:229
static void Undercover(XrdSysError &eDest, int noLog, int *pipeFD=0)
static char * getFile(const char *path, int &rc, int maxsz=10240, bool notempty=true)
Definition: XrdOucUtils.cc:502
static char * subLogfn(XrdSysError &eDest, const char *inst, char *logfn)
XrdCmsConfig Config
@ hex
Definition: XrdSysTrace.hh:42