Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:27:55

0001 #ifndef __XRDOUCUTILS_HH__
0002 #define __XRDOUCUTILS_HH__
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                        X r d O u c U t i l s . h h                         */
0006 /*                                                                            */
0007 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*                            All Rights Reserved                             */
0009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0011 /*                                                                            */
0012 /* This file is part of the XRootD software suite.                            */
0013 /*                                                                            */
0014 /* XRootD is free software: you can redistribute it and/or modify it under    */
0015 /* the terms of the GNU Lesser General Public License as published by the     */
0016 /* Free Software Foundation, either version 3 of the License, or (at your     */
0017 /* option) any later version.                                                 */
0018 /*                                                                            */
0019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0022 /* License for more details.                                                  */
0023 /*                                                                            */
0024 /* You should have received a copy of the GNU Lesser General Public License   */
0025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0027 /*                                                                            */
0028 /* The copyright holder's institutional names and contributor's names may not */
0029 /* be used to endorse or promote products derived from this software without  */
0030 /* specific prior written permission of the institution or contributor.       */
0031 /******************************************************************************/
0032 
0033 #include <sys/types.h>
0034 #include <sys/stat.h>
0035 #include <string>
0036 #include <unordered_set>
0037   
0038 class XrdSysError;
0039 class XrdOucString;
0040 class XrdOucStream;
0041 
0042 class XrdOucUtils
0043 {
0044 public:
0045 
0046 static inline std::string OBFUSCATION_STR = "REDACTED";
0047 
0048 static const mode_t pathMode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
0049 
0050 static int   argList(char *args, char **argV, int argC);
0051 
0052 static char *bin2hex(char *inbuff, int dlen, char *buff, int blen, bool sep=true);
0053 
0054 static bool  endsWith(const char *text, const char *ending, int endlen);
0055 
0056 static char *eText(int rc, char *eBuff, int eBlen);
0057 
0058 static int   doIf(XrdSysError *eDest, XrdOucStream &Config,
0059                   const char *what, const char *hname, 
0060                                     const char *nname, const char *pname);
0061 
0062 static bool  findPgm(const char *pgm, XrdOucString& path);
0063  
0064 static int   fmtBytes(long long val, char *buff, int bsz);
0065 
0066 static char *genPath(const char *path, const char *inst, const char *psfx=0);
0067 
0068 static int   genPath(char *buff, int blen, const char *path, const char *psfx=0);
0069 
0070 static char *getFile(const char *path, int &rc, int maxsz=10240,
0071                      bool notempty=true);
0072 
0073 static bool  getGID(const char *gName, gid_t &gID);
0074 
0075 static bool  getUID(const char *uName, uid_t &uID, gid_t *gID=0);
0076 
0077 static int   GidName(gid_t gID, char *gName, int gNsz, time_t keepT=0);
0078 
0079 static int   GroupName(gid_t gID, char *gName, int gNsz);
0080 
0081 static const char *i2bstr(char *buff, int blen, int val, bool pad=false);
0082 
0083 static char *Ident(long long  &mySID, char *iBuff, int iBlen,
0084                    const char *iHost, const char *iProg, const char *iName,
0085                    int Port);
0086 
0087 static const char *InstName(int TranOpt=0);
0088 
0089 static const char *InstName(const char *name, int Fillit=1);
0090 
0091 static int   is1of(char *val, const char **clist);
0092 
0093 static int   isFWD(const char *path, int *port=0, char *hBuff=0, int hBLen=0,
0094                    bool pTrim=false);
0095 
0096 static int   Log2(unsigned long long n);
0097 
0098 static int   Log10(unsigned long long n);
0099 
0100 static void  makeHome(XrdSysError &eDest, const char *inst);
0101 
0102 static bool  makeHome(XrdSysError &eDest, const char *inst,
0103                                           const char *path, mode_t mode);
0104 
0105 static int   makePath(char *path, mode_t mode, bool reset=false);
0106 
0107 static bool  mode2mask(const char *mode, mode_t &mask);
0108 
0109 static bool  parseLib(XrdSysError &eDest, XrdOucStream &Config,
0110                       const char *libName, char *&path, char **libparm);
0111 
0112 static char *parseHome(XrdSysError &eDest, XrdOucStream &Config, int &mode);
0113 
0114 static int   ReLink(const char *path, const char *target, mode_t mode=0);
0115 
0116 static void  Sanitize(char *instr, char subc='_');
0117  
0118 static char *subLogfn(XrdSysError &eDest, const char *inst, char *logfn);
0119 
0120 static void  toLower(char *str);
0121 
0122 static int   Token(const char **str, char delim, char *buff, int bsz);
0123 
0124 static void  Undercover(XrdSysError &eDest, int noLog, int *pipeFD = 0);
0125 
0126 static int   UidName(uid_t uID, char *uName, int uNsz, time_t keepT=0);
0127 
0128 static int   UserName(uid_t uID, char *uName, int uNsz);
0129 
0130 static
0131 const char  *ValPath(const char *path, mode_t allow, bool isdir);
0132 
0133 static bool PidFile(XrdSysError &eDest, const char *path);
0134 
0135 static int getModificationTime(const char * path, time_t & modificationTime);
0136 
0137 static void trim(std::string & str);
0138 
0139 static std::string obfuscate(const std::string & input, const std::unordered_set<std::string> & keysToObfuscate,const char keyValueDelimiter, const char listDelimiter);
0140 
0141     XrdOucUtils() {}
0142     ~XrdOucUtils() {}
0143 };
0144 #endif