mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2025-02-03 11:08:26 +00:00
Merge pull request #727 from ggtakec/master
Fixed Travis CI error about cppcheck - #713
This commit is contained in:
commit
824124fedc
@ -32,11 +32,12 @@ cppcheck:
|
||||
cppcheck --quiet --error-exitcode=1 \
|
||||
--inline-suppr \
|
||||
--std=c++03 \
|
||||
-D HAVE_ATTR_XATTR_H \
|
||||
-D HAVE_SYS_EXTATTR_H \
|
||||
-D HAVE_MALLOC_TRIM \
|
||||
-U CURLE_PEER_FAILED_VERIFICATION \
|
||||
-U P_tmpdir \
|
||||
-U ENOATTR \
|
||||
--enable=all \
|
||||
--enable=warning,style,information,missingInclude \
|
||||
--suppress=missingIncludeSystem \
|
||||
--suppress=unusedFunction \
|
||||
--suppress=variableScope \
|
||||
src/ test/
|
||||
|
@ -130,8 +130,8 @@ bool AdditionalHeader::Load(const char* file)
|
||||
// compile
|
||||
regex_t* preg = new regex_t;
|
||||
int result;
|
||||
char errbuf[256];
|
||||
if(0 != (result = regcomp(preg, key.c_str(), REG_EXTENDED | REG_NOSUB))){ // we do not need matching info
|
||||
char errbuf[256];
|
||||
regerror(result, preg, errbuf, sizeof(errbuf));
|
||||
S3FS_PRN_ERR("failed to compile regex from %s key by %s.", key.c_str(), errbuf);
|
||||
delete preg;
|
||||
|
28
src/curl.cpp
28
src/curl.cpp
@ -226,8 +226,8 @@ bool BodyData::Append(void* ptr, size_t bytes)
|
||||
|
||||
const char* BodyData::str(void) const
|
||||
{
|
||||
static const char* strnull = "";
|
||||
if(!text){
|
||||
static const char* strnull = "";
|
||||
return strnull;
|
||||
}
|
||||
return text;
|
||||
@ -697,10 +697,8 @@ bool S3fsCurl::LocateBundle(void)
|
||||
// See if environment variable CURL_CA_BUNDLE is set
|
||||
// if so, check it, if it is a good path, then set the
|
||||
// curl_ca_bundle variable to it
|
||||
char *CURL_CA_BUNDLE;
|
||||
|
||||
if(0 == S3fsCurl::curl_ca_bundle.size()){
|
||||
CURL_CA_BUNDLE = getenv("CURL_CA_BUNDLE");
|
||||
char* CURL_CA_BUNDLE = getenv("CURL_CA_BUNDLE");
|
||||
if(CURL_CA_BUNDLE != NULL) {
|
||||
// check for existence and readability of the file
|
||||
ifstream BF(CURL_CA_BUNDLE);
|
||||
@ -1620,8 +1618,7 @@ int S3fsCurl::CurlDebugFunc(CURL* hcurl, curl_infotype type, char* data, size_t
|
||||
break;
|
||||
case CURLINFO_HEADER_IN:
|
||||
case CURLINFO_HEADER_OUT:
|
||||
size_t length, remaining;
|
||||
int newline;
|
||||
size_t remaining;
|
||||
char* p;
|
||||
|
||||
// Print each line individually for tidy output
|
||||
@ -1629,7 +1626,7 @@ int S3fsCurl::CurlDebugFunc(CURL* hcurl, curl_infotype type, char* data, size_t
|
||||
p = data;
|
||||
do {
|
||||
char* eol = (char*)memchr(p, '\n', remaining);
|
||||
newline = 0;
|
||||
int newline = 0;
|
||||
if (eol == NULL) {
|
||||
eol = (char*)memchr(p, '\r', remaining);
|
||||
} else if (eol > p && *(eol - 1) == '\r') {
|
||||
@ -1639,7 +1636,7 @@ int S3fsCurl::CurlDebugFunc(CURL* hcurl, curl_infotype type, char* data, size_t
|
||||
newline++;
|
||||
eol++;
|
||||
}
|
||||
length = eol - p;
|
||||
size_t length = eol - p;
|
||||
S3FS_PRN_CURL("%c %.*s", CURLINFO_HEADER_IN == type ? '<' : '>', (int)length - newline, p);
|
||||
remaining -= length;
|
||||
p = eol;
|
||||
@ -2867,7 +2864,6 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd)
|
||||
{
|
||||
struct stat st;
|
||||
FILE* file = NULL;
|
||||
int fd2;
|
||||
|
||||
S3FS_PRN_INFO3("[tpath=%s]", SAFESTRPTR(tpath));
|
||||
|
||||
@ -2876,6 +2872,7 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd)
|
||||
}
|
||||
if(-1 != fd){
|
||||
// duplicate fd
|
||||
int fd2;
|
||||
if(-1 == (fd2 = dup(fd)) || -1 == fstat(fd2, &st) || 0 != lseek(fd2, 0, SEEK_SET) || NULL == (file = fdopen(fd2, "rb"))){
|
||||
S3FS_PRN_ERR("Could not duplicate file descriptor(errno=%d)", errno);
|
||||
if(-1 != fd2){
|
||||
@ -2980,7 +2977,7 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd)
|
||||
|
||||
int S3fsCurl::PreGetObjectRequest(const char* tpath, int fd, off_t start, ssize_t size, sse_type_t ssetype, string& ssevalue)
|
||||
{
|
||||
S3FS_PRN_INFO3("[tpath=%s][start=%jd][size=%zd]", SAFESTRPTR(tpath), (intmax_t)start, size);
|
||||
S3FS_PRN_INFO3("[tpath=%s][start=%jd][size=%jd]", SAFESTRPTR(tpath), (intmax_t)start, (intmax_t)size);
|
||||
|
||||
if(!tpath || -1 == fd || 0 > start || 0 > size){
|
||||
return -1;
|
||||
@ -3040,7 +3037,7 @@ int S3fsCurl::GetObjectRequest(const char* tpath, int fd, off_t start, ssize_t s
|
||||
{
|
||||
int result;
|
||||
|
||||
S3FS_PRN_INFO3("[tpath=%s][start=%jd][size=%zd]", SAFESTRPTR(tpath), (intmax_t)start, size);
|
||||
S3FS_PRN_INFO3("[tpath=%s][start=%jd][size=%jd]", SAFESTRPTR(tpath), (intmax_t)start, (intmax_t)size);
|
||||
|
||||
if(!tpath){
|
||||
return -1;
|
||||
@ -3418,7 +3415,7 @@ int S3fsCurl::AbortMultipartUpload(const char* tpath, string& upload_id)
|
||||
|
||||
int S3fsCurl::UploadMultipartPostSetup(const char* tpath, int part_num, const string& upload_id)
|
||||
{
|
||||
S3FS_PRN_INFO3("[tpath=%s][start=%jd][size=%zd][part=%d]", SAFESTRPTR(tpath), (intmax_t)(partdata.startpos), partdata.size, part_num);
|
||||
S3FS_PRN_INFO3("[tpath=%s][start=%jd][size=%jd][part=%d]", SAFESTRPTR(tpath), (intmax_t)(partdata.startpos), (intmax_t)(partdata.size), part_num);
|
||||
|
||||
if(-1 == partdata.fd || -1 == partdata.startpos || -1 == partdata.size){
|
||||
return -1;
|
||||
@ -3492,7 +3489,7 @@ int S3fsCurl::UploadMultipartPostRequest(const char* tpath, int part_num, const
|
||||
{
|
||||
int result;
|
||||
|
||||
S3FS_PRN_INFO3("[tpath=%s][start=%jd][size=%zd][part=%d]", SAFESTRPTR(tpath), (intmax_t)(partdata.startpos), partdata.size, part_num);
|
||||
S3FS_PRN_INFO3("[tpath=%s][start=%jd][size=%jd][part=%d]", SAFESTRPTR(tpath), (intmax_t)(partdata.startpos), (intmax_t)(partdata.size), part_num);
|
||||
|
||||
// setup
|
||||
if(0 != (result = S3fsCurl::UploadMultipartPostSetup(tpath, part_num, upload_id))){
|
||||
@ -3994,8 +3991,6 @@ int S3fsMultiCurl::MultiRead(void)
|
||||
|
||||
int S3fsMultiCurl::Request(void)
|
||||
{
|
||||
int result;
|
||||
|
||||
S3FS_PRN_INFO3("[count=%zu]", cMap_all.size());
|
||||
|
||||
// Make request list.
|
||||
@ -4005,6 +4000,7 @@ int S3fsMultiCurl::Request(void)
|
||||
//
|
||||
while(!cMap_all.empty()){
|
||||
// set curl handle to multi handle
|
||||
int result;
|
||||
int cnt;
|
||||
s3fscurlmap_t::iterator iter;
|
||||
for(cnt = 0, iter = cMap_all.begin(); cnt < S3fsMultiCurl::max_multireq && iter != cMap_all.end(); cMap_all.erase(iter++), cnt++){
|
||||
@ -4071,7 +4067,7 @@ struct curl_slist* curl_slist_sort_insert(struct curl_slist* list, const char* k
|
||||
if(!key){
|
||||
return list;
|
||||
}
|
||||
if(NULL == (new_item = (struct curl_slist*)malloc(sizeof(struct curl_slist)))){
|
||||
if(NULL == (new_item = reinterpret_cast<struct curl_slist*>(malloc(sizeof(struct curl_slist))))){
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@ -1571,7 +1571,6 @@ ssize_t FdEntity::Read(char* bytes, off_t start, size_t size, bool force_load)
|
||||
pagelist.SetPageLoadedStatus(start, size, false);
|
||||
}
|
||||
|
||||
int result;
|
||||
ssize_t rsize;
|
||||
|
||||
// check disk space
|
||||
@ -1605,6 +1604,7 @@ ssize_t FdEntity::Read(char* bytes, off_t start, size_t size, bool force_load)
|
||||
}
|
||||
}
|
||||
// Loading
|
||||
int result;
|
||||
if(0 < size && 0 != (result = Load(start, load_size))){
|
||||
S3FS_PRN_ERR("could not download. start(%jd), size(%zu), errno(%d)", (intmax_t)start, size, result);
|
||||
return -EIO;
|
||||
|
@ -107,7 +107,7 @@ bool s3fs_HMAC(const void* key, size_t keylen, const unsigned char* data, size_t
|
||||
return false;
|
||||
}
|
||||
|
||||
if(NULL == (*digest = (unsigned char*)malloc(SHA1_DIGEST_SIZE))){
|
||||
if(NULL == (*digest = reinterpret_cast<unsigned char*>(malloc(SHA1_DIGEST_SIZE)))){
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ bool s3fs_HMAC256(const void* key, size_t keylen, const unsigned char* data, siz
|
||||
return false;
|
||||
}
|
||||
|
||||
if(NULL == (*digest = (unsigned char*)malloc(SHA256_DIGEST_SIZE))){
|
||||
if(NULL == (*digest = reinterpret_cast<unsigned char*>(malloc(SHA256_DIGEST_SIZE)))){
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ bool s3fs_HMAC(const void* key, size_t keylen, const unsigned char* data, size_t
|
||||
if(0 == (*digestlen = gnutls_hmac_get_len(GNUTLS_MAC_SHA1))){
|
||||
return false;
|
||||
}
|
||||
if(NULL == (*digest = (unsigned char*)malloc(*digestlen + 1))){
|
||||
if(NULL == (*digest = reinterpret_cast<unsigned char*>(malloc(*digestlen + 1)))){
|
||||
return false;
|
||||
}
|
||||
if(0 > gnutls_hmac_fast(GNUTLS_MAC_SHA1, key, keylen, data, datalen, *digest)){
|
||||
@ -170,7 +170,7 @@ bool s3fs_HMAC256(const void* key, size_t keylen, const unsigned char* data, siz
|
||||
if(0 == (*digestlen = gnutls_hmac_get_len(GNUTLS_MAC_SHA256))){
|
||||
return false;
|
||||
}
|
||||
if(NULL == (*digest = (unsigned char*)malloc(*digestlen + 1))){
|
||||
if(NULL == (*digest = reinterpret_cast<unsigned char*>(malloc(*digestlen + 1)))){
|
||||
return false;
|
||||
}
|
||||
if(0 > gnutls_hmac_fast(GNUTLS_MAC_SHA256, key, keylen, data, datalen, *digest)){
|
||||
@ -221,7 +221,7 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size)
|
||||
md5_update(&ctx_md5, bytes, buf);
|
||||
memset(buf, 0, 512);
|
||||
}
|
||||
if(NULL == (result = (unsigned char*)malloc(get_md5_digest_length()))){
|
||||
if(NULL == (result = reinterpret_cast<unsigned char*>(malloc(get_md5_digest_length())))){
|
||||
return NULL;
|
||||
}
|
||||
md5_digest(&ctx_md5, get_md5_digest_length(), result);
|
||||
@ -277,7 +277,7 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size)
|
||||
gcry_md_write(ctx_md5, buf, bytes);
|
||||
memset(buf, 0, 512);
|
||||
}
|
||||
if(NULL == (result = (unsigned char*)malloc(get_md5_digest_length()))){
|
||||
if(NULL == (result = reinterpret_cast<unsigned char*>(malloc(get_md5_digest_length())))){
|
||||
return NULL;
|
||||
}
|
||||
memcpy(result, gcry_md_read(ctx_md5, 0), get_md5_digest_length());
|
||||
@ -346,7 +346,7 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size)
|
||||
sha256_update(&ctx_sha256, bytes, buf);
|
||||
memset(buf, 0, 512);
|
||||
}
|
||||
if(NULL == (result = (unsigned char*)malloc(get_sha256_digest_length()))){
|
||||
if(NULL == (result = reinterpret_cast<unsigned char*>(malloc(get_sha256_digest_length())))){
|
||||
return NULL;
|
||||
}
|
||||
sha256_digest(&ctx_sha256, get_sha256_digest_length(), result);
|
||||
@ -423,7 +423,7 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size)
|
||||
gcry_md_write(ctx_sha256, buf, bytes);
|
||||
memset(buf, 0, 512);
|
||||
}
|
||||
if(NULL == (result = (unsigned char*)malloc(get_sha256_digest_length()))){
|
||||
if(NULL == (result = reinterpret_cast<unsigned char*>(malloc(get_sha256_digest_length())))){
|
||||
return NULL;
|
||||
}
|
||||
memcpy(result, gcry_md_read(ctx_sha256, 0), get_sha256_digest_length());
|
||||
|
@ -124,7 +124,7 @@ static bool s3fs_HMAC_RAW(const void* key, size_t keylen, const unsigned char* d
|
||||
PK11_FreeSymKey(pKey);
|
||||
PK11_FreeSlot(Slot);
|
||||
|
||||
if(NULL == (*digest = (unsigned char*)malloc(*digestlen))){
|
||||
if(NULL == (*digest = reinterpret_cast<unsigned char*>(malloc(*digestlen)))){
|
||||
return false;
|
||||
}
|
||||
memcpy(*digest, tmpdigest, *digestlen);
|
||||
@ -188,7 +188,7 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size)
|
||||
PK11_DigestOp(md5ctx, buf, bytes);
|
||||
memset(buf, 0, 512);
|
||||
}
|
||||
if(NULL == (result = (unsigned char*)malloc(get_md5_digest_length()))){
|
||||
if(NULL == (result = reinterpret_cast<unsigned char*>(malloc(get_md5_digest_length())))){
|
||||
PK11_DestroyContext(md5ctx, PR_TRUE);
|
||||
return NULL;
|
||||
}
|
||||
@ -269,7 +269,7 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size)
|
||||
PK11_DigestOp(sha256ctx, buf, bytes);
|
||||
memset(buf, 0, 512);
|
||||
}
|
||||
if(NULL == (result = (unsigned char*)malloc(get_sha256_digest_length()))){
|
||||
if(NULL == (result = reinterpret_cast<unsigned char*>(malloc(get_sha256_digest_length())))){
|
||||
PK11_DestroyContext(sha256ctx, PR_TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
233
src/s3fs.cpp
233
src/s3fs.cpp
@ -136,8 +136,8 @@ static bool is_specified_endpoint = false;
|
||||
static int s3fs_init_deferred_exit_status = 0;
|
||||
static bool support_compat_dir = true;// default supports compatibility directory type
|
||||
|
||||
static const std::string allbucket_fields_type = ""; // special key for mapping(This name is absolutely not used as a bucket name)
|
||||
static const std::string keyval_fields_type = "\t"; // special key for mapping(This name is absolutely not used as a bucket name)
|
||||
static const std::string allbucket_fields_type = ""; // special key for mapping(This name is absolutely not used as a bucket name)
|
||||
static const std::string keyval_fields_type = "\t"; // special key for mapping(This name is absolutely not used as a bucket name)
|
||||
static const std::string aws_accesskeyid = "AWSAccessKeyId";
|
||||
static const std::string aws_secretkey = "AWSSecretKey";
|
||||
|
||||
@ -892,7 +892,7 @@ static int s3fs_readlink(const char* path, char* buf, size_t size)
|
||||
// Read
|
||||
ssize_t ressize;
|
||||
if(0 > (ressize = ent->Read(buf, 0, readsize))){
|
||||
S3FS_PRN_ERR("could not read file(file=%s, errno=%zd)", path, ressize);
|
||||
S3FS_PRN_ERR("could not read file(file=%s, ressize=%jd)", path, (intmax_t)ressize);
|
||||
FdManager::get()->Close(ent);
|
||||
return static_cast<int>(ressize);
|
||||
}
|
||||
@ -2138,7 +2138,7 @@ static int s3fs_read(const char* path, char* buf, size_t size, off_t offset, str
|
||||
}
|
||||
|
||||
if(0 > (res = ent->Read(buf, offset, size, false))){
|
||||
S3FS_PRN_WARN("failed to read file(%s). result=%zd", path, res);
|
||||
S3FS_PRN_WARN("failed to read file(%s). result=%jd", path, (intmax_t)res);
|
||||
}
|
||||
FdManager::get()->Close(ent);
|
||||
|
||||
@ -2160,7 +2160,7 @@ static int s3fs_write(const char* path, const char* buf, size_t size, off_t offs
|
||||
S3FS_PRN_WARN("different fd(%d - %llu)", ent->GetFd(), (unsigned long long)(fi->fh));
|
||||
}
|
||||
if(0 > (res = ent->Write(buf, offset, size))){
|
||||
S3FS_PRN_WARN("failed to write file(%s). result=%zd", path, res);
|
||||
S3FS_PRN_WARN("failed to write file(%s). result=%jd", path, (intmax_t)res);
|
||||
}
|
||||
FdManager::get()->Close(ent);
|
||||
|
||||
@ -2463,7 +2463,6 @@ static int s3fs_readdir(const char* path, void* buf, fuse_fill_dir_t filler, off
|
||||
|
||||
static int list_bucket(const char* path, S3ObjList& head, const char* delimiter, bool check_content_only)
|
||||
{
|
||||
int result;
|
||||
string s3_realpath;
|
||||
string query_delimiter;;
|
||||
string query_prefix;;
|
||||
@ -2472,7 +2471,6 @@ static int list_bucket(const char* path, S3ObjList& head, const char* delimiter,
|
||||
bool truncated = true;
|
||||
S3fsCurl s3fscurl;
|
||||
xmlDocPtr doc;
|
||||
BodyData* body;
|
||||
|
||||
S3FS_PRN_INFO1("[path=%s]", path);
|
||||
|
||||
@ -2508,11 +2506,12 @@ static int list_bucket(const char* path, S3ObjList& head, const char* delimiter,
|
||||
each_query += query_prefix;
|
||||
|
||||
// request
|
||||
int result;
|
||||
if(0 != (result = s3fscurl.ListBucketRequest(path, each_query.c_str()))){
|
||||
S3FS_PRN_ERR("ListBucketRequest returns with error.");
|
||||
return result;
|
||||
}
|
||||
body = s3fscurl.GetBodyData();
|
||||
BodyData* body = s3fscurl.GetBodyData();
|
||||
|
||||
// xmlDocPtr
|
||||
if(NULL == (doc = xmlReadMemory(body->str(), static_cast<int>(body->size()), "", NULL, 0))){
|
||||
@ -3828,46 +3827,45 @@ static int s3fs_check_service(void)
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
//
|
||||
// Read and Parse passwd file
|
||||
//
|
||||
// The line of the password file is one of the following formats:
|
||||
// (1) "accesskey:secretkey" : AWS format for default(all) access key/secret key
|
||||
// (2) "bucket:accesskey:secretkey" : AWS format for bucket's access key/secret key
|
||||
// (3) "key=value" : Content-dependent KeyValue contents
|
||||
//
|
||||
// This function sets result into bucketkvmap_t, it bucket name and key&value mapping.
|
||||
// If bucket name is empty(1 or 3 format), bucket name for mapping is set "\t" or "".
|
||||
//
|
||||
//
|
||||
// Read and Parse passwd file
|
||||
//
|
||||
// The line of the password file is one of the following formats:
|
||||
// (1) "accesskey:secretkey" : AWS format for default(all) access key/secret key
|
||||
// (2) "bucket:accesskey:secretkey" : AWS format for bucket's access key/secret key
|
||||
// (3) "key=value" : Content-dependent KeyValue contents
|
||||
//
|
||||
// This function sets result into bucketkvmap_t, it bucket name and key&value mapping.
|
||||
// If bucket name is empty(1 or 3 format), bucket name for mapping is set "\t" or "".
|
||||
//
|
||||
// Return: 1 - OK(could parse and set mapping etc.)
|
||||
// 0 - NG(could not read any value)
|
||||
// -1 - Should shutdown immediately
|
||||
//
|
||||
//
|
||||
static int parse_passwd_file(bucketkvmap_t& resmap)
|
||||
{
|
||||
string line;
|
||||
size_t first_pos;
|
||||
size_t last_pos;
|
||||
size_t first_pos;
|
||||
readline_t linelist;
|
||||
readline_t::iterator iter;
|
||||
|
||||
// open passwd file
|
||||
|
||||
// open passwd file
|
||||
ifstream PF(passwd_file.c_str());
|
||||
if(!PF.good()){
|
||||
if(!PF.good()){
|
||||
S3FS_PRN_EXIT("could not open passwd file : %s", passwd_file.c_str());
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// read each line
|
||||
|
||||
// read each line
|
||||
while(getline(PF, line)){
|
||||
line = trim(line);
|
||||
line = trim(line);
|
||||
if(0 == line.size()){
|
||||
continue;
|
||||
}
|
||||
if('#' == line[0]){
|
||||
continue;
|
||||
}
|
||||
if(string::npos != line.find_first_of(" \t")){
|
||||
if(string::npos != line.find_first_of(" \t")){
|
||||
S3FS_PRN_EXIT("invalid line in passwd file, found whitespace character.");
|
||||
return -1;
|
||||
}
|
||||
@ -3875,89 +3873,89 @@ static int parse_passwd_file(bucketkvmap_t& resmap)
|
||||
S3FS_PRN_EXIT("invalid line in passwd file, found a bracket \"[\" character.");
|
||||
return -1;
|
||||
}
|
||||
linelist.push_back(line);
|
||||
}
|
||||
|
||||
// read '=' type
|
||||
linelist.push_back(line);
|
||||
}
|
||||
|
||||
// read '=' type
|
||||
kvmap_t kv;
|
||||
for(iter = linelist.begin(); iter != linelist.end(); ++iter){
|
||||
first_pos = iter->find_first_of("=");
|
||||
if(first_pos == string::npos){
|
||||
continue;
|
||||
}
|
||||
// formatted by "key=val"
|
||||
if(first_pos == string::npos){
|
||||
continue;
|
||||
}
|
||||
// formatted by "key=val"
|
||||
string key = trim(iter->substr(0, first_pos));
|
||||
string val = trim(iter->substr(first_pos + 1, string::npos));
|
||||
if(key.empty()){
|
||||
continue;
|
||||
}
|
||||
if(kv.end() != kv.find(key)){
|
||||
if(key.empty()){
|
||||
continue;
|
||||
}
|
||||
if(kv.end() != kv.find(key)){
|
||||
S3FS_PRN_WARN("same key name(%s) found in passwd file, skip this.", key.c_str());
|
||||
continue;
|
||||
}
|
||||
kv[key] = val;
|
||||
}
|
||||
// set special key name
|
||||
resmap[string(keyval_fields_type)] = kv;
|
||||
|
||||
// read ':' type
|
||||
continue;
|
||||
}
|
||||
kv[key] = val;
|
||||
}
|
||||
// set special key name
|
||||
resmap[string(keyval_fields_type)] = kv;
|
||||
|
||||
// read ':' type
|
||||
for(iter = linelist.begin(); iter != linelist.end(); ++iter){
|
||||
first_pos = iter->find_first_of(":");
|
||||
last_pos = iter->find_last_of(":");
|
||||
if(first_pos == string::npos){
|
||||
continue;
|
||||
}
|
||||
string bucket;
|
||||
string accesskey;
|
||||
string secret;
|
||||
if(first_pos != last_pos){
|
||||
// formatted by "bucket:accesskey:secretkey"
|
||||
bucket = trim(iter->substr(0, first_pos));
|
||||
accesskey = trim(iter->substr(first_pos + 1, last_pos - first_pos - 1));
|
||||
secret = trim(iter->substr(last_pos + 1, string::npos));
|
||||
}else{
|
||||
// formatted by "accesskey:secretkey"
|
||||
bucket = allbucket_fields_type;
|
||||
accesskey = trim(iter->substr(0, first_pos));
|
||||
secret = trim(iter->substr(first_pos + 1, string::npos));
|
||||
}
|
||||
if(resmap.end() != resmap.find(bucket)){
|
||||
first_pos = iter->find_first_of(":");
|
||||
size_t last_pos = iter->find_last_of(":");
|
||||
if(first_pos == string::npos){
|
||||
continue;
|
||||
}
|
||||
string bucket;
|
||||
string accesskey;
|
||||
string secret;
|
||||
if(first_pos != last_pos){
|
||||
// formatted by "bucket:accesskey:secretkey"
|
||||
bucket = trim(iter->substr(0, first_pos));
|
||||
accesskey = trim(iter->substr(first_pos + 1, last_pos - first_pos - 1));
|
||||
secret = trim(iter->substr(last_pos + 1, string::npos));
|
||||
}else{
|
||||
// formatted by "accesskey:secretkey"
|
||||
bucket = allbucket_fields_type;
|
||||
accesskey = trim(iter->substr(0, first_pos));
|
||||
secret = trim(iter->substr(first_pos + 1, string::npos));
|
||||
}
|
||||
if(resmap.end() != resmap.find(bucket)){
|
||||
S3FS_PRN_EXIT("same bucket(%s) passwd setting found in passwd file.", ("" == bucket ? "default" : bucket.c_str()));
|
||||
return -1;
|
||||
}
|
||||
kv.clear();
|
||||
kv[string(aws_accesskeyid)] = accesskey;
|
||||
kv[string(aws_secretkey)] = secret;
|
||||
resmap[bucket] = kv;
|
||||
}
|
||||
return (resmap.empty() ? 0 : 1);
|
||||
}
|
||||
|
||||
//
|
||||
return -1;
|
||||
}
|
||||
kv.clear();
|
||||
kv[string(aws_accesskeyid)] = accesskey;
|
||||
kv[string(aws_secretkey)] = secret;
|
||||
resmap[bucket] = kv;
|
||||
}
|
||||
return (resmap.empty() ? 0 : 1);
|
||||
}
|
||||
|
||||
//
|
||||
// Return: 1 - OK(could read and set accesskey etc.)
|
||||
// 0 - NG(could not read)
|
||||
// -1 - Should shutdown immediately
|
||||
//
|
||||
//
|
||||
static int check_for_aws_format(const kvmap_t& kvmap)
|
||||
{
|
||||
string str1(aws_accesskeyid);
|
||||
string str2(aws_secretkey);
|
||||
|
||||
if(kvmap.empty()){
|
||||
return 0;
|
||||
}
|
||||
if(kvmap.end() == kvmap.find(str1) && kvmap.end() == kvmap.find(str2)){
|
||||
return 0;
|
||||
}
|
||||
if(kvmap.end() == kvmap.find(str1) || kvmap.end() == kvmap.find(str2)){
|
||||
if(kvmap.empty()){
|
||||
return 0;
|
||||
}
|
||||
if(kvmap.end() == kvmap.find(str1) && kvmap.end() == kvmap.find(str2)){
|
||||
return 0;
|
||||
}
|
||||
if(kvmap.end() == kvmap.find(str1) || kvmap.end() == kvmap.find(str2)){
|
||||
S3FS_PRN_EXIT("AWSAccesskey or AWSSecretkey is not specified.");
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if(!S3fsCurl::SetAccessKey(kvmap.at(str1).c_str(), kvmap.at(str2).c_str())){
|
||||
S3FS_PRN_EXIT("failed to set access key/secret key.");
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//
|
||||
@ -4030,10 +4028,10 @@ static int check_passwd_file_perms(void)
|
||||
//
|
||||
static int read_passwd_file(void)
|
||||
{
|
||||
bucketkvmap_t bucketmap;
|
||||
kvmap_t keyval;
|
||||
bucketkvmap_t bucketmap;
|
||||
kvmap_t keyval;
|
||||
int result;
|
||||
|
||||
|
||||
// if you got here, the password file
|
||||
// exists and is readable by the
|
||||
// current user, check for permissions
|
||||
@ -4041,41 +4039,41 @@ static int read_passwd_file(void)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
//
|
||||
// parse passwd file
|
||||
//
|
||||
//
|
||||
// parse passwd file
|
||||
//
|
||||
result = parse_passwd_file(bucketmap);
|
||||
if(-1 == result){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
//
|
||||
// check key=value type format.
|
||||
//
|
||||
|
||||
//
|
||||
// check key=value type format.
|
||||
//
|
||||
if(bucketmap.end() != bucketmap.find(keyval_fields_type)){
|
||||
// aws format
|
||||
// aws format
|
||||
result = check_for_aws_format(bucketmap[keyval_fields_type]);
|
||||
if(-1 == result){
|
||||
return EXIT_FAILURE;
|
||||
}else if(1 == result){
|
||||
// success to set
|
||||
}else if(1 == result){
|
||||
// success to set
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string bucket_key = allbucket_fields_type;
|
||||
if(0 < bucket.size() && bucketmap.end() != bucketmap.find(bucket)){
|
||||
bucket_key = bucket;
|
||||
}
|
||||
if(bucketmap.end() == bucketmap.find(bucket_key)){
|
||||
string bucket_key = allbucket_fields_type;
|
||||
if(0 < bucket.size() && bucketmap.end() != bucketmap.find(bucket)){
|
||||
bucket_key = bucket;
|
||||
}
|
||||
if(bucketmap.end() == bucketmap.find(bucket_key)){
|
||||
S3FS_PRN_EXIT("Not found access key/secret key in passwd file.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
keyval = bucketmap[bucket_key];
|
||||
if(keyval.end() == keyval.find(string(aws_accesskeyid)) || keyval.end() == keyval.find(string(aws_secretkey))){
|
||||
}
|
||||
keyval = bucketmap[bucket_key];
|
||||
if(keyval.end() == keyval.find(string(aws_accesskeyid)) || keyval.end() == keyval.find(string(aws_secretkey))){
|
||||
S3FS_PRN_EXIT("Not found access key/secret key in passwd file.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
if(!S3fsCurl::SetAccessKey(keyval.at(string(aws_accesskeyid)).c_str(), keyval.at(string(aws_secretkey)).c_str())){
|
||||
S3FS_PRN_EXIT("failed to set internal data for access key/secret key from passwd file.");
|
||||
return EXIT_FAILURE;
|
||||
@ -4860,9 +4858,8 @@ int main(int argc, char* argv[])
|
||||
LIBXML_TEST_VERSION
|
||||
|
||||
// get program name - emulate basename
|
||||
size_t found = string::npos;
|
||||
program_name.assign(argv[0]);
|
||||
found = program_name.find_last_of("/");
|
||||
size_t found = program_name.find_last_of("/");
|
||||
if(found != string::npos){
|
||||
program_name.replace(0, found+1, "");
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ char* s3fs_base64(const unsigned char* input, size_t length)
|
||||
if(!input || 0 >= length){
|
||||
return NULL;
|
||||
}
|
||||
if(NULL == (result = (char*)malloc((((length / 3) + 1) * 4 + 1) * sizeof(char)))){
|
||||
if(NULL == (result = reinterpret_cast<char*>(malloc((((length / 3) + 1) * 4 + 1) * sizeof(char))))){
|
||||
return NULL; // ENOMEM
|
||||
}
|
||||
|
||||
@ -353,7 +353,7 @@ unsigned char* s3fs_decode64(const char* input, size_t* plength)
|
||||
if(!input || 0 == strlen(input) || !plength){
|
||||
return NULL;
|
||||
}
|
||||
if(NULL == (result = (unsigned char*)malloc((strlen(input) + 1)))){
|
||||
if(NULL == (result = reinterpret_cast<unsigned char*>(malloc((strlen(input) + 1))))){
|
||||
return NULL; // ENOMEM
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user