xrootd
XrdSutAux.hh
Go to the documentation of this file.
1 #ifndef __SUT_AUX_H__
2 #define __SUT_AUX_H__
3 /******************************************************************************/
4 /* */
5 /* X r d S u t A u x . h h */
6 /* */
7 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC03-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 #ifndef WIN32
14 #include "XrdSys/XrdSysHeaders.hh"
15 #endif
16 #ifndef __XPROTOCOL_H
17 #include <XProtocol/XProtocol.hh>
18 #endif
19 
20 class XrdCryptoFactory;
21 
22 class XrdOucString;
23 class XrdSutBucket;
24 class XrdSutBuffer;
25 
26 /******************************************************************************/
27 /* U t i l i t y D e f i n i t i o n s */
28 /******************************************************************************/
29 
30 #define XrdSutMAXBUF 4096
31 #define XrdSutMAXPPT 512
32 #define XrdSutMAXBUCKS 10
33 #define XrdSutMAXINT64LEN 25
34 #define XrdSutPRINTLEN 100
35 
37  kXRS_none = 0, // end-of-vector
38  kXRS_inactive = 1, // inactive (dropped at serialization)
39  kXRS_cryptomod = 3000, // 3000 Name of crypto module to use
40  kXRS_main, // 3001 Main buffer
41  kXRS_srv_seal, // 3002 Server secrets sent back as they are
42  kXRS_clnt_seal, // 3003 Client secrets sent back as they are
43  kXRS_puk, // 3004 Public Key
44  kXRS_cipher, // 3005 Cipher
45  kXRS_rtag, // 3006 Random Tag
46  kXRS_signed_rtag, // 3007 Random Tag signed by the client
47  kXRS_user, // 3008 User name
48  kXRS_host, // 3009 Remote Host name
49  kXRS_creds, // 3010 Credentials (password, ...)
50  kXRS_message, // 3011 Message (null-terminated string)
51  kXRS_srvID, // 3012 Server unique ID
52  kXRS_sessionID, // 3013 Handshake session ID
53  kXRS_version, // 3014 Package version
54  kXRS_status, // 3015 Status code
55  kXRS_localstatus, // 3016 Status code(s) saved in sealed buffer
56  kXRS_othercreds, // 3017 Alternative creds (e.g. other crypto)
57  kXRS_cache_idx, // 3018 Cache entry index
58  kXRS_clnt_opts, // 3019 Client options, if any
59  kXRS_error_code, // 3020 Error code
60  kXRS_timestamp, // 3021 Time stamp
61  kXRS_x509, // 3022 X509 certificate
62  kXRS_issuer_hash, // 3023 Issuer hash
63  kXRS_x509_req, // 3024 X509 certificate request
64  kXRS_cipher_alg, // 3025 Cipher algorithm (list)
65  kXRS_md_alg, // 3026 MD algorithm (list)
66  kXRS_afsinfo, // 3027 AFS information
67  kXRS_reserved // Reserved
68 };
69 
70 /******************************************************************************/
71 /* X r d S u t B u c k S t r */
72 /* Return bucket string */
73 /******************************************************************************/
74 const char *XrdSutBuckStr(int kbck);
75 
76 /******************************************************************************/
77 /* E r r o r L o g g i n g / T r a c i n g F l a g s */
78 /******************************************************************************/
79 #define sutTRACE_ALL 0x0007
80 #define sutTRACE_Dump 0x0004
81 #define sutTRACE_Debug 0x0002
82 #define sutTRACE_Notify 0x0001
83 
84 /******************************************************************************/
85 /* U t i l i t y F u n c t i o n s */
86 /******************************************************************************/
87 
88 /******************************************************************************/
89 /* X r d S u t S e t T r a c e */
90 /* */
91 /* Set trace flags according to 'trace' */
92 /* */
93 /******************************************************************************/
94 //______________________________________________________________________________
95 void XrdSutSetTrace(kXR_int32 trace);
96 
97 /******************************************************************************/
98 /* X r d S u t M e m S e t */
99 /* */
100 /* Memory setter avoiding problems from compiler optmization */
101 /* Taken from Viega&Messier, "Secure Programming Cookbook", O'Really, #13.2 */
102 /* */
103 /******************************************************************************/
104 volatile void *XrdSutMemSet(volatile void *dst, int c, int len);
105 
106 /******************************************************************************/
107 /* X r d S u t G e t P a s s */
108 /* */
109 /* Getter for secret input: can be user defined */
110 /* */
111 /******************************************************************************/
112 #ifdef USE_EXTERNAL_GETPASS
113 extern int XrdSutGetPass(const char *prompt, XrdOucString &passwd);
114 #else
115 int XrdSutGetPass(const char *prompt, XrdOucString &passwd);
116 #endif
117 
118 /******************************************************************************/
119 /* X r d S u t G e t L i n e */
120 /* */
121 /* Get line from main input stream */
122 /* */
123 /******************************************************************************/
124 int XrdSutGetLine(XrdOucString &line, const char *prompt = 0);
125 
126 /******************************************************************************/
127 /* X r d S u t A s k C o n f i r m */
128 /* */
129 /* Ask confirmation to main input stream */
130 /* */
131 /******************************************************************************/
132 bool XrdSutAskConfirm(const char *msg1, bool defact, const char *msg2 = 0);
133 
134 /******************************************************************************/
135 /* X r d S u t T o H e x */
136 /* */
137 /* Transform a buffer in an hexadecimal string */
138 /* */
139 /******************************************************************************/
140 int XrdSutToHex(const char *in, int lin, char *out);
141 
142 /******************************************************************************/
143 /* X r d S u t F r o m H e x */
144 /* */
145 /* Extract buffer from an hexadecimal string */
146 /* */
147 /******************************************************************************/
148 int XrdSutFromHex(const char *in, char *out, int &lout);
149 
150 /******************************************************************************/
151 /* X r d S u t T i m e S t r i n g */
152 /* */
153 /* Trasform a time in secs since 1Jan1970 in a string of the format */
154 /* 24Apr2006:09:10:23 */
155 /* The buffer st must be supplied by the caller to contain at least 20 bytes.*/
156 /* This length is returned when calling the function with t=-1. */
157 /* */
158 /******************************************************************************/
159 int XrdSutTimeString(int t, char *st, int opt = 0);
160 
161 /******************************************************************************/
162 /* X r d S u t E x p a n d */
163 /* */
164 /* Expand '~' or $PWD for relative paths */
165 /******************************************************************************/
166 int XrdSutExpand(XrdOucString &path);
167 
168 /******************************************************************************/
169 /* X r d S u t R e s o l v e */
170 /* */
171 /* Resolve templates <host>, <vo>, <group>, <user> (if any) */
172 /******************************************************************************/
173 int XrdSutResolve(XrdOucString &path,
174  const char *ho, const char *vo, const char *gr, const char *us);
175 
176 /******************************************************************************/
177 /* X r d S u t H o m e */
178 /* */
179 /* Return the home directory */
180 /* Checks, in the order, HOME and pwd entry */
181 /******************************************************************************/
182 const char *XrdSutHome();
183 
184 /******************************************************************************/
185 /* X r d S u t M k d i r */
186 /* */
187 /* Make directory dir */
188 /******************************************************************************/
189 int XrdSutMkdir(const char *dir, unsigned int mode = 0777,
190  const char *opt = "-p");
191 /******************************************************************************/
192 /* X r d S u t P a r s e T i m e */
193 /* */
194 /* Parse time string of the form "<val1><unit1>:<val2><unit2>:..." */
195 /* with <val> any integer and <unit> one of the following chars: */
196 /* 'y' for years */
197 /* 'd' for days */
198 /* 'h' for hours */
199 /* 'm' for minutes */
200 /* 's' for seconds */
201 /* (e.g. "34d:10h:20s") */
202 /* If opt == 1, assume a string in the form "<hh>[:<ss>[:<mm>]]" */
203 /* (e.g. "12:24:35" for 12 hours, 24 minutes and 35 secs) */
204 /* Return the corresponding number of seconds */
205 /******************************************************************************/
206 int XrdSutParseTime(const char *tstr, int opt = 0);
207 
208 /******************************************************************************/
209 /* X r d S u t F i l e L o c k e r */
210 /* */
211 /* Guard class for file locking */
212 /* Usage: */
213 /* { */
214 /* XrdSutFileLocker fl(fd,XrdSutFileLocker::kExcl); */
215 /* // File exclusively locked */
216 /* ... */
217 /* } // Unlocks file descriptor 'fd' */
218 /* */
219 /******************************************************************************/
221 private:
222  int fdesk;
223  bool valid;
224 public:
225  enum ELockType { kShared = 0, kExcl = 1 };
226  XrdSutFileLocker(int fd, ELockType lock);
228  bool IsValid() const { return valid; }
229 };
230 
231 #endif
232