00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __XRDHTTP_PROTOCOL_H__
00025 #define __XRDHTTP_PROTOCOL_H__
00026
00037 #include <stdlib.h>
00038 #include <unistd.h>
00039 #include <sys/types.h>
00040
00041 #include "XrdSys/XrdSysError.hh"
00042 #include "XrdSys/XrdSysPthread.hh"
00043 #include "XrdSec/XrdSecInterface.hh"
00044 #include "XrdCrypto/XrdCryptoFactory.hh"
00045 #include "Xrd/XrdObject.hh"
00046 #include "XrdXrootd/XrdXrootdBridge.hh"
00047 #include "XrdOuc/XrdOucStream.hh"
00048 #include "Xrd/XrdProtocol.hh"
00049 #include "XrdOuc/XrdOucHash.hh"
00050
00051 #include <openssl/ssl.h>
00052
00053 #include <vector>
00054
00055 #include "XrdHttpReq.hh"
00056
00057
00058
00059
00060
00061
00062 #ifndef __GNUC__
00063 #define __attribute__(x)
00064 #endif
00065
00066 class XrdOucTokenizer;
00067 class XrdOucTrace;
00068 class XrdBuffer;
00069 class XrdLink;
00070 class XrdXrootdProtocol;
00071 class XrdHttpSecXtractor;
00072 class XrdHttpExtHandler;
00073 struct XrdVersionInfo;
00074 class XrdOucGMap;
00075 class XrdCryptoFactory;
00076
00077 class XrdHttpProtocol : public XrdProtocol {
00078
00079 friend class XrdHttpReq;
00080 friend class XrdHttpExtReq;
00081
00082 public:
00083
00085 static int Configure(char *parms, XrdProtocol_Config *pi);
00086
00088 void DoIt() {
00089 if (Resume) (*this.*Resume)();
00090 }
00091
00093 XrdProtocol *Match(XrdLink *lp);
00094
00096 int Process(XrdLink *lp);
00097
00098
00100 void Recycle(XrdLink *lp, int consec, const char *reason);
00101
00103 int Stats(char *buff, int blen, int do_sync = 0);
00104
00105
00106
00107
00109 int doStat(char *fname);
00110
00112 int doChksum(const XrdOucString &fname);
00113
00115 XrdHttpProtocol(const XrdHttpProtocol&) = default;
00116 XrdHttpProtocol operator =(const XrdHttpProtocol &rhs);
00117 XrdHttpProtocol(bool imhttps);
00118 ~XrdHttpProtocol() {
00119 Cleanup();
00120 }
00121
00122 static XrdObjectQ<XrdHttpProtocol> ProtStack;
00123 XrdObject<XrdHttpProtocol> ProtLink;
00124
00125
00127 XrdSecEntity SecEntity;
00128
00130 bool isHTTPS() { return ishttps; }
00131
00133 static void PeriodicUpdate();
00134
00135 private:
00136
00137
00139 int (XrdHttpProtocol::*Resume)();
00140
00142 static int InitSecurity();
00143
00145 static X509_STORE *PrepareStore();
00146
00148 int StartSimpleResp(int code, const char *desc, const char *header_to_add, long long bodylen, bool keepalive);
00149
00151 int SendData(const char *body, int bodylen);
00152
00154 void Cleanup();
00155
00157 void Reset();
00158
00161 int HandleAuthentication(XrdLink* lp);
00162
00165 int GetVOMSData(XrdLink *lp);
00166
00167
00168
00169
00170 int HandleGridMap(XrdLink* lp);
00171
00174 int getDataOneShot(int blen, bool wait=false);
00175
00177 static BIO *CreateBIO(XrdLink *lp);
00178
00180 static int Config(const char *fn, XrdOucEnv *myEnv);
00181 static int xtrace(XrdOucStream &Config);
00182 static int xsslcert(XrdOucStream &Config);
00183 static int xsslkey(XrdOucStream &Config);
00184 static int xsecxtractor(XrdOucStream &Config);
00185 static int xexthandler(XrdOucStream & Config, const char *ConfigFN, XrdOucEnv *myEnv);
00186 static int xsslcadir(XrdOucStream &Config);
00187 static int xsslcipherfilter(XrdOucStream &Config);
00188 static int xdesthttps(XrdOucStream &Config);
00189 static int xlistdeny(XrdOucStream &Config);
00190 static int xlistredir(XrdOucStream &Config);
00191 static int xselfhttps2http(XrdOucStream &Config);
00192 static int xembeddedstatic(XrdOucStream &Config);
00193 static int xstaticredir(XrdOucStream &Config);
00194 static int xstaticpreload(XrdOucStream &Config);
00195 static int xgmap(XrdOucStream &Config);
00196 static int xsslcafile(XrdOucStream &Config);
00197 static int xsslverifydepth(XrdOucStream &Config);
00198 static int xsecretkey(XrdOucStream &Config);
00199 static int xheader2cgi(XrdOucStream &Config);
00200
00201 static bool isRequiredXtractor;
00202 static XrdHttpSecXtractor *secxtractor;
00203
00204
00205 static int LoadSecXtractor(XrdSysError *eDest, const char *libName,
00206 const char *libParms);
00207
00208
00209 #define MAX_XRDHTTPEXTHANDLERS 4
00210 static struct XrdHttpExtHandlerInfo {
00211 char name[16];
00212 XrdHttpExtHandler *ptr;
00213 } exthandler[MAX_XRDHTTPEXTHANDLERS];
00214 static int exthandlercnt;
00215
00216
00217 static int LoadExtHandler(XrdSysError *eDest, const char *libName,
00218 const char *configFN, const char *libParms,
00219 XrdOucEnv *myEnv, const char *instName);
00220
00221
00222
00223
00224
00225 static XrdHttpExtHandler *FindMatchingExtHandler(const XrdHttpReq &);
00226
00227
00228 static bool ExtHandlerLoaded(const char *handlername);
00229
00231 XrdBuffer *myBuff;
00233 char *myBuffStart, *myBuffEnd;
00234
00236 XrdOucString tmpline;
00237
00239 int BuffAvailable();
00241 int BuffUsed();
00243 int BuffFree();
00244
00246 void BuffConsume(int blen);
00248 int BuffgetData(int blen, char **data, bool wait);
00250 int BuffgetLine(XrdOucString &dest);
00251
00253 int SendSimpleResp(int code, const char *desc, const char *header_to_add, const char *body, long long bodylen, bool keepalive);
00254
00256
00257 int StartChunkedResp(int code, const char *desc, const char *header_to_add, bool keepalive);
00258
00260
00261 int ChunkResp(const char *body, long long bodylen);
00262
00264 char *GetClientIPStr();
00265
00267 bool DoingLogin;
00268
00270 long ResumeBytes;
00271
00273 static SSL_CTX *sslctx;
00274
00276 static X509_STORE *verify_store;
00277 static XrdSysRWLock x509_store_lock;
00278
00280 SSL *ssl;
00281
00283 BIO *sbio;
00284
00286 static BIO *sslbio_err;
00287
00289 bool ishttps;
00290
00293 bool ssldone;
00294 static XrdCryptoFactory *myCryptoFactory;
00295
00296 protected:
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317 static XrdScheduler *Sched;
00318 static XrdBuffManager *BPool;
00319 static XrdSysError eDest;
00320 static XrdSecService *CIA;
00321
00323 XrdLink *Link;
00324
00327 char *Addr_str;
00328
00330 static XrdOucGMap *servGMap;
00331
00333 XrdXrootd::Bridge *Bridge;
00334
00335
00338 XrdHttpReq CurrentReq;
00339
00340
00341
00342
00343
00344
00346 static int hailWait;
00347
00349 static int readWait;
00350
00352 static int Port;
00353
00355 static char * Port_str;
00356
00358 static int Window;
00359
00361 static char *sslcert, *sslkey, *sslcadir, *sslcafile, *sslcipherfilter;
00362
00364 static char *gridmap;
00365 static bool isRequiredGridmap;
00366
00368 static char *secretkey;
00369
00371 static int sslverifydepth;
00372
00374 static bool isdesthttps;
00375
00377 static char *listredir;
00378
00380 static bool listdeny;
00381
00383 static bool selfhttps2http;
00384
00386 static bool embeddedstatic;
00387
00388
00389 static char *staticredir;
00390
00391
00392 struct StaticPreloadInfo {
00393 char *data;
00394 int len;
00395 };
00396 static XrdOucHash<StaticPreloadInfo> *staticpreload;
00397
00399 static kXR_int32 myRole;
00400
00402 static std::map< std::string, std::string > hdr2cgimap;
00403
00405 static int m_bio_type;
00406
00408 static BIO_METHOD *m_bio_method;
00409 };
00410 #endif