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