Use scoped enums for acl_t, sse_type_t, and storage_class_t

This prevents some kinds of implicit conversions.  Also deduplicate
str/from_str logic.  References #1371.
This commit is contained in:
Andrew Gaul 2020-08-20 11:09:49 +09:00
parent bcf6838e86
commit 60d456a993
4 changed files with 258 additions and 179 deletions

View File

@ -399,11 +399,11 @@ long S3fsCurl::connect_timeout = 300; // default
time_t S3fsCurl::readwrite_timeout = 120; // default
int S3fsCurl::retries = 5; // default
bool S3fsCurl::is_public_bucket = false;
acl_t S3fsCurl::default_acl = PRIVATE;
storage_class_t S3fsCurl::storage_class = STANDARD;
acl_t S3fsCurl::default_acl = acl_t::PRIVATE;
storage_class_t S3fsCurl::storage_class = storage_class_t::STANDARD;
sseckeylist_t S3fsCurl::sseckeys;
std::string S3fsCurl::ssekmsid;
sse_type_t S3fsCurl::ssetype = SSE_DISABLE;
sse_type_t S3fsCurl::ssetype = sse_type_t::SSE_DISABLE;
bool S3fsCurl::is_content_md5 = false;
bool S3fsCurl::is_verbose = false;
bool S3fsCurl::is_dump_body = false;
@ -1172,17 +1172,21 @@ bool S3fsCurl::SetSseKmsid(const char* kmsid)
// this function check the integrity of the SSE data finally.
bool S3fsCurl::FinalCheckSse()
{
if(SSE_DISABLE == S3fsCurl::ssetype){
switch(S3fsCurl::ssetype){
case sse_type_t::SSE_DISABLE:
S3fsCurl::ssekmsid.erase();
}else if(SSE_S3 == S3fsCurl::ssetype){
return true;
case sse_type_t::SSE_S3:
S3fsCurl::ssekmsid.erase();
}else if(SSE_C == S3fsCurl::ssetype){
return true;
case sse_type_t::SSE_C:
if(S3fsCurl::sseckeys.empty()){
S3FS_PRN_ERR("sse type is SSE-C, but there is no custom key.");
return false;
}
S3fsCurl::ssekmsid.erase();
}else if(SSE_KMS == S3fsCurl::ssetype){
return true;
case sse_type_t::SSE_KMS:
if(S3fsCurl::ssekmsid.empty()){
S3FS_PRN_ERR("sse type is SSE-KMS, but there is no specified kms id.");
return false;
@ -1191,11 +1195,10 @@ bool S3fsCurl::FinalCheckSse()
S3FS_PRN_ERR("sse type is SSE-KMS, but signature type is not v4. SSE-KMS require signature v4.");
return false;
}
}else{
S3FS_PRN_ERR("sse type is unknown(%d).", S3fsCurl::ssetype);
return false;
return true;
}
return true;
S3FS_PRN_ERR("sse type is unknown(%d).", static_cast<int>(S3fsCurl::ssetype));
return false;
}
bool S3fsCurl::LoadEnvSseCKeys()
@ -1761,7 +1764,7 @@ int S3fsCurl::ParallelGetObjectRequest(const char* tpath, int fd, off_t start, s
{
S3FS_PRN_INFO3("[tpath=%s][fd=%d]", SAFESTRPTR(tpath), fd);
sse_type_t ssetype;
sse_type_t ssetype = sse_type_t::SSE_DISABLE;
string ssevalue;
if(!get_object_sse_type(tpath, ssetype, ssevalue)){
S3FS_PRN_WARN("Failed to get SSE type for file(%s).", SAFESTRPTR(tpath));
@ -2125,7 +2128,7 @@ S3fsCurl::S3fsCurl(bool ahbe) :
hCurl(NULL), type(REQTYPE_UNSET), path(""), base_path(""), saved_path(""), url(""), requestHeaders(NULL),
LastResponseCode(S3FSCURL_RESPONSECODE_NOTSET), postdata(NULL), postdata_remaining(0), is_use_ahbe(ahbe),
retry_count(0), b_infile(NULL), b_postdata(NULL), b_postdata_remaining(0), b_partdata_startpos(0), b_partdata_size(0),
b_ssekey_pos(-1), b_ssevalue(""), b_ssetype(SSE_DISABLE), op(""), query_string(""),
b_ssekey_pos(-1), b_ssevalue(""), b_ssetype(sse_type_t::SSE_DISABLE), op(""), query_string(""),
sem(NULL), completed_tids_lock(NULL), completed_tids(NULL), fpLazySetup(NULL)
{
}
@ -3082,11 +3085,15 @@ bool S3fsCurl::LoadIAMRoleFromMetaData()
bool S3fsCurl::AddSseRequestHead(sse_type_t ssetype, string& ssevalue, bool is_only_c, bool is_copy)
{
if(SSE_S3 == ssetype){
switch(ssetype){
case sse_type_t::SSE_DISABLE:
return true;
case sse_type_t::SSE_S3:
if(!is_only_c){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-server-side-encryption", "AES256");
}
}else if(SSE_C == ssetype){
return true;
case sse_type_t::SSE_C: {
string sseckey;
if(S3fsCurl::GetSseKey(ssevalue, sseckey)){
if(is_copy){
@ -3101,8 +3108,9 @@ bool S3fsCurl::AddSseRequestHead(sse_type_t ssetype, string& ssevalue, bool is_o
}else{
S3FS_PRN_WARN("Failed to insert SSE-C header.");
}
}else if(SSE_KMS == ssetype){
return true;
}
case sse_type_t::SSE_KMS:
if(!is_only_c){
if(ssevalue.empty()){
ssevalue = S3fsCurl::GetSseKmsId();
@ -3110,8 +3118,10 @@ bool S3fsCurl::AddSseRequestHead(sse_type_t ssetype, string& ssevalue, bool is_o
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-server-side-encryption", "aws:kms");
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-server-side-encryption-aws-kms-key-id", ssevalue.c_str());
}
return true;
}
return true;
S3FS_PRN_ERR("sse type is unknown(%d).", static_cast<int>(S3fsCurl::ssetype));
return false;
}
//
@ -3143,7 +3153,7 @@ bool S3fsCurl::PreHeadRequest(const char* tpath, const char* bpath, const char*
// requestHeaders
if(0 <= ssekey_pos){
string md5;
if(!S3fsCurl::GetSseKeyMd5(ssekey_pos, md5) || !AddSseRequestHead(SSE_C, md5, true, false)){
if(!S3fsCurl::GetSseKeyMd5(ssekey_pos, md5) || !AddSseRequestHead(sse_type_t::SSE_C, md5, true, false)){
S3FS_PRN_ERR("Failed to set SSE-C headers for sse-c key pos(%d)(=md5(%s)).", ssekey_pos, md5.c_str());
return false;
}
@ -3245,18 +3255,18 @@ int S3fsCurl::PutHeadRequest(const char* tpath, headers_t& meta, bool is_copy)
requestHeaders = curl_slist_sort_insert(requestHeaders, iter->first.c_str(), value.c_str());
}else if(key == "x-amz-server-side-encryption" && value != "aws:kms"){
// Only copy mode.
if(is_copy && !AddSseRequestHead(SSE_S3, value, false, true)){
if(is_copy && !AddSseRequestHead(sse_type_t::SSE_S3, value, false, true)){
S3FS_PRN_WARN("Failed to insert SSE-S3 header.");
}
}else if(key == "x-amz-server-side-encryption-aws-kms-key-id"){
// Only copy mode.
if(is_copy && !value.empty() && !AddSseRequestHead(SSE_KMS, value, false, true)){
if(is_copy && !value.empty() && !AddSseRequestHead(sse_type_t::SSE_KMS, value, false, true)){
S3FS_PRN_WARN("Failed to insert SSE-KMS header.");
}
}else if(key == "x-amz-server-side-encryption-customer-key-md5"){
// Only copy mode.
if(is_copy){
if(!AddSseRequestHead(SSE_C, value, true, true) || !AddSseRequestHead(SSE_C, value, true, false)){
if(!AddSseRequestHead(sse_type_t::SSE_C, value, true, true) || !AddSseRequestHead(sse_type_t::SSE_C, value, true, false)){
S3FS_PRN_WARN("Failed to insert SSE-C header.");
}
}
@ -3264,19 +3274,11 @@ int S3fsCurl::PutHeadRequest(const char* tpath, headers_t& meta, bool is_copy)
}
// "x-amz-acl", storage class, sse
if(S3fsCurl::default_acl != PRIVATE){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-acl", acl_to_string(S3fsCurl::default_acl));
if(S3fsCurl::default_acl != acl_t::PRIVATE){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-acl", S3fsCurl::default_acl.str());
}
if(REDUCED_REDUNDANCY == GetStorageClass()){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", "REDUCED_REDUNDANCY");
} else if(STANDARD_IA == GetStorageClass()){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", "STANDARD_IA");
} else if(ONEZONE_IA == GetStorageClass()){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", "ONEZONE_IA");
} else if(INTELLIGENT_TIERING == GetStorageClass()) {
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", "INTELLIGENT_TIERING");
} else if(GLACIER == GetStorageClass()) {
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", "GLACIER");
if(GetStorageClass() != storage_class_t::STANDARD){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", GetStorageClass().str());
}
// SSE
if(!is_copy){
@ -3397,19 +3399,11 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd)
}
}
// "x-amz-acl", storage class, sse
if(S3fsCurl::default_acl != PRIVATE){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-acl", acl_to_string(S3fsCurl::default_acl));
if(S3fsCurl::default_acl != acl_t::PRIVATE){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-acl", S3fsCurl::default_acl.str());
}
if(REDUCED_REDUNDANCY == GetStorageClass()){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", "REDUCED_REDUNDANCY");
} else if(STANDARD_IA == GetStorageClass()){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", "STANDARD_IA");
} else if(ONEZONE_IA == GetStorageClass()){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", "ONEZONE_IA");
} else if(INTELLIGENT_TIERING == GetStorageClass()) {
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", "INTELLIGENT_TIERING");
} else if(GLACIER == GetStorageClass()) {
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", "GLACIER");
if(GetStorageClass() != storage_class_t::STANDARD){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", GetStorageClass().str());
}
// SSE
string ssevalue;
@ -3507,7 +3501,7 @@ int S3fsCurl::GetObjectRequest(const char* tpath, int fd, off_t start, ssize_t s
if(!tpath){
return -1;
}
sse_type_t ssetype;
sse_type_t ssetype = sse_type_t::SSE_DISABLE;
string ssevalue;
if(!get_object_sse_type(tpath, ssetype, ssevalue)){
S3FS_PRN_WARN("Failed to get SSE type for file(%s).", SAFESTRPTR(tpath));
@ -3644,37 +3638,29 @@ int S3fsCurl::PreMultipartPostRequest(const char* tpath, headers_t& meta, string
requestHeaders = curl_slist_sort_insert(requestHeaders, iter->first.c_str(), value.c_str());
}else if(key == "x-amz-server-side-encryption" && value != "aws:kms"){
// Only copy mode.
if(is_copy && !AddSseRequestHead(SSE_S3, value, false, true)){
if(is_copy && !AddSseRequestHead(sse_type_t::SSE_S3, value, false, true)){
S3FS_PRN_WARN("Failed to insert SSE-S3 header.");
}
}else if(key == "x-amz-server-side-encryption-aws-kms-key-id"){
// Only copy mode.
if(is_copy && !value.empty() && !AddSseRequestHead(SSE_KMS, value, false, true)){
if(is_copy && !value.empty() && !AddSseRequestHead(sse_type_t::SSE_KMS, value, false, true)){
S3FS_PRN_WARN("Failed to insert SSE-KMS header.");
}
}else if(key == "x-amz-server-side-encryption-customer-key-md5"){
// Only copy mode.
if(is_copy){
if(!AddSseRequestHead(SSE_C, value, true, true) || !AddSseRequestHead(SSE_C, value, true, false)){
if(!AddSseRequestHead(sse_type_t::SSE_C, value, true, true) || !AddSseRequestHead(sse_type_t::SSE_C, value, true, false)){
S3FS_PRN_WARN("Failed to insert SSE-C header.");
}
}
}
}
// "x-amz-acl", storage class, sse
if(S3fsCurl::default_acl != PRIVATE){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-acl", acl_to_string(S3fsCurl::default_acl));
if(S3fsCurl::default_acl != acl_t::PRIVATE){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-acl", S3fsCurl::default_acl.str());
}
if(REDUCED_REDUNDANCY == GetStorageClass()){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", "REDUCED_REDUNDANCY");
} else if(STANDARD_IA == GetStorageClass()){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", "STANDARD_IA");
} else if(ONEZONE_IA == GetStorageClass()){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", "ONEZONE_IA");
} else if(INTELLIGENT_TIERING == GetStorageClass()) {
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", "INTELLIGENT_TIERING");
} else if(GLACIER == GetStorageClass()) {
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", "GLACIER");
if(GetStorageClass() != storage_class_t::STANDARD){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-storage-class", GetStorageClass().str());
}
// SSE
if(!is_copy){
@ -3917,7 +3903,7 @@ int S3fsCurl::UploadMultipartPostSetup(const char* tpath, int part_num, const st
responseHeaders.clear();
// SSE
if(SSE_C == S3fsCurl::GetSseType()){
if(sse_type_t::SSE_C == S3fsCurl::GetSseType()){
string ssevalue;
if(!AddSseRequestHead(S3fsCurl::GetSseType(), ssevalue, false, false)){
S3FS_PRN_WARN("Failed to set SSE header, but continue...");
@ -4026,7 +4012,7 @@ bool S3fsCurl::UploadMultipartPostComplete()
// SSE_KMS is ignored in the above, but in the following it states the same in the highlights:
// https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingKMSEncryption.html
//
if(S3fsCurl::is_content_md5 && SSE_C != S3fsCurl::GetSseType() && SSE_KMS != S3fsCurl::GetSseType()){
if(S3fsCurl::is_content_md5 && sse_type_t::SSE_C != S3fsCurl::GetSseType() && sse_type_t::SSE_KMS != S3fsCurl::GetSseType()){
if(!etag_equals(it->second, partdata.etag)){
return false;
}
@ -4873,54 +4859,6 @@ string prepare_url(const char* url)
return url_str;
}
const char *acl_to_string(acl_t acl)
{
switch(acl){
case PRIVATE:
return "private";
case PUBLIC_READ:
return "public-read";
case PUBLIC_READ_WRITE:
return "public-read-write";
case AWS_EXEC_READ:
return "aws-exec-read";
case AUTHENTICATED_READ:
return "authenticated-read";
case BUCKET_OWNER_READ:
return "bucket-owner-read";
case BUCKET_OWNER_FULL_CONTROL:
return "bucket-owner-full-control";
case LOG_DELIVERY_WRITE:
return "log-delivery-write";
case INVALID_ACL:
return NULL;
}
abort();
}
acl_t string_to_acl(const char *acl)
{
if(0 == strcmp(acl, "private")){
return PRIVATE;
}else if(0 == strcmp(acl, "public-read")){
return PUBLIC_READ;
}else if(0 == strcmp(acl, "public-read-write")){
return PUBLIC_READ_WRITE;
}else if(0 == strcmp(acl, "aws-exec-read")){
return AWS_EXEC_READ;
}else if(0 == strcmp(acl, "authenticated-read")){
return AUTHENTICATED_READ;
}else if(0 == strcmp(acl, "bucket-owner-read")){
return BUCKET_OWNER_READ;
}else if(0 == strcmp(acl, "bucket-owner-full-control")){
return BUCKET_OWNER_FULL_CONTROL;
}else if(0 == strcmp(acl, "log-delivery-write")){
return LOG_DELIVERY_WRITE;
}else{
return INVALID_ACL;
}
}
/*
* Local variables:
* tab-width: 2

View File

@ -24,6 +24,7 @@
#include <cassert>
#include "psemaphore.h"
#include "types.h"
//----------------------------------------------
// Avoid dependency on libcurl version
@ -197,36 +198,6 @@ typedef std::map<std::string, std::string> iamcredmap_t;
typedef std::map<std::string, std::string> sseckeymap_t;
typedef std::list<sseckeymap_t> sseckeylist_t;
// storage class(rrs)
enum storage_class_t {
STANDARD,
STANDARD_IA,
ONEZONE_IA,
REDUCED_REDUNDANCY,
INTELLIGENT_TIERING,
GLACIER
};
enum acl_t {
PRIVATE,
PUBLIC_READ,
PUBLIC_READ_WRITE,
AWS_EXEC_READ,
AUTHENTICATED_READ,
BUCKET_OWNER_READ,
BUCKET_OWNER_FULL_CONTROL,
LOG_DELIVERY_WRITE,
INVALID_ACL
};
// sse type
enum sse_type_t {
SSE_DISABLE = 0, // not use server side encrypting
SSE_S3, // server side encrypting by S3 key
SSE_C, // server side encrypting by custom key
SSE_KMS // server side encrypting by kms id
};
// Class for lapping curl
//
class S3fsCurl
@ -435,10 +406,10 @@ class S3fsCurl
static bool LoadEnvSse(void) { return (S3fsCurl::LoadEnvSseCKeys() && S3fsCurl::LoadEnvSseKmsid()); }
static sse_type_t SetSseType(sse_type_t type);
static sse_type_t GetSseType(void) { return S3fsCurl::ssetype; }
static bool IsSseDisable(void) { return (SSE_DISABLE == S3fsCurl::ssetype); }
static bool IsSseS3Type(void) { return (SSE_S3 == S3fsCurl::ssetype); }
static bool IsSseCType(void) { return (SSE_C == S3fsCurl::ssetype); }
static bool IsSseKmsType(void) { return (SSE_KMS == S3fsCurl::ssetype); }
static bool IsSseDisable(void) { return (sse_type_t::SSE_DISABLE == S3fsCurl::ssetype); }
static bool IsSseS3Type(void) { return (sse_type_t::SSE_S3 == S3fsCurl::ssetype); }
static bool IsSseCType(void) { return (sse_type_t::SSE_C == S3fsCurl::ssetype); }
static bool IsSseKmsType(void) { return (sse_type_t::SSE_KMS == S3fsCurl::ssetype); }
static bool FinalCheckSse(void);
static bool SetSseCKeys(const char* filepath);
static bool SetSseKmsid(const char* kmsid);
@ -594,8 +565,6 @@ std::string get_header_value(const struct curl_slist* list, const std::string &k
bool MakeUrlResource(const char* realpath, std::string& resourcepath, std::string& url);
std::string prepare_url(const char* url);
bool get_object_sse_type(const char* path, sse_type_t& ssetype, std::string& ssevalue); // implement in s3fs.cpp
const char *acl_to_string(acl_t acl);
acl_t string_to_acl(const char *acl);
#endif // S3FS_CURL_H_

View File

@ -720,17 +720,17 @@ bool get_object_sse_type(const char* path, sse_type_t& ssetype, string& ssevalue
return false;
}
ssetype = SSE_DISABLE;
ssetype = sse_type_t::SSE_DISABLE;
ssevalue.erase();
for(headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter){
string key = (*iter).first;
if(0 == strcasecmp(key.c_str(), "x-amz-server-side-encryption") && 0 == strcasecmp((*iter).second.c_str(), "AES256")){
ssetype = SSE_S3;
ssetype = sse_type_t::SSE_S3;
}else if(0 == strcasecmp(key.c_str(), "x-amz-server-side-encryption-aws-kms-key-id")){
ssetype = SSE_KMS;
ssetype = sse_type_t::SSE_KMS;
ssevalue = (*iter).second;
}else if(0 == strcasecmp(key.c_str(), "x-amz-server-side-encryption-customer-key-md5")){
ssetype = SSE_C;
ssetype = sse_type_t::SSE_C;
ssevalue = (*iter).second;
}
}
@ -4665,8 +4665,8 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
}
if(0 == STR2NCMP(arg, "default_acl=")){
const char* acl_string = strchr(arg, '=') + sizeof(char);
acl_t acl = string_to_acl(acl_string);
if(acl == INVALID_ACL){
acl_t acl = acl_t::from_str(acl_string);
if(acl == acl_t::UNKNOWN){
S3FS_PRN_EXIT("unknown value for default_acl: %s", acl_string);
return -1;
}
@ -4715,9 +4715,9 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
rrs = cvt_strtoofft(strchr(arg, '=') + sizeof(char));
}
if(0 == rrs){
S3fsCurl::SetStorageClass(STANDARD);
S3fsCurl::SetStorageClass(storage_class_t::STANDARD);
}else if(1 == rrs){
S3fsCurl::SetStorageClass(REDUCED_REDUNDANCY);
S3fsCurl::SetStorageClass(storage_class_t::REDUCED_REDUNDANCY);
}else{
S3FS_PRN_EXIT("poorly formed argument to option: use_rrs");
return -1;
@ -4725,23 +4725,13 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
return 0;
}
if(0 == STR2NCMP(arg, "storage_class=")){
const char *storage_class = strchr(arg, '=') + sizeof(char);
if(0 == strcmp(storage_class, "standard")){
S3fsCurl::SetStorageClass(STANDARD);
}else if(0 == strcmp(storage_class, "standard_ia")){
S3fsCurl::SetStorageClass(STANDARD_IA);
}else if(0 == strcmp(storage_class, "onezone_ia")){
S3fsCurl::SetStorageClass(ONEZONE_IA);
}else if(0 == strcmp(storage_class, "reduced_redundancy")){
S3fsCurl::SetStorageClass(REDUCED_REDUNDANCY);
}else if(0 == strcmp(storage_class, "intelligent_tiering")){
S3fsCurl::SetStorageClass(INTELLIGENT_TIERING);
}else if(0 == strcmp(storage_class, "glacier")){
S3fsCurl::SetStorageClass(GLACIER);
}else{
S3FS_PRN_EXIT("unknown value for storage_class: %s", storage_class);
const char *storage_class_str = strchr(arg, '=') + sizeof(char);
storage_class_t storage_class = storage_class_t::from_str(storage_class_str);
if(storage_class == storage_class_t::UNKNOWN){
S3FS_PRN_EXIT("unknown value for storage_class: %s", storage_class_str);
return -1;
}
S3fsCurl::SetStorageClass(storage_class);
return 0;
}
//
@ -4766,7 +4756,7 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
S3FS_PRN_EXIT("already set SSE another type, so conflict use_sse option or environment.");
return -1;
}
S3fsCurl::SetSseType(SSE_S3);
S3fsCurl::SetSseType(sse_type_t::SSE_S3);
}else if(0 == strcmp(arg, "use_sse=kmsid") || 0 == strcmp(arg, "use_sse=k")){
// sse type is SSE_KMS with out kmsid(expecting id is loaded by environment)
@ -4778,7 +4768,7 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
S3FS_PRN_EXIT("use_sse=kms but not loaded kms id by environment.");
return -1;
}
S3fsCurl::SetSseType(SSE_KMS);
S3fsCurl::SetSseType(sse_type_t::SSE_KMS);
}else if(0 == STR2NCMP(arg, "use_sse=kmsid:") || 0 == STR2NCMP(arg, "use_sse=k:")){
// sse type is SSE_KMS with kmsid
@ -4796,7 +4786,7 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
S3FS_PRN_EXIT("failed to load use_sse kms id.");
return -1;
}
S3fsCurl::SetSseType(SSE_KMS);
S3fsCurl::SetSseType(sse_type_t::SSE_KMS);
}else if(0 == strcmp(arg, "use_sse=custom") || 0 == strcmp(arg, "use_sse=c")){
// sse type is SSE_C with out custom keys(expecting keys are loaded by environment or load_sse_c option)
@ -4807,7 +4797,7 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
// [NOTE]
// do not check ckeys exists here.
//
S3fsCurl::SetSseType(SSE_C);
S3fsCurl::SetSseType(sse_type_t::SSE_C);
}else if(0 == STR2NCMP(arg, "use_sse=custom:") || 0 == STR2NCMP(arg, "use_sse=c:")){
// sse type is SSE_C with custom keys
@ -4825,7 +4815,7 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
S3FS_PRN_EXIT("failed to load use_sse custom key file(%s).", ssecfile);
return -1;
}
S3fsCurl::SetSseType(SSE_C);
S3fsCurl::SetSseType(sse_type_t::SSE_C);
}else if(0 == strcmp(arg, "use_sse=")){ // this type is old style(parameter is custom key file path)
// SSE_C with custom keys.
@ -4834,7 +4824,7 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
S3FS_PRN_EXIT("failed to load use_sse custom key file(%s).", ssecfile);
return -1;
}
S3fsCurl::SetSseType(SSE_C);
S3fsCurl::SetSseType(sse_type_t::SSE_C);
}else{
// never come here.
@ -5395,7 +5385,7 @@ int main(int argc, char* argv[])
// [NOTE]
// exclusive option check here.
//
if(REDUCED_REDUNDANCY == S3fsCurl::GetStorageClass() && !S3fsCurl::IsSseDisable()){
if(storage_class_t::REDUCED_REDUNDANCY == S3fsCurl::GetStorageClass() && !S3fsCurl::IsSseDisable()){
S3FS_PRN_EXIT("use_sse option could not be specified with storage class reduced_redundancy.");
S3fsCurl::DestroyS3fsCurl();
s3fs_destroy_global_ssl();
@ -5497,7 +5487,7 @@ int main(int argc, char* argv[])
// check that default ACL is either public-read or private
acl_t defaultACL = S3fsCurl::GetDefaultAcl();
if(defaultACL != PRIVATE && defaultACL != PUBLIC_READ){
if(defaultACL != acl_t::PRIVATE && defaultACL != acl_t::PUBLIC_READ){
S3FS_PRN_EXIT("can only use 'public-read' or 'private' ACL while using ibm_iam_auth");
S3fsCurl::DestroyS3fsCurl();
s3fs_destroy_global_ssl();

182
src/types.h Normal file
View File

@ -0,0 +1,182 @@
/*
* s3fs - FUSE-based file system backed by Amazon S3
*
* Copyright(C) 2007 Randy Rizun <rrizun@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef S3FS_TYPES_H_
#define S3FS_TYPES_H_
class storage_class_t{
public:
enum Value{
STANDARD,
STANDARD_IA,
ONEZONE_IA,
REDUCED_REDUNDANCY,
INTELLIGENT_TIERING,
GLACIER,
UNKNOWN
};
// cppcheck-suppress noExplicitConstructor
storage_class_t(Value value) : value_(value) {}
operator Value() const { return value_; }
const char* str() const {
switch(value_){
case STANDARD:
return "STANDARD";
case STANDARD_IA:
return "STANDARD_IA";
case ONEZONE_IA:
return "ONEZONE_IA";
case REDUCED_REDUNDANCY:
return "REDUCED_REDUNDANCY";
case INTELLIGENT_TIERING:
return "INTELLIGENT_TIERING";
case GLACIER:
return "GLACIER";
case UNKNOWN:
return NULL;
}
abort();
}
static storage_class_t from_str(const char* str) {
if(0 == strcmp(str, "standard")){
return STANDARD;
}else if(0 == strcmp(str, "standard_ia")){
return STANDARD_IA;
}else if(0 == strcmp(str, "onezone_ia")){
return ONEZONE_IA;
}else if(0 == strcmp(str, "reduced_redundancy")){
return REDUCED_REDUNDANCY;
}else if(0 == strcmp(str, "intelligent_tiering")){
return INTELLIGENT_TIERING;
}else if(0 == strcmp(str, "glacier")){
return GLACIER;
}else{
return UNKNOWN;
}
}
private:
explicit operator bool();
Value value_;
};
class acl_t{
public:
enum Value{
PRIVATE,
PUBLIC_READ,
PUBLIC_READ_WRITE,
AWS_EXEC_READ,
AUTHENTICATED_READ,
BUCKET_OWNER_READ,
BUCKET_OWNER_FULL_CONTROL,
LOG_DELIVERY_WRITE,
UNKNOWN
};
// cppcheck-suppress noExplicitConstructor
acl_t(Value value) : value_(value) {}
operator Value() const { return value_; }
const char* str() const {
switch(value_){
case PRIVATE:
return "private";
case PUBLIC_READ:
return "public-read";
case PUBLIC_READ_WRITE:
return "public-read-write";
case AWS_EXEC_READ:
return "aws-exec-read";
case AUTHENTICATED_READ:
return "authenticated-read";
case BUCKET_OWNER_READ:
return "bucket-owner-read";
case BUCKET_OWNER_FULL_CONTROL:
return "bucket-owner-full-control";
case LOG_DELIVERY_WRITE:
return "log-delivery-write";
case UNKNOWN:
return NULL;
}
abort();
}
static acl_t from_str(const char *acl) {
if(0 == strcmp(acl, "private")){
return PRIVATE;
}else if(0 == strcmp(acl, "public-read")){
return PUBLIC_READ;
}else if(0 == strcmp(acl, "public-read-write")){
return PUBLIC_READ_WRITE;
}else if(0 == strcmp(acl, "aws-exec-read")){
return AWS_EXEC_READ;
}else if(0 == strcmp(acl, "authenticated-read")){
return AUTHENTICATED_READ;
}else if(0 == strcmp(acl, "bucket-owner-read")){
return BUCKET_OWNER_READ;
}else if(0 == strcmp(acl, "bucket-owner-full-control")){
return BUCKET_OWNER_FULL_CONTROL;
}else if(0 == strcmp(acl, "log-delivery-write")){
return LOG_DELIVERY_WRITE;
}else{
return UNKNOWN;
}
}
private:
explicit operator bool();
Value value_;
};
class sse_type_t{
public:
enum Value{
SSE_DISABLE = 0, // not use server side encrypting
SSE_S3, // server side encrypting by S3 key
SSE_C, // server side encrypting by custom key
SSE_KMS // server side encrypting by kms id
};
// cppcheck-suppress noExplicitConstructor
sse_type_t(Value value) : value_(value) {}
operator Value() const { return value_; }
private:
explicit operator bool();
Value value_;
};
#endif // S3FS_TYPES_H_
/*
* Local variables:
* tab-width: 2
* c-basic-offset: 2
* End:
* vim600: expandtab sw=2 ts=2 fdm=marker
* vim<600: expandtab sw=2 ts=2
*/