|
|
|||
File indexing completed on 2026-01-08 10:33:34
0001 #ifndef __SUT_AUX_H__ 0002 #define __SUT_AUX_H__ 0003 /******************************************************************************/ 0004 /* */ 0005 /* X r d S u t A u x . h h */ 0006 /* */ 0007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */ 0008 /* Produced by Gerri Ganis for CERN */ 0009 /* */ 0010 /* This file is part of the XRootD software suite. */ 0011 /* */ 0012 /* XRootD is free software: you can redistribute it and/or modify it under */ 0013 /* the terms of the GNU Lesser General Public License as published by the */ 0014 /* Free Software Foundation, either version 3 of the License, or (at your */ 0015 /* option) any later version. */ 0016 /* */ 0017 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 0018 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 0019 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 0020 /* License for more details. */ 0021 /* */ 0022 /* You should have received a copy of the GNU Lesser General Public License */ 0023 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 0024 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 0025 /* */ 0026 /* The copyright holder's institutional names and contributor's names may not */ 0027 /* be used to endorse or promote products derived from this software without */ 0028 /* specific prior written permission of the institution or contributor. */ 0029 /******************************************************************************/ 0030 0031 #ifndef WIN32 0032 #include "XrdSys/XrdSysHeaders.hh" 0033 #endif 0034 #ifndef __XPROTOCOL_H 0035 #include "XProtocol/XPtypes.hh" 0036 #endif 0037 0038 class XrdCryptoFactory; 0039 0040 class XrdOucString; 0041 class XrdSutBucket; 0042 class XrdSutBuffer; 0043 0044 /******************************************************************************/ 0045 /* U t i l i t y D e f i n i t i o n s */ 0046 /******************************************************************************/ 0047 0048 #define XrdSutMAXBUF 4096 0049 #define XrdSutMAXPPT 512 0050 #define XrdSutMAXBUCKS 10 0051 #define XrdSutMAXINT64LEN 25 0052 #define XrdSutPRINTLEN 100 0053 0054 enum kXRSBucketTypes { 0055 kXRS_none = 0, // end-of-vector 0056 kXRS_inactive = 1, // inactive (dropped at serialization) 0057 kXRS_cryptomod = 3000, // 3000 Name of crypto module to use 0058 kXRS_main, // 3001 Main buffer 0059 kXRS_srv_seal, // 3002 Server secrets sent back as they are 0060 kXRS_clnt_seal, // 3003 Client secrets sent back as they are 0061 kXRS_puk, // 3004 Public Key 0062 kXRS_cipher, // 3005 Cipher 0063 kXRS_rtag, // 3006 Random Tag 0064 kXRS_signed_rtag, // 3007 Random Tag signed by the client 0065 kXRS_user, // 3008 User name 0066 kXRS_host, // 3009 Remote Host name 0067 kXRS_creds, // 3010 Credentials (password, ...) 0068 kXRS_message, // 3011 Message (null-terminated string) 0069 kXRS_srvID, // 3012 Server unique ID 0070 kXRS_sessionID, // 3013 Handshake session ID 0071 kXRS_version, // 3014 Package version 0072 kXRS_status, // 3015 Status code 0073 kXRS_localstatus, // 3016 Status code(s) saved in sealed buffer 0074 kXRS_othercreds, // 3017 Alternative creds (e.g. other crypto) 0075 kXRS_cache_idx, // 3018 Cache entry index 0076 kXRS_clnt_opts, // 3019 Client options, if any 0077 kXRS_error_code, // 3020 Error code 0078 kXRS_timestamp, // 3021 Time stamp 0079 kXRS_x509, // 3022 X509 certificate 0080 kXRS_issuer_hash, // 3023 Issuer hash 0081 kXRS_x509_req, // 3024 X509 certificate request 0082 kXRS_cipher_alg, // 3025 Cipher algorithm (list) 0083 kXRS_md_alg, // 3026 MD algorithm (list) 0084 kXRS_afsinfo, // 3027 AFS information 0085 kXRS_reserved // Reserved 0086 }; 0087 0088 /******************************************************************************/ 0089 /* X r d S u t B u c k S t r */ 0090 /* Return bucket string */ 0091 /******************************************************************************/ 0092 const char *XrdSutBuckStr(int kbck); 0093 0094 /******************************************************************************/ 0095 /* E r r o r L o g g i n g / T r a c i n g F l a g s */ 0096 /******************************************************************************/ 0097 #define sutTRACE_ALL 0x0007 0098 #define sutTRACE_Dump 0x0004 0099 #define sutTRACE_Debug 0x0002 0100 #define sutTRACE_Notify 0x0001 0101 0102 /******************************************************************************/ 0103 /* U t i l i t y F u n c t i o n s */ 0104 /******************************************************************************/ 0105 0106 /******************************************************************************/ 0107 /* X r d S u t S e t T r a c e */ 0108 /* */ 0109 /* Set trace flags according to 'trace' */ 0110 /* */ 0111 /******************************************************************************/ 0112 //______________________________________________________________________________ 0113 void XrdSutSetTrace(kXR_int32 trace); 0114 0115 /******************************************************************************/ 0116 /* X r d S u t M e m S e t */ 0117 /* */ 0118 /* Memory setter avoiding problems from compiler optmization */ 0119 /* Taken from Viega&Messier, "Secure Programming Cookbook", O'Really, #13.2 */ 0120 /* */ 0121 /******************************************************************************/ 0122 volatile void *XrdSutMemSet(volatile void *dst, int c, int len); 0123 0124 /******************************************************************************/ 0125 /* X r d S u t G e t P a s s */ 0126 /* */ 0127 /* Getter for secret input: can be user defined */ 0128 /* */ 0129 /******************************************************************************/ 0130 #ifdef USE_EXTERNAL_GETPASS 0131 extern int XrdSutGetPass(const char *prompt, XrdOucString &passwd); 0132 #else 0133 int XrdSutGetPass(const char *prompt, XrdOucString &passwd); 0134 #endif 0135 0136 /******************************************************************************/ 0137 /* X r d S u t G e t L i n e */ 0138 /* */ 0139 /* Get line from main input stream */ 0140 /* */ 0141 /******************************************************************************/ 0142 int XrdSutGetLine(XrdOucString &line, const char *prompt = 0); 0143 0144 /******************************************************************************/ 0145 /* X r d S u t A s k C o n f i r m */ 0146 /* */ 0147 /* Ask confirmation to main input stream */ 0148 /* */ 0149 /******************************************************************************/ 0150 bool XrdSutAskConfirm(const char *msg1, bool defact, const char *msg2 = 0); 0151 0152 /******************************************************************************/ 0153 /* X r d S u t T o H e x */ 0154 /* */ 0155 /* Transform a buffer in an hexadecimal string */ 0156 /* */ 0157 /******************************************************************************/ 0158 int XrdSutToHex(const char *in, int lin, char *out); 0159 0160 /******************************************************************************/ 0161 /* X r d S u t F r o m H e x */ 0162 /* */ 0163 /* Extract buffer from an hexadecimal string */ 0164 /* */ 0165 /******************************************************************************/ 0166 int XrdSutFromHex(const char *in, char *out, int &lout); 0167 0168 /******************************************************************************/ 0169 /* X r d S u t T i m e S t r i n g */ 0170 /* */ 0171 /* Trasform a time in secs since 1Jan1970 in a string of the format */ 0172 /* 24Apr2006:09:10:23 */ 0173 /* The buffer st must be supplied by the caller to contain at least 20 bytes.*/ 0174 /* This length is returned when calling the function with t=-1. */ 0175 /* */ 0176 /******************************************************************************/ 0177 int XrdSutTimeString(int t, char *st, int opt = 0); 0178 0179 /******************************************************************************/ 0180 /* X r d S u t E x p a n d */ 0181 /* */ 0182 /* Expand '~' or $PWD for relative paths */ 0183 /******************************************************************************/ 0184 int XrdSutExpand(XrdOucString &path); 0185 0186 /******************************************************************************/ 0187 /* X r d S u t R e s o l v e */ 0188 /* */ 0189 /* Resolve templates <host>, <vo>, <group>, <user> (if any) */ 0190 /******************************************************************************/ 0191 int XrdSutResolve(XrdOucString &path, 0192 const char *ho, const char *vo, const char *gr, const char *us); 0193 0194 /******************************************************************************/ 0195 /* X r d S u t H o m e */ 0196 /* */ 0197 /* Return the home directory */ 0198 /* Checks, in the order, HOME and pwd entry */ 0199 /******************************************************************************/ 0200 const char *XrdSutHome(); 0201 0202 /******************************************************************************/ 0203 /* X r d S u t M k d i r */ 0204 /* */ 0205 /* Make directory dir */ 0206 /******************************************************************************/ 0207 int XrdSutMkdir(const char *dir, unsigned int mode = 0777, 0208 const char *opt = "-p"); 0209 /******************************************************************************/ 0210 /* X r d S u t P a r s e T i m e */ 0211 /* */ 0212 /* Parse time string of the form "<val1><unit1>:<val2><unit2>:..." */ 0213 /* with <val> any integer and <unit> one of the following chars: */ 0214 /* 'y' for years */ 0215 /* 'd' for days */ 0216 /* 'h' for hours */ 0217 /* 'm' for minutes */ 0218 /* 's' for seconds */ 0219 /* (e.g. "34d:10h:20s") */ 0220 /* If opt == 1, assume a string in the form ".hh"[:<ss>[:<mm>]]" */ 0221 /* (e.g. "12:24:35" for 12 hours, 24 minutes and 35 secs) */ 0222 /* Return the corresponding number of seconds */ 0223 /******************************************************************************/ 0224 int XrdSutParseTime(const char *tstr, int opt = 0); 0225 0226 /******************************************************************************/ 0227 /* X r d S u t F i l e L o c k e r */ 0228 /* */ 0229 /* Guard class for file locking */ 0230 /* Usage: */ 0231 /* { */ 0232 /* XrdSutFileLocker fl(fd,XrdSutFileLocker::kExcl); */ 0233 /* // File exclusively locked */ 0234 /* ... */ 0235 /* } // Unlocks file descriptor 'fd' */ 0236 /* */ 0237 /******************************************************************************/ 0238 class XrdSutFileLocker { 0239 private: 0240 int fdesk; 0241 bool valid; 0242 public: 0243 enum ELockType { kShared = 0, kExcl = 1 }; 0244 XrdSutFileLocker(int fd, ELockType lock); 0245 ~XrdSutFileLocker(); 0246 bool IsValid() const { return valid; } 0247 }; 0248 0249 #endif 0250
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|