xrootd
XrdSutAux.hh
Go to the documentation of this file.
00001 #ifndef __SUT_AUX_H__
00002 #define __SUT_AUX_H__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                        X r d S u t A u x . h h                             */
00006 /*                                                                            */
00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
00008 /*       All Rights Reserved. See XrdInfo.cc for complete License Terms       */
00009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00010 /*              DE-AC03-76-SFO0515 with the Department of Energy              */
00011 /******************************************************************************/
00012 
00013 #ifndef WIN32
00014 #include "XrdSys/XrdSysHeaders.hh"
00015 #endif
00016 #ifndef __XPROTOCOL_H
00017 #include <XProtocol/XProtocol.hh>
00018 #endif
00019 
00020 class XrdCryptoFactory;
00021 
00022 class XrdOucString;
00023 class XrdSutBucket;
00024 class XrdSutBuffer;
00025 
00026 /******************************************************************************/
00027 /*  U t i l i t y   D e f i n i t i o n s                                     */
00028 /******************************************************************************/
00029 
00030 #define XrdSutMAXBUF      4096
00031 #define XrdSutMAXPPT      512
00032 #define XrdSutMAXBUCKS    10
00033 #define XrdSutMAXINT64LEN 25
00034 #define XrdSutPRINTLEN    100
00035 
00036 enum kXRSBucketTypes {
00037    kXRS_none     =     0,      // end-of-vector
00038    kXRS_inactive =     1,      // inactive (dropped at serialization)
00039    kXRS_cryptomod = 3000,      // 3000    Name of crypto module to use
00040    kXRS_main,                  // 3001    Main buffer
00041    kXRS_srv_seal,              // 3002    Server secrets sent back as they are
00042    kXRS_clnt_seal,             // 3003    Client secrets sent back as they are
00043    kXRS_puk,                   // 3004    Public Key
00044    kXRS_cipher,                // 3005    Cipher
00045    kXRS_rtag,                  // 3006    Random Tag
00046    kXRS_signed_rtag,           // 3007    Random Tag signed by the client
00047    kXRS_user,                  // 3008    User name
00048    kXRS_host,                  // 3009    Remote Host name
00049    kXRS_creds,                 // 3010    Credentials (password, ...)
00050    kXRS_message,               // 3011    Message (null-terminated string)
00051    kXRS_srvID,                 // 3012    Server unique ID
00052    kXRS_sessionID,             // 3013    Handshake session ID
00053    kXRS_version,               // 3014    Package version 
00054    kXRS_status,                // 3015    Status code  
00055    kXRS_localstatus,           // 3016    Status code(s) saved in sealed buffer  
00056    kXRS_othercreds,            // 3017    Alternative creds (e.g. other crypto)  
00057    kXRS_cache_idx,             // 3018    Cache entry index  
00058    kXRS_clnt_opts,             // 3019    Client options, if any  
00059    kXRS_error_code,            // 3020    Error code
00060    kXRS_timestamp,             // 3021    Time stamp
00061    kXRS_x509,                  // 3022    X509 certificate
00062    kXRS_issuer_hash,           // 3023    Issuer hash
00063    kXRS_x509_req,              // 3024    X509 certificate request
00064    kXRS_cipher_alg,            // 3025    Cipher algorithm (list)
00065    kXRS_md_alg,                // 3026    MD algorithm (list)
00066    kXRS_afsinfo,               // 3027    AFS information
00067    kXRS_reserved               //         Reserved
00068 };
00069 
00070 /******************************************************************************/
00071 /*  X r d S u t B u c k S t r                                                 */
00072 /*  Return bucket string                                                      */
00073 /******************************************************************************/
00074 const char *XrdSutBuckStr(int kbck);
00075 
00076 /******************************************************************************/
00077 /*          E r r o r   L o g g i n g / T r a c i n g   F l a g s             */
00078 /******************************************************************************/
00079 #define sutTRACE_ALL       0x0007
00080 #define sutTRACE_Dump      0x0004
00081 #define sutTRACE_Debug     0x0002
00082 #define sutTRACE_Notify    0x0001
00083 
00084 /******************************************************************************/
00085 /*  U t i l i t y   F u n c t i o n s                                         */
00086 /******************************************************************************/
00087 
00088 /******************************************************************************/
00089 /*  X r d S u t S e t T r a c e                                               */
00090 /*                                                                            */
00091 /*  Set trace flags according to 'trace'                                      */
00092 /*                                                                            */
00093 /******************************************************************************/
00094 //______________________________________________________________________________
00095 void XrdSutSetTrace(kXR_int32 trace);
00096 
00097 /******************************************************************************/
00098 /*  X r d S u t M e m S e t                                                   */
00099 /*                                                                            */
00100 /*  Memory setter avoiding problems from compiler optmization                 */
00101 /*  Taken from Viega&Messier, "Secure Programming Cookbook", O'Really, #13.2  */
00102 /*                                                                            */
00103 /******************************************************************************/
00104 volatile void *XrdSutMemSet(volatile void *dst, int c, int len);
00105 
00106 /******************************************************************************/
00107 /*  X r d S u t G e t P a s s                                                 */
00108 /*                                                                            */
00109 /*  Getter for secret input: can be user defined                              */
00110 /*                                                                            */
00111 /******************************************************************************/
00112 #ifdef USE_EXTERNAL_GETPASS
00113 extern int XrdSutGetPass(const char *prompt, XrdOucString &passwd);
00114 #else
00115 int XrdSutGetPass(const char *prompt, XrdOucString &passwd);
00116 #endif
00117 
00118 /******************************************************************************/
00119 /*  X r d S u t G e t L i n e                                                 */
00120 /*                                                                            */
00121 /*  Get line from main input stream                                           */
00122 /*                                                                            */
00123 /******************************************************************************/
00124 int XrdSutGetLine(XrdOucString &line, const char *prompt = 0);
00125 
00126 /******************************************************************************/
00127 /*  X r d S u t A s k C o n f i r m                                           */
00128 /*                                                                            */
00129 /*  Ask confirmation to main input stream                                     */
00130 /*                                                                            */
00131 /******************************************************************************/
00132 bool XrdSutAskConfirm(const char *msg1, bool defact, const char *msg2 = 0);
00133 
00134 /******************************************************************************/
00135 /*  X r d S u t T o H e x                                                     */
00136 /*                                                                            */
00137 /*  Transform a buffer in an hexadecimal string                               */
00138 /*                                                                            */
00139 /******************************************************************************/
00140 int XrdSutToHex(const char *in, int lin, char *out);
00141 
00142 /******************************************************************************/
00143 /*  X r d S u t F r o m H e x                                                 */
00144 /*                                                                            */
00145 /*  Extract buffer from an hexadecimal string                                 */
00146 /*                                                                            */
00147 /******************************************************************************/
00148 int XrdSutFromHex(const char *in, char *out, int &lout);
00149 
00150 /******************************************************************************/
00151 /*  X r d S u t T i m e S t r i n g                                           */
00152 /*                                                                            */
00153 /*  Trasform a time in secs since 1Jan1970 in a string of the format          */
00154 /*     24Apr2006:09:10:23                                                     */
00155 /*  The buffer st must be supplied by the caller to contain at least 20 bytes.*/
00156 /*  This length is returned when calling the function with t=-1.              */ 
00157 /*                                                                            */
00158 /******************************************************************************/
00159 int XrdSutTimeString(int t, char *st, int opt = 0);
00160 
00161 /******************************************************************************/
00162 /*  X r d S u t E x p a n d                                                   */
00163 /*                                                                            */
00164 /*  Expand '~' or $PWD for relative paths                                     */
00165 /******************************************************************************/
00166 int XrdSutExpand(XrdOucString &path);
00167 
00168 /******************************************************************************/
00169 /*  X r d S u t R e s o l v e                                                 */
00170 /*                                                                            */
00171 /*  Resolve templates <host>, <vo>, <group>, <user> (if any)                  */
00172 /******************************************************************************/
00173 int XrdSutResolve(XrdOucString &path,
00174                   const char *ho, const char *vo, const char *gr, const char *us);
00175 
00176 /******************************************************************************/
00177 /*  X r d S u t H o m e                                                       */
00178 /*                                                                            */
00179 /*  Return the home directory                                                 */
00180 /*  Checks, in the order, HOME and pwd entry
00181 /******************************************************************************/
00182 const char *XrdSutHome();
00183 
00184 /******************************************************************************/
00185 /*  X r d S u t M k d i r                                                     */
00186 /*                                                                            */
00187 /*  Make directory dir                                                        */
00188 /******************************************************************************/
00189 int XrdSutMkdir(const char *dir, unsigned int mode = 0777,
00190                                  const char *opt = "-p");
00191 /******************************************************************************/
00192 /*  X r d S u t P a r s e T i m e                                             */
00193 /*                                                                            */
00194 /*  Parse time string of the form "<val1><unit1>:<val2><unit2>:..."           */
00195 /*  with <val> any integer and <unit> one of the following chars:             */
00196 /*        'y'     for years                                                   */
00197 /*        'd'     for days                                                    */
00198 /*        'h'     for hours                                                   */
00199 /*        'm'     for minutes                                                 */
00200 /*        's'     for seconds                                                 */
00201 /*  (e.g. "34d:10h:20s")                                                      */
00202 /*  If opt == 1, assume a string in the form "<hh>[:<ss>[:<mm>]]"             */
00203 /*  (e.g. "12:24:35" for 12 hours, 24 minutes and 35 secs)                    */
00204 /*  Return the corresponding number of seconds                                */
00205 /******************************************************************************/
00206 int XrdSutParseTime(const char *tstr, int opt = 0);
00207 
00208 /******************************************************************************/
00209 /*  X r d S u t F i l e L o c k e r                                           */
00210 /*                                                                            */
00211 /*  Guard class for file locking                                              */
00212 /*  Usage:                                                                    */
00213 /*  {                                                                         */
00214 /*     XrdSutFileLocker fl(fd,XrdSutFileLocker::kExcl);                       */
00215 /*     // File exclusively locked                                             */
00216 /*     ...                                                                    */
00217 /*  } // Unlocks file descriptor 'fd'                                         */
00218 /*                                                                            */
00219 /******************************************************************************/
00220 class XrdSutFileLocker {
00221 private:
00222    int  fdesk;
00223    bool valid;
00224 public:
00225    enum ELockType { kShared = 0, kExcl = 1 };
00226    XrdSutFileLocker(int fd, ELockType lock);
00227    ~XrdSutFileLocker();
00228    bool IsValid() const { return valid; }
00229 };
00230 
00231 #endif
00232