Skip to content

Commit

Permalink
Merge pull request #44 from rw2/403-fix
Browse files Browse the repository at this point in the history
403 fix
  • Loading branch information
bbockelm authored Oct 6, 2024
2 parents 9aaea58 + 32d95ba commit 6995fcd
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 23 deletions.
82 changes: 66 additions & 16 deletions src/HTTPCommands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,32 +103,78 @@ bool HTTPRequest::SendHTTPRequest(const std::string &payload) {
return sendPreparedRequest(protocol, hostUrl, payload);
}

int debug_callback(CURL *, curl_infotype ci, char *data, size_t size, void *) {
switch (ci) {
default:
break;
static void dump(const char *text, FILE *stream, unsigned char *ptr,
size_t size) {
size_t i;
size_t c;
unsigned int width = 0x10;

fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)\n", text, (long)size,
(long)size);

for (i = 0; i < size; i += width) {
fprintf(stream, "%4.4lx: ", (long)i);

/* show hex to the left */
for (c = 0; c < width; c++) {
if (i + c < size)
fprintf(stream, "%02x ", ptr[i + c]);
else
fputs(" ", stream);
}

case CURLINFO_TEXT:
break;
/* show data on the right */
for (c = 0; (c < width) && (i + c < size); c++) {
char x =
(ptr[i + c] >= 0x20 && ptr[i + c] < 0x80) ? ptr[i + c] : '.';
fputc(x, stream);
}

case CURLINFO_HEADER_IN:
break;
fputc('\n', stream); /* newline */
}
}

case CURLINFO_HEADER_OUT:
break;
static void dump_plain(const char *text, FILE *stream, unsigned char *ptr,
size_t size) {
fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)\n", text, (long)size,
(long)size);
fprintf(stream, "%s\n", ptr);
}

case CURLINFO_DATA_IN:
break;
int debugCallback(CURL *handle, curl_infotype ci, char *data, size_t size,
void *clientp) {
const char *text;
(void)handle; /* prevent compiler warning */
(void)clientp;

case CURLINFO_DATA_OUT:
break;
switch (ci) {
case CURLINFO_TEXT:
fputs("== Info: ", stderr);
fwrite(data, size, 1, stderr);
default: /* in case a new one is introduced to shock us */
return 0;

case CURLINFO_SSL_DATA_IN:
case CURLINFO_HEADER_OUT:
text = "=> Send header";
dump_plain(text, stderr, (unsigned char *)data, size);
break;
case CURLINFO_DATA_OUT:
text = "=> Send data";
break;

case CURLINFO_SSL_DATA_OUT:
text = "=> Send SSL data";
break;
case CURLINFO_HEADER_IN:
text = "<= Recv header";
break;
case CURLINFO_DATA_IN:
text = "<= Recv data";
break;
case CURLINFO_SSL_DATA_IN:
text = "<= Recv SSL data";
break;
}
dump(text, stderr, (unsigned char *)data, size);

return 0;
}
Expand Down Expand Up @@ -380,6 +426,10 @@ bool HTTPRequest::sendPreparedRequest(const std::string &protocol,
}
return false;
}
if (m_log.getMsgMask() & LogMask::Dump) {
rv = curl_easy_setopt(curl.get(), CURLOPT_DEBUGFUNCTION, debugCallback);
rv = curl_easy_setopt(curl.get(), CURLOPT_VERBOSE, 1L);
}

retry:
rv = curl_easy_perform(curl.get());
Expand Down
7 changes: 6 additions & 1 deletion src/S3Commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ bool AmazonRequest::parseURL(const std::string &url, std::string &bucket_path,
// everything between
// :// up until the last /, but with <bucket> appended to the front.
host = bucket + "." + substring(url, hostStartIdx);
path = "/" + object;
if (retainObject) {
path = "/" + object;
} else {
path = "/";
}

bucket_path = "/";
}

Expand Down
11 changes: 7 additions & 4 deletions src/S3Commands.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@
class AmazonRequest : public HTTPRequest {
public:
AmazonRequest(const S3AccessInfo &ai, const std::string objectName,
XrdSysError &log)
XrdSysError &log, bool ro = true)
: AmazonRequest(ai.getS3ServiceUrl(), ai.getS3AccessKeyFile(),
ai.getS3SecretKeyFile(), ai.getS3BucketName(),
objectName, ai.getS3UrlStyle(),
ai.getS3SignatureVersion(), log) {}
ai.getS3SignatureVersion(), log, ro) {}

AmazonRequest(const std::string &s, const std::string &akf,
const std::string &skf, const std::string &b,
const std::string &o, const std::string &style, int sv,
XrdSysError &log)
XrdSysError &log, bool ro = true)
: HTTPRequest(s, log, nullptr), accessKeyFile(akf), secretKeyFile(skf),
signatureVersion(sv), bucket(b), object(o), m_style(style) {
requiresSignature = true;
retainObject = ro;
// Start off by parsing the hostUrl, which we use in conjunction with
// the bucket to fill in the host (for setting host header). For
// example, if the incoming hostUrl (which we get from config) is
Expand Down Expand Up @@ -87,6 +88,8 @@ class AmazonRequest : public HTTPRequest {
protected:
bool sendV4Request(const std::string &payload, bool sendContentSHA = false);

bool retainObject;

std::string accessKeyFile;
std::string secretKeyFile;

Expand Down Expand Up @@ -260,7 +263,7 @@ class AmazonS3List : public AmazonRequest {
public:
AmazonS3List(const S3AccessInfo &ai, const std::string &objectName,
size_t maxKeys, XrdSysError &log)
: AmazonRequest(ai, objectName, log), m_maxKeys(maxKeys) {}
: AmazonRequest(ai, objectName, log, false), m_maxKeys(maxKeys) {}

virtual ~AmazonS3List() {}

Expand Down
8 changes: 8 additions & 0 deletions src/S3FileSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,16 @@ bool S3FileSystem::Config(XrdSysLogger *lp, const char *configfn) {
Config.Attach(cfgFD);
std::shared_ptr<S3AccessInfo> newAccessInfo(new S3AccessInfo());
std::string exposedPath;
m_log.setMsgMask(0);
while ((temporary = Config.GetMyFirstWord())) {
attribute = temporary;
if (attribute == "s3.trace") {
if (!XrdHTTPServer::ConfigLog(Config, m_log)) {
m_log.Emsg("Config", "Failed to configure the log level");
}
continue;
}

temporary = Config.GetWord();
if (attribute == "s3.end") {
m_s3_access_map[exposedPath] = newAccessInfo;
Expand Down
7 changes: 6 additions & 1 deletion src/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ std::string XrdHTTPServer::LogMaskToString(int mask) {

bool has_entry = false;
std::stringstream ss;
if (mask & LogMask::Dump) {
ss << "dump";
has_entry = true;
}
if (mask & LogMask::Debug) {
ss << "debug";
has_entry = true;
Expand All @@ -53,7 +57,6 @@ std::string XrdHTTPServer::LogMaskToString(int mask) {

bool XrdHTTPServer::ConfigLog(XrdOucStream &conf, XrdSysError &log) {
std::string map_filename;
log.setMsgMask(0);
char *val = nullptr;
if (!(val = conf.GetToken())) {
log.Emsg("Config",
Expand All @@ -70,6 +73,8 @@ bool XrdHTTPServer::ConfigLog(XrdOucStream &conf, XrdSysError &log) {
log.setMsgMask(log.getMsgMask() | LogMask::Warning);
} else if (!strcmp(val, "info")) {
log.setMsgMask(log.getMsgMask() | LogMask::Info);
} else if (!strcmp(val, "dump")) {
log.setMsgMask(log.getMsgMask() | LogMask::Dump);
} else if (!strcmp(val, "debug")) {
log.setMsgMask(log.getMsgMask() | LogMask::Debug);
} else if (!strcmp(val, "none")) {
Expand Down
3 changes: 2 additions & 1 deletion src/logging.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ enum LogMask {
Info = 0x02,
Warning = 0x04,
Error = 0x08,
All = 0xff
All = 0x0f,
Dump = 0x10
};

// Given a bitset based on LogMask, return a human-readable string of the set
Expand Down

0 comments on commit 6995fcd

Please sign in to comment.