xrootd
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"
49
50#include <openssl/ssl.h>
51
52#include <vector>
53
54#include "XrdHttpReq.hh"
55
56/******************************************************************************/
57/* D e f i n e s */
58/******************************************************************************/
59
60
61#ifndef __GNUC__
62#define __attribute__(x)
63#endif
64
65class XrdOucTokenizer;
66class XrdOucTrace;
67class XrdBuffer;
68class XrdLink;
72struct XrdVersionInfo;
73class XrdOucGMap;
75
77
78 friend class XrdHttpReq;
79 friend class XrdHttpExtReq;
80
81public:
82
84 static int Configure(char *parms, XrdProtocol_Config *pi);
85
87 void DoIt() {
88 if (Resume) (*this.*Resume)();
89 }
90
93
95 int Process(XrdLink *lp); // Sync: Job->Link.DoIt->Process
96
97
99 void Recycle(XrdLink *lp, int consec, const char *reason);
100
102 int Stats(char *buff, int blen, int do_sync = 0);
103
104
105
106
108 int doStat(char *fname);
109
111 int doChksum(const XrdOucString &fname);
112
116 XrdHttpProtocol(bool imhttps);
118 Cleanup();
119 }
120
123
124
127
129 bool isHTTPS() { return ishttps; }
130
131private:
132
133
136
138 static bool InitTLS();
139
141 static bool InitSecurity();
142
144 int StartSimpleResp(int code, const char *desc, const char *header_to_add, long long bodylen, bool keepalive);
145
147 int SendData(const char *body, int bodylen);
148
150 void Cleanup();
151
153 void Reset();
154
158
162
163 // Handle gridmap file mapping if present
164 // Second argument is the OpenSSL hash of the EEC, if present; this allows
165 // a consistent fallback if the user is not in the mapfile.
166 //
167 // @return 0 if successful, otherwise !0
168 int HandleGridMap(XrdLink* lp, const char * eechash);
169
172 int getDataOneShot(int blen, bool wait=false);
173
175 static BIO *CreateBIO(XrdLink *lp);
176
180 struct extHInfo
181 {XrdOucString extHName; // The instance name (1 to 16 characters)
182 XrdOucString extHPath; // The shared library path
183 XrdOucString extHParm; // The parameter (sort of)
184
185 extHInfo(const char *hName, const char *hPath, const char *hParm)
186 : extHName(hName), extHPath(hPath), extHParm(hParm) {}
188 };
190 static int Config(const char *fn, XrdOucEnv *myEnv);
191 static const char *Configed();
196 static int xexthandler(XrdOucStream & Config, std::vector<extHInfo> &hiVec);
213
214 static bool isRequiredXtractor; // If true treat secxtractor errors as fatal
216
217 static bool usingEC; // using XrdEC
218 // Loads the SecXtractor plugin, if available
219 static int LoadSecXtractor(XrdSysError *eDest, const char *libName,
220 const char *libParms);
221
222 // An oldstyle struct array to hold exthandlers
223 #define MAX_XRDHTTPEXTHANDLERS 4
224 static struct XrdHttpExtHandlerInfo {
225 char name[16];
228 static int exthandlercnt;
229
230 // Loads the ExtHandler plugin, if available
231 static int LoadExtHandler(std::vector<extHInfo> &hiVec,
232 const char *cFN, XrdOucEnv &myEnv);
233
234 static int LoadExtHandler(XrdSysError *eDest, const char *libName,
235 const char *configFN, const char *libParms,
236 XrdOucEnv *myEnv, const char *instName);
237
238 // Determines whether one of the loaded ExtHandlers are interested in
239 // handling a given request.
240 //
241 // Returns NULL if there is no matching handler.
243
244 // Tells if an ext handler with the given name has already been loaded
245 static bool ExtHandlerLoaded(const char *handlername);
246
251
254
258 int BuffUsed();
260 int BuffFree();
261
263 void BuffConsume(int blen);
265 int BuffgetData(int blen, char **data, bool wait);
268
270 int SendSimpleResp(int code, const char *desc, const char *header_to_add, const char *body, long long bodylen, bool keepalive);
271
273 // API.
274 int StartChunkedResp(int code, const char *desc, const char *header_to_add, bool keepalive);
275
277 // indicates that this is the last chunk in the response.
278 int ChunkResp(const char *body, long long bodylen);
279
282
285
288
290 SSL *ssl;
291
293 BIO *sbio;
294
296 static BIO *sslbio_err;
297
300
305
306protected:
307
308 // Statistical area
309 //
310// static XrdXrootdStats *SI;
311// int numReads; // Count for kXR_read
312// int numReadP; // Count for kXR_read pre-preads
313// int numReadV; // Count for kR_readv
314// int numSegsV; // Count for kR_readv segmens
315// int numWrites; // Count
316// int numFiles; // Count
317//
318// int cumReads; // Count less numReads
319// int cumReadP; // Count less numReadP
320// int cumReadV; // Count less numReadV
321// int cumSegsV; // Count less numSegsV
322// int cumWrites; // Count less numWrites
323// long long totReadP; // Bytes
324
325 static XrdScheduler *Sched; // System scheduler
326 static XrdBuffManager *BPool; // Buffer manager
327 static XrdSysError eDest; // Error message handler
328 static XrdSecService *CIA; // Authentication Server
329
332
335 char *Addr_str;
336
338 static XrdOucGMap *servGMap; // Grid mapping service
339
342
343
347
348
349 //
350 // Processing configuration values
351 //
352
354 static int hailWait;
355
357 static int readWait;
358
360 static int Port;
361
363 static char * Port_str;
364
367
369 static char *gridmap;// [s] gridmap file [/etc/grid-security/gridmap]
370 static bool isRequiredGridmap; // If true treat gridmap errors as fatal
371 static bool compatNameGeneration; // If true, utilize the old algorithm for username generation for unknown users.
372
374 static char *secretkey;
375
377 static int sslverifydepth;
378
380 static bool isdesthttps;
381
383 static char *listredir;
384
386 static bool listdeny;
387
389 static bool selfhttps2http;
390
392 static bool embeddedstatic;
393
394 // Url to redirect to in the case a /static is requested
395 static char *staticredir;
396
397 // Hash that keeps preloaded files
399 char *data;
400 int len;
401 };
403
406
408 static std::map< std::string, std::string > hdr2cgimap;
409
411 static int m_bio_type;
412
414 static BIO_METHOD *m_bio_method;
415};
416#endif
int kXR_int32
Definition: XPtypes.hh:89
#define MAX_XRDHTTPEXTHANDLERS
Definition: XrdHttpProtocol.hh:223
Main request/response class, handling the logical status of the communication.
Definition: XrdBuffer.hh:72
Definition: XrdBuffer.hh:42
Definition: XrdCryptoFactory.hh:122
Definition: XrdHttpExtHandler.hh:82
Definition: XrdHttpExtHandler.hh:45
Definition: XrdHttpProtocol.hh:76
void BuffConsume(int blen)
Consume some bytes from the buffer.
static XrdCryptoFactory * myCryptoFactory
Definition: XrdHttpProtocol.hh:304
int BuffFree()
How many bytes free in the buffer.
static BIO * sslbio_err
bio to print SSL errors
Definition: XrdHttpProtocol.hh:296
void Reset()
Reset values, counters, in order to reutilize an object of this class.
int BuffUsed()
How many bytes in the buffer.
int HandleGridMap(XrdLink *lp, const char *eechash)
static kXR_int32 myRole
Our role.
Definition: XrdHttpProtocol.hh:405
static char * sslcafile
Definition: XrdHttpProtocol.hh:366
static int xlistredir(XrdOucStream &Config)
static int LoadExtHandler(std::vector< extHInfo > &hiVec, const char *cFN, XrdOucEnv &myEnv)
static XrdOucHash< StaticPreloadInfo > * staticpreload
Definition: XrdHttpProtocol.hh:402
static char * listredir
Url to redirect to in the case a listing is requested.
Definition: XrdHttpProtocol.hh:383
static bool InitTLS()
Initialization of the ssl security things.
static int Configure(char *parms, XrdProtocol_Config *pi)
Read and apply the configuration.
static int xsecretkey(XrdOucStream &Config)
static int xembeddedstatic(XrdOucStream &Config)
static const char * Configed()
XrdXrootd::Bridge * Bridge
The Bridge that we use to exercise the xrootd internals.
Definition: XrdHttpProtocol.hh:341
static XrdSysError eDest
Definition: XrdHttpProtocol.hh:327
void Cleanup()
Deallocate resources, in order to reutilize an object of this class.
static bool selfhttps2http
If client is HTTPS, self-redirect with HTTP+token.
Definition: XrdHttpProtocol.hh:389
static XrdHttpSecXtractor * secxtractor
Definition: XrdHttpProtocol.hh:215
static int hailWait
Timeout for reading the handshake.
Definition: XrdHttpProtocol.hh:354
static int xdesthttps(XrdOucStream &Config)
int doChksum(const XrdOucString &fname)
Perform a checksum request.
static int xexthandler(XrdOucStream &Config, std::vector< extHInfo > &hiVec)
static char * sslcipherfilter
Definition: XrdHttpProtocol.hh:366
static int m_bio_type
Type identifier for our custom BIO objects.
Definition: XrdHttpProtocol.hh:411
static std::map< std::string, std::string > hdr2cgimap
Rules that turn HTTP headers to cgi tokens in the URL, for internal comsumption.
Definition: XrdHttpProtocol.hh:408
XrdHttpProtocol(bool imhttps)
static int xtlsreuse(XrdOucStream &Config)
static int xsslkey(XrdOucStream &Config)
static int LoadExtHandler(XrdSysError *eDest, const char *libName, const char *configFN, const char *libParms, XrdOucEnv *myEnv, const char *instName)
static int xgmap(XrdOucStream &Config)
static char * gridmap
Gridmap file location. The same used by XrdSecGsi.
Definition: XrdHttpProtocol.hh:369
static int xselfhttps2http(XrdOucStream &Config)
static int xsslcafile(XrdOucStream &Config)
static int xstaticredir(XrdOucStream &Config)
static bool ExtHandlerLoaded(const char *handlername)
bool ssldone
Definition: XrdHttpProtocol.hh:303
XrdLink * Link
The link we are bound to.
Definition: XrdHttpProtocol.hh:331
static char * sslkey
Definition: XrdHttpProtocol.hh:366
int doStat(char *fname)
Perform a Stat request.
XrdObject< XrdHttpProtocol > ProtLink
Definition: XrdHttpProtocol.hh:122
static int readWait
Timeout for reading data.
Definition: XrdHttpProtocol.hh:357
void Recycle(XrdLink *lp, int consec, const char *reason)
Recycle this instance.
BIO * sbio
Private SSL bio.
Definition: XrdHttpProtocol.hh:293
int ChunkResp(const char *body, long long bodylen)
Send a (potentially partial) body in a chunked response; invoking with NULL body.
static int xsslcipherfilter(XrdOucStream &Config)
static XrdOucGMap * servGMap
The instance of the DN mapper. Created only when a valid path is given.
Definition: XrdHttpProtocol.hh:338
void DoIt()
Override from the base class.
Definition: XrdHttpProtocol.hh:87
static BIO * CreateBIO(XrdLink *lp)
Create a new BIO object from an XrdLink. Returns NULL on failure.
int GetVOMSData(XrdLink *lp)
XrdOucString tmpline
A nice var to hold the current header line.
Definition: XrdHttpProtocol.hh:253
static int xheader2cgi(XrdOucStream &Config)
long ResumeBytes
Tells that we are just waiting to have N bytes in the buffer.
Definition: XrdHttpProtocol.hh:287
static int LoadSecXtractor(XrdSysError *eDest, const char *libName, const char *libParms)
static int xsslcert(XrdOucStream &Config)
int BuffgetLine(XrdOucString &dest)
Copy a full line of text from the buffer into dest. Zero if no line can be found in the buffer.
static BIO_METHOD * m_bio_method
C-style vptr table for our custom BIO objects.
Definition: XrdHttpProtocol.hh:414
static XrdScheduler * Sched
Definition: XrdHttpProtocol.hh:325
static char * sslcadir
Definition: XrdHttpProtocol.hh:366
int BuffAvailable()
How many bytes still fit into the buffer in a contiguous way.
static XrdSecService * CIA
Definition: XrdHttpProtocol.hh:328
static char * Port_str
Our port, as a string.
Definition: XrdHttpProtocol.hh:363
XrdHttpProtocol operator=(const XrdHttpProtocol &rhs)
static XrdBuffManager * BPool
Definition: XrdHttpProtocol.hh:326
bool isHTTPS()
called via https
Definition: XrdHttpProtocol.hh:129
static int xstaticpreload(XrdOucStream &Config)
int StartChunkedResp(int code, const char *desc, const char *header_to_add, bool keepalive)
Starts a chunked response; body of request is sent over multiple parts using the SendChunkResp.
static bool compatNameGeneration
Definition: XrdHttpProtocol.hh:371
static int Config(const char *fn, XrdOucEnv *myEnv)
Functions related to the configuration.
static int xhttpsmode(XrdOucStream &Config)
int SendData(const char *body, int bodylen)
Send some generic data to the client.
static int xsecxtractor(XrdOucStream &Config)
static bool isdesthttps
True if the redirections must be towards https targets.
Definition: XrdHttpProtocol.hh:380
XrdBuffer * myBuff
Circular Buffer used to read the request.
Definition: XrdHttpProtocol.hh:248
int getDataOneShot(int blen, bool wait=false)
static char * secretkey
The key used to calculate the url hashes.
Definition: XrdHttpProtocol.hh:374
XrdProtocol * Match(XrdLink *lp)
Tells if the oustanding bytes on the socket match this protocol implementation.
SSL * ssl
Private SSL context.
Definition: XrdHttpProtocol.hh:290
static char * sslcert
OpenSSL stuff.
Definition: XrdHttpProtocol.hh:366
static bool usingEC
Definition: XrdHttpProtocol.hh:217
int BuffgetData(int blen, char **data, bool wait)
Get a pointer, valid for up to blen bytes from the buffer. Returns the validity.
static int xlistdeny(XrdOucStream &Config)
static bool isRequiredGridmap
Definition: XrdHttpProtocol.hh:370
static int xtrace(XrdOucStream &Config)
int HandleAuthentication(XrdLink *lp)
int StartSimpleResp(int code, const char *desc, const char *header_to_add, long long bodylen, bool keepalive)
Start a response back to the client.
static struct XrdHttpProtocol::XrdHttpExtHandlerInfo exthandler[MAX_XRDHTTPEXTHANDLERS]
static int xsslverifydepth(XrdOucStream &Config)
int Stats(char *buff, int blen, int do_sync=0)
Get activity stats.
int SendSimpleResp(int code, const char *desc, const char *header_to_add, const char *body, long long bodylen, bool keepalive)
Sends a basic response. If the length is < 0 then it is calculated internally.
XrdHttpReq CurrentReq
Definition: XrdHttpProtocol.hh:346
static bool isRequiredXtractor
Definition: XrdHttpProtocol.hh:214
char * GetClientIPStr()
Gets a string that represents the IP address of the client. Must be freed.
static int Port
Our port.
Definition: XrdHttpProtocol.hh:360
bool ishttps
Tells if the client is https.
Definition: XrdHttpProtocol.hh:299
char * myBuffEnd
Definition: XrdHttpProtocol.hh:250
static int exthandlercnt
Definition: XrdHttpProtocol.hh:228
static bool InitSecurity()
Initialization fo security addon.
int Process(XrdLink *lp)
Process data incoming from the socket.
XrdHttpProtocol(const XrdHttpProtocol &)=default
Ctor, dtors and copy ctor.
static char * staticredir
Definition: XrdHttpProtocol.hh:395
~XrdHttpProtocol()
Definition: XrdHttpProtocol.hh:117
static int xsslcadir(XrdOucStream &Config)
bool DoingLogin
Tells that we are just logging in.
Definition: XrdHttpProtocol.hh:284
char * myBuffStart
The circular pointers.
Definition: XrdHttpProtocol.hh:250
static bool listdeny
If true, any form of listing is denied.
Definition: XrdHttpProtocol.hh:386
XrdSecEntity SecEntity
Authentication area.
Definition: XrdHttpProtocol.hh:126
static XrdObjectQ< XrdHttpProtocol > ProtStack
Definition: XrdHttpProtocol.hh:121
static bool embeddedstatic
If true, use the embedded css and icons.
Definition: XrdHttpProtocol.hh:392
char * Addr_str
Definition: XrdHttpProtocol.hh:335
int(XrdHttpProtocol::* Resume)()
The resume function.
Definition: XrdHttpProtocol.hh:135
static int sslverifydepth
Depth of verification of a certificate chain.
Definition: XrdHttpProtocol.hh:377
static XrdHttpExtHandler * FindMatchingExtHandler(const XrdHttpReq &)
Definition: XrdHttpReq.hh:77
Definition: XrdHttpSecXtractor.hh:42
Definition: XrdOucEnv.hh:42
Definition: XrdOucGMap.hh:49
Definition: XrdOucHash.hh:128
Definition: XrdOucStream.hh:47
Definition: XrdOucString.hh:254
Definition: XrdOucTokenizer.hh:33
Definition: XrdOucTrace.hh:36
Definition: XrdProtocol.hh:56
Definition: XrdProtocol.hh:125
Definition: XrdScheduler.hh:46
Definition: XrdSecEntity.hh:64
Definition: XrdSecInterface.hh:554
Definition: XrdSysError.hh:90
Definition: XrdXrootdProtocol.hh:156
Definition: XrdXrootdBridge.hh:62
Definition: XrdHttpProtocol.hh:398
char * data
Definition: XrdHttpProtocol.hh:399
int len
Definition: XrdHttpProtocol.hh:400
Definition: XrdHttpProtocol.hh:224
char name[16]
Definition: XrdHttpProtocol.hh:225
XrdHttpExtHandler * ptr
Definition: XrdHttpProtocol.hh:226
Definition: XrdHttpProtocol.hh:181
XrdOucString extHParm
Definition: XrdHttpProtocol.hh:183
~extHInfo()
Definition: XrdHttpProtocol.hh:187
XrdOucString extHPath
Definition: XrdHttpProtocol.hh:182
XrdOucString extHName
Definition: XrdHttpProtocol.hh:181
extHInfo(const char *hName, const char *hPath, const char *hParm)
Definition: XrdHttpProtocol.hh:185