XrdSutAux.hh

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

Generated on Tue Jul 5 14:47:02 2011 for ROOT_528-00b_version by  doxygen 1.5.1