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
28 std::string authLib;
29 std::string authLibParms;
30 int cfgFD = open(configfn, O_RDONLY, 0);
31 if (cfgFD < 0) {
32 m_log.Emsg("Config", errno, "open config file", configfn);
33 return false;
34 }
35 Config.Attach(cfgFD);
36 static const char *cvec[] = { "*** http tpc plugin config:", 0 };
37 Config.Capture(cvec);
38 const char *val;
39 while ((val = Config.GetMyFirstWord())) {
40 if (!strcmp("http.desthttps", val)) {
41 if (!(val = Config.GetWord())) {
42 Config.Close();
43 m_log.Emsg("Config", "http.desthttps value not specified");
44 return false;
45 }
46 if (!strcmp("1", val) || !strcasecmp("yes", val) || !strcasecmp("true", val)) {
47 m_desthttps = true;
48 } else if (!strcmp("0", val) || !strcasecmp("no", val) || !strcasecmp("false", val)) {
49 m_desthttps = false;
50 } else {
51 Config.Close();
52 m_log.Emsg("Config", "https.desthttps value is invalid", val);
53 return false;
54 }
55 } else if (!strcmp("tpc.allow", val)) {
56 if (!(val = Config.GetWord())) {
57 Config.Close();
58 m_log.Emsg("Config", "tpc.allow value not specified");
59 return false;
60 }
61 if (strcmp(val, "local") == 0) {
62 m_allow_local = true;
63 } else if (strcmp(val, "private") == 0) {
64 m_allow_private = true;
65 } else {
66 Config.Close();
67 m_log.Emsg("Config", "tpc.allow value is invalid", val);
68 return false;
69 }
70 } else if (!strcmp("tpc.deny", val)) {
71 if (!(val = Config.GetWord())) {
72 Config.Close();
73 m_log.Emsg("Config", "tpc.deny value not specified");
74 return false;
75 }
76 if (strcmp(val, "local") == 0) {
77 m_allow_local = false;
78 } else if (strcmp(val, "private") == 0) {
79 m_allow_private = false;
80 } else {
81 Config.Close();
82 m_log.Emsg("Config", "tpc.deny value is invalid", val);
83 return false;
84 }
85 } else if (!strcmp("tpc.trace", val)) {
86 if (!ConfigureLogger(Config)) {
87 Config.Close();
88 return false;
89 }
90 } else if (!strcmp("tpc.fixed_route", val)) {
91 if (!(val = Config.GetWord())) {
92 Config.Close();
93 m_log.Emsg("Config", "tpc.fixed_route value not specified");
94 return false;
95 }
96 if (!strcmp("1", val) || !strcasecmp("yes", val) || !strcasecmp("true", val)) {
97 m_fixed_route= true;
98 } else if (!strcmp("0", val) || !strcasecmp("no", val) || !strcasecmp("false", val)) {
99 m_fixed_route= false;
100 } else {
101 Config.Close();
102 m_log.Emsg("Config", "tpc.fixed_route value is invalid", val);
103 return false;
104 }
105 } else if (!strcmp("tpc.header2cgi",val)) {
106 // header2cgi parsing
107 if(XrdHttpProtocol::parseHeader2CGI(Config,m_log,hdr2cgimap)){
108 Config.Close();
109 return false;
110 }
111 // remove authorization header2cgi parsing as it will anyway be added to the CGI before the file open
112 // by the HTTP/TPC logic
113 auto authHdr = XrdOucTUtils::caseInsensitiveFind(hdr2cgimap,"authorization");
114 if(authHdr != hdr2cgimap.end()) {
115 hdr2cgimap.erase(authHdr);
116 }
117 } else if (!strcmp("tpc.timeout", val)) {
118 if (!(val = Config.GetWord())) {
119 Config.Close();
120 m_log.Emsg("Config","tpc.timeout value not specified."); return false;
121 }
122 if (XrdOuca2x::a2tm(m_log, "timeout value", val, &m_timeout, 0)) return false;
123 // First byte timeout can be set separately from the continuous timeout.
124 if ((val = Config.GetWord())) {
125 if (XrdOuca2x::a2tm(m_log, "first byte timeout value", val, &m_first_timeout, 0)) return false;
126 } else {
127 m_first_timeout = 2*m_timeout;
128 }
129 }
130 }
131 Config.Close();
132
133 // Internal override: allow xrdtpc to use a different ca dir from the one prepared by the xrootd
134 // framework. meant for exceptional situations where the site might need a specially-prepared set
135 // of cas only for tpc (such as trying out various workarounds for libnss). Explicitly disables
136 // the NSS hack below.
137 auto env_cadir = getenv("XRDTPC_CADIR");
138 if (env_cadir) m_cadir = env_cadir;
139
140 const char *cadir = nullptr, *cafile = nullptr;
141 if ((cadir = env_cadir ? env_cadir : myEnv->Get("http.cadir"))) {
142 m_cadir = cadir;
143 if (!env_cadir) {
144 m_ca_file.reset(new XrdTlsTempCA(&m_log, m_cadir));
145 if (!m_ca_file->IsValid()) {
146 m_log.Emsg("Config", "CAs / CRL generation for libcurl failed.");
147 return false;
148 }
149 }
150 }
151 if ((cafile = myEnv->Get("http.cafile"))) {
152 m_cafile = cafile;
153 }
154
155 if (!cadir && !cafile) {
156 // We do not necessary need TLS to perform HTTP TPC transfers, just log that these values were not specified
157 m_log.Emsg("Config", "neither xrd.tls cadir nor certfile value specified; is TLS enabled?");
158 }
159
160 void *sfs_raw_ptr;
161 if ((sfs_raw_ptr = myEnv->GetPtr("XrdSfsFileSystem*"))) {
162 m_sfs = static_cast<XrdSfsFileSystem*>(sfs_raw_ptr);
163 m_log.Emsg("Config", "Using filesystem object from the framework.");
164 return true;
165 } else {
166 m_log.Emsg("Config", "No filesystem object available to HTTP-TPC subsystem. Internal error.");
167 return false;
168 }
169 return true;
170}
171
172bool TPCHandler::ConfigureLogger(XrdOucStream &config_obj)
173{
174 char *val = config_obj.GetWord();
175 if (!val || !val[0])
176 {
177 m_log.Emsg("Config", "tpc.trace requires at least one directive [all | error | warning | info | debug | none]");
178 return false;
179 }
180 // If the config option is given, reset the log mask.
181 m_log.setMsgMask(0);
182
183 do {
184 if (!strcasecmp(val, "all"))
185 {
186 m_log.setMsgMask(m_log.getMsgMask() | LogMask::All);
187 }
188 else if (!strcasecmp(val, "error"))
189 {
190 m_log.setMsgMask(m_log.getMsgMask() | LogMask::Error);
191 }
192 else if (!strcasecmp(val, "warning"))
193 {
194 m_log.setMsgMask(m_log.getMsgMask() | LogMask::Warning);
195 }
196 else if (!strcasecmp(val, "info"))
197 {
198 m_log.setMsgMask(m_log.getMsgMask() | LogMask::Info);
199 }
200 else if (!strcasecmp(val, "debug"))
201 {
202 m_log.setMsgMask(m_log.getMsgMask() | LogMask::Debug);
203 }
204 else if (!strcasecmp(val, "none"))
205 {
206 m_log.setMsgMask(0);
207 }
208 else
209 {
210 m_log.Emsg("Config", "tpc.trace encountered an unknown directive (valid values: [all | error | warning | info | debug | none]):", val);
211 return false;
212 }
213 val = config_obj.GetWord();
214 } while (val);
215
216 return true;
217}
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.
char * Get(const char *varname)
Definition XrdOucEnv.hh:69
void * GetPtr(const char *varname)
Definition XrdOucEnv.cc:281
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