mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-12-23 09:18:55 +00:00
commit
d7bb834bcb
@ -147,9 +147,7 @@ typedef struct xattr_value{
|
|||||||
explicit xattr_value(unsigned char* pval = NULL, size_t len = 0) : pvalue(pval), length(len) {}
|
explicit xattr_value(unsigned char* pval = NULL, size_t len = 0) : pvalue(pval), length(len) {}
|
||||||
~xattr_value()
|
~xattr_value()
|
||||||
{
|
{
|
||||||
if(pvalue){
|
delete[] pvalue;
|
||||||
free(pvalue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}XATTRVAL, *PXATTRVAL;
|
}XATTRVAL, *PXATTRVAL;
|
||||||
|
|
||||||
|
@ -44,10 +44,10 @@ string s3fs_get_content_md5(int fd)
|
|||||||
if(NULL == (base64 = s3fs_base64(md5hex, get_md5_digest_length()))){
|
if(NULL == (base64 = s3fs_base64(md5hex, get_md5_digest_length()))){
|
||||||
return string(""); // ENOMEM
|
return string(""); // ENOMEM
|
||||||
}
|
}
|
||||||
free(md5hex);
|
delete[] md5hex;
|
||||||
|
|
||||||
Signature = base64;
|
Signature = base64;
|
||||||
free(base64);
|
delete[] base64;
|
||||||
|
|
||||||
return Signature;
|
return Signature;
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ string s3fs_md5sum(int fd, off_t start, ssize_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string md5 = s3fs_hex(md5hex, digestlen);
|
std::string md5 = s3fs_hex(md5hex, digestlen);
|
||||||
free(md5hex);
|
delete[] md5hex;
|
||||||
|
|
||||||
return md5;
|
return md5;
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ string s3fs_sha256sum(int fd, off_t start, ssize_t size)
|
|||||||
for(size_t pos = 0; pos < digestlen; pos++){
|
for(size_t pos = 0; pos < digestlen; pos++){
|
||||||
snprintf(sha256 + 2 * pos, 3, "%02x", sha256hex[pos]);
|
snprintf(sha256 + 2 * pos, 3, "%02x", sha256hex[pos]);
|
||||||
}
|
}
|
||||||
free(sha256hex);
|
delete[] sha256hex;
|
||||||
|
|
||||||
return string(sha256);
|
return string(sha256);
|
||||||
}
|
}
|
||||||
|
24
src/curl.cpp
24
src/curl.cpp
@ -986,7 +986,7 @@ bool S3fsCurl::PushbackSseKeys(string& onekey)
|
|||||||
if(NULL != (p_key = (char *)s3fs_decode64(onekey.c_str(), &keylength))) {
|
if(NULL != (p_key = (char *)s3fs_decode64(onekey.c_str(), &keylength))) {
|
||||||
raw_key = string(p_key, keylength);
|
raw_key = string(p_key, keylength);
|
||||||
base64_key = onekey;
|
base64_key = onekey;
|
||||||
free(p_key);
|
delete[] p_key;
|
||||||
} else {
|
} else {
|
||||||
S3FS_PRN_ERR("Failed to convert base64 to SSE-C key %s", onekey.c_str());
|
S3FS_PRN_ERR("Failed to convert base64 to SSE-C key %s", onekey.c_str());
|
||||||
return false;
|
return false;
|
||||||
@ -997,7 +997,7 @@ bool S3fsCurl::PushbackSseKeys(string& onekey)
|
|||||||
if(NULL != (pbase64_key = s3fs_base64((unsigned char*)onekey.c_str(), onekey.length()))) {
|
if(NULL != (pbase64_key = s3fs_base64((unsigned char*)onekey.c_str(), onekey.length()))) {
|
||||||
raw_key = onekey;
|
raw_key = onekey;
|
||||||
base64_key = pbase64_key;
|
base64_key = pbase64_key;
|
||||||
free(pbase64_key);
|
delete[] pbase64_key;
|
||||||
} else {
|
} else {
|
||||||
S3FS_PRN_ERR("Failed to convert base64 from SSE-C key %s", onekey.c_str());
|
S3FS_PRN_ERR("Failed to convert base64 from SSE-C key %s", onekey.c_str());
|
||||||
return false;
|
return false;
|
||||||
@ -2436,7 +2436,7 @@ string S3fsCurl::CalcSignatureV2(const string& method, const string& strMD5, con
|
|||||||
free(md);
|
free(md);
|
||||||
|
|
||||||
Signature = base64;
|
Signature = base64;
|
||||||
free(base64);
|
delete[] base64;
|
||||||
|
|
||||||
return Signature;
|
return Signature;
|
||||||
}
|
}
|
||||||
@ -2479,9 +2479,9 @@ string S3fsCurl::CalcSignature(const string& method, const string& canonical_uri
|
|||||||
s3fs_HMAC256(kDate, kDate_len, reinterpret_cast<const unsigned char*>(endpoint.c_str()), endpoint.size(), &kRegion, &kRegion_len);
|
s3fs_HMAC256(kDate, kDate_len, reinterpret_cast<const unsigned char*>(endpoint.c_str()), endpoint.size(), &kRegion, &kRegion_len);
|
||||||
s3fs_HMAC256(kRegion, kRegion_len, reinterpret_cast<const unsigned char*>("s3"), sizeof("s3") - 1, &kService, &kService_len);
|
s3fs_HMAC256(kRegion, kRegion_len, reinterpret_cast<const unsigned char*>("s3"), sizeof("s3") - 1, &kService, &kService_len);
|
||||||
s3fs_HMAC256(kService, kService_len, reinterpret_cast<const unsigned char*>("aws4_request"), sizeof("aws4_request") - 1, &kSigning, &kSigning_len);
|
s3fs_HMAC256(kService, kService_len, reinterpret_cast<const unsigned char*>("aws4_request"), sizeof("aws4_request") - 1, &kSigning, &kSigning_len);
|
||||||
free(kDate);
|
delete[] kDate;
|
||||||
free(kRegion);
|
delete[] kRegion;
|
||||||
free(kService);
|
delete[] kService;
|
||||||
|
|
||||||
const unsigned char* cRequest = reinterpret_cast<const unsigned char*>(StringCQ.c_str());
|
const unsigned char* cRequest = reinterpret_cast<const unsigned char*>(StringCQ.c_str());
|
||||||
unsigned int cRequest_len = StringCQ.size();
|
unsigned int cRequest_len = StringCQ.size();
|
||||||
@ -2489,7 +2489,7 @@ string S3fsCurl::CalcSignature(const string& method, const string& canonical_uri
|
|||||||
for(cnt = 0; cnt < sRequest_len; cnt++){
|
for(cnt = 0; cnt < sRequest_len; cnt++){
|
||||||
sprintf(&hexsRequest[cnt * 2], "%02x", sRequest[cnt]);
|
sprintf(&hexsRequest[cnt * 2], "%02x", sRequest[cnt]);
|
||||||
}
|
}
|
||||||
free(sRequest);
|
delete[] sRequest;
|
||||||
|
|
||||||
StringToSign = "AWS4-HMAC-SHA256\n";
|
StringToSign = "AWS4-HMAC-SHA256\n";
|
||||||
StringToSign += date8601 + "\n";
|
StringToSign += date8601 + "\n";
|
||||||
@ -2506,8 +2506,8 @@ string S3fsCurl::CalcSignature(const string& method, const string& canonical_uri
|
|||||||
for(cnt = 0; cnt < md_len; cnt++){
|
for(cnt = 0; cnt < md_len; cnt++){
|
||||||
sprintf(&hexSig[cnt * 2], "%02x", md[cnt]);
|
sprintf(&hexSig[cnt * 2], "%02x", md[cnt]);
|
||||||
}
|
}
|
||||||
free(kSigning);
|
delete[] kSigning;
|
||||||
free(md);
|
delete[] md;
|
||||||
|
|
||||||
Signature = hexSig;
|
Signature = hexSig;
|
||||||
|
|
||||||
@ -2578,7 +2578,7 @@ void S3fsCurl::insertV4Headers()
|
|||||||
for(cnt = 0; cnt < sRequest_len; cnt++){
|
for(cnt = 0; cnt < sRequest_len; cnt++){
|
||||||
sprintf(&hexsRequest[cnt * 2], "%02x", sRequest[cnt]);
|
sprintf(&hexsRequest[cnt * 2], "%02x", sRequest[cnt]);
|
||||||
}
|
}
|
||||||
free(sRequest);
|
delete[] sRequest;
|
||||||
payload_hash.assign(hexsRequest, &hexsRequest[sRequest_len * 2]);
|
payload_hash.assign(hexsRequest, &hexsRequest[sRequest_len * 2]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -3628,8 +3628,8 @@ int S3fsCurl::UploadMultipartPostSetup(const char* tpath, int part_num, const st
|
|||||||
partdata.etag = s3fs_hex(md5raw, get_md5_digest_length());
|
partdata.etag = s3fs_hex(md5raw, get_md5_digest_length());
|
||||||
char* md5base64p = s3fs_base64(md5raw, get_md5_digest_length());
|
char* md5base64p = s3fs_base64(md5raw, get_md5_digest_length());
|
||||||
requestHeaders = curl_slist_sort_insert(requestHeaders, "Content-MD5", md5base64p);
|
requestHeaders = curl_slist_sort_insert(requestHeaders, "Content-MD5", md5base64p);
|
||||||
free(md5base64p);
|
delete[] md5base64p;
|
||||||
free(md5raw);
|
delete[] md5raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make request
|
// make request
|
||||||
|
@ -531,16 +531,12 @@ bool PageList::Serialize(CacheFileStat& file, bool is_output)
|
|||||||
Init(0, false);
|
Init(0, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
char* ptmp;
|
char* ptmp = new char[st.st_size + 1];
|
||||||
if(NULL == (ptmp = (char*)calloc(st.st_size + 1, sizeof(char)))){
|
ptmp[st.st_size] = '\0';
|
||||||
S3FS_PRN_CRIT("could not allocate memory.");
|
|
||||||
S3FS_FUSE_EXIT();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// read from file
|
// read from file
|
||||||
if(0 >= pread(file.GetFd(), ptmp, st.st_size, 0)){
|
if(0 >= pread(file.GetFd(), ptmp, st.st_size, 0)){
|
||||||
S3FS_PRN_ERR("failed to read stats(%d)", errno);
|
S3FS_PRN_ERR("failed to read stats(%d)", errno);
|
||||||
free(ptmp);
|
delete[] ptmp;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
string oneline;
|
string oneline;
|
||||||
@ -552,7 +548,7 @@ bool PageList::Serialize(CacheFileStat& file, bool is_output)
|
|||||||
// load(size)
|
// load(size)
|
||||||
if(!getline(ssall, oneline, '\n')){
|
if(!getline(ssall, oneline, '\n')){
|
||||||
S3FS_PRN_ERR("failed to parse stats.");
|
S3FS_PRN_ERR("failed to parse stats.");
|
||||||
free(ptmp);
|
delete[] ptmp;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
size_t total = s3fs_strtoofft(oneline.c_str());
|
size_t total = s3fs_strtoofft(oneline.c_str());
|
||||||
@ -583,7 +579,7 @@ bool PageList::Serialize(CacheFileStat& file, bool is_output)
|
|||||||
// add new area
|
// add new area
|
||||||
SetPageLoadedStatus(offset, size, is_loaded);
|
SetPageLoadedStatus(offset, size, is_loaded);
|
||||||
}
|
}
|
||||||
free(ptmp);
|
delete[] ptmp;
|
||||||
if(is_err){
|
if(is_err){
|
||||||
S3FS_PRN_ERR("failed to parse stats.");
|
S3FS_PRN_ERR("failed to parse stats.");
|
||||||
Clear();
|
Clear();
|
||||||
|
@ -112,9 +112,7 @@ bool s3fs_HMAC(const void* key, size_t keylen, const unsigned char* data, size_t
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NULL == (*digest = reinterpret_cast<unsigned char*>(malloc(SHA1_DIGEST_SIZE)))){
|
*digest = new unsigned char[SHA1_DIGEST_SIZE];
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct hmac_sha1_ctx ctx_hmac;
|
struct hmac_sha1_ctx ctx_hmac;
|
||||||
hmac_sha1_set_key(&ctx_hmac, keylen, reinterpret_cast<const uint8_t*>(key));
|
hmac_sha1_set_key(&ctx_hmac, keylen, reinterpret_cast<const uint8_t*>(key));
|
||||||
@ -131,9 +129,7 @@ bool s3fs_HMAC256(const void* key, size_t keylen, const unsigned char* data, siz
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NULL == (*digest = reinterpret_cast<unsigned char*>(malloc(SHA256_DIGEST_SIZE)))){
|
*digest = new unsigned char[SHA256_DIGEST_SIZE];
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct hmac_sha256_ctx ctx_hmac;
|
struct hmac_sha256_ctx ctx_hmac;
|
||||||
hmac_sha256_set_key(&ctx_hmac, keylen, reinterpret_cast<const uint8_t*>(key));
|
hmac_sha256_set_key(&ctx_hmac, keylen, reinterpret_cast<const uint8_t*>(key));
|
||||||
@ -155,11 +151,9 @@ 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))){
|
if(0 == (*digestlen = gnutls_hmac_get_len(GNUTLS_MAC_SHA1))){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(NULL == (*digest = reinterpret_cast<unsigned char*>(malloc(*digestlen + 1)))){
|
*digest = new unsigned char[*digestlen + 1];
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(0 > gnutls_hmac_fast(GNUTLS_MAC_SHA1, key, keylen, data, datalen, *digest)){
|
if(0 > gnutls_hmac_fast(GNUTLS_MAC_SHA1, key, keylen, data, datalen, *digest)){
|
||||||
free(*digest);
|
delete[] *digest;
|
||||||
*digest = NULL;
|
*digest = NULL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -175,11 +169,9 @@ bool s3fs_HMAC256(const void* key, size_t keylen, const unsigned char* data, siz
|
|||||||
if(0 == (*digestlen = gnutls_hmac_get_len(GNUTLS_MAC_SHA256))){
|
if(0 == (*digestlen = gnutls_hmac_get_len(GNUTLS_MAC_SHA256))){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(NULL == (*digest = reinterpret_cast<unsigned char*>(malloc(*digestlen + 1)))){
|
*digest = new unsigned char[*digestlen + 1];
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(0 > gnutls_hmac_fast(GNUTLS_MAC_SHA256, key, keylen, data, datalen, *digest)){
|
if(0 > gnutls_hmac_fast(GNUTLS_MAC_SHA256, key, keylen, data, datalen, *digest)){
|
||||||
free(*digest);
|
delete[] *digest;
|
||||||
*digest = NULL;
|
*digest = NULL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -226,13 +218,11 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size)
|
|||||||
md5_update(&ctx_md5, bytes, buf);
|
md5_update(&ctx_md5, bytes, buf);
|
||||||
memset(buf, 0, 512);
|
memset(buf, 0, 512);
|
||||||
}
|
}
|
||||||
if(NULL == (result = reinterpret_cast<unsigned char*>(malloc(get_md5_digest_length())))){
|
result = new unsigned char[get_md5_digest_length()];
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
md5_digest(&ctx_md5, get_md5_digest_length(), result);
|
md5_digest(&ctx_md5, get_md5_digest_length(), result);
|
||||||
|
|
||||||
if(-1 == lseek(fd, start, SEEK_SET)){
|
if(-1 == lseek(fd, start, SEEK_SET)){
|
||||||
free(result);
|
delete[] result;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,15 +273,12 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size)
|
|||||||
gcry_md_write(ctx_md5, buf, bytes);
|
gcry_md_write(ctx_md5, buf, bytes);
|
||||||
memset(buf, 0, 512);
|
memset(buf, 0, 512);
|
||||||
}
|
}
|
||||||
if(NULL == (result = reinterpret_cast<unsigned char*>(malloc(get_md5_digest_length())))){
|
result = new unsigned char[get_md5_digest_length()];
|
||||||
gcry_md_close(ctx_md5);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
memcpy(result, gcry_md_read(ctx_md5, 0), get_md5_digest_length());
|
memcpy(result, gcry_md_read(ctx_md5, 0), get_md5_digest_length());
|
||||||
gcry_md_close(ctx_md5);
|
gcry_md_close(ctx_md5);
|
||||||
|
|
||||||
if(-1 == lseek(fd, start, SEEK_SET)){
|
if(-1 == lseek(fd, start, SEEK_SET)){
|
||||||
free(result);
|
delete[] result;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,9 +299,7 @@ size_t get_sha256_digest_length()
|
|||||||
bool s3fs_sha256(const unsigned char* data, unsigned int datalen, unsigned char** digest, unsigned int* digestlen)
|
bool s3fs_sha256(const unsigned char* data, unsigned int datalen, unsigned char** digest, unsigned int* digestlen)
|
||||||
{
|
{
|
||||||
(*digestlen) = static_cast<unsigned int>(get_sha256_digest_length());
|
(*digestlen) = static_cast<unsigned int>(get_sha256_digest_length());
|
||||||
if(NULL == ((*digest) = reinterpret_cast<unsigned char*>(malloc(*digestlen)))){
|
*digest = new unsigned char[*digestlen];
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sha256_ctx ctx_sha256;
|
struct sha256_ctx ctx_sha256;
|
||||||
sha256_init(&ctx_sha256);
|
sha256_init(&ctx_sha256);
|
||||||
@ -353,13 +338,11 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size)
|
|||||||
sha256_update(&ctx_sha256, bytes, buf);
|
sha256_update(&ctx_sha256, bytes, buf);
|
||||||
memset(buf, 0, 512);
|
memset(buf, 0, 512);
|
||||||
}
|
}
|
||||||
if(NULL == (result = reinterpret_cast<unsigned char*>(malloc(get_sha256_digest_length())))){
|
result = new unsigned char[get_sha256_digest_length()];
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
sha256_digest(&ctx_sha256, get_sha256_digest_length(), result);
|
sha256_digest(&ctx_sha256, get_sha256_digest_length(), result);
|
||||||
|
|
||||||
if(-1 == lseek(fd, start, SEEK_SET)){
|
if(-1 == lseek(fd, start, SEEK_SET)){
|
||||||
free(result);
|
delete[] result;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,15 +354,13 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size)
|
|||||||
bool s3fs_sha256(const unsigned char* data, unsigned int datalen, unsigned char** digest, unsigned int* digestlen)
|
bool s3fs_sha256(const unsigned char* data, unsigned int datalen, unsigned char** digest, unsigned int* digestlen)
|
||||||
{
|
{
|
||||||
size_t len = (*digestlen) = static_cast<unsigned int>(get_sha256_digest_length());
|
size_t len = (*digestlen) = static_cast<unsigned int>(get_sha256_digest_length());
|
||||||
if(NULL == ((*digest) = reinterpret_cast<unsigned char*>(malloc(len)))){
|
*digest = new unsigned char[len];
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
gcry_md_hd_t ctx_sha256;
|
gcry_md_hd_t ctx_sha256;
|
||||||
gcry_error_t err;
|
gcry_error_t err;
|
||||||
if(GPG_ERR_NO_ERROR != (err = gcry_md_open(&ctx_sha256, GCRY_MD_SHA256, 0))){
|
if(GPG_ERR_NO_ERROR != (err = gcry_md_open(&ctx_sha256, GCRY_MD_SHA256, 0))){
|
||||||
S3FS_PRN_ERR("SHA256 context creation failure: %s/%s", gcry_strsource(err), gcry_strerror(err));
|
S3FS_PRN_ERR("SHA256 context creation failure: %s/%s", gcry_strsource(err), gcry_strerror(err));
|
||||||
free(*digest);
|
delete[] *digest;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
gcry_md_write(ctx_sha256, data, datalen);
|
gcry_md_write(ctx_sha256, data, datalen);
|
||||||
@ -431,15 +412,12 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size)
|
|||||||
gcry_md_write(ctx_sha256, buf, bytes);
|
gcry_md_write(ctx_sha256, buf, bytes);
|
||||||
memset(buf, 0, 512);
|
memset(buf, 0, 512);
|
||||||
}
|
}
|
||||||
if(NULL == (result = reinterpret_cast<unsigned char*>(malloc(get_sha256_digest_length())))){
|
result = new unsigned char[get_sha256_digest_length()];
|
||||||
gcry_md_close(ctx_sha256);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
memcpy(result, gcry_md_read(ctx_sha256, 0), get_sha256_digest_length());
|
memcpy(result, gcry_md_read(ctx_sha256, 0), get_sha256_digest_length());
|
||||||
gcry_md_close(ctx_sha256);
|
gcry_md_close(ctx_sha256);
|
||||||
|
|
||||||
if(-1 == lseek(fd, start, SEEK_SET)){
|
if(-1 == lseek(fd, start, SEEK_SET)){
|
||||||
free(result);
|
delete[] result;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,9 +127,7 @@ static bool s3fs_HMAC_RAW(const void* key, size_t keylen, const unsigned char* d
|
|||||||
PK11_FreeSymKey(pKey);
|
PK11_FreeSymKey(pKey);
|
||||||
PK11_FreeSlot(Slot);
|
PK11_FreeSlot(Slot);
|
||||||
|
|
||||||
if(NULL == (*digest = reinterpret_cast<unsigned char*>(malloc(*digestlen)))){
|
*digest = new unsigned char[*digestlen];
|
||||||
return false;
|
|
||||||
}
|
|
||||||
memcpy(*digest, tmpdigest, *digestlen);
|
memcpy(*digest, tmpdigest, *digestlen);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -192,15 +190,12 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size)
|
|||||||
PK11_DigestOp(md5ctx, buf, bytes);
|
PK11_DigestOp(md5ctx, buf, bytes);
|
||||||
memset(buf, 0, 512);
|
memset(buf, 0, 512);
|
||||||
}
|
}
|
||||||
if(NULL == (result = reinterpret_cast<unsigned char*>(malloc(get_md5_digest_length())))){
|
result = new unsigned char[get_md5_digest_length()];
|
||||||
PK11_DestroyContext(md5ctx, PR_TRUE);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
PK11_DigestFinal(md5ctx, result, &md5outlen, get_md5_digest_length());
|
PK11_DigestFinal(md5ctx, result, &md5outlen, get_md5_digest_length());
|
||||||
PK11_DestroyContext(md5ctx, PR_TRUE);
|
PK11_DestroyContext(md5ctx, PR_TRUE);
|
||||||
|
|
||||||
if(-1 == lseek(fd, start, SEEK_SET)){
|
if(-1 == lseek(fd, start, SEEK_SET)){
|
||||||
free(result);
|
delete[] result;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,9 +213,7 @@ size_t get_sha256_digest_length()
|
|||||||
bool s3fs_sha256(const unsigned char* data, unsigned int datalen, unsigned char** digest, unsigned int* digestlen)
|
bool s3fs_sha256(const unsigned char* data, unsigned int datalen, unsigned char** digest, unsigned int* digestlen)
|
||||||
{
|
{
|
||||||
(*digestlen) = static_cast<unsigned int>(get_sha256_digest_length());
|
(*digestlen) = static_cast<unsigned int>(get_sha256_digest_length());
|
||||||
if(NULL == ((*digest) = reinterpret_cast<unsigned char*>(malloc(*digestlen)))){
|
*digest = new unsigned char[*digestlen];
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
PK11Context* sha256ctx;
|
PK11Context* sha256ctx;
|
||||||
unsigned int sha256outlen;
|
unsigned int sha256outlen;
|
||||||
@ -273,15 +266,12 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size)
|
|||||||
PK11_DigestOp(sha256ctx, buf, bytes);
|
PK11_DigestOp(sha256ctx, buf, bytes);
|
||||||
memset(buf, 0, 512);
|
memset(buf, 0, 512);
|
||||||
}
|
}
|
||||||
if(NULL == (result = reinterpret_cast<unsigned char*>(malloc(get_sha256_digest_length())))){
|
result = new unsigned char[get_sha256_digest_length()];
|
||||||
PK11_DestroyContext(sha256ctx, PR_TRUE);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
PK11_DigestFinal(sha256ctx, result, &sha256outlen, get_sha256_digest_length());
|
PK11_DigestFinal(sha256ctx, result, &sha256outlen, get_sha256_digest_length());
|
||||||
PK11_DestroyContext(sha256ctx, PR_TRUE);
|
PK11_DestroyContext(sha256ctx, PR_TRUE);
|
||||||
|
|
||||||
if(-1 == lseek(fd, start, SEEK_SET)){
|
if(-1 == lseek(fd, start, SEEK_SET)){
|
||||||
free(result);
|
delete[] result;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,12 +102,7 @@ static unsigned long s3fs_crypt_get_threadid()
|
|||||||
|
|
||||||
static struct CRYPTO_dynlock_value* s3fs_dyn_crypt_mutex(const char* file, int line)
|
static struct CRYPTO_dynlock_value* s3fs_dyn_crypt_mutex(const char* file, int line)
|
||||||
{
|
{
|
||||||
struct CRYPTO_dynlock_value* dyndata;
|
struct CRYPTO_dynlock_value* dyndata = new CRYPTO_dynlock_value();
|
||||||
|
|
||||||
if(NULL == (dyndata = static_cast<struct CRYPTO_dynlock_value*>(malloc(sizeof(struct CRYPTO_dynlock_value))))){
|
|
||||||
S3FS_PRN_CRIT("Could not allocate memory for CRYPTO_dynlock_value");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
pthread_mutex_init(&(dyndata->dyn_mutex), NULL);
|
pthread_mutex_init(&(dyndata->dyn_mutex), NULL);
|
||||||
return dyndata;
|
return dyndata;
|
||||||
}
|
}
|
||||||
@ -127,7 +122,7 @@ static void s3fs_destroy_dyn_crypt_mutex(struct CRYPTO_dynlock_value* dyndata, c
|
|||||||
{
|
{
|
||||||
if(dyndata){
|
if(dyndata){
|
||||||
pthread_mutex_destroy(&(dyndata->dyn_mutex));
|
pthread_mutex_destroy(&(dyndata->dyn_mutex));
|
||||||
free(dyndata);
|
delete dyndata;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,10 +135,7 @@ bool s3fs_init_crypt_mutex()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(NULL == (s3fs_crypt_mutex = static_cast<pthread_mutex_t*>(malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t))))){
|
s3fs_crypt_mutex = new pthread_mutex_t[CRYPTO_num_locks()];
|
||||||
S3FS_PRN_CRIT("Could not allocate memory for s3fs_crypt_mutex");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for(int cnt = 0; cnt < CRYPTO_num_locks(); cnt++){
|
for(int cnt = 0; cnt < CRYPTO_num_locks(); cnt++){
|
||||||
pthread_mutex_init(&s3fs_crypt_mutex[cnt], NULL);
|
pthread_mutex_init(&s3fs_crypt_mutex[cnt], NULL);
|
||||||
}
|
}
|
||||||
@ -174,7 +166,7 @@ bool s3fs_destroy_crypt_mutex()
|
|||||||
pthread_mutex_destroy(&s3fs_crypt_mutex[cnt]);
|
pthread_mutex_destroy(&s3fs_crypt_mutex[cnt]);
|
||||||
}
|
}
|
||||||
CRYPTO_cleanup_all_ex_data();
|
CRYPTO_cleanup_all_ex_data();
|
||||||
free(s3fs_crypt_mutex);
|
delete[] s3fs_crypt_mutex;
|
||||||
s3fs_crypt_mutex = NULL;
|
s3fs_crypt_mutex = NULL;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -189,9 +181,7 @@ static bool s3fs_HMAC_RAW(const void* key, size_t keylen, const unsigned char* d
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
(*digestlen) = EVP_MAX_MD_SIZE * sizeof(unsigned char);
|
(*digestlen) = EVP_MAX_MD_SIZE * sizeof(unsigned char);
|
||||||
if(NULL == ((*digest) = (unsigned char*)malloc(*digestlen))){
|
*digest = new unsigned char[*digestlen];
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(is_sha256){
|
if(is_sha256){
|
||||||
HMAC(EVP_sha256(), key, keylen, data, datalen, *digest, digestlen);
|
HMAC(EVP_sha256(), key, keylen, data, datalen, *digest, digestlen);
|
||||||
}else{
|
}else{
|
||||||
@ -257,13 +247,11 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size)
|
|||||||
memset(buf, 0, 512);
|
memset(buf, 0, 512);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NULL == (result = (unsigned char*)malloc(get_md5_digest_length()))){
|
result = new unsigned char[get_md5_digest_length()];
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
MD5_Final(result, &md5ctx);
|
MD5_Final(result, &md5ctx);
|
||||||
|
|
||||||
if(-1 == lseek(fd, start, SEEK_SET)){
|
if(-1 == lseek(fd, start, SEEK_SET)){
|
||||||
free(result);
|
delete[] result;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,9 +269,7 @@ size_t get_sha256_digest_length()
|
|||||||
bool s3fs_sha256(const unsigned char* data, unsigned int datalen, unsigned char** digest, unsigned int* digestlen)
|
bool s3fs_sha256(const unsigned char* data, unsigned int datalen, unsigned char** digest, unsigned int* digestlen)
|
||||||
{
|
{
|
||||||
(*digestlen) = EVP_MAX_MD_SIZE * sizeof(unsigned char);
|
(*digestlen) = EVP_MAX_MD_SIZE * sizeof(unsigned char);
|
||||||
if(NULL == ((*digest) = reinterpret_cast<unsigned char*>(malloc(*digestlen)))){
|
*digest = new unsigned char[*digestlen];
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const EVP_MD* md = EVP_get_digestbyname("sha256");
|
const EVP_MD* md = EVP_get_digestbyname("sha256");
|
||||||
EVP_MD_CTX* mdctx = EVP_MD_CTX_create();
|
EVP_MD_CTX* mdctx = EVP_MD_CTX_create();
|
||||||
@ -335,15 +321,12 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size)
|
|||||||
EVP_DigestUpdate(sha256ctx, buf, bytes);
|
EVP_DigestUpdate(sha256ctx, buf, bytes);
|
||||||
memset(buf, 0, 512);
|
memset(buf, 0, 512);
|
||||||
}
|
}
|
||||||
if(NULL == (result = (unsigned char*)malloc(get_sha256_digest_length()))){
|
result = new unsigned char[get_sha256_digest_length()];
|
||||||
EVP_MD_CTX_destroy(sha256ctx);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
EVP_DigestFinal_ex(sha256ctx, result, NULL);
|
EVP_DigestFinal_ex(sha256ctx, result, NULL);
|
||||||
EVP_MD_CTX_destroy(sha256ctx);
|
EVP_MD_CTX_destroy(sha256ctx);
|
||||||
|
|
||||||
if(-1 == lseek(fd, start, SEEK_SET)){
|
if(-1 == lseek(fd, start, SEEK_SET)){
|
||||||
free(result);
|
delete[] result;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -3035,7 +3035,7 @@ static std::string build_xattrs(const xattrs_t& xattrs)
|
|||||||
char* base64val = s3fs_base64((iter->second)->pvalue, (iter->second)->length);
|
char* base64val = s3fs_base64((iter->second)->pvalue, (iter->second)->length);
|
||||||
if(base64val){
|
if(base64val){
|
||||||
strxattrs += base64val;
|
strxattrs += base64val;
|
||||||
free(base64val);
|
delete[] base64val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strxattrs += '\"';
|
strxattrs += '\"';
|
||||||
@ -3083,11 +3083,7 @@ static int set_xattrs_to_header(headers_t& meta, const char* name, const char* v
|
|||||||
PXATTRVAL pval = new XATTRVAL;
|
PXATTRVAL pval = new XATTRVAL;
|
||||||
pval->length = size;
|
pval->length = size;
|
||||||
if(0 < size){
|
if(0 < size){
|
||||||
if(NULL == (pval->pvalue = (unsigned char*)malloc(size))){
|
pval->pvalue = new unsigned char[size];
|
||||||
delete pval;
|
|
||||||
free_xattrs(xattrs);
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
memcpy(pval->pvalue, value, size);
|
memcpy(pval->pvalue, value, size);
|
||||||
}else{
|
}else{
|
||||||
pval->pvalue = NULL;
|
pval->pvalue = NULL;
|
||||||
|
@ -318,22 +318,17 @@ MVNODE *create_mvnode(const char *old_path, const char *new_path, bool is_dir, b
|
|||||||
char *p_old_path;
|
char *p_old_path;
|
||||||
char *p_new_path;
|
char *p_new_path;
|
||||||
|
|
||||||
p = (MVNODE *) malloc(sizeof(MVNODE));
|
p = new MVNODE();
|
||||||
if (p == NULL) {
|
|
||||||
printf("create_mvnode: could not allocation memory for p\n");
|
|
||||||
S3FS_FUSE_EXIT();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(NULL == (p_old_path = strdup(old_path))){
|
if(NULL == (p_old_path = strdup(old_path))){
|
||||||
free(p);
|
delete p;
|
||||||
printf("create_mvnode: could not allocation memory for p_old_path\n");
|
printf("create_mvnode: could not allocation memory for p_old_path\n");
|
||||||
S3FS_FUSE_EXIT();
|
S3FS_FUSE_EXIT();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NULL == (p_new_path = strdup(new_path))){
|
if(NULL == (p_new_path = strdup(new_path))){
|
||||||
free(p);
|
delete p;
|
||||||
free(p_old_path);
|
free(p_old_path);
|
||||||
printf("create_mvnode: could not allocation memory for p_new_path\n");
|
printf("create_mvnode: could not allocation memory for p_new_path\n");
|
||||||
S3FS_FUSE_EXIT();
|
S3FS_FUSE_EXIT();
|
||||||
@ -417,7 +412,7 @@ void free_mvnodes(MVNODE *head)
|
|||||||
next = my_head->next;
|
next = my_head->next;
|
||||||
free(my_head->old_path);
|
free(my_head->old_path);
|
||||||
free(my_head->new_path);
|
free(my_head->new_path);
|
||||||
free(my_head);
|
delete my_head;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,33 +470,27 @@ string get_username(uid_t uid)
|
|||||||
}
|
}
|
||||||
maxlen = res;
|
maxlen = res;
|
||||||
}
|
}
|
||||||
if(NULL == (pbuf = (char*)malloc(sizeof(char) * maxlen))){
|
pbuf = new char[maxlen];
|
||||||
S3FS_PRN_CRIT("failed to allocate memory.");
|
|
||||||
return string("");
|
|
||||||
}
|
|
||||||
// get pw information
|
// get pw information
|
||||||
while(ERANGE == (result = getpwuid_r(uid, &pwinfo, pbuf, maxlen, &ppwinfo))){
|
while(ERANGE == (result = getpwuid_r(uid, &pwinfo, pbuf, maxlen, &ppwinfo))){
|
||||||
free(pbuf);
|
delete[] pbuf;
|
||||||
maxlen *= 2;
|
maxlen *= 2;
|
||||||
if(NULL == (pbuf = (char*)malloc(sizeof(char) * maxlen))){
|
pbuf = new char[maxlen];
|
||||||
S3FS_PRN_CRIT("failed to allocate memory.");
|
|
||||||
return string("");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(0 != result){
|
if(0 != result){
|
||||||
S3FS_PRN_ERR("could not get pw information(%d).", result);
|
S3FS_PRN_ERR("could not get pw information(%d).", result);
|
||||||
free(pbuf);
|
delete[] pbuf;
|
||||||
return string("");
|
return string("");
|
||||||
}
|
}
|
||||||
|
|
||||||
// check pw
|
// check pw
|
||||||
if(NULL == ppwinfo){
|
if(NULL == ppwinfo){
|
||||||
free(pbuf);
|
delete[] pbuf;
|
||||||
return string("");
|
return string("");
|
||||||
}
|
}
|
||||||
string name = SAFESTRPTR(ppwinfo->pw_name);
|
string name = SAFESTRPTR(ppwinfo->pw_name);
|
||||||
free(pbuf);
|
delete[] pbuf;
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -531,30 +520,24 @@ int is_uid_include_group(uid_t uid, gid_t gid)
|
|||||||
}
|
}
|
||||||
maxlen = res;
|
maxlen = res;
|
||||||
}
|
}
|
||||||
if(NULL == (pbuf = (char*)malloc(sizeof(char) * maxlen))){
|
pbuf = new char[maxlen];
|
||||||
S3FS_PRN_CRIT("failed to allocate memory.");
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
// get group information
|
// get group information
|
||||||
while(ERANGE == (result = getgrgid_r(gid, &ginfo, pbuf, maxlen, &pginfo))){
|
while(ERANGE == (result = getgrgid_r(gid, &ginfo, pbuf, maxlen, &pginfo))){
|
||||||
free(pbuf);
|
delete[] pbuf;
|
||||||
maxlen *= 2;
|
maxlen *= 2;
|
||||||
if(NULL == (pbuf = (char*)malloc(sizeof(char) * maxlen))){
|
pbuf = new char[maxlen];
|
||||||
S3FS_PRN_CRIT("failed to allocate memory.");
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(0 != result){
|
if(0 != result){
|
||||||
S3FS_PRN_ERR("could not get group information(%d).", result);
|
S3FS_PRN_ERR("could not get group information(%d).", result);
|
||||||
free(pbuf);
|
delete[] pbuf;
|
||||||
return -result;
|
return -result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check group
|
// check group
|
||||||
if(NULL == pginfo){
|
if(NULL == pginfo){
|
||||||
// there is not gid in group.
|
// there is not gid in group.
|
||||||
free(pbuf);
|
delete[] pbuf;
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -564,11 +547,11 @@ int is_uid_include_group(uid_t uid, gid_t gid)
|
|||||||
for(ppgr_mem = pginfo->gr_mem; ppgr_mem && *ppgr_mem; ppgr_mem++){
|
for(ppgr_mem = pginfo->gr_mem; ppgr_mem && *ppgr_mem; ppgr_mem++){
|
||||||
if(username == *ppgr_mem){
|
if(username == *ppgr_mem){
|
||||||
// Found username in group.
|
// Found username in group.
|
||||||
free(pbuf);
|
delete[] pbuf;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(pbuf);
|
delete[] pbuf;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,9 +372,7 @@ char* s3fs_base64(const unsigned char* input, size_t length)
|
|||||||
if(!input || 0 == length){
|
if(!input || 0 == length){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(NULL == (result = reinterpret_cast<char*>(malloc((((length / 3) + 1) * 4 + 1) * sizeof(char))))){
|
result = new char[((length / 3) + 1) * 4 + 1];
|
||||||
return NULL; // ENOMEM
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char parts[4];
|
unsigned char parts[4];
|
||||||
size_t rpos;
|
size_t rpos;
|
||||||
@ -422,9 +420,7 @@ unsigned char* s3fs_decode64(const char* input, size_t* plength)
|
|||||||
if(!input || 0 == strlen(input) || !plength){
|
if(!input || 0 == strlen(input) || !plength){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(NULL == (result = reinterpret_cast<unsigned char*>(malloc((strlen(input) + 1))))){
|
result = new unsigned char[strlen(input) + 1];
|
||||||
return NULL; // ENOMEM
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char parts[4];
|
unsigned char parts[4];
|
||||||
size_t input_len = strlen(input);
|
size_t input_len = strlen(input);
|
||||||
|
Loading…
Reference in New Issue
Block a user