XRootD
XrdClXRootDTransport.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@cern.ch>
4 //------------------------------------------------------------------------------
5 // This file is part of the XRootD software suite.
6 //
7 // XRootD is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // XRootD is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19 //
20 // In applying this licence, CERN does not waive the privileges and immunities
21 // granted to it by virtue of its status as an Intergovernmental Organization
22 // or submit itself to any jurisdiction.
23 //------------------------------------------------------------------------------
24 
25 #ifndef __XRD_CL_XROOTD_TRANSPORT_HH__
26 #define __XRD_CL_XROOTD_TRANSPORT_HH__
27 
28 #include "XrdCl/XrdClPostMaster.hh"
29 #include "XrdCl/XrdClMessage.hh"
30 #include "XProtocol/XProtocol.hh"
32 #include "XrdOuc/XrdOucEnv.hh"
33 
34 class XrdSysPlugin;
35 class XrdSecProtect;
36 
37 namespace XrdCl
38 {
39  class Tls;
40  class Socket;
41  struct XRootDChannelInfo;
42  struct PluginUnloadHandler;
43 
44  //----------------------------------------------------------------------------
46  //----------------------------------------------------------------------------
48  {
49  public:
50  //------------------------------------------------------------------------
52  //------------------------------------------------------------------------
54 
55  //------------------------------------------------------------------------
57  //------------------------------------------------------------------------
59 
60  //------------------------------------------------------------------------
71  //------------------------------------------------------------------------
72  virtual XRootDStatus GetHeader( Message &message, Socket *socket );
73 
74  //------------------------------------------------------------------------
83  //------------------------------------------------------------------------
84  virtual XRootDStatus GetBody( Message &message, Socket *socket );
85 
86  //------------------------------------------------------------------------
96  //------------------------------------------------------------------------
97  virtual XRootDStatus GetMore( Message &message, Socket *socket );
98 
99  //------------------------------------------------------------------------
101  //------------------------------------------------------------------------
102  virtual void InitializeChannel( const URL &url,
103  AnyObject &channelData );
104 
105  //------------------------------------------------------------------------
107  //------------------------------------------------------------------------
108  virtual void FinalizeChannel( AnyObject &channelData );
109 
110  //------------------------------------------------------------------------
112  //------------------------------------------------------------------------
113  virtual XRootDStatus HandShake( HandShakeData *handShakeData,
114  AnyObject &channelData );
115 
116  //------------------------------------------------------------------------
117  // @return true if handshake has been done and stream is connected,
118  // false otherwise
119  //------------------------------------------------------------------------
120  virtual bool HandShakeDone( HandShakeData *handShakeData,
121  AnyObject &channelData );
122 
123  //------------------------------------------------------------------------
125  //------------------------------------------------------------------------
126  virtual bool IsStreamTTLElapsed( time_t time,
127  AnyObject &channelData );
128 
129  //------------------------------------------------------------------------
132  //------------------------------------------------------------------------
133  virtual Status IsStreamBroken( time_t inactiveTime,
134  AnyObject &channelData );
135 
136  //------------------------------------------------------------------------
142  //------------------------------------------------------------------------
143  virtual PathID Multiplex( Message *msg,
144  AnyObject &channelData,
145  PathID *hint = 0 );
146 
147  //------------------------------------------------------------------------
153  //------------------------------------------------------------------------
154  virtual PathID MultiplexSubStream( Message *msg,
155  AnyObject &channelData,
156  PathID *hint = 0 );
157 
158  //------------------------------------------------------------------------
160  //------------------------------------------------------------------------
161  virtual uint16_t SubStreamNumber( AnyObject &channelData );
162 
163  //------------------------------------------------------------------------
166  //------------------------------------------------------------------------
167  virtual bool NeedControlConnection()
168  {
169  return true;
170  }
171 
172  //------------------------------------------------------------------------
174  //------------------------------------------------------------------------
175  inline static XRootDStatus MarshallRequest( Message *msg )
176  {
177  MarshallRequest( msg->GetBuffer() );
178  msg->SetIsMarshalled( true );
179  return XRootDStatus();
180  }
181 
182  //------------------------------------------------------------------------
184  //------------------------------------------------------------------------
185  static XRootDStatus MarshallRequest( char *msg );
186 
187  //------------------------------------------------------------------------
190  //------------------------------------------------------------------------
191  static XRootDStatus UnMarshallRequest( Message *msg );
192 
193  //------------------------------------------------------------------------
195  //------------------------------------------------------------------------
196  static XRootDStatus UnMarshallBody( Message *msg, uint16_t reqType );
197 
198  //------------------------------------------------------------------------
200  //------------------------------------------------------------------------
201  static XRootDStatus UnMarshalStatusBody( Message &msg, uint16_t reqType );
202 
203  //------------------------------------------------------------------------
205  //------------------------------------------------------------------------
207 
208  //------------------------------------------------------------------------
210  //------------------------------------------------------------------------
211  static void UnMarshallHeader( Message &msg );
212 
213  //------------------------------------------------------------------------
215  //------------------------------------------------------------------------
216  static void LogErrorResponse( const Message &msg );
217 
218  //------------------------------------------------------------------------
220  //------------------------------------------------------------------------
221  static uint16_t NbConnectedStrm( AnyObject &channelData );
222 
223  //------------------------------------------------------------------------
225  //------------------------------------------------------------------------
226  virtual void Disconnect( AnyObject &channelData,
227  uint16_t subStreamId );
228 
229  //------------------------------------------------------------------------
231  //------------------------------------------------------------------------
232  virtual Status Query( uint16_t query,
233  AnyObject &result,
234  AnyObject &channelData );
235 
236 
237  //------------------------------------------------------------------------
239  //------------------------------------------------------------------------
240  static void GenerateDescription( char *msg, std::ostringstream &o );
241 
242  //------------------------------------------------------------------------
244  //------------------------------------------------------------------------
245  inline static void SetDescription( Message *msg )
246  {
247  std::ostringstream o;
248  GenerateDescription( msg->GetBuffer(), o );
249  msg->SetDescription( o.str() );
250  }
251 
252  //------------------------------------------------------------------------
254  //------------------------------------------------------------------------
255  virtual uint32_t MessageReceived( Message &msg,
256  uint16_t subStream,
257  AnyObject &channelData );
258 
259  //------------------------------------------------------------------------
261  //------------------------------------------------------------------------
262  virtual void MessageSent( Message *msg,
263  uint16_t subStream,
264  uint32_t bytesSent,
265  AnyObject &channelData );
266 
267  //------------------------------------------------------------------------
269  //------------------------------------------------------------------------
270  virtual Status GetSignature( Message *toSign, Message *&sign,
271  AnyObject &channelData );
272 
273  //------------------------------------------------------------------------
275  //------------------------------------------------------------------------
276  virtual Status GetSignature( Message *toSign, Message *&sign,
277  XRootDChannelInfo *info );
278 
279  //------------------------------------------------------------------------
281  //------------------------------------------------------------------------
282  virtual void DecFileInstCnt( AnyObject &channelData );
283 
284  //------------------------------------------------------------------------
286  //------------------------------------------------------------------------
287  virtual void WaitBeforeExit();
288 
289  //------------------------------------------------------------------------
291  //------------------------------------------------------------------------
292  virtual bool NeedEncryption( HandShakeData *handShakeData,
293  AnyObject &channelData );
294 
295  //------------------------------------------------------------------------
297  //------------------------------------------------------------------------
298  virtual URL GetBindPreference( const URL &url,
299  AnyObject &channelData );
300 
301  private:
302 
303  //------------------------------------------------------------------------
304  // Hand shake the main stream
305  //------------------------------------------------------------------------
306  XRootDStatus HandShakeMain( HandShakeData *handShakeData,
307  AnyObject &channelData );
308 
309  //------------------------------------------------------------------------
310  // Hand shake a parallel stream
311  //------------------------------------------------------------------------
312  XRootDStatus HandShakeParallel( HandShakeData *handShakeData,
313  AnyObject &channelData );
314 
315  //------------------------------------------------------------------------
316  // Generate the message to be sent as an initial handshake
317  // (handshake + kXR_protocol)
318  //------------------------------------------------------------------------
319  Message *GenerateInitialHSProtocol( HandShakeData *hsData,
320  XRootDChannelInfo *info,
321  kXR_char expect );
322 
323  //------------------------------------------------------------------------
324  // Generate the protocol message
325  //------------------------------------------------------------------------
326  Message *GenerateProtocol( HandShakeData *hsData,
327  XRootDChannelInfo *info,
328  kXR_char expect );
329 
330  //------------------------------------------------------------------------
331  // Initialize protocol request
332  //------------------------------------------------------------------------
333  void InitProtocolReq( ClientProtocolRequest *request,
334  XRootDChannelInfo *info,
335  kXR_char expect );
336 
337  //------------------------------------------------------------------------
338  // Process the server initial handshake response
339  //------------------------------------------------------------------------
340  XRootDStatus ProcessServerHS( HandShakeData *hsData,
341  XRootDChannelInfo *info );
342 
343  //------------------------------------------------------------------------
344  // Process the protocol response
345  //------------------------------------------------------------------------
346  XRootDStatus ProcessProtocolResp( HandShakeData *hsData,
347  XRootDChannelInfo *info );
348 
349  //------------------------------------------------------------------------
350  // Process the protocol body:
351  // * 'B' : bind preferences
352  // * 'S' : security requirements
353  //------------------------------------------------------------------------
354  XRootDStatus ProcessProtocolBody( char *bodybuff,
355  size_t bodysize,
356  XRootDChannelInfo *info );
357 
358  //------------------------------------------------------------------------
359  // Generate the bind message
360  //------------------------------------------------------------------------
361  Message *GenerateBind( HandShakeData *hsData,
362  XRootDChannelInfo *info );
363 
364  //------------------------------------------------------------------------
365  // Generate the bind message
366  //------------------------------------------------------------------------
367  XRootDStatus ProcessBindResp( HandShakeData *hsData,
368  XRootDChannelInfo *info );
369 
370  //------------------------------------------------------------------------
371  // Generate the login message
372  //------------------------------------------------------------------------
373  Message *GenerateLogIn( HandShakeData *hsData,
374  XRootDChannelInfo *info );
375 
376  //------------------------------------------------------------------------
377  // Process the login response
378  //------------------------------------------------------------------------
379  XRootDStatus ProcessLogInResp( HandShakeData *hsData,
380  XRootDChannelInfo *info );
381 
382  //------------------------------------------------------------------------
383  // Do the authentication
384  //------------------------------------------------------------------------
385  XRootDStatus DoAuthentication( HandShakeData *hsData,
386  XRootDChannelInfo *info );
387 
388  //------------------------------------------------------------------------
389  // Get the initial credentials using one of the protocols
390  //------------------------------------------------------------------------
391  XRootDStatus GetCredentials( XrdSecCredentials *&credentials,
392  HandShakeData *hsData,
393  XRootDChannelInfo *info );
394 
395  //------------------------------------------------------------------------
396  // Clean up the data structures created for the authentication process
397  //------------------------------------------------------------------------
398  Status CleanUpAuthentication( XRootDChannelInfo *info );
399 
400  //------------------------------------------------------------------------
401  // Clean up the data structures created for the protection purposes
402  //------------------------------------------------------------------------
403  Status CleanUpProtection( XRootDChannelInfo *info );
404 
405  //------------------------------------------------------------------------
406  // Get the authentication function handle
407  //------------------------------------------------------------------------
408  XrdSecGetProt_t GetAuthHandler();
409 
410  //------------------------------------------------------------------------
411  // Generate the end session message
412  //------------------------------------------------------------------------
413  Message *GenerateEndSession( HandShakeData *hsData,
414  XRootDChannelInfo *info );
415 
416  //------------------------------------------------------------------------
417  // Process the end session response
418  //------------------------------------------------------------------------
419  Status ProcessEndSessionResp( HandShakeData *hsData,
420  XRootDChannelInfo *info );
421 
422  //------------------------------------------------------------------------
423  // Get a string representation of the server flags
424  //------------------------------------------------------------------------
425  static std::string ServerFlagsToStr( uint32_t flags );
426 
427  //------------------------------------------------------------------------
428  // Get a string representation of file handle
429  //------------------------------------------------------------------------
430  static std::string FileHandleToStr( const unsigned char handle[4] );
431 
432  friend struct PluginUnloadHandler;
433  PluginUnloadHandler *pSecUnloadHandler;
434  };
435 }
436 
437 #endif // __XRD_CL_XROOTD_TRANSPORT_HANDLER_HH__
unsigned char kXR_char
Definition: XPtypes.hh:65
XrdSecProtocol *(* XrdSecGetProt_t)(const char *hostname, XrdNetAddrInfo &endPoint, XrdSecParameters &sectoken, XrdOucErrInfo *einfo)
Typedef to simplify the encoding of methods returning XrdSecProtocol.
const char * GetBuffer(uint32_t offset=0) const
Get the message buffer.
Definition: XrdClBuffer.hh:72
The message representation used throughout the system.
Definition: XrdClMessage.hh:32
void SetDescription(const std::string &description)
Set the description of the message.
Definition: XrdClMessage.hh:89
void SetIsMarshalled(bool isMarshalled)
Set the marshalling status.
Definition: XrdClMessage.hh:81
A network socket.
Definition: XrdClSocket.hh:43
Perform the handshake and the authentication for each physical stream.
URL representation.
Definition: XrdClURL.hh:31
XRootD transport handler.
static uint16_t NbConnectedStrm(AnyObject &channelData)
Number of currently connected data streams.
virtual bool IsStreamTTLElapsed(time_t time, AnyObject &channelData)
Check if the stream should be disconnected.
virtual bool NeedControlConnection()
virtual void Disconnect(AnyObject &channelData, uint16_t subStreamId)
The stream has been disconnected, do the cleanups.
static void SetDescription(Message *msg)
Get the description of a message.
virtual uint32_t MessageReceived(Message &msg, uint16_t subStream, AnyObject &channelData)
Check if the message invokes a stream action.
virtual void WaitBeforeExit()
Wait until the program can safely exit.
static XRootDStatus UnMarshallBody(Message *msg, uint16_t reqType)
Unmarshall the body of the incoming message.
virtual XRootDStatus GetBody(Message &message, Socket *socket)
virtual XRootDStatus GetHeader(Message &message, Socket *socket)
virtual uint16_t SubStreamNumber(AnyObject &channelData)
Return a number of substreams per stream that should be created.
virtual void FinalizeChannel(AnyObject &channelData)
Finalize channel.
virtual bool HandShakeDone(HandShakeData *handShakeData, AnyObject &channelData)
virtual Status GetSignature(Message *toSign, Message *&sign, AnyObject &channelData)
Get signature for given message.
virtual void MessageSent(Message *msg, uint16_t subStream, uint32_t bytesSent, AnyObject &channelData)
Notify the transport about a message having been sent.
virtual XRootDStatus HandShake(HandShakeData *handShakeData, AnyObject &channelData)
HandShake.
virtual XRootDStatus GetMore(Message &message, Socket *socket)
static void GenerateDescription(char *msg, std::ostringstream &o)
Get the description of a message.
static XRootDStatus UnMarshallRequest(Message *msg)
static XRootDStatus UnMarchalStatusMore(Message &msg)
Unmarshall the correction-segment of the status response for pgwrite.
static void LogErrorResponse(const Message &msg)
Log server error response.
virtual void DecFileInstCnt(AnyObject &channelData)
Decrement file object instance count bound to this channel.
virtual PathID Multiplex(Message *msg, AnyObject &channelData, PathID *hint=0)
virtual void InitializeChannel(const URL &url, AnyObject &channelData)
Initialize channel.
virtual Status Query(uint16_t query, AnyObject &result, AnyObject &channelData)
Query the channel.
static void UnMarshallHeader(Message &msg)
Unmarshall the header incoming message.
static XRootDStatus UnMarshalStatusBody(Message &msg, uint16_t reqType)
Unmarshall the body of the status response.
static XRootDStatus MarshallRequest(Message *msg)
Marshal the outgoing message.
virtual URL GetBindPreference(const URL &url, AnyObject &channelData)
Get bind preference for the next data stream.
virtual PathID MultiplexSubStream(Message *msg, AnyObject &channelData, PathID *hint=0)
virtual bool NeedEncryption(HandShakeData *handShakeData, AnyObject &channelData)
virtual Status IsStreamBroken(time_t inactiveTime, AnyObject &channelData)
Data structure that carries the handshake information.
Procedure execution status.
Definition: XrdClStatus.hh:115
Information holder for xrootd channels.
Generic structure to pass security information back and forth.