diff options
Diffstat (limited to 'src/Platform')
-rw-r--r-- | src/Platform/Buffer.cpp | 4 | ||||
-rw-r--r-- | src/Platform/Buffer.h | 26 | ||||
-rw-r--r-- | src/Platform/Exception.h | 4 | ||||
-rw-r--r-- | src/Platform/File.h | 6 | ||||
-rw-r--r-- | src/Platform/FileStream.h | 2 | ||||
-rw-r--r-- | src/Platform/Memory.cpp | 6 | ||||
-rw-r--r-- | src/Platform/Memory.h | 30 | ||||
-rw-r--r-- | src/Platform/MemoryStream.cpp | 2 | ||||
-rw-r--r-- | src/Platform/MemoryStream.h | 2 | ||||
-rw-r--r-- | src/Platform/PlatformBase.h | 4 | ||||
-rw-r--r-- | src/Platform/PlatformTest.cpp | 6 | ||||
-rw-r--r-- | src/Platform/Serializer.cpp | 26 | ||||
-rw-r--r-- | src/Platform/Serializer.h | 4 | ||||
-rw-r--r-- | src/Platform/SharedPtr.h | 17 | ||||
-rw-r--r-- | src/Platform/StringConverter.cpp | 6 | ||||
-rw-r--r-- | src/Platform/TextReader.cpp | 2 | ||||
-rw-r--r-- | src/Platform/Unix/File.cpp | 55 | ||||
-rw-r--r-- | src/Platform/Unix/FilesystemPath.cpp | 10 | ||||
-rw-r--r-- | src/Platform/Unix/Process.cpp | 33 | ||||
-rw-r--r-- | src/Platform/Unix/SystemInfo.cpp | 2 |
20 files changed, 152 insertions, 95 deletions
diff --git a/src/Platform/Buffer.cpp b/src/Platform/Buffer.cpp index 7c61dc48..5829b1d9 100644 --- a/src/Platform/Buffer.cpp +++ b/src/Platform/Buffer.cpp @@ -44,7 +44,7 @@ namespace VeraCrypt try { - DataPtr = static_cast<byte *> ((alignment > 0)? Memory::AllocateAligned (size, alignment) : Memory::Allocate (size)); + DataPtr = static_cast<uint8 *> ((alignment > 0)? Memory::AllocateAligned (size, alignment) : Memory::Allocate (size)); DataSize = size; DataAlignment = alignment; } @@ -77,7 +77,7 @@ namespace VeraCrypt void Buffer::Erase () { if (DataSize > 0) - Memory::Erase (DataPtr, DataSize); + burn (DataPtr, DataSize); } void Buffer::Free () diff --git a/src/Platform/Buffer.h b/src/Platform/Buffer.h index 1150fcf5..a1eb0918 100644 --- a/src/Platform/Buffer.h +++ b/src/Platform/Buffer.h @@ -24,20 +24,20 @@ namespace VeraCrypt public: ConstBufferPtr () : DataPtr (nullptr), DataSize (0) { } - ConstBufferPtr (const byte *data, size_t size) + ConstBufferPtr (const uint8 *data, size_t size) : DataPtr (data), DataSize (size) { } virtual ~ConstBufferPtr () { } - operator const byte * () const { return DataPtr; } + operator const uint8 * () const { return DataPtr; } bool IsDataEqual (const ConstBufferPtr &other) const { return Memory::Compare (DataPtr, DataSize, other.DataPtr, other.DataSize) == 0; } - const byte *Get () const { return DataPtr; } + const uint8 *Get () const { return DataPtr; } ConstBufferPtr GetRange (size_t offset, size_t size) const; - void Set (const byte *data, size_t size) { DataPtr = data; DataSize = size; } + void Set (const uint8 *data, size_t size) { DataPtr = data; DataSize = size; } size_t Size () const { return DataSize; } protected: - const byte *DataPtr; + const uint8 *DataPtr; size_t DataSize; }; @@ -47,23 +47,23 @@ namespace VeraCrypt public: BufferPtr () : DataPtr (nullptr), DataSize (0) { } - BufferPtr (byte *data, size_t size) + BufferPtr (uint8 *data, size_t size) : DataPtr (data), DataSize (size) { } virtual ~BufferPtr () { } - operator byte * () const { return DataPtr; } + operator uint8 * () const { return DataPtr; } void CopyFrom (const ConstBufferPtr &bufferPtr) const; void Erase () const { Zero(); } - byte *Get () const { return DataPtr; } + uint8 *Get () const { return DataPtr; } BufferPtr GetRange (size_t offset, size_t size) const; - void Set (byte *data, size_t size) { DataPtr = data; DataSize = size; } + void Set (uint8 *data, size_t size) { DataPtr = data; DataSize = size; } size_t Size () const { return DataSize; } void Zero () const { Memory::Zero (DataPtr, DataSize); } operator ConstBufferPtr () const { return ConstBufferPtr (DataPtr, DataSize); } protected: - byte *DataPtr; + uint8 *DataPtr; size_t DataSize; }; @@ -77,7 +77,7 @@ namespace VeraCrypt virtual void Allocate (size_t size, size_t alignment = 0); virtual void CopyFrom (const ConstBufferPtr &bufferPtr, size_t alignment = 0); - virtual byte *Ptr () const { return DataPtr; } + virtual uint8 *Ptr () const { return DataPtr; } virtual void Erase (); virtual void Free (); virtual BufferPtr GetRange (size_t offset, size_t size) const; @@ -86,12 +86,12 @@ namespace VeraCrypt virtual bool IsAllocated () const { return DataSize != 0; } virtual void Zero (); - virtual operator byte * () const { return DataPtr; } + virtual operator uint8 * () const { return DataPtr; } virtual operator BufferPtr () const { return BufferPtr (DataPtr, DataSize); } virtual operator ConstBufferPtr () const { return ConstBufferPtr (DataPtr, DataSize); } protected: - byte *DataPtr; + uint8 *DataPtr; size_t DataSize; size_t DataAlignment; diff --git a/src/Platform/Exception.h b/src/Platform/Exception.h index 71cfa1c5..36981a74 100644 --- a/src/Platform/Exception.h +++ b/src/Platform/Exception.h @@ -82,6 +82,7 @@ namespace VeraCrypt TC_EXCEPTION_NODECL (ExecutedProcessFailed); \ TC_EXCEPTION (AlreadyInitialized); \ TC_EXCEPTION (AssertionFailed); \ + TC_EXCEPTION (DeviceSectorSizeMismatch); \ TC_EXCEPTION (ExternalException); \ TC_EXCEPTION (InsufficientData); \ TC_EXCEPTION (NotApplicable); \ @@ -91,11 +92,10 @@ namespace VeraCrypt TC_EXCEPTION (ParameterTooLarge); \ TC_EXCEPTION (PartitionDeviceRequired); \ TC_EXCEPTION (StringConversionFailed); \ + TC_EXCEPTION (TerminalNotFound); \ TC_EXCEPTION (TestFailed); \ TC_EXCEPTION (TimeOut); \ TC_EXCEPTION (UnknownException); \ - TC_EXCEPTION (UnsupportedAlgoInTrueCryptMode); \ - TC_EXCEPTION (UnsupportedTrueCryptFormat); \ TC_EXCEPTION (UserAbort) TC_EXCEPTION_SET; diff --git a/src/Platform/File.h b/src/Platform/File.h index 09924b29..a8befe38 100644 --- a/src/Platform/File.h +++ b/src/Platform/File.h @@ -54,7 +54,11 @@ namespace VeraCrypt typedef int SystemFileHandleType; #endif - File () : FileIsOpen (false), SharedHandle (false) { } + File () : FileIsOpen (false), mFileOpenFlags (FlagsNone), SharedHandle (false), FileHandle (0) +#ifndef TC_WINDOWS + ,AccTime(0), ModTime (0) +#endif + { } virtual ~File (); void AssignSystemHandle (SystemFileHandleType openFileHandle, bool sharedHandle = true) diff --git a/src/Platform/FileStream.h b/src/Platform/FileStream.h index 0ef40862..66df1999 100644 --- a/src/Platform/FileStream.h +++ b/src/Platform/FileStream.h @@ -43,7 +43,7 @@ namespace VeraCrypt vector <char> buffer (4096); uint64 len; - while ((len = DataFile->Read (BufferPtr (reinterpret_cast <byte *> (&buffer[0]), buffer.size()))) > 0) + while ((len = DataFile->Read (BufferPtr (reinterpret_cast <uint8 *> (&buffer[0]), buffer.size()))) > 0) str.insert (str.end(), buffer.begin(), buffer.begin() + static_cast <int> (len)); return str; diff --git a/src/Platform/Memory.cpp b/src/Platform/Memory.cpp index 785f758c..c4afed64 100644 --- a/src/Platform/Memory.cpp +++ b/src/Platform/Memory.cpp @@ -10,7 +10,6 @@ code distribution packages. */ -#include "Common/Tcdefs.h" #include "Memory.h" #include "Exception.h" #include <stdlib.h> @@ -62,11 +61,6 @@ namespace VeraCrypt memcpy (memoryDestination, memorySource, size); } - void Memory::Erase (void *memory, size_t size) - { - burn (memory, size); - } - void Memory::Zero (void *memory, size_t size) { memset (memory, 0, size); diff --git a/src/Platform/Memory.h b/src/Platform/Memory.h index 2b022dfd..b124022f 100644 --- a/src/Platform/Memory.h +++ b/src/Platform/Memory.h @@ -16,6 +16,7 @@ #include <new> #include <memory.h> #include "PlatformBase.h" +#include "Common/Tcdefs.h" #ifdef TC_WINDOWS @@ -76,7 +77,6 @@ namespace VeraCrypt static void *AllocateAligned (size_t size, size_t alignment); static int Compare (const void *memory1, size_t size1, const void *memory2, size_t size2); static void Copy (void *memoryDestination, const void *memorySource, size_t size); - static void Erase (void *memory, size_t size); static void Free (void *memory); static void FreeAligned (void *memory); static void Zero (void *memory, size_t size); @@ -85,7 +85,7 @@ namespace VeraCrypt class Endian { public: - static byte Big (const byte &x) + static uint8 Big (const uint8 &x) { return x; } @@ -117,7 +117,7 @@ namespace VeraCrypt #endif } - static byte Little (const byte &x) + static uint8 Little (const uint8 &x) { return x; } @@ -157,22 +157,22 @@ namespace VeraCrypt static uint32 MirrorBytes (const uint32 &x) { - uint32 n = (byte) x; - n <<= 8; n |= (byte) (x >> 8); - n <<= 8; n |= (byte) (x >> 16); - return (n << 8) | (byte) (x >> 24); + uint32 n = (uint8) x; + n <<= 8; n |= (uint8) (x >> 8); + n <<= 8; n |= (uint8) (x >> 16); + return (n << 8) | (uint8) (x >> 24); } static uint64 MirrorBytes (const uint64 &x) { - uint64 n = (byte) x; - n <<= 8; n |= (byte) (x >> 8); - n <<= 8; n |= (byte) (x >> 16); - n <<= 8; n |= (byte) (x >> 24); - n <<= 8; n |= (byte) (x >> 32); - n <<= 8; n |= (byte) (x >> 40); - n <<= 8; n |= (byte) (x >> 48); - return (n << 8) | (byte) (x >> 56); + uint64 n = (uint8) x; + n <<= 8; n |= (uint8) (x >> 8); + n <<= 8; n |= (uint8) (x >> 16); + n <<= 8; n |= (uint8) (x >> 24); + n <<= 8; n |= (uint8) (x >> 32); + n <<= 8; n |= (uint8) (x >> 40); + n <<= 8; n |= (uint8) (x >> 48); + return (n << 8) | (uint8) (x >> 56); } }; } diff --git a/src/Platform/MemoryStream.cpp b/src/Platform/MemoryStream.cpp index 8bf229fe..1bd090b9 100644 --- a/src/Platform/MemoryStream.cpp +++ b/src/Platform/MemoryStream.cpp @@ -18,7 +18,7 @@ namespace VeraCrypt MemoryStream::MemoryStream (const ConstBufferPtr &data) : ReadPosition (0) { - Data = vector <byte> (data.Size()); + Data = vector <uint8> (data.Size()); BufferPtr (&Data[0], Data.size()).CopyFrom (data); } diff --git a/src/Platform/MemoryStream.h b/src/Platform/MemoryStream.h index 3df0bd13..068e6d6e 100644 --- a/src/Platform/MemoryStream.h +++ b/src/Platform/MemoryStream.h @@ -32,7 +32,7 @@ namespace VeraCrypt virtual void Write (const ConstBufferPtr &data); protected: - vector <byte> Data; + vector <uint8> Data; size_t ReadPosition; }; } diff --git a/src/Platform/PlatformBase.h b/src/Platform/PlatformBase.h index 22022dc7..e378704c 100644 --- a/src/Platform/PlatformBase.h +++ b/src/Platform/PlatformBase.h @@ -43,7 +43,7 @@ namespace VeraCrypt typedef __int16 int16; typedef __int32 int32; typedef __int64 int64; - typedef unsigned __int8 byte; + typedef unsigned __int8 uint8; typedef unsigned __int16 uint16; typedef unsigned __int32 uint32; typedef unsigned __int64 uint64; @@ -53,7 +53,7 @@ namespace VeraCrypt typedef int16_t int16; typedef int32_t int32; typedef int64_t int64; - typedef uint8_t byte; + typedef uint8_t uint8; typedef uint16_t uint16; typedef uint32_t uint32; typedef uint64_t uint64; diff --git a/src/Platform/PlatformTest.cpp b/src/Platform/PlatformTest.cpp index 7362d6bf..9a3faae2 100644 --- a/src/Platform/PlatformTest.cpp +++ b/src/Platform/PlatformTest.cpp @@ -76,7 +76,7 @@ namespace VeraCrypt Buffer buffer (10); for (size_t i = 0; i < buffer.Size(); i++) - buffer[i] = (byte) i; + buffer[i] = (uint8) i; ser.Serialize ("int32", i32); ser.Serialize ("int64", i64); @@ -141,7 +141,7 @@ namespace VeraCrypt Buffer dbuffer (10); ser.Deserialize ("buffer", buffer); for (size_t i = 0; i < buffer.Size(); i++) - if (buffer[i] != (byte) i) + if (buffer[i] != (uint8) i) throw TestFailed (SRC_POS); shared_ptr <ExecutedProcessFailed> dex = Serializable::DeserializeNew <ExecutedProcessFailed> (stream); @@ -238,7 +238,7 @@ namespace VeraCrypt bool PlatformTest::TestAll () { // Integer types - if (sizeof (byte) != 1 || sizeof (int8) != 1 || sizeof (__int8) != 1) throw TestFailed (SRC_POS); + if (sizeof (uint8) != 1 || sizeof (int8) != 1 || sizeof (__int8) != 1) throw TestFailed (SRC_POS); if (sizeof (uint16) != 2 || sizeof (int16) != 2 || sizeof (__int16) != 2) throw TestFailed (SRC_POS); if (sizeof (uint32) != 4 || sizeof (int32) != 4 || sizeof (__int32) != 4) throw TestFailed (SRC_POS); if (sizeof (uint64) != 8 || sizeof (int64) != 8) throw TestFailed (SRC_POS); diff --git a/src/Platform/Serializer.cpp b/src/Platform/Serializer.cpp index b69fe891..6f428b15 100644 --- a/src/Platform/Serializer.cpp +++ b/src/Platform/Serializer.cpp @@ -21,13 +21,13 @@ namespace VeraCrypt T Serializer::Deserialize () { uint64 size; - DataStream->ReadCompleteBuffer (BufferPtr ((byte *) &size, sizeof (size))); + DataStream->ReadCompleteBuffer (BufferPtr ((uint8 *) &size, sizeof (size))); if (Endian::Big (size) != sizeof (T)) throw ParameterIncorrect (SRC_POS); T data; - DataStream->ReadCompleteBuffer (BufferPtr ((byte *) &data, sizeof (data))); + DataStream->ReadCompleteBuffer (BufferPtr ((uint8 *) &data, sizeof (data))); return Endian::Big (data); } @@ -35,13 +35,13 @@ namespace VeraCrypt void Serializer::Deserialize (const string &name, bool &data) { ValidateName (name); - data = Deserialize <byte> () == 1; + data = Deserialize <uint8> () == 1; } - void Serializer::Deserialize (const string &name, byte &data) + void Serializer::Deserialize (const string &name, uint8 &data) { ValidateName (name); - data = Deserialize <byte> (); + data = Deserialize <uint8> (); } void Serializer::Deserialize (const string &name, int32 &data) @@ -127,7 +127,7 @@ namespace VeraCrypt uint64 size = Deserialize <uint64> (); vector <char> data ((size_t) size); - DataStream->ReadCompleteBuffer (BufferPtr ((byte *) &data[0], (size_t) size)); + DataStream->ReadCompleteBuffer (BufferPtr ((uint8 *) &data[0], (size_t) size)); return string (&data[0]); } @@ -155,7 +155,7 @@ namespace VeraCrypt uint64 size = Deserialize <uint64> (); vector <wchar_t> data ((size_t) size / sizeof (wchar_t)); - DataStream->ReadCompleteBuffer (BufferPtr ((byte *) &data[0], (size_t) size)); + DataStream->ReadCompleteBuffer (BufferPtr ((uint8 *) &data[0], (size_t) size)); return wstring (&data[0]); } @@ -182,20 +182,20 @@ namespace VeraCrypt void Serializer::Serialize (T data) { uint64 size = Endian::Big (uint64 (sizeof (data))); - DataStream->Write (ConstBufferPtr ((byte *) &size, sizeof (size))); + DataStream->Write (ConstBufferPtr ((uint8 *) &size, sizeof (size))); data = Endian::Big (data); - DataStream->Write (ConstBufferPtr ((byte *) &data, sizeof (data))); + DataStream->Write (ConstBufferPtr ((uint8 *) &data, sizeof (data))); } void Serializer::Serialize (const string &name, bool data) { SerializeString (name); - byte d = data ? 1 : 0; + uint8 d = data ? 1 : 0; Serialize (d); } - void Serializer::Serialize (const string &name, byte data) + void Serializer::Serialize (const string &name, uint8 data) { SerializeString (name); Serialize (data); @@ -282,14 +282,14 @@ namespace VeraCrypt void Serializer::SerializeString (const string &data) { Serialize ((uint64) data.size() + 1); - DataStream->Write (ConstBufferPtr ((byte *) (data.data() ? data.data() : data.c_str()), data.size() + 1)); + DataStream->Write (ConstBufferPtr ((uint8 *) (data.data() ? data.data() : data.c_str()), data.size() + 1)); } void Serializer::SerializeWString (const wstring &data) { uint64 size = (data.size() + 1) * sizeof (wchar_t); Serialize (size); - DataStream->Write (ConstBufferPtr ((byte *) (data.data() ? data.data() : data.c_str()), (size_t) size)); + DataStream->Write (ConstBufferPtr ((uint8 *) (data.data() ? data.data() : data.c_str()), (size_t) size)); } void Serializer::ValidateName (const string &name) diff --git a/src/Platform/Serializer.h b/src/Platform/Serializer.h index c2dac324..3617a83b 100644 --- a/src/Platform/Serializer.h +++ b/src/Platform/Serializer.h @@ -27,7 +27,7 @@ namespace VeraCrypt virtual ~Serializer () { } void Deserialize (const string &name, bool &data); - void Deserialize (const string &name, byte &data); + void Deserialize (const string &name, uint8 &data); void Deserialize (const string &name, int32 &data); void Deserialize (const string &name, int64 &data); void Deserialize (const string &name, uint32 &data); @@ -45,7 +45,7 @@ namespace VeraCrypt wstring DeserializeWString (const string &name); list <wstring> DeserializeWStringList (const string &name); void Serialize (const string &name, bool data); - void Serialize (const string &name, byte data); + void Serialize (const string &name, uint8 data); void Serialize (const string &name, const char *data); void Serialize (const string &name, int32 data); void Serialize (const string &name, int64 data); diff --git a/src/Platform/SharedPtr.h b/src/Platform/SharedPtr.h index 7675c2a5..f80b2167 100644 --- a/src/Platform/SharedPtr.h +++ b/src/Platform/SharedPtr.h @@ -14,12 +14,25 @@ #define TC_HEADER_Platform_SharedPtr #include <stdexcept> +#include <memory> #include "SharedVal.h" #ifdef nullptr namespace VeraCrypt { +#if (__cplusplus >= 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X__) + #define VC_USE_NATIVE_PTR 1 +#endif + +#ifdef VC_USE_NATIVE_PTR + +#define shared_ptr std::shared_ptr +#define make_shared std::make_shared +#define move_ptr std::move + +#else + template <class T> class SharedPtr { @@ -157,6 +170,10 @@ namespace VeraCrypt #define make_shared VeraCrypt::make_shared +#define unique_ptr auto_ptr +#define move_ptr(p) p + +#endif } #endif // nullptr diff --git a/src/Platform/StringConverter.cpp b/src/Platform/StringConverter.cpp index 6975bb39..7b3134ee 100644 --- a/src/Platform/StringConverter.cpp +++ b/src/Platform/StringConverter.cpp @@ -233,7 +233,7 @@ namespace VeraCrypt str.clear(); str.insert (0, &buf.front(), size); - Memory::Erase (&buf.front(), buf.size()); + burn (&buf.front(), buf.size()); } catch (...) { @@ -385,9 +385,9 @@ namespace VeraCrypt } BufferPtr ( - (byte *) buffer, + (uint8 *) buffer, bufferSize).CopyFrom ( - ConstBufferPtr ((byte *) (wstring (str).c_str()), + ConstBufferPtr ((uint8 *) (wstring (str).c_str()), (str.length() + 1) * sizeof (wchar_t) ) ); diff --git a/src/Platform/TextReader.cpp b/src/Platform/TextReader.cpp index 7d6a0c64..bdaf19c2 100644 --- a/src/Platform/TextReader.cpp +++ b/src/Platform/TextReader.cpp @@ -26,7 +26,7 @@ namespace VeraCrypt outputString.erase(); char c; - while (InputStream->Read (BufferPtr ((byte *) &c, sizeof (c))) == sizeof (c)) + while (InputStream->Read (BufferPtr ((uint8 *) &c, sizeof (c))) == sizeof (c)) { if (c == '\r') continue; diff --git a/src/Platform/Unix/File.cpp b/src/Platform/Unix/File.cpp index cfb17e13..207efb4e 100644 --- a/src/Platform/Unix/File.cpp +++ b/src/Platform/Unix/File.cpp @@ -23,6 +23,12 @@ #include <sys/disk.h> #endif +#ifdef TC_OPENBSD +#include <sys/ioctl.h> +#include <sys/dkio.h> +#include <sys/disklabel.h> +#endif + #ifdef TC_SOLARIS #include <stropts.h> #include <sys/dkio.h> @@ -32,6 +38,10 @@ #include <sys/types.h> #include <sys/stat.h> +#ifdef TC_FREEBSD +#include <sys/sysctl.h> +#endif + #include "Platform/File.h" #include "Platform/TextReader.h" @@ -113,6 +123,11 @@ namespace VeraCrypt throw_sys_sub_if (ioctl (FileHandle, DIOCGSECTORSIZE, §orSize) == -1, wstring (Path)); return (uint32) sectorSize; +#elif defined (TC_OPENBSD) + struct disklabel dl; + throw_sys_sub_if (ioctl (FileHandle, DIOCGPDINFO, &dl) == -1, wstring (Path)); + return (uint32) dl.d_secsize; + #elif defined (TC_SOLARIS) struct dk_minfo mediaInfo; throw_sys_sub_if (ioctl (FileHandle, DKIOCGMEDIAINFO, &mediaInfo) == -1, wstring (Path)); @@ -146,6 +161,31 @@ namespace VeraCrypt throw_sys_sub_if (ioctl (FileHandle, DKIOCGETBASE, &offset) == -1, wstring (Path)); return offset; +#elif defined (TC_FREEBSD) + // Get the kernel GEOM configuration + size_t sysctlDataLen, mibLen; + int mib[4]; + mibLen = 4; + throw_sys_sub_if (sysctlnametomib ("kern.geom.conftxt", mib, &mibLen), wstring (Path)); + throw_sys_sub_if (sysctl (mib, mibLen, NULL, &sysctlDataLen, NULL, 0), wstring (Path)); + vector<char> conftxt(sysctlDataLen); + throw_sys_sub_if (sysctl (mib, mibLen, (void *)conftxt.data(), &sysctlDataLen, NULL, 0), wstring (Path)); + + // Find the slice/partition data + string conftxtStr (conftxt.begin(), conftxt.end()); + size_t confLoc = conftxtStr.find (Path.ToBaseName()); + throw_sys_sub_if (confLoc == string::npos, wstring (Path)); + + // Skip to the ninth column + for (int i = 0; i < 6;i++) { + confLoc = conftxtStr.find (" ", confLoc + 1); + throw_sys_sub_if (confLoc == string::npos, wstring (Path)); + } + confLoc++; + size_t end = conftxtStr.find (" ", confLoc); + throw_sys_sub_if (end == string::npos, wstring (Path)); + return StringConverter::ToUInt64 (conftxtStr.substr (confLoc, end - confLoc)); + #elif defined (TC_SOLARIS) struct extpart_info partInfo; @@ -171,6 +211,10 @@ namespace VeraCrypt throw_sys_sub_if (ioctl (FileHandle, DKIOCGETBLOCKSIZE, &blockSize) == -1, wstring (Path)); throw_sys_sub_if (ioctl (FileHandle, DKIOCGETBLOCKCOUNT, &blockCount) == -1, wstring (Path)); return blockCount * blockSize; +# elif TC_OPENBSD + struct disklabel dl; + throw_sys_sub_if (ioctl (FileHandle, DIOCGPDINFO, &dl) == -1, wstring (Path)); + return DL_GETDSIZE(&dl); # else uint64 mediaSize; throw_sys_sub_if (ioctl (FileHandle, DIOCGMEDIASIZE, &mediaSize) == -1, wstring (Path)); @@ -178,6 +222,17 @@ namespace VeraCrypt # endif } #endif +#ifdef TC_LINUX + // On Linux, try to use BLKGETSIZE64 for devices + if (Path.IsDevice()) + { + uint64 mediaSize; + if (ioctl (FileHandle, BLKGETSIZE64, &mediaSize) != -1) + { + return mediaSize; + } + } +#endif off_t current = lseek (FileHandle, 0, SEEK_CUR); throw_sys_sub_if (current == -1, wstring (Path)); SeekEnd (0); diff --git a/src/Platform/Unix/FilesystemPath.cpp b/src/Platform/Unix/FilesystemPath.cpp index d6c9cd2b..1230c2aa 100644 --- a/src/Platform/Unix/FilesystemPath.cpp +++ b/src/Platform/Unix/FilesystemPath.cpp @@ -15,6 +15,9 @@ #include "Platform/StringConverter.h" #include <stdio.h> #include <sys/stat.h> +#if !defined(__FreeBSD__) && !defined(__APPLE__) && !defined(__OpenBSD__) +#include <sys/sysmacros.h> +#endif namespace VeraCrypt { @@ -104,8 +107,11 @@ namespace VeraCrypt string pathStr = StringConverter::ToSingle (Path); size_t p = pathStr.rfind ("s"); - if (p == string::npos) - throw PartitionDeviceRequired (SRC_POS); + if (p == string::npos) { + p = pathStr.rfind ("p"); + if (p == string::npos) + throw PartitionDeviceRequired (SRC_POS); + } path = pathStr.substr (0, p); #elif defined (TC_SOLARIS) diff --git a/src/Platform/Unix/Process.cpp b/src/Platform/Unix/Process.cpp index 4a7f9a15..46b14a1e 100644 --- a/src/Platform/Unix/Process.cpp +++ b/src/Platform/Unix/Process.cpp @@ -30,7 +30,7 @@ namespace VeraCrypt string Process::Execute (const string &processName, const list <string> &arguments, int timeOut, ProcessExecFunctor *execFunctor, const Buffer *inputData) { char *args[32]; - if (array_capacity (args) <= arguments.size()) + if (array_capacity (args) <= (arguments.size() + 1)) throw ParameterTooLarge (SRC_POS); #if 0 @@ -53,33 +53,13 @@ namespace VeraCrypt try { int argIndex = 0; - /* Workaround for gcc 5.X issue related to the use of STL (string and list) with muliple fork calls. - * - * The char* pointers retrieved from the elements of parameter "arguments" are no longer valid after - * a second fork is called. "arguments" was created in the parent of the current child process. - * - * The only solution is to copy the elements of "arguments" parameter in a local string array on this - * child process and then use char* pointers retrieved from this local copies before calling fork. - * - * gcc 4.x doesn't suffer from this issue. - * - */ - string argsCopy[array_capacity (args)]; if (!execFunctor) - { - argsCopy[argIndex++] = processName; - } - - foreach (const string &arg, arguments) - { - argsCopy[argIndex++] = arg; - } + args[argIndex++] = const_cast <char*> (processName.c_str()); - for (int i = 0; i < argIndex; i++) + for (list<string>::const_iterator it = arguments.begin(); it != arguments.end(); it++) { - args[i] = const_cast <char*> (argsCopy[i].c_str()); + args[argIndex++] = const_cast <char*> (it->c_str()); } - args[argIndex] = nullptr; if (inputData) @@ -139,7 +119,6 @@ namespace VeraCrypt throw_sys_if (fcntl (exceptionPipe.GetReadFD(), F_SETFL, O_NONBLOCK) == -1); vector <char> buffer (4096), stdOutput (4096), errOutput (4096), exOutput (4096); - buffer.clear (); stdOutput.clear (); errOutput.clear (); exOutput.clear (); @@ -190,12 +169,12 @@ namespace VeraCrypt if (!exOutput.empty()) { - auto_ptr <Serializable> deserializedObject; + unique_ptr <Serializable> deserializedObject; Exception *deserializedException = nullptr; try { - shared_ptr <Stream> stream (new MemoryStream (ConstBufferPtr ((byte *) &exOutput[0], exOutput.size()))); + shared_ptr <Stream> stream (new MemoryStream (ConstBufferPtr ((uint8 *) &exOutput[0], exOutput.size()))); deserializedObject.reset (Serializable::DeserializeNew (stream)); deserializedException = dynamic_cast <Exception*> (deserializedObject.get()); } diff --git a/src/Platform/Unix/SystemInfo.cpp b/src/Platform/Unix/SystemInfo.cpp index d4f648bb..f09674aa 100644 --- a/src/Platform/Unix/SystemInfo.cpp +++ b/src/Platform/Unix/SystemInfo.cpp @@ -24,6 +24,8 @@ namespace VeraCrypt return L"Mac OS X"; #elif defined (TC_FREEBSD) return L"FreeBSD"; +#elif defined (TC_OPENBSD) + return L"OpenBSD"; #elif defined (TC_SOLARIS) return L"Solaris"; #else |