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 SIDManager = 1001; 00047 static const uint16_t ServerFlags = 1002; 00048 static const uint16_t ProtocolVersion = 1003; 00049 }; 00050 00051 //---------------------------------------------------------------------------- 00053 //---------------------------------------------------------------------------- 00054 class XRootDTransport: public TransportHandler 00055 { 00056 public: 00057 //------------------------------------------------------------------------ 00059 //------------------------------------------------------------------------ 00060 XRootDTransport(); 00061 00062 //------------------------------------------------------------------------ 00064 //------------------------------------------------------------------------ 00065 ~XRootDTransport(); 00066 00067 //------------------------------------------------------------------------ 00078 //------------------------------------------------------------------------ 00079 virtual Status GetHeader( Message *message, int socket ); 00080 00081 //------------------------------------------------------------------------ 00090 //------------------------------------------------------------------------ 00091 virtual Status GetBody( Message *message, int socket ); 00092 00093 //------------------------------------------------------------------------ 00095 //------------------------------------------------------------------------ 00096 virtual void InitializeChannel( 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 virtual void Disconnect( AnyObject &channelData, 00196 uint16_t streamId, 00197 uint16_t subStreamId ); 00198 00199 //------------------------------------------------------------------------ 00201 //------------------------------------------------------------------------ 00202 virtual Status Query( uint16_t query, 00203 AnyObject &result, 00204 AnyObject &channelData ); 00205 00206 //------------------------------------------------------------------------ 00208 //------------------------------------------------------------------------ 00209 static void SetDescription( Message *msg ); 00210 00211 //------------------------------------------------------------------------ 00213 //------------------------------------------------------------------------ 00214 virtual uint32_t MessageReceived( Message *msg, 00215 uint16_t streamId, 00216 uint16_t subStream, 00217 AnyObject &channelData ); 00218 00219 //------------------------------------------------------------------------ 00221 //------------------------------------------------------------------------ 00222 virtual void MessageSent( Message *msg, 00223 uint16_t streamId, 00224 uint16_t subStream, 00225 uint32_t bytesSent, 00226 AnyObject &channelData ); 00227 00228 //------------------------------------------------------------------------ 00230 //------------------------------------------------------------------------ 00231 virtual Status GetSignature( Message *toSign, Message *&sign, 00232 AnyObject &channelData ); 00233 00234 //------------------------------------------------------------------------ 00236 //------------------------------------------------------------------------ 00237 Status ClassifyErrno( int error ); 00238 00239 private: 00240 00241 //------------------------------------------------------------------------ 00242 // Hand shake the main stream 00243 //------------------------------------------------------------------------ 00244 Status HandShakeMain( HandShakeData *handShakeData, 00245 AnyObject &channelData ); 00246 00247 //------------------------------------------------------------------------ 00248 // Hand shake a parallel stream 00249 //------------------------------------------------------------------------ 00250 Status HandShakeParallel( HandShakeData *handShakeData, 00251 AnyObject &channelData ); 00252 00253 //------------------------------------------------------------------------ 00254 // Generate the message to be sent as an initial handshake 00255 //------------------------------------------------------------------------ 00256 Message *GenerateInitialHS( HandShakeData *hsData, 00257 XRootDChannelInfo *info ); 00258 00259 //------------------------------------------------------------------------ 00260 // Generate the message to be sent as an initial handshake 00261 // (handshake + kXR_protocol) 00262 //------------------------------------------------------------------------ 00263 Message *GenerateInitialHSProtocol( HandShakeData *hsData, 00264 XRootDChannelInfo *info ); 00265 00266 //------------------------------------------------------------------------ 00267 // Process the server initial handshake response 00268 //------------------------------------------------------------------------ 00269 Status ProcessServerHS( HandShakeData *hsData, 00270 XRootDChannelInfo *info ); 00271 00272 //----------------------------------------------------------------------- 00273 // Process the protocol response 00274 //------------------------------------------------------------------------ 00275 Status ProcessProtocolResp( HandShakeData *hsData, 00276 XRootDChannelInfo *info ); 00277 00278 //------------------------------------------------------------------------ 00279 // Generate the bind message 00280 //------------------------------------------------------------------------ 00281 Message *GenerateBind( HandShakeData *hsData, 00282 XRootDChannelInfo *info ); 00283 00284 //------------------------------------------------------------------------ 00285 // Generate the bind message 00286 //------------------------------------------------------------------------ 00287 Status ProcessBindResp( HandShakeData *hsData, 00288 XRootDChannelInfo *info ); 00289 00290 //------------------------------------------------------------------------ 00291 // Generate the login message 00292 //------------------------------------------------------------------------ 00293 Message *GenerateLogIn( HandShakeData *hsData, 00294 XRootDChannelInfo *info ); 00295 00296 //------------------------------------------------------------------------ 00297 // Process the login response 00298 //------------------------------------------------------------------------ 00299 Status ProcessLogInResp( HandShakeData *hsData, 00300 XRootDChannelInfo *info ); 00301 00302 //------------------------------------------------------------------------ 00303 // Do the authentication 00304 //------------------------------------------------------------------------ 00305 Status DoAuthentication( HandShakeData *hsData, 00306 XRootDChannelInfo *info ); 00307 00308 //------------------------------------------------------------------------ 00309 // Get the initial credentials using one of the protocols 00310 //------------------------------------------------------------------------ 00311 Status GetCredentials( XrdSecCredentials *&credentials, 00312 HandShakeData *hsData, 00313 XRootDChannelInfo *info ); 00314 00315 //------------------------------------------------------------------------ 00316 // Clean up the data structures created for the authentication process 00317 //------------------------------------------------------------------------ 00318 Status CleanUpAuthentication( XRootDChannelInfo *info ); 00319 00320 //------------------------------------------------------------------------ 00321 // Clean up the data structures created for the protection purposes 00322 //------------------------------------------------------------------------ 00323 Status CleanUpProtection( XRootDChannelInfo *info ); 00324 00325 //------------------------------------------------------------------------ 00326 // Get the authentication function handle 00327 //------------------------------------------------------------------------ 00328 XrdSecGetProt_t GetAuthHandler(); 00329 00330 //------------------------------------------------------------------------ 00331 // Generate the end session message 00332 //------------------------------------------------------------------------ 00333 Message *GenerateEndSession( HandShakeData *hsData, 00334 XRootDChannelInfo *info ); 00335 00336 //------------------------------------------------------------------------ 00337 // Process the end session response 00338 //------------------------------------------------------------------------ 00339 Status ProcessEndSessionResp( HandShakeData *hsData, 00340 XRootDChannelInfo *info ); 00341 00342 //------------------------------------------------------------------------ 00343 // Get a string representation of the server flags 00344 //------------------------------------------------------------------------ 00345 static std::string ServerFlagsToStr( uint32_t flags ); 00346 00347 //------------------------------------------------------------------------ 00348 // Get a string representation of file handle 00349 //------------------------------------------------------------------------ 00350 static std::string FileHandleToStr( const unsigned char handle[4] ); 00351 00352 XrdSecGetProt_t pAuthHandler; 00353 00354 friend struct PluginUnloadHandler; 00355 PluginUnloadHandler *pSecUnloadHandler; 00356 }; 00357 } 00358 00359 #endif // __XRD_CL_XROOTD_TRANSPORT_HANDLER_HH__