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