Skip to content

Commit

Permalink
S3: reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
apeters1971 committed Jun 19, 2024
1 parent 3681a3f commit 14dc2f1
Show file tree
Hide file tree
Showing 23 changed files with 820 additions and 475 deletions.
67 changes: 45 additions & 22 deletions src/XrdS3/XrdS3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "XrdS3.hh"
//------------------------------------------------------------------------------
#include <fcntl.h>

#include <algorithm>
#include <sstream>
//------------------------------------------------------------------------------
Expand All @@ -43,10 +44,10 @@
//! XRootD S3 plug-in implementation
//------------------------------------------------------------------------------


namespace S3 {
XrdVERSIONINFO(XrdHttpGetExtHandler, HttpS3);
S3Handler* S3Handler::sInstance = nullptr; // for convenience to get access to our logger
S3Handler *S3Handler::sInstance =
nullptr; // for convenience to get access to our logger
//------------------------------------------------------------------------------
//! This is the default handler for requests that are not handled by the
//! router. It returns a 404 error.
Expand All @@ -68,7 +69,7 @@ S3Handler::S3Handler(XrdSysError *log, const char *config, XrdOucEnv *myEnv)
S3Handler::sInstance = this;
mLog.Init(&mErr);

S3::ScopedFsId::Validate(); // verify we can switch filesystem IDs !
S3::ScopedFsId::Validate(); // verify we can switch filesystem IDs !

if (!ParseConfig(config, *myEnv)) {
throw std::runtime_error("Failed to configure the HTTP S3 handler.");
Expand Down Expand Up @@ -537,62 +538,84 @@ bool S3Handler::ParseConfig(const char *config, XrdOucEnv &env) {

const char *val;

mErr.setMsgMask(LogMask::ERROR | LogMask::WARN); // by default don't log so much
mErr.setMsgMask(LogMask::ERROR |
LogMask::WARN); // by default don't log so much

while ((val = Config.GetMyFirstWord())) {
if (!strcmp("s3.config", val)) {
if (!(val = Config.GetWord())) {
Config.Close();
std::cerr << "error: s3.config value not defined" << std::endl;
std::cerr << "error: s3.config value not defined" << std::endl;
return false;
}
mConfig.config_dir = val;
} else if (!strcmp("s3.region", val)) {
if (!(val = Config.GetWord())) {
Config.Close();
std::cerr << "error: s3.region value not defined" << std::endl;
std::cerr << "error: s3.region value not defined" << std::endl;
return false;
}
mConfig.region = val;
} else if (!strcmp("s3.service", val)) {
if (!(val = Config.GetWord())) {
Config.Close();
std::cerr << "error: s3.service value not defined" << std::endl;
std::cerr << "error: s3.service value not defined" << std::endl;
return false;
}
mConfig.service = val;
} else if (!strcmp("s3.multipart", val)) {
if (!(val = Config.GetWord())) {
Config.Close();
std::cerr << "error: s3.multipart value not defined" << std::endl;
std::cerr << "error: s3.multipart value not defined" << std::endl;
return false;
}
mConfig.multipart_upload_dir = val;
} else if (!strcmp("s3.trace", val)) {
if (!(val = Config.GetWord())) {
Config.Close();
std::cerr << "error: s3.trace value not defined" << std::endl;
std::cerr << "error: s3.trace value not defined" << std::endl;
return false;
}
mConfig.trace = val;
mErr.setMsgMask(0);
if (!strcmp(val, "all")) {mErr.setMsgMask(LogMask::ALL);}
else if (!strcmp(val, "error")) {mErr.setMsgMask(LogMask::ERROR);}
else if (!strcmp(val, "warning")) {mErr.setMsgMask(LogMask::ERROR | LogMask::WARN);}
else if (!strcmp(val, "info")) {mErr.setMsgMask(LogMask::ERROR | LogMask::WARN | LogMask::INFO);}
else if (!strcmp(val, "debug")) {mErr.setMsgMask(LogMask::ERROR | LogMask::WARN | LogMask::INFO | LogMask::DEBUG);}
else if (!strcmp(val, "none")) {mErr.setMsgMask(0);}
else {
std::cerr << "error: s3.trace encountered an unknown directive: " << val << std::endl;
if (!strcmp(val, "all")) {
mErr.setMsgMask(LogMask::ALL);
} else if (!strcmp(val, "error")) {
mErr.setMsgMask(LogMask::ERROR);
} else if (!strcmp(val, "warning")) {
mErr.setMsgMask(LogMask::ERROR | LogMask::WARN);
} else if (!strcmp(val, "info")) {
mErr.setMsgMask(LogMask::ERROR | LogMask::WARN | LogMask::INFO);
} else if (!strcmp(val, "debug")) {
mErr.setMsgMask(LogMask::ERROR | LogMask::WARN | LogMask::INFO |
LogMask::DEBUG);
} else if (!strcmp(val, "none")) {
mErr.setMsgMask(0);
} else {
std::cerr << "error: s3.trace encountered an unknown directive: " << val
<< std::endl;
return false;
} }
}
}
}
Config.Close();

if (mConfig.config_dir.empty()) { std::cerr << "error: s3.config not defined in configuration file" << std::endl; }
if (mConfig.service.empty()) { std::cerr << "error: s3.service not defined in configuration file" << std::endl; }
if (mConfig.region.empty()) { std::cerr << "error: s3.region not defined in configuration file" << std::endl; }
if (mConfig.multipart_upload_dir.empty()) { std::cerr << "error: s3.multipar not defined in configuration file" << std::endl; }
if (mConfig.config_dir.empty()) {
std::cerr << "error: s3.config not defined in configuration file"
<< std::endl;
}
if (mConfig.service.empty()) {
std::cerr << "error: s3.service not defined in configuration file"
<< std::endl;
}
if (mConfig.region.empty()) {
std::cerr << "error: s3.region not defined in configuration file"
<< std::endl;
}
if (mConfig.multipart_upload_dir.empty()) {
std::cerr << "error: s3.multipar not defined in configuration file"
<< std::endl;
}

return (!mConfig.config_dir.empty() && !mConfig.service.empty() &&
!mConfig.region.empty() && !mConfig.multipart_upload_dir.empty());
Expand Down
9 changes: 4 additions & 5 deletions src/XrdS3/XrdS3.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@
#include "XrdS3Api.hh"
#include "XrdS3Auth.hh"
#include "XrdS3Crypt.hh"
#include "XrdS3Log.hh"
#include "XrdS3Router.hh"
#include "XrdS3Utils.hh"
#include "XrdS3Log.hh"
#include "XrdSys/XrdSysError.hh"
//------------------------------------------------------------------------------


namespace S3 {
//------------------------------------------------------------------------------
//! \brief S3Handler is a class that implements the XRootD HTTP extension
Expand All @@ -58,10 +57,10 @@ class S3Handler : public XrdHttpExtHandler {
// Abstract method in the base class, but does not seem to be used
int Init(const char *cfgfile) override { return 0; }

static S3Handler* sInstance;
static S3Log* Logger() { return sInstance->GetLogger(); }
static S3Handler *sInstance;
static S3Log *Logger() { return sInstance->GetLogger(); }

S3Log* GetLogger() { return &mLog; }
S3Log *GetLogger() { return &mLog; }

Context ctx;

Expand Down
3 changes: 1 addition & 2 deletions src/XrdS3/XrdS3Action.hh
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,4 @@ enum class Action {
WriteGetObjectResponse,
};

} // namespace S

} // namespace S3
4 changes: 2 additions & 2 deletions src/XrdS3/XrdS3Api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
// In applying this licence, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
//------------------------------------------------------------------------------
//--------------------------å----------------------------------------------------

//------------------------------------------------------------------------------
#include "XrdS3Api.hh"
//------------------------------------------------------------------------------
#include <tinyxml2.h>
//------------------------------------------------------------------------------
#include "XrdCks/XrdCksCalcmd5.hh"
#include "XrdS3.hh"
#include "XrdS3Auth.hh"
#include "XrdS3ErrorResponse.hh"
#include "XrdS3Response.hh"
#include "XrdS3.hh"
//------------------------------------------------------------------------------

namespace S3 {
Expand Down
14 changes: 7 additions & 7 deletions src/XrdS3/XrdS3Api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

#pragma once
#include <cstdint>
#include <string>
#include <vector>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "XrdS3Auth.hh"
#include "XrdS3ObjectStore.hh"
Expand All @@ -46,9 +46,10 @@ namespace S3 {
class S3Api {
public:
S3Api() = default;
S3Api(const std::string &config_path, const std::string &region, const std::string &service,
const std::string &mtpu_path)
: objectStore(config_path, mtpu_path), auth(config_path, region, service) {}
S3Api(const std::string &config_path, const std::string &region,
const std::string &service, const std::string &mtpu_path)
: objectStore(config_path, mtpu_path),
auth(config_path, region, service) {}

~S3Api() = default;

Expand Down Expand Up @@ -310,10 +311,9 @@ class S3Api {
}

private:
S3Log* mLog;
S3Log *mLog;
S3ObjectStore objectStore;
S3Auth auth;
};

} // namespace S3

8 changes: 6 additions & 2 deletions src/XrdS3/XrdS3Auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

//------------------------------------------------------------------------------
#include "XrdS3Auth.hh"

#include "XrdS3.hh"
//------------------------------------------------------------------------------
#include <fcntl.h>
#include <sys/xattr.h>

#include <algorithm>
#include <utility>
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -237,7 +239,9 @@ S3Error S3Auth::VerifySigV4(XrdS3Req &req) {
AWS4_ALGORITHM, req.date, canonical_request_hash, sig.credentials);

const auto signature = GetSignature(key, sig.credentials, string_to_sign);
S3::S3Handler::Logger()->Log(S3::DEBUG, "VerifySignature", "sign=%s calc-sign=%s", sig.signature.c_str(), signature.c_str());
S3::S3Handler::Logger()->Log(S3::DEBUG, "VerifySignature",
"sign=%s calc-sign=%s", sig.signature.c_str(),
signature.c_str());

if (signature == sig.signature) {
return S3Error::None;
Expand Down Expand Up @@ -413,7 +417,7 @@ S3Auth::S3Auth(const std::filesystem::path &path, std::string region,
std::string access_key_id = entry->d_name;

auto filepath = keystore / access_key_id;

auto user_id = S3Utils::GetXattr(filepath, "user");
if (user_id.empty()) {
continue;
Expand Down
17 changes: 8 additions & 9 deletions src/XrdS3/XrdS3Auth.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@
#pragma once

//------------------------------------------------------------------------------
#include <pwd.h>
#include <sys/types.h>

#include <set>
#include <shared_mutex>
#include <string>
#include <vector>
#include <sys/types.h>
#include <pwd.h>
//------------------------------------------------------------------------------
#include "XrdS3ErrorResponse.hh"
#include "XrdS3Action.hh"
#include "XrdS3Crypt.hh"
#include "XrdS3ErrorResponse.hh"
#include "XrdS3Req.hh"

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -88,11 +89,11 @@ class S3Auth {
// translate username
struct passwd *pwd = getpwnam(id.c_str());
if (pwd == nullptr) {
uid=99;
gid=99;
uid = 99;
gid = 99;
} else {
uid = pwd->pw_uid;
gid = pwd->pw_gid;
uid = pwd->pw_uid;
gid = pwd->pw_gid;
}
}
};
Expand Down Expand Up @@ -162,5 +163,3 @@ class S3Auth {
};

} // namespace S3


27 changes: 24 additions & 3 deletions src/XrdS3/XrdS3Crypt.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
//------------------------------------------------------------------------------
// Copyright (c) 2024 by European Organization for Nuclear Research (CERN)
// Author: Mano Segransan / CERN EOS Project <[email protected]>
//------------------------------------------------------------------------------
// This file is part of the XRootD software suite.
//
// XRootD is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// XRootD is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// Created by segransm on 11/3/23.
// You should have received a copy of the GNU Lesser General Public License
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
//
// In applying this licence, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
#include "XrdS3Crypt.hh"
//------------------------------------------------------------------------------
#include <openssl/evp.h>

#include <exception>
#include <stdexcept>
//------------------------------------------------------------------------------
Expand All @@ -17,7 +38,7 @@ namespace S3 {
//! \brief SHA256 implementation using OpenSSL
//------------------------------------------------------------------------------
S3Crypt::S3SHA256::S3SHA256() {
md = (EVP_MD*)EVP_sha256();
md = (EVP_MD *)EVP_sha256();
if (md == nullptr) {
throw std::bad_alloc();
}
Expand Down Expand Up @@ -86,7 +107,7 @@ S3Crypt::S3SHA256::~S3SHA256() {
void S3Crypt::S3SHA256::Init() { EVP_DigestInit_ex2(ctx, nullptr, nullptr); }

#endif

//------------------------------------------------------------------------------
//! \brief Update the digest
//! @param src The source buffer
Expand Down
8 changes: 3 additions & 5 deletions src/XrdS3/XrdS3Crypt.hh
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ class S3Crypt {
return digest;
}

//------------------------------------------------------------------------------
//! S3SHA256 - SHA256 hash
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//! S3SHA256 - SHA256 hash
//------------------------------------------------------------------------------
class S3SHA256 {
public:
S3SHA256();
Expand Down Expand Up @@ -141,5 +141,3 @@ class S3Crypt {
};

} // namespace S3


2 changes: 1 addition & 1 deletion src/XrdS3/XrdS3ErrorResponse.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
namespace S3 {

//------------------------------------------------------------------------------
//! \brief S3 error code
//! \brief S3 error code
//------------------------------------------------------------------------------
struct S3ErrorCode {
std::string code;
Expand Down
Loading

0 comments on commit 14dc2f1

Please sign in to comment.