XRootD
Loading...
Searching...
No Matches
XrdHttpTpcConfigure.cc
Go to the documentation of this file.
1
2#include "XrdHttpTpcTPC.hh"
3
4#include <dlfcn.h>
5#include <fcntl.h>
6
7#include "XrdOuc/XrdOuca2x.hh"
8#include "XrdOuc/XrdOucEnv.hh"
14
15using namespace TPC;
16
17
18bool TPCHandler::Configure(const char *configfn, XrdOucEnv *myEnv)
19{
20 XrdOucEnv cfgEnv;
21 XrdOucStream Config(&m_log, getenv("XRDINSTANCE"), &cfgEnv, "=====> ");
22
23 m_log.setMsgMask(LogMask::Warning | LogMask::Error);
24
25 // test if XrdEC is used
26 usingEC = getenv("XRDCL_EC")? true : false;
27 // Test if the CRL checking is enabled
28 allowMissingCRL = (bool) myEnv->GetInt("http.allowmissingcrl");
29 std::string authLib;
30 std::string authLibParms;
31 int cfgFD = open(configfn, O_RDONLY, 0);
32 if (cfgFD < 0) {
33 m_log.Emsg("Config", errno, "open config file", configfn);
34 return false;
35 }
36 Config.Attach(cfgFD);
37 static const char *cvec[] = { "*** http tpc plugin config:", 0 };
38 Config.Capture(cvec);
39 const char *val;
40 while ((val = Config.GetMyFirstWord())) {
41 if (!strcmp("http.desthttps", val)) {
42 if (!(val = Config.GetWord())) {
43 Config.Close();
44 m_log.Emsg("Config", "http.desthttps value not specified");
45 return false;
46 }
47 if (!strcmp("1", val) || !strcasecmp("yes", val) || !strcasecmp("true", val)) {
48 m_desthttps = true;
49 } else if (!strcmp("0", val) || !strcasecmp("no", val) || !strcasecmp("false", val)) {
50 m_desthttps = false;
51 } else {
52 Config.Close();
53 m_log.Emsg("Config", "https.desthttps value is invalid", val);
54 return false;
55 }
56 } else if (!strcmp("tpc.trace", val)) {
57 if (!ConfigureLogger(Config)) {
58 Config.Close();
59 return false;
60 }
61 } else if (!strcmp("tpc.fixed_route", val)) {
62 if (!(val = Config.GetWord())) {
63 Config.Close();
64 m_log.Emsg("Config", "tpc.fixed_route value not specified");
65 return false;
66 }
67 if (!strcmp("1", val) || !strcasecmp("yes", val) || !strcasecmp("true", val)) {
68 m_fixed_route= true;
69 } else if (!strcmp("0", val) || !strcasecmp("no", val) || !strcasecmp("false", val)) {
70 m_fixed_route= false;
71 } else {
72 Config.Close();
73 m_log.Emsg("Config", "tpc.fixed_route value is invalid", val);
74 return false;
75 }
76 } else if (!strcmp("tpc.header2cgi",val)) {
77 // header2cgi parsing
78 if(XrdHttpProtocol::parseHeader2CGI(Config,m_log,hdr2cgimap)){
79 Config.Close();
80 return false;
81 }
82 // remove authorization header2cgi parsing as it will anyway be added to the CGI before the file open
83 // by the HTTP/TPC logic
84 auto authHdr = XrdOucTUtils::caseInsensitiveFind(hdr2cgimap,"authorization");
85 if(authHdr != hdr2cgimap.end()) {
86 hdr2cgimap.erase(authHdr);
87 }
88 } else if (!strcmp("tpc.timeout", val)) {
89 if (!(val = Config.GetWord())) {
90 Config.Close();
91 m_log.Emsg("Config","tpc.timeout value not specified."); return false;
92 }
93 if (XrdOuca2x::a2tm(m_log, "timeout value", val, &m_timeout, 0)) return false;
94 // First byte timeout can be set separately from the continuous timeout.
95 if ((val = Config.GetWord())) {
96 if (XrdOuca2x::a2tm(m_log, "first byte timeout value", val, &m_first_timeout, 0)) return false;
97 } else {
98 m_first_timeout = 2*m_timeout;
99 }
100 }
101 }
102 Config.Close();
103
104 // Internal override: allow xrdtpc to use a different ca dir from the one prepared by the xrootd
105 // framework. meant for exceptional situations where the site might need a specially-prepared set
106 // of cas only for tpc (such as trying out various workarounds for libnss). Explicitly disables
107 // the NSS hack below.
108 auto env_cadir = getenv("XRDTPC_CADIR");
109 if (env_cadir) m_cadir = env_cadir;
110
111 const char *cadir = nullptr, *cafile = nullptr;
112 if ((cadir = env_cadir ? env_cadir : myEnv->Get("http.cadir"))) {
113 m_cadir = cadir;
114 if (!env_cadir) {
115 m_ca_file.reset(new XrdTlsTempCA(&m_log, m_cadir));
116 if (!m_ca_file->IsValid()) {
117 m_log.Emsg("Config", "CAs / CRL generation for libcurl failed.");
118 return false;
119 }
120 }
121 }
122 if ((cafile = myEnv->Get("http.cafile"))) {
123 m_cafile = cafile;
124 }
125
126 if (!cadir && !cafile) {
127 // We do not necessary need TLS to perform HTTP TPC transfers, just log that these values were not specified
128 m_log.Emsg("Config", "neither xrd.tls cadir nor certfile value specified; is TLS enabled?");
129 }
130
131 void *sfs_raw_ptr;
132 if ((sfs_raw_ptr = myEnv->GetPtr("XrdSfsFileSystem*"))) {
133 m_sfs = static_cast<XrdSfsFileSystem*>(sfs_raw_ptr);
134 m_log.Emsg("Config", "Using filesystem object from the framework.");
135 return true;
136 } else {
137 m_log.Emsg("Config", "No filesystem object available to HTTP-TPC subsystem. Internal error.");
138 return false;
139 }
140 return true;
141}
142
143bool TPCHandler::ConfigureLogger(XrdOucStream &config_obj)
144{
145 char *val = config_obj.GetWord();
146 if (!val || !val[0])
147 {
148 m_log.Emsg("Config", "tpc.trace requires at least one directive [all | error | warning | info | debug | none]");
149 return false;
150 }
151 // If the config option is given, reset the log mask.
152 m_log.setMsgMask(0);
153
154 do {
155 if (!strcasecmp(val, "all"))
156 {
157 m_log.setMsgMask(m_log.getMsgMask() | LogMask::All);
158 }
159 else if (!strcasecmp(val, "error"))
160 {
161 m_log.setMsgMask(m_log.getMsgMask() | LogMask::Error);
162 }
163 else if (!strcasecmp(val, "warning"))
164 {
165 m_log.setMsgMask(m_log.getMsgMask() | LogMask::Warning);
166 }
167 else if (!strcasecmp(val, "info"))
168 {
169 m_log.setMsgMask(m_log.getMsgMask() | LogMask::Info);
170 }
171 else if (!strcasecmp(val, "debug"))
172 {
173 m_log.setMsgMask(m_log.getMsgMask() | LogMask::Debug);
174 }
175 else if (!strcasecmp(val, "none"))
176 {
177 m_log.setMsgMask(0);
178 }
179 else
180 {
181 m_log.Emsg("Config", "tpc.trace encountered an unknown directive (valid values: [all | error | warning | info | debug | none]):", val);
182 return false;
183 }
184 val = config_obj.GetWord();
185 } while (val);
186
187 return true;
188}
A pragmatic implementation of the HTTP/DAV protocol for the Xrd framework.
#define open
Definition XrdPosix.hh:76
static int parseHeader2CGI(XrdOucStream &Config, XrdSysError &err, std::map< std::string, std::string > &header2cgi)
Use this function to parse header2cgi configurations.
long GetInt(const char *varname)
Definition XrdOucEnv.cc:235
char * Get(const char *varname)
Definition XrdOucEnv.hh:69
void * GetPtr(const char *varname)
Definition XrdOucEnv.cc:263
char * GetWord(int lowcase=0)
static std::map< std::string, T >::const_iterator caseInsensitiveFind(const std::map< std::string, T > &m, const std::string &lowerCaseSearchKey)
static int a2tm(XrdSysError &, const char *emsg, const char *item, int *val, int minv=-1, int maxv=-1)
Definition XrdOuca2x.cc:288
XrdCmsConfig Config