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
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.trace", val)) {
56 if (!ConfigureLogger(Config)) {
57 Config.Close();
58 return false;
59 }
60 } else if (!strcmp("tpc.fixed_route", val)) {
61 if (!(val = Config.GetWord())) {
62 Config.Close();
63 m_log.Emsg("Config", "tpc.fixed_route value not specified");
64 return false;
65 }
66 if (!strcmp("1", val) || !strcasecmp("yes", val) || !strcasecmp("true", val)) {
67 m_fixed_route= true;
68 } else if (!strcmp("0", val) || !strcasecmp("no", val) || !strcasecmp("false", val)) {
69 m_fixed_route= false;
70 } else {
71 Config.Close();
72 m_log.Emsg("Config", "tpc.fixed_route value is invalid", val);
73 return false;
74 }
75 } else if (!strcmp("tpc.header2cgi",val)) {
76 // header2cgi parsing
77 if(XrdHttpProtocol::parseHeader2CGI(Config,m_log,hdr2cgimap)){
78 Config.Close();
79 return false;
80 }
81 // remove authorization header2cgi parsing as it will anyway be added to the CGI before the file open
82 // by the HTTP/TPC logic
83 auto authHdr = XrdOucTUtils::caseInsensitiveFind(hdr2cgimap,"authorization");
84 if(authHdr != hdr2cgimap.end()) {
85 hdr2cgimap.erase(authHdr);
86 }
87 } else if (!strcmp("tpc.timeout", val)) {
88 if (!(val = Config.GetWord())) {
89 Config.Close();
90 m_log.Emsg("Config","tpc.timeout value not specified."); return false;
91 }
92 if (XrdOuca2x::a2tm(m_log, "timeout value", val, &m_timeout, 0)) return false;
93 // First byte timeout can be set separately from the continuous timeout.
94 if ((val = Config.GetWord())) {
95 if (XrdOuca2x::a2tm(m_log, "first byte timeout value", val, &m_first_timeout, 0)) return false;
96 } else {
97 m_first_timeout = 2*m_timeout;
98 }
99 }
100 }
101 Config.Close();
102
103 // Internal override: allow xrdtpc to use a different ca dir from the one prepared by the xrootd
104 // framework. meant for exceptional situations where the site might need a specially-prepared set
105 // of cas only for tpc (such as trying out various workarounds for libnss). Explicitly disables
106 // the NSS hack below.
107 auto env_cadir = getenv("XRDTPC_CADIR");
108 if (env_cadir) m_cadir = env_cadir;
109
110 const char *cadir = nullptr, *cafile = nullptr;
111 if ((cadir = env_cadir ? env_cadir : myEnv->Get("http.cadir"))) {
112 m_cadir = cadir;
113 if (!env_cadir) {
114 m_ca_file.reset(new XrdTlsTempCA(&m_log, m_cadir));
115 if (!m_ca_file->IsValid()) {
116 m_log.Emsg("Config", "CAs / CRL generation for libcurl failed.");
117 return false;
118 }
119 }
120 }
121 if ((cafile = myEnv->Get("http.cafile"))) {
122 m_cafile = cafile;
123 }
124
125 if (!cadir && !cafile) {
126 // We do not necessary need TLS to perform HTTP TPC transfers, just log that these values were not specified
127 m_log.Emsg("Config", "neither xrd.tls cadir nor certfile value specified; is TLS enabled?");
128 }
129
130 void *sfs_raw_ptr;
131 if ((sfs_raw_ptr = myEnv->GetPtr("XrdSfsFileSystem*"))) {
132 m_sfs = static_cast<XrdSfsFileSystem*>(sfs_raw_ptr);
133 m_log.Emsg("Config", "Using filesystem object from the framework.");
134 return true;
135 } else {
136 m_log.Emsg("Config", "No filesystem object available to HTTP-TPC subsystem. Internal error.");
137 return false;
138 }
139 return true;
140}
141
142bool TPCHandler::ConfigureLogger(XrdOucStream &config_obj)
143{
144 char *val = config_obj.GetWord();
145 if (!val || !val[0])
146 {
147 m_log.Emsg("Config", "tpc.trace requires at least one directive [all | error | warning | info | debug | none]");
148 return false;
149 }
150 // If the config option is given, reset the log mask.
151 m_log.setMsgMask(0);
152
153 do {
154 if (!strcasecmp(val, "all"))
155 {
156 m_log.setMsgMask(m_log.getMsgMask() | LogMask::All);
157 }
158 else if (!strcasecmp(val, "error"))
159 {
160 m_log.setMsgMask(m_log.getMsgMask() | LogMask::Error);
161 }
162 else if (!strcasecmp(val, "warning"))
163 {
164 m_log.setMsgMask(m_log.getMsgMask() | LogMask::Warning);
165 }
166 else if (!strcasecmp(val, "info"))
167 {
168 m_log.setMsgMask(m_log.getMsgMask() | LogMask::Info);
169 }
170 else if (!strcasecmp(val, "debug"))
171 {
172 m_log.setMsgMask(m_log.getMsgMask() | LogMask::Debug);
173 }
174 else if (!strcasecmp(val, "none"))
175 {
176 m_log.setMsgMask(0);
177 }
178 else
179 {
180 m_log.Emsg("Config", "tpc.trace encountered an unknown directive (valid values: [all | error | warning | info | debug | none]):", val);
181 return false;
182 }
183 val = config_obj.GetWord();
184 } while (val);
185
186 return true;
187}
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: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
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
void setMsgMask(int mask)
XrdCmsConfig Config