VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Platform
diff options
context:
space:
mode:
Diffstat (limited to 'src/Platform')
-rw-r--r--src/Platform/Buffer.cpp2
-rw-r--r--src/Platform/Exception.h4
-rw-r--r--src/Platform/File.h6
-rw-r--r--src/Platform/Memory.cpp6
-rw-r--r--src/Platform/Memory.h2
-rw-r--r--src/Platform/SharedPtr.h17
-rw-r--r--src/Platform/StringConverter.cpp2
-rw-r--r--src/Platform/Unix/File.cpp55
-rw-r--r--src/Platform/Unix/FilesystemPath.cpp9
-rw-r--r--src/Platform/Unix/Process.cpp5
-rw-r--r--src/Platform/Unix/SystemInfo.cpp2
11 files changed, 92 insertions, 18 deletions
diff --git a/src/Platform/Buffer.cpp b/src/Platform/Buffer.cpp
index 7c61dc48..82c2a3f1 100644
--- a/src/Platform/Buffer.cpp
+++ b/src/Platform/Buffer.cpp
@@ -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/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/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..e0d4bfe3 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);
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..e1a6df98 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 (...)
{
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, &sectorSize) == -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 674b395b..1230c2aa 100644
--- a/src/Platform/Unix/FilesystemPath.cpp
+++ b/src/Platform/Unix/FilesystemPath.cpp
@@ -15,7 +15,7 @@
#include "Platform/StringConverter.h"
#include <stdio.h>
#include <sys/stat.h>
-#if !defined(__FreeBSD__) && !defined(__APPLE__)
+#if !defined(__FreeBSD__) && !defined(__APPLE__) && !defined(__OpenBSD__)
#include <sys/sysmacros.h>
#endif
@@ -107,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 ac8598f0..36b01e6b 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
@@ -119,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 ();
@@ -170,7 +169,7 @@ namespace VeraCrypt
if (!exOutput.empty())
{
- auto_ptr <Serializable> deserializedObject;
+ unique_ptr <Serializable> deserializedObject;
Exception *deserializedException = nullptr;
try
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