XRootD
Loading...
Searching...
No Matches
XrdHttpProtocol.hh
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// This file is part of XrdHTTP: A pragmatic implementation of the
3// HTTP/WebDAV protocol for the Xrootd framework
4//
5// Copyright (c) 2013 by European Organization for Nuclear Research (CERN)
6// Author: Fabrizio Furano <furano@cern.ch>
7// File Date: Nov 2012
8//------------------------------------------------------------------------------
9// XRootD is free software: you can redistribute it and/or modify
10// it under the terms of the GNU Lesser General Public License as published by
11// the Free Software Foundation, either version 3 of the License, or
12// (at your option) any later version.
13//
14// XRootD is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public License
20// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
21//------------------------------------------------------------------------------
22
23
24#ifndef __XRDHTTP_PROTOCOL_H__
25#define __XRDHTTP_PROTOCOL_H__
26
37#include <cstdlib>
38#include <unistd.h>
39#include <sys/types.h>
40
41#include "XrdSys/XrdSysError.hh"
44#include "Xrd/XrdObject.hh"
47#include "Xrd/XrdProtocol.hh"
48#include "XrdOuc/XrdOucHash.hh"
51#include "XrdNet/XrdNetPMark.hh"
52
53#include <openssl/ssl.h>
54
55#include <vector>
56
57#include "XrdHttpReq.hh"
58
59/******************************************************************************/
60/* D e f i n e s */
61/******************************************************************************/
62
63
64#ifndef __GNUC__
65#define __attribute__(x)
66#endif
67
68class XrdOucTokenizer;
69class XrdOucTrace;
70class XrdBuffer;
71class XrdLink;
75struct XrdVersionInfo;
76class XrdOucGMap;
78
80
81 friend class XrdHttpReq;
82 friend class XrdHttpExtReq;
83
84public:
85
87 static int Configure(char *parms, XrdProtocol_Config *pi);
88
90 void DoIt() {
91 if (Resume) (*this.*Resume)();
92 }
93
95 static int parseHeader2CGI(XrdOucStream &Config, XrdSysError & err, std::map<std::string, std::string> & header2cgi);
96
99
101 int Process(XrdLink *lp); // Sync: Job->Link.DoIt->Process
102
103
105 void Recycle(XrdLink *lp, int consec, const char *reason);
106
108 int Stats(char *buff, int blen, int do_sync = 0);
109
110
111
112
114 int doStat(char *fname);
115
117 int doChksum(const XrdOucString &fname);
118
122 XrdHttpProtocol(bool imhttps);
124 Cleanup();
125 }
126
129
130
133
134 // XrdHttp checksum handling class
136
139
141 bool isHTTPS() { return ishttps; }
142
143private:
144
145
147 int (XrdHttpProtocol::*Resume)();
148
150 static bool InitTLS();
151
153 static bool InitSecurity();
154
156 int StartSimpleResp(int code, const char *desc, const char *header_to_add, long long bodylen, bool keepalive);
157
159 int SendData(const char *body, int bodylen);
160
162 void Cleanup();
163
165 void Reset();
166
169 int HandleAuthentication(XrdLink* lp);
170
173 int GetVOMSData(XrdLink *lp);
174
175 // Handle gridmap file mapping if present
176 // Second argument is the OpenSSL hash of the EEC, if present; this allows
177 // a consistent fallback if the user is not in the mapfile.
178 //
179 // @return 0 if successful, otherwise !0
180 int HandleGridMap(XrdLink* lp, const char * eechash);
181
184 int getDataOneShot(int blen, bool wait=false);
185
187 static BIO *CreateBIO(XrdLink *lp);
188
192 struct extHInfo
193 {XrdOucString extHName; // The instance name (1 to 16 characters)
194 XrdOucString extHPath; // The shared library path
195 XrdOucString extHParm; // The parameter (sort of)
196 bool extHNoTlsOK; // If true the exthandler can be loaded if TLS has NOT been configured
197 extHInfo(const char *hName, const char *hPath, const char *hParm, const bool hNoTlsOK)
198 : extHName(hName), extHPath(hPath), extHParm(hParm), extHNoTlsOK(hNoTlsOK) {}
199 ~extHInfo() {}
200 };
202 static int Config(const char *fn, XrdOucEnv *myEnv);
203 static const char *Configed();
204 static int xtrace(XrdOucStream &Config);
205 static int xsslcert(XrdOucStream &Config);
206 static int xsslkey(XrdOucStream &Config);
207 static int xsecxtractor(XrdOucStream &Config);
208 static int xexthandler(XrdOucStream & Config, std::vector<extHInfo> &hiVec);
209 static int xsslcadir(XrdOucStream &Config);
210 static int xsslcipherfilter(XrdOucStream &Config);
211 static int xdesthttps(XrdOucStream &Config);
212 static int xlistdeny(XrdOucStream &Config);
213 static int xlistredir(XrdOucStream &Config);
214 static int xselfhttps2http(XrdOucStream &Config);
215 static int xembeddedstatic(XrdOucStream &Config);
216 static int xstaticredir(XrdOucStream &Config);
217 static int xstaticpreload(XrdOucStream &Config);
218 static int xgmap(XrdOucStream &Config);
219 static int xsslcafile(XrdOucStream &Config);
220 static int xsslverifydepth(XrdOucStream &Config);
221 static int xsecretkey(XrdOucStream &Config);
222 static int xheader2cgi(XrdOucStream &Config);
223 static int xhttpsmode(XrdOucStream &Config);
224 static int xtlsreuse(XrdOucStream &Config);
225 static int xauth(XrdOucStream &Config);
226
227 static bool isRequiredXtractor; // If true treat secxtractor errors as fatal
228 static XrdHttpSecXtractor *secxtractor;
229
230 static bool usingEC; // using XrdEC
231 // Loads the SecXtractor plugin, if available
232 static int LoadSecXtractor(XrdSysError *eDest, const char *libName,
233 const char *libParms);
234
235 // An oldstyle struct array to hold exthandlers
236 #define MAX_XRDHTTPEXTHANDLERS 4
237 static struct XrdHttpExtHandlerInfo {
238 char name[16];
240 } exthandler[MAX_XRDHTTPEXTHANDLERS];
241 static int exthandlercnt;
242
243 static int LoadExtHandlerNoTls(std::vector<extHInfo> &hiVec,
244 const char *cFN, XrdOucEnv &myEnv);
245
246 // Loads the ExtHandler plugin, if available
247 static int LoadExtHandler(std::vector<extHInfo> &hiVec,
248 const char *cFN, XrdOucEnv &myEnv);
249
250 static int LoadExtHandler(XrdSysError *eDest, const char *libName,
251 const char *configFN, const char *libParms,
252 XrdOucEnv *myEnv, const char *instName);
253
254 // Determines whether one of the loaded ExtHandlers are interested in
255 // handling a given request.
256 //
257 // Returns NULL if there is no matching handler.
258 static XrdHttpExtHandler *FindMatchingExtHandler(const XrdHttpReq &);
259
260 // Tells if an ext handler with the given name has already been loaded
261 static bool ExtHandlerLoaded(const char *handlername);
262
264 XrdBuffer *myBuff;
266 char *myBuffStart, *myBuffEnd;
267
269 XrdOucString tmpline;
270
272 int BuffAvailable();
274 int BuffUsed();
276 int BuffFree();
277
279 void BuffConsume(int blen);
281 int BuffgetData(int blen, char **data, bool wait);
283 int BuffgetLine(XrdOucString &dest);
284
286 int SendSimpleResp(int code, const char *desc, const char *header_to_add, const char *body, long long bodylen, bool keepalive);
287
289 // API.
290 int StartChunkedResp(int code, const char *desc, const char *header_to_add, long long bodylen, bool keepalive);
291
293 // indicates that this is the last chunk in the response.
294 int ChunkResp(const char *body, long long bodylen);
295
297 // of the chunk is known but the body is not immediately available.
298 int ChunkRespHeader(long long bodylen);
299
301 int ChunkRespFooter();
302
304 char *GetClientIPStr();
305
307 bool DoingLogin;
308
310 bool DoneSetInfo;
311
313 long ResumeBytes;
314
316 SSL *ssl;
317
319 BIO *sbio;
320
322 static BIO *sslbio_err;
323
325 bool ishttps;
326
329 bool ssldone;
330 static XrdCryptoFactory *myCryptoFactory;
331
332protected:
333
334 // Statistical area
335 //
336// static XrdXrootdStats *SI;
337// int numReads; // Count for kXR_read
338// int numReadP; // Count for kXR_read pre-preads
339// int numReadV; // Count for kR_readv
340// int numSegsV; // Count for kR_readv segmens
341// int numWrites; // Count
342// int numFiles; // Count
343//
344// int cumReads; // Count less numReads
345// int cumReadP; // Count less numReadP
346// int cumReadV; // Count less numReadV
347// int cumSegsV; // Count less numSegsV
348// int cumWrites; // Count less numWrites
349// long long totReadP; // Bytes
350
351 static XrdScheduler *Sched; // System scheduler
352 static XrdBuffManager *BPool; // Buffer manager
353 static XrdSysError eDest; // Error message handler
354 static XrdSecService *CIA; // Authentication Server
355
358
361 char *Addr_str;
362
364 static XrdOucGMap *servGMap; // Grid mapping service
365
368
369
373
374
375 //
376 // Processing configuration values
377 //
378
380 static int hailWait;
381
383 static int readWait;
384
386 static int Port;
387
389 static char * Port_str;
390
393
396
398 static char *gridmap;// [s] gridmap file [/etc/grid-security/gridmap]
399 static bool isRequiredGridmap; // If true treat gridmap errors as fatal
400 static bool compatNameGeneration; // If true, utilize the old algorithm for username generation for unknown users.
401
403 static char *secretkey;
404
406 static int sslverifydepth;
407
409 static bool isdesthttps;
410
412 static char *listredir;
413
415 static bool listdeny;
416
418 static bool selfhttps2http;
419
421 static bool embeddedstatic;
422
423 // Url to redirect to in the case a /static is requested
424 static char *staticredir;
425
426 // Hash that keeps preloaded files
428 char *data;
429 int len;
430 };
432
435
437 static std::map< std::string, std::string > hdr2cgimap;
438
440 static int m_bio_type;
441
443 static BIO_METHOD *m_bio_method;
444
446 static char * xrd_cslist;
447
450
452 static bool tpcForwardCreds;
453};
454#endif
int kXR_int32
Definition XPtypes.hh:89
#define MAX_XRDHTTPEXTHANDLERS
Main request/response class, handling the logical status of the communication.
static char * secretkey
The key used to calculate the url hashes.
static BIO_METHOD * m_bio_method
C-style vptr table for our custom BIO objects.
static char * gridmap
Gridmap file location. The same used by XrdSecGsi.
static XrdScheduler * Sched
static kXR_int32 myRole
Our role.
static char * sslcafile
static XrdNetPMark * pmarkHandle
Packet marking handler pointer (assigned from the environment during the Config() call)
static char * Port_str
Our port, as a string.
XrdXrootd::Bridge * Bridge
The Bridge that we use to exercise the xrootd internals.
static char * staticredir
static XrdSysError eDest
static bool selfhttps2http
If client is HTTPS, self-redirect with HTTP+token.
static XrdHttpChecksumHandler cksumHandler
static XrdOucGMap * servGMap
The instance of the DN mapper. Created only when a valid path is given.
static int hailWait
Timeout for reading the handshake.
int doChksum(const XrdOucString &fname)
Perform a checksum request.
static XrdOucHash< StaticPreloadInfo > * staticpreload
static char * xrd_cslist
The list of checksums that were configured via the xrd.cksum parameter on the server config file.
static char * sslcipherfilter
static int m_bio_type
Type identifier for our custom BIO objects.
static std::map< std::string, std::string > hdr2cgimap
Rules that turn HTTP headers to cgi tokens in the URL, for internal comsumption.
static char * sslcert
OpenSSL stuff.
XrdLink * Link
The link we are bound to.
static char * sslkey
int doStat(char *fname)
Perform a Stat request.
XrdObject< XrdHttpProtocol > ProtLink
static int readWait
Timeout for reading data.
void Recycle(XrdLink *lp, int consec, const char *reason)
Recycle this instance.
void DoIt()
Override from the base class.
static char * sslcadir
XrdHttpProtocol operator=(const XrdHttpProtocol &rhs)
bool isHTTPS()
called via https
static bool compatNameGeneration
static bool isdesthttps
True if the redirections must be towards https targets.
static XrdObjectQ< XrdHttpProtocol > ProtStack
XrdProtocol * Match(XrdLink *lp)
Tells if the oustanding bytes on the socket match this protocol implementation.
static bool isRequiredGridmap
static char * listredir
Url to redirect to in the case a listing is requested.
int Stats(char *buff, int blen, int do_sync=0)
Get activity stats.
static int crlRefIntervalSec
CRL thread refresh interval.
static int Port
Our port.
static XrdHttpReadRangeHandler::Configuration ReadRangeConfig
configuration for the read range handler
static XrdSecService * CIA
static XrdBuffManager * BPool
static bool tpcForwardCreds
If set to true, the HTTP TPC transfers will forward the credentials to redirected hosts.
int Process(XrdLink *lp)
Process data incoming from the socket.
XrdHttpProtocol(const XrdHttpProtocol &)=default
Ctor, dtors and copy ctor.
static bool listdeny
If true, any form of listing is denied.
static int parseHeader2CGI(XrdOucStream &Config, XrdSysError &err, std::map< std::string, std::string > &header2cgi)
Use this function to parse header2cgi configurations.
XrdSecEntity SecEntity
Authentication area.
static bool embeddedstatic
If true, use the embedded css and icons.
static int sslverifydepth
Depth of verification of a certificate chain.
static int Configure(char *parms, XrdProtocol_Config *pi)
Read and apply the configuration.