summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2016-05-18 22:59:46 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2016-05-18 22:59:46 +0900
commit949a580a14cd3afcdf9904acd1d32397c344dd28 (patch)
treeeefafd27a0d683902faf65b6dd4ca1427bc99218
parent1603d8ea7bb0074f8e268f37bc941fa5dffba067 (diff)
mingw32: Gain privilege before opening files
-rw-r--r--src/FallocFileAllocationIterator.cc17
-rw-r--r--src/FallocFileAllocationIterator.h4
-rw-r--r--src/RequestGroup.cc29
-rw-r--r--src/option_processing.cc10
4 files changed, 29 insertions, 31 deletions
diff --git a/src/FallocFileAllocationIterator.cc b/src/FallocFileAllocationIterator.cc
index 04590557..ec64c539 100644
--- a/src/FallocFileAllocationIterator.cc
+++ b/src/FallocFileAllocationIterator.cc
@@ -39,28 +39,11 @@
namespace aria2 {
-#ifdef __MINGW32__
-bool FallocFileAllocationIterator::gainPrivilegeAttempted_ = false;
-#endif // __MINGW32__
-
FallocFileAllocationIterator::FallocFileAllocationIterator(BinaryStream* stream,
int64_t offset,
int64_t totalLength)
: stream_(stream), offset_(offset), totalLength_(totalLength)
{
-#ifdef __MINGW32__
- // Windows build: --file-allocation=falloc uses SetFileValidData
- // which requires SE_MANAGE_VOLUME_NAME privilege. SetFileValidData
- // has security implications (see
- // https://msdn.microsoft.com/en-us/library/windows/desktop/aa365544%28v=vs.85%29.aspx).
- if (!gainPrivilegeAttempted_) {
- if (!util::gainPrivilege(SE_MANAGE_VOLUME_NAME)) {
- A2_LOG_WARN("--file-allocation=falloc will not work properly.");
- }
-
- gainPrivilegeAttempted_ = true;
- }
-#endif // __MINGW32__
}
void FallocFileAllocationIterator::allocateChunk()
diff --git a/src/FallocFileAllocationIterator.h b/src/FallocFileAllocationIterator.h
index 08b8b4a1..fb306af1 100644
--- a/src/FallocFileAllocationIterator.h
+++ b/src/FallocFileAllocationIterator.h
@@ -47,10 +47,6 @@ private:
int64_t offset_;
int64_t totalLength_;
-#ifdef __MINGW32__
- static bool gainPrivilegeAttempted_;
-#endif // __MINGW32__
-
public:
FallocFileAllocationIterator(BinaryStream* stream, int64_t offset,
int64_t totalLength);
diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc
index 85b75a45..fd8cda49 100644
--- a/src/RequestGroup.cc
+++ b/src/RequestGroup.cc
@@ -604,6 +604,35 @@ void RequestGroup::initPieceStorage()
segmentMan_ =
std::make_shared<SegmentMan>(downloadContext_, tempPieceStorage);
pieceStorage_ = tempPieceStorage;
+
+#ifdef __MINGW32__
+ // Windows build: --file-allocation=falloc uses SetFileValidData
+ // which requires SE_MANAGE_VOLUME_NAME privilege. SetFileValidData
+ // has security implications (see
+ // https://msdn.microsoft.com/en-us/library/windows/desktop/aa365544%28v=vs.85%29.aspx).
+ static auto gainPrivilegeAttempted = false;
+
+ if (!gainPrivilegeAttempted &&
+ pieceStorage_->getDiskAdaptor()->getFileAllocationMethod() ==
+ DiskAdaptor::FILE_ALLOC_FALLOC &&
+ isFileAllocationEnabled()) {
+ if (!util::gainPrivilege(SE_MANAGE_VOLUME_NAME)) {
+ A2_LOG_WARN("--file-allocation=falloc will not work properly.");
+ }
+ else {
+ A2_LOG_DEBUG("SE_MANAGE_VOLUME_NAME privilege acquired");
+
+ A2_LOG_WARN(
+ "--file-allocation=falloc will use SetFileValidData() API, and "
+ "aria2 uses uninitialized disk space which may contain "
+ "confidential data as the download file space. If it is "
+ "undesirable, --file-allocation=prealloc is slower, but safer "
+ "option.");
+ }
+
+ gainPrivilegeAttempted = true;
+ }
+#endif // __MINGW32__
}
void RequestGroup::dropPieceStorage()
diff --git a/src/option_processing.cc b/src/option_processing.cc
index f6b12358..652a3bd3 100644
--- a/src/option_processing.cc
+++ b/src/option_processing.cc
@@ -341,16 +341,6 @@ error_code::Value option_processing(Option& op, bool standalone,
op.remove(PREF_DEFERRED_INPUT);
}
-#ifdef __MINGW32__
- if (op.get(PREF_FILE_ALLOCATION) == V_FALLOC) {
- A2_LOG_WARN(
- "--file-allocation=falloc will use SetFileValidData() API, and "
- "aria2 uses uninitialized disk space which may contain "
- "confidential data as the download file space. If it is "
- "undesirable, --file-allocation=prealloc is slower, but safer option.");
- }
-#endif // __MINGW32__
-
return error_code::FINISHED;
}