diff --git a/src/curl.cpp b/src/curl.cpp index cbb4ae6..c6bdeda 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -1586,7 +1586,6 @@ bool S3fsCurl::UploadMultipartPostSetCurlOpts(S3fsCurl* s3fscurl) curl_easy_setopt(s3fscurl->hCurl, CURLOPT_INFILESIZE_LARGE, static_cast(s3fscurl->partdata.size)); // Content-Length curl_easy_setopt(s3fscurl->hCurl, CURLOPT_READFUNCTION, UploadReadCallback); curl_easy_setopt(s3fscurl->hCurl, CURLOPT_READDATA, (void*)s3fscurl); - curl_easy_setopt(s3fscurl->hCurl, CURLOPT_HTTPHEADER, s3fscurl->requestHeaders); S3fsCurl::AddUserAgent(s3fscurl->hCurl); // put User-Agent return true; @@ -1608,7 +1607,6 @@ bool S3fsCurl::CopyMultipartPostSetCurlOpts(S3fsCurl* s3fscurl) curl_easy_setopt(s3fscurl->hCurl, CURLOPT_HEADERDATA, (void*)(&s3fscurl->headdata)); curl_easy_setopt(s3fscurl->hCurl, CURLOPT_HEADERFUNCTION, WriteMemoryCallback); curl_easy_setopt(s3fscurl->hCurl, CURLOPT_INFILESIZE, 0); // Content-Length - curl_easy_setopt(s3fscurl->hCurl, CURLOPT_HTTPHEADER, s3fscurl->requestHeaders); S3fsCurl::AddUserAgent(s3fscurl->hCurl); // put User-Agent return true; @@ -1624,7 +1622,6 @@ bool S3fsCurl::PreGetObjectRequestSetCurlOpts(S3fsCurl* s3fscurl) } curl_easy_setopt(s3fscurl->hCurl, CURLOPT_URL, s3fscurl->url.c_str()); - curl_easy_setopt(s3fscurl->hCurl, CURLOPT_HTTPHEADER, s3fscurl->requestHeaders); curl_easy_setopt(s3fscurl->hCurl, CURLOPT_WRITEFUNCTION, DownloadWriteCallback); curl_easy_setopt(s3fscurl->hCurl, CURLOPT_WRITEDATA, (void*)s3fscurl); S3fsCurl::AddUserAgent(s3fscurl->hCurl); // put User-Agent @@ -1644,7 +1641,6 @@ bool S3fsCurl::PreHeadRequestSetCurlOpts(S3fsCurl* s3fscurl) curl_easy_setopt(s3fscurl->hCurl, CURLOPT_URL, s3fscurl->url.c_str()); curl_easy_setopt(s3fscurl->hCurl, CURLOPT_NOBODY, true); // HEAD curl_easy_setopt(s3fscurl->hCurl, CURLOPT_FILETIME, true); // Last-Modified - curl_easy_setopt(s3fscurl->hCurl, CURLOPT_HTTPHEADER, s3fscurl->requestHeaders); // responseHeaders curl_easy_setopt(s3fscurl->hCurl, CURLOPT_HEADERDATA, (void*)&(s3fscurl->responseHeaders)); @@ -1951,6 +1947,13 @@ bool S3fsCurl::CreateCurlHandle(bool only_pool, bool remake) } } + ResetHandle(); + + return true; +} + +bool S3fsCurl::DestroyCurlHandle(bool restore_pool, bool clear_internal_data) +{ // [NOTE] // If type is REQTYPE_IAMCRED or REQTYPE_IAMROLE, do not clear type. // Because that type only uses HTTP protocol, then the special @@ -1960,13 +1963,6 @@ bool S3fsCurl::CreateCurlHandle(bool only_pool, bool remake) type = REQTYPE_UNSET; } - ResetHandle(); - - return true; -} - -bool S3fsCurl::DestroyCurlHandle(bool restore_pool, bool clear_internal_data) -{ if(clear_internal_data){ ClearInternalData(); } @@ -2089,14 +2085,12 @@ bool S3fsCurl::RemakeHandle() case REQTYPE_DELETE: curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); curl_easy_setopt(hCurl, CURLOPT_CUSTOMREQUEST, "DELETE"); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); break; case REQTYPE_HEAD: curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); curl_easy_setopt(hCurl, CURLOPT_NOBODY, true); curl_easy_setopt(hCurl, CURLOPT_FILETIME, true); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); // responseHeaders curl_easy_setopt(hCurl, CURLOPT_HEADERDATA, (void*)&responseHeaders); curl_easy_setopt(hCurl, CURLOPT_HEADERFUNCTION, HeaderCallback); @@ -2108,7 +2102,6 @@ bool S3fsCurl::RemakeHandle() curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)&bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(hCurl, CURLOPT_INFILESIZE, 0); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); break; case REQTYPE_PUT: @@ -2116,7 +2109,6 @@ bool S3fsCurl::RemakeHandle() curl_easy_setopt(hCurl, CURLOPT_UPLOAD, true); curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)&bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); if(b_infile){ curl_easy_setopt(hCurl, CURLOPT_INFILESIZE_LARGE, static_cast(st.st_size)); curl_easy_setopt(hCurl, CURLOPT_INFILE, b_infile); @@ -2127,7 +2119,6 @@ bool S3fsCurl::RemakeHandle() case REQTYPE_GET: curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, S3fsCurl::DownloadWriteCallback); curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)this); break; @@ -2136,14 +2127,12 @@ bool S3fsCurl::RemakeHandle() curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)&bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); break; case REQTYPE_LISTBUCKET: curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)&bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); break; case REQTYPE_PREMULTIPOST: @@ -2152,12 +2141,10 @@ bool S3fsCurl::RemakeHandle() curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)&bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(hCurl, CURLOPT_POSTFIELDSIZE, 0); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); break; case REQTYPE_COMPLETEMULTIPOST: curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); curl_easy_setopt(hCurl, CURLOPT_POST, true); curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)&bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); @@ -2176,7 +2163,6 @@ bool S3fsCurl::RemakeHandle() curl_easy_setopt(hCurl, CURLOPT_INFILESIZE_LARGE, static_cast(partdata.size)); curl_easy_setopt(hCurl, CURLOPT_READFUNCTION, S3fsCurl::UploadReadCallback); curl_easy_setopt(hCurl, CURLOPT_READDATA, (void*)this); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); break; case REQTYPE_COPYMULTIPOST: @@ -2187,21 +2173,18 @@ bool S3fsCurl::RemakeHandle() curl_easy_setopt(hCurl, CURLOPT_HEADERDATA, (void*)&headdata); curl_easy_setopt(hCurl, CURLOPT_HEADERFUNCTION, WriteMemoryCallback); curl_easy_setopt(hCurl, CURLOPT_INFILESIZE, 0); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); break; case REQTYPE_MULTILIST: curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)&bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); break; case REQTYPE_IAMCRED: curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)&bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); if(S3fsCurl::is_ibm_iam_auth){ curl_easy_setopt(hCurl, CURLOPT_POST, true); curl_easy_setopt(hCurl, CURLOPT_POSTFIELDSIZE, static_cast(postdata_remaining)); @@ -2213,7 +2196,6 @@ bool S3fsCurl::RemakeHandle() case REQTYPE_ABORTMULTIUPLOAD: curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); curl_easy_setopt(hCurl, CURLOPT_CUSTOMREQUEST, "DELETE"); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); break; case REQTYPE_IAMROLE: @@ -2246,6 +2228,9 @@ int S3fsCurl::RequestPerform() long responseCode; int result = S3FSCURL_PERFORM_RESULT_NOTSET; + insertAuthHeaders(); + curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); + // 1 attempt + retries... for(int retrycnt = 0; S3FSCURL_PERFORM_RESULT_NOTSET == result && retrycnt < S3fsCurl::retries; ++retrycnt){ // Reset response code @@ -2692,11 +2677,9 @@ int S3fsCurl::DeleteRequest(const char* tpath) op = "DELETE"; type = REQTYPE_DELETE; - insertAuthHeaders(); curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); curl_easy_setopt(hCurl, CURLOPT_CUSTOMREQUEST, "DELETE"); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); S3fsCurl::AddUserAgent(hCurl); // put User-Agent return RequestPerform(); @@ -2762,7 +2745,6 @@ int S3fsCurl::GetIAMCredentials() curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)&bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); S3fsCurl::AddUserAgent(hCurl); // put User-Agent int result = RequestPerform(); @@ -2886,7 +2868,6 @@ bool S3fsCurl::PreHeadRequest(const char* tpath, const char* bpath, const char* op = "HEAD"; type = REQTYPE_HEAD; - insertAuthHeaders(); // set lazy function fpLazySetup = PreHeadRequestSetCurlOpts; @@ -3023,7 +3004,6 @@ int S3fsCurl::PutHeadRequest(const char* tpath, headers_t& meta, bool is_copy) op = "PUT"; type = REQTYPE_PUTHEAD; - insertAuthHeaders(); // setopt curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); @@ -3031,7 +3011,6 @@ int S3fsCurl::PutHeadRequest(const char* tpath, headers_t& meta, bool is_copy) curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)&bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(hCurl, CURLOPT_INFILESIZE, 0); // Content-Length - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); S3fsCurl::AddUserAgent(hCurl); // put User-Agent S3FS_PRN_INFO3("copying... [path=%s]", tpath); @@ -3152,14 +3131,12 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd) op = "PUT"; type = REQTYPE_PUT; - insertAuthHeaders(); // setopt curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); curl_easy_setopt(hCurl, CURLOPT_UPLOAD, true); // HTTP PUT curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)&bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); if(file){ curl_easy_setopt(hCurl, CURLOPT_INFILESIZE_LARGE, static_cast(st.st_size)); // Content-Length curl_easy_setopt(hCurl, CURLOPT_INFILE, file); @@ -3210,7 +3187,6 @@ int S3fsCurl::PreGetObjectRequest(const char* tpath, int fd, off_t start, ssize_ op = "GET"; type = REQTYPE_GET; - insertAuthHeaders(); // set lazy function fpLazySetup = PreGetObjectRequestSetCurlOpts; @@ -3280,13 +3256,11 @@ int S3fsCurl::CheckBucket() op = "GET"; type = REQTYPE_CHKBUCKET; - insertAuthHeaders(); // setopt curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)&bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); S3fsCurl::AddUserAgent(hCurl); // put User-Agent int result = RequestPerform(); @@ -3323,13 +3297,11 @@ int S3fsCurl::ListBucketRequest(const char* tpath, const char* query) op = "GET"; type = REQTYPE_LISTBUCKET; - insertAuthHeaders(); // setopt curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)&bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); S3fsCurl::AddUserAgent(hCurl); // put User-Agent return RequestPerform(); @@ -3423,7 +3395,6 @@ int S3fsCurl::PreMultipartPostRequest(const char* tpath, headers_t& meta, string op = "POST"; type = REQTYPE_PREMULTIPOST; - insertAuthHeaders(); // setopt curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); @@ -3431,7 +3402,6 @@ int S3fsCurl::PreMultipartPostRequest(const char* tpath, headers_t& meta, string curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)&bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(hCurl, CURLOPT_POSTFIELDSIZE, 0); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); S3fsCurl::AddUserAgent(hCurl); // put User-Agent // request @@ -3500,11 +3470,9 @@ int S3fsCurl::CompleteMultipartPostRequest(const char* tpath, string& upload_id, op = "POST"; type = REQTYPE_COMPLETEMULTIPOST; - insertAuthHeaders(); // setopt curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); curl_easy_setopt(hCurl, CURLOPT_POST, true); // POST curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)&bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); @@ -3544,13 +3512,11 @@ int S3fsCurl::MultipartListRequest(string& body) op = "GET"; type = REQTYPE_MULTILIST; - insertAuthHeaders(); // setopt curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)&bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); S3fsCurl::AddUserAgent(hCurl); // put User-Agent int result; @@ -3587,11 +3553,9 @@ int S3fsCurl::AbortMultipartUpload(const char* tpath, string& upload_id) op = "DELETE"; type = REQTYPE_ABORTMULTIUPLOAD; - insertAuthHeaders(); curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); curl_easy_setopt(hCurl, CURLOPT_CUSTOMREQUEST, "DELETE"); - curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); S3fsCurl::AddUserAgent(hCurl); // put User-Agent return RequestPerform(); @@ -3662,7 +3626,6 @@ int S3fsCurl::UploadMultipartPostSetup(const char* tpath, int part_num, const st op = "PUT"; type = REQTYPE_UPLOADMULTIPOST; - insertAuthHeaders(); // set lazy function fpLazySetup = UploadMultipartPostSetCurlOpts; @@ -3737,7 +3700,6 @@ int S3fsCurl::CopyMultipartPostSetup(const char* from, const char* to, int part_ op = "PUT"; type = REQTYPE_COPYMULTIPOST; - insertAuthHeaders(); // set lazy function fpLazySetup = CopyMultipartPostSetCurlOpts; diff --git a/src/gnutls_auth.cpp b/src/gnutls_auth.cpp index 477cd71..1395ccd 100644 --- a/src/gnutls_auth.cpp +++ b/src/gnutls_auth.cpp @@ -196,17 +196,12 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size) ssize_t bytes; unsigned char* result; - // seek to top of file. - if(-1 == lseek(fd, start, SEEK_SET)){ - return NULL; - } - memset(buf, 0, 512); md5_init(&ctx_md5); for(ssize_t total = 0; total < size; total += bytes){ bytes = 512 < (size - total) ? 512 : (size - total); - bytes = read(fd, buf, bytes); + bytes = pread(fd, buf, bytes, start + total); if(0 == bytes){ // end of file break; @@ -221,11 +216,6 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size) result = new unsigned char[get_md5_digest_length()]; md5_digest(&ctx_md5, get_md5_digest_length(), result); - if(-1 == lseek(fd, start, SEEK_SET)){ - delete[] result; - return NULL; - } - return result; } @@ -247,11 +237,6 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size) size = static_cast(st.st_size); } - // seek to top of file. - if(-1 == lseek(fd, start, SEEK_SET)){ - return NULL; - } - memset(buf, 0, 512); if(GPG_ERR_NO_ERROR != (err = gcry_md_open(&ctx_md5, GCRY_MD_MD5, 0))){ S3FS_PRN_ERR("MD5 context creation failure: %s/%s", gcry_strsource(err), gcry_strerror(err)); @@ -260,7 +245,7 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size) for(ssize_t total = 0; total < size; total += bytes){ bytes = 512 < (size - total) ? 512 : (size - total); - bytes = read(fd, buf, bytes); + bytes = pread(fd, buf, bytes, start + total); if(0 == bytes){ // end of file break; @@ -277,11 +262,6 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size) memcpy(result, gcry_md_read(ctx_md5, 0), get_md5_digest_length()); gcry_md_close(ctx_md5); - if(-1 == lseek(fd, start, SEEK_SET)){ - delete[] result; - return NULL; - } - return result; } @@ -316,17 +296,12 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size) ssize_t bytes; unsigned char* result; - // seek to top of file. - if(-1 == lseek(fd, start, SEEK_SET)){ - return NULL; - } - memset(buf, 0, 512); sha256_init(&ctx_sha256); for(ssize_t total = 0; total < size; total += bytes){ bytes = 512 < (size - total) ? 512 : (size - total); - bytes = read(fd, buf, bytes); + bytes = pread(fd, buf, bytes, start + total); if(0 == bytes){ // end of file break; @@ -341,11 +316,6 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size) result = new unsigned char[get_sha256_digest_length()]; sha256_digest(&ctx_sha256, get_sha256_digest_length(), result); - if(-1 == lseek(fd, start, SEEK_SET)){ - delete[] result; - return NULL; - } - return result; } @@ -386,11 +356,6 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size) size = static_cast(st.st_size); } - // seek to top of file. - if(-1 == lseek(fd, start, SEEK_SET)){ - return NULL; - } - memset(buf, 0, 512); 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)); @@ -399,7 +364,7 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size) for(ssize_t total = 0; total < size; total += bytes){ bytes = 512 < (size - total) ? 512 : (size - total); - bytes = read(fd, buf, bytes); + bytes = pread(fd, buf, bytes, start + total); if(0 == bytes){ // end of file break; @@ -416,11 +381,6 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size) memcpy(result, gcry_md_read(ctx_sha256, 0), get_sha256_digest_length()); gcry_md_close(ctx_sha256); - if(-1 == lseek(fd, start, SEEK_SET)){ - delete[] result; - return NULL; - } - return result; } diff --git a/src/nss_auth.cpp b/src/nss_auth.cpp index 90c96d6..15a726e 100644 --- a/src/nss_auth.cpp +++ b/src/nss_auth.cpp @@ -167,17 +167,12 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size) size = static_cast(st.st_size); } - // seek to top of file. - if(-1 == lseek(fd, start, SEEK_SET)){ - return NULL; - } - memset(buf, 0, 512); md5ctx = PK11_CreateDigestContext(SEC_OID_MD5); for(ssize_t total = 0; total < size; total += bytes){ bytes = 512 < (size - total) ? 512 : (size - total); - bytes = read(fd, buf, bytes); + bytes = pread(fd, buf, bytes, start + total); if(0 == bytes){ // end of file break; @@ -194,11 +189,6 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size) PK11_DigestFinal(md5ctx, result, &md5outlen, get_md5_digest_length()); PK11_DestroyContext(md5ctx, PR_TRUE); - if(-1 == lseek(fd, start, SEEK_SET)){ - delete[] result; - return NULL; - } - return result; } @@ -243,17 +233,12 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size) size = static_cast(st.st_size); } - // seek to top of file. - if(-1 == lseek(fd, start, SEEK_SET)){ - return NULL; - } - memset(buf, 0, 512); sha256ctx = PK11_CreateDigestContext(SEC_OID_SHA256); for(ssize_t total = 0; total < size; total += bytes){ bytes = 512 < (size - total) ? 512 : (size - total); - bytes = read(fd, buf, bytes); + bytes = pread(fd, buf, bytes, start + total); if(0 == bytes){ // end of file break; @@ -270,11 +255,6 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size) PK11_DigestFinal(sha256ctx, result, &sha256outlen, get_sha256_digest_length()); PK11_DestroyContext(sha256ctx, PR_TRUE); - if(-1 == lseek(fd, start, SEEK_SET)){ - delete[] result; - return NULL; - } - return result; } diff --git a/src/openssl_auth.cpp b/src/openssl_auth.cpp index 6e7be01..f94b2a5 100644 --- a/src/openssl_auth.cpp +++ b/src/openssl_auth.cpp @@ -239,17 +239,12 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size) size = static_cast(st.st_size); } - // seek to top of file. - if(-1 == lseek(fd, start, SEEK_SET)){ - return NULL; - } - memset(buf, 0, 512); MD5_Init(&md5ctx); for(ssize_t total = 0; total < size; total += bytes){ bytes = 512 < (size - total) ? 512 : (size - total); - bytes = read(fd, buf, bytes); + bytes = pread(fd, buf, bytes, start + total); if(0 == bytes){ // end of file break; @@ -265,11 +260,6 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size) result = new unsigned char[get_md5_digest_length()]; MD5_Final(result, &md5ctx); - if(-1 == lseek(fd, start, SEEK_SET)){ - delete[] result; - return NULL; - } - return result; } @@ -312,18 +302,13 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size) size = static_cast(st.st_size); } - // seek to top of file. - if(-1 == lseek(fd, start, SEEK_SET)){ - return NULL; - } - sha256ctx = EVP_MD_CTX_create(); EVP_DigestInit_ex(sha256ctx, md, NULL); memset(buf, 0, 512); for(ssize_t total = 0; total < size; total += bytes){ bytes = 512 < (size - total) ? 512 : (size - total); - bytes = read(fd, buf, bytes); + bytes = pread(fd, buf, bytes, start + total); if(0 == bytes){ // end of file break; @@ -340,10 +325,6 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size) EVP_DigestFinal_ex(sha256ctx, result, NULL); EVP_MD_CTX_destroy(sha256ctx); - if(-1 == lseek(fd, start, SEEK_SET)){ - delete[] result; - return NULL; - } return result; }