00001 //------------------------------------------------------------------------------ 00002 // Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN) 00003 // Author: Lukasz Janyst <ljanyst@cern.ch> 00004 //------------------------------------------------------------------------------ 00005 // This file is part of the XRootD software suite. 00006 // 00007 // XRootD is free software: you can redistribute it and/or modify 00008 // it under the terms of the GNU Lesser General Public License as published by 00009 // the Free Software Foundation, either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // XRootD is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU Lesser General Public License 00018 // along with XRootD. If not, see <http://www.gnu.org/licenses/>. 00019 // 00020 // In applying this licence, CERN does not waive the privileges and immunities 00021 // granted to it by virtue of its status as an Intergovernmental Organization 00022 // or submit itself to any jurisdiction. 00023 //------------------------------------------------------------------------------ 00024 00025 #ifndef __XRD_CL_XROOTD_TRANSPORT_HH__ 00026 #define __XRD_CL_XROOTD_TRANSPORT_HH__ 00027 00028 #include "XrdCl/XrdClPostMaster.hh" 00029 #include "XProtocol/XProtocol.hh" 00030 #include "XrdSec/XrdSecInterface.hh" 00031 #include "XrdOuc/XrdOucEnv.hh" 00032 00033 class XrdSysPlugin; 00034 class XrdSecProtect; 00035 00036 namespace XrdCl 00037 { 00038 struct XRootDChannelInfo; 00039 struct PluginUnloadHandler; 00040 00041 //---------------------------------------------------------------------------- 00043 //---------------------------------------------------------------------------- 00044 struct XRootDQuery 00045 { 00046 static const uint16_t ServerFlags = 1002; 00047 static const uint16_t ProtocolVersion = 1003; 00048 }; 00049 00050 //---------------------------------------------------------------------------- 00052 //---------------------------------------------------------------------------- 00053 class XRootDTransport: public TransportHandler 00054 { 00055 public: 00056 //------------------------------------------------------------------------ 00058 //------------------------------------------------------------------------ 00059 XRootDTransport(); 00060 00061 //------------------------------------------------------------------------ 00063 //------------------------------------------------------------------------ 00064 ~XRootDTransport(); 00065 00066 //------------------------------------------------------------------------ 00077 //------------------------------------------------------------------------ 00078 virtual Status GetHeader( Message *message, int socket ); 00079 00080 //------------------------------------------------------------------------ 00089 //------------------------------------------------------------------------ 00090 virtual Status GetBody( Message *message, int socket ); 00091 00092 //------------------------------------------------------------------------ 00094 //------------------------------------------------------------------------ 00095 virtual void InitializeChannel( AnyObject &channelData ); //< we keep this as we need to implement the abstract method 00096 virtual void InitializeChannel( const URL &url, AnyObject &channelData ); 00097 00098 //------------------------------------------------------------------------ 00100 //------------------------------------------------------------------------ 00101 virtual void FinalizeChannel( AnyObject &channelData ); 00102 00103 //------------------------------------------------------------------------ 00105 //------------------------------------------------------------------------ 00106 virtual Status HandShake( HandShakeData *handShakeData, 00107 AnyObject &channelData ); 00108 00109 //------------------------------------------------------------------------ 00111 //------------------------------------------------------------------------ 00112 virtual bool IsStreamTTLElapsed( time_t time, 00113 uint16_t streamId, 00114 AnyObject &channelData ); 00115 00116 //------------------------------------------------------------------------ 00119 //------------------------------------------------------------------------ 00120 virtual Status IsStreamBroken( time_t inactiveTime, 00121 uint16_t streamId, 00122 AnyObject &channelData ); 00123 00124 //------------------------------------------------------------------------ 00130 //------------------------------------------------------------------------ 00131 virtual PathID Multiplex( Message *msg, 00132 AnyObject &channelData, 00133 PathID *hint = 0 ); 00134 00135 //------------------------------------------------------------------------ 00141 //------------------------------------------------------------------------ 00142 virtual PathID MultiplexSubStream( Message *msg, 00143 uint16_t streamId, 00144 AnyObject &channelData, 00145 PathID *hint = 0 ); 00146 00147 //------------------------------------------------------------------------ 00149 //------------------------------------------------------------------------ 00150 virtual uint16_t StreamNumber( AnyObject &channelData ); 00151 00152 //------------------------------------------------------------------------ 00154 //------------------------------------------------------------------------ 00155 virtual uint16_t SubStreamNumber( AnyObject &channelData ); 00156 00157 //------------------------------------------------------------------------ 00160 //------------------------------------------------------------------------ 00161 virtual bool NeedControlConnection() 00162 { 00163 return true; 00164 } 00165 00166 //------------------------------------------------------------------------ 00168 //------------------------------------------------------------------------ 00169 static Status MarshallRequest( Message *msg ); 00170 00171 //------------------------------------------------------------------------ 00174 //------------------------------------------------------------------------ 00175 static Status UnMarshallRequest( Message *msg ); 00176 00177 //------------------------------------------------------------------------ 00179 //------------------------------------------------------------------------ 00180 static Status UnMarshallBody( Message *msg, uint16_t reqType ); 00181 00182 //------------------------------------------------------------------------ 00184 //------------------------------------------------------------------------ 00185 static void UnMarshallHeader( Message *msg ); 00186 00187 //------------------------------------------------------------------------ 00189 //------------------------------------------------------------------------ 00190 static void LogErrorResponse( const Message &msg ); 00191 00192 //------------------------------------------------------------------------ 00194 //------------------------------------------------------------------------ 00195 static uint16_t NbConnectedStrm( AnyObject &channelData ); 00196 00197 //------------------------------------------------------------------------ 00199 //------------------------------------------------------------------------ 00200 virtual void Disconnect( AnyObject &channelData, 00201 uint16_t streamId, 00202 uint16_t subStreamId ); 00203 00204 //------------------------------------------------------------------------ 00206 //------------------------------------------------------------------------ 00207 virtual Status Query( uint16_t query, 00208 AnyObject &result, 00209 AnyObject &channelData ); 00210 00211 //------------------------------------------------------------------------ 00213 //------------------------------------------------------------------------ 00214 static void SetDescription( Message *msg ); 00215 00216 //------------------------------------------------------------------------ 00218 //------------------------------------------------------------------------ 00219 virtual uint32_t MessageReceived( Message *msg, 00220 uint16_t streamId, 00221 uint16_t subStream, 00222 AnyObject &channelData ); 00223 00224 //------------------------------------------------------------------------ 00226 //------------------------------------------------------------------------ 00227 virtual void MessageSent( Message *msg, 00228 uint16_t streamId, 00229 uint16_t subStream, 00230 uint32_t bytesSent, 00231 AnyObject &channelData ); 00232 00233 //------------------------------------------------------------------------ 00235 //------------------------------------------------------------------------ 00236 virtual Status GetSignature( Message *toSign, Message *&sign, 00237 AnyObject &channelData ); 00238 00239 //------------------------------------------------------------------------ 00241 //------------------------------------------------------------------------ 00242 Status GetSignature( Message *toSign, Message *&sign, XRootDChannelInfo *info ); 00243 00244 //------------------------------------------------------------------------ 00246 //------------------------------------------------------------------------ 00247 Status ClassifyErrno( int error ); 00248 00249 private: 00250 00251 //------------------------------------------------------------------------ 00252 // Hand shake the main stream 00253 //------------------------------------------------------------------------ 00254 Status HandShakeMain( HandShakeData *handShakeData, 00255 AnyObject &channelData ); 00256 00257 //------------------------------------------------------------------------ 00258 // Hand shake a parallel stream 00259 //------------------------------------------------------------------------ 00260 Status HandShakeParallel( HandShakeData *handShakeData, 00261 AnyObject &channelData ); 00262 00263 //------------------------------------------------------------------------ 00264 // Generate the message to be sent as an initial handshake 00265 //------------------------------------------------------------------------ 00266 Message *GenerateInitialHS( HandShakeData *hsData, 00267 XRootDChannelInfo *info ); 00268 00269 //------------------------------------------------------------------------ 00270 // Generate the message to be sent as an initial handshake 00271 // (handshake + kXR_protocol) 00272 //------------------------------------------------------------------------ 00273 Message *GenerateInitialHSProtocol( HandShakeData *hsData, 00274 XRootDChannelInfo *info ); 00275 00276 //------------------------------------------------------------------------ 00277 // Process the server initial handshake response 00278 //------------------------------------------------------------------------ 00279 Status ProcessServerHS( HandShakeData *hsData, 00280 XRootDChannelInfo *info ); 00281 00282 //----------------------------------------------------------------------- 00283 // Process the protocol response 00284 //------------------------------------------------------------------------ 00285 Status ProcessProtocolResp( HandShakeData *hsData, 00286 XRootDChannelInfo *info ); 00287 00288 //------------------------------------------------------------------------ 00289 // Generate the bind message 00290 //------------------------------------------------------------------------ 00291 Message *GenerateBind( HandShakeData *hsData, 00292 XRootDChannelInfo *info ); 00293 00294 //------------------------------------------------------------------------ 00295 // Generate the bind message 00296 //------------------------------------------------------------------------ 00297 Status ProcessBindResp( HandShakeData *hsData, 00298 XRootDChannelInfo *info ); 00299 00300 //------------------------------------------------------------------------ 00301 // Generate the login message 00302 //------------------------------------------------------------------------ 00303 Message *GenerateLogIn( HandShakeData *hsData, 00304 XRootDChannelInfo *info ); 00305 00306 //------------------------------------------------------------------------ 00307 // Process the login response 00308 //------------------------------------------------------------------------ 00309 Status ProcessLogInResp( HandShakeData *hsData, 00310 XRootDChannelInfo *info ); 00311 00312 //------------------------------------------------------------------------ 00313 // Do the authentication 00314 //------------------------------------------------------------------------ 00315 Status DoAuthentication( HandShakeData *hsData, 00316 XRootDChannelInfo *info ); 00317 00318 //------------------------------------------------------------------------ 00319 // Get the initial credentials using one of the protocols 00320 //------------------------------------------------------------------------ 00321 Status GetCredentials( XrdSecCredentials *&credentials, 00322 HandShakeData *hsData, 00323 XRootDChannelInfo *info ); 00324 00325 //------------------------------------------------------------------------ 00326 // Clean up the data structures created for the authentication process 00327 //------------------------------------------------------------------------ 00328 Status CleanUpAuthentication( XRootDChannelInfo *info ); 00329 00330 //------------------------------------------------------------------------ 00331 // Clean up the data structures created for the protection purposes 00332 //------------------------------------------------------------------------ 00333 Status CleanUpProtection( XRootDChannelInfo *info ); 00334 00335 //------------------------------------------------------------------------ 00336 // Get the authentication function handle 00337 //------------------------------------------------------------------------ 00338 XrdSecGetProt_t GetAuthHandler(); 00339 00340 //------------------------------------------------------------------------ 00341 // Generate the end session message 00342 //------------------------------------------------------------------------ 00343 Message *GenerateEndSession( HandShakeData *hsData, 00344 XRootDChannelInfo *info ); 00345 00346 //------------------------------------------------------------------------ 00347 // Process the end session response 00348 //------------------------------------------------------------------------ 00349 Status ProcessEndSessionResp( HandShakeData *hsData, 00350 XRootDChannelInfo *info ); 00351 00352 //------------------------------------------------------------------------ 00353 // Get a string representation of the server flags 00354 //------------------------------------------------------------------------ 00355 static std::string ServerFlagsToStr( uint32_t flags ); 00356 00357 //------------------------------------------------------------------------ 00358 // Get a string representation of file handle 00359 //------------------------------------------------------------------------ 00360 static std::string FileHandleToStr( const unsigned char handle[4] ); 00361 00362 friend struct PluginUnloadHandler; 00363 PluginUnloadHandler *pSecUnloadHandler; 00364 }; 00365 } 00366 00367 #endif // __XRD_CL_XROOTD_TRANSPORT_HANDLER_HH__