VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Platform/Unix
diff options
context:
space:
mode:
Diffstat (limited to 'src/Platform/Unix')
-rw-r--r--src/Platform/Unix/Directory.cpp2
-rw-r--r--src/Platform/Unix/File.cpp57
-rw-r--r--src/Platform/Unix/FilesystemPath.cpp35
-rw-r--r--src/Platform/Unix/Mutex.cpp2
-rw-r--r--src/Platform/Unix/Pipe.cpp2
-rw-r--r--src/Platform/Unix/Pipe.h2
-rw-r--r--src/Platform/Unix/Poller.cpp2
-rw-r--r--src/Platform/Unix/Poller.h2
-rw-r--r--src/Platform/Unix/Process.cpp35
-rw-r--r--src/Platform/Unix/Process.h2
-rw-r--r--src/Platform/Unix/SyncEvent.cpp2
-rw-r--r--src/Platform/Unix/System.h2
-rw-r--r--src/Platform/Unix/SystemException.cpp2
-rw-r--r--src/Platform/Unix/SystemInfo.cpp4
-rw-r--r--src/Platform/Unix/SystemLog.cpp2
-rw-r--r--src/Platform/Unix/Thread.cpp2
-rw-r--r--src/Platform/Unix/Time.cpp2
17 files changed, 111 insertions, 46 deletions
diff --git a/src/Platform/Unix/Directory.cpp b/src/Platform/Unix/Directory.cpp
index 9c0590cb..50de000b 100644
--- a/src/Platform/Unix/Directory.cpp
+++ b/src/Platform/Unix/Directory.cpp
@@ -3,9 +3,9 @@
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
diff --git a/src/Platform/Unix/File.cpp b/src/Platform/Unix/File.cpp
index 5c45dcfc..207efb4e 100644
--- a/src/Platform/Unix/File.cpp
+++ b/src/Platform/Unix/File.cpp
@@ -3,9 +3,9 @@
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
@@ -22,8 +22,14 @@
#ifdef TC_BSD
#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>
#endif
@@ -31,8 +37,12 @@
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
+#ifdef TC_FREEBSD
+#include <sys/sysctl.h>
+#endif
+
#include "Platform/File.h"
#include "Platform/TextReader.h"
namespace VeraCrypt
@@ -112,8 +122,13 @@ namespace VeraCrypt
u_int sectorSize;
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));
return mediaInfo.dki_lbsize;
@@ -145,8 +160,33 @@ namespace VeraCrypt
uint64 offset;
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;
throw_sys_sub_if (ioctl (FileHandle, DKIOCEXTPARTINFO, &partInfo) == -1, wstring (Path));
@@ -170,15 +210,30 @@ namespace VeraCrypt
uint64 blockCount;
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));
return mediaSize;
# 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);
uint64 length = lseek (FileHandle, 0, SEEK_CUR);
diff --git a/src/Platform/Unix/FilesystemPath.cpp b/src/Platform/Unix/FilesystemPath.cpp
index f5d59f9f..1230c2aa 100644
--- a/src/Platform/Unix/FilesystemPath.cpp
+++ b/src/Platform/Unix/FilesystemPath.cpp
@@ -3,9 +3,9 @@
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
@@ -14,8 +14,11 @@
#include "Platform/SystemException.h"
#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
{
void FilesystemPath::Delete () const
@@ -71,8 +74,31 @@ namespace VeraCrypt
#ifdef TC_LINUX
path = StringConverter::StripTrailingNumber (StringConverter::ToSingle (Path));
+ // If simply removing trailing number didn't produce a valid drive name, try to use sysfs to get the right one
+ if (!path.IsDevice()) {
+ struct stat st;
+
+ if(stat (StringConverter::ToSingle (Path).c_str (), &st) == 0) {
+ const long maxPathLength = pathconf ("/", _PC_PATH_MAX);
+
+ if(maxPathLength != -1) {
+ string linkPathName ("/sys/dev/block/");
+ linkPathName += StringConverter::ToSingle (major (st.st_rdev)) + string (":") + StringConverter::ToSingle (minor (st.st_rdev));
+
+ vector<char> linkTargetPath(maxPathLength+1);
+
+ if(readlink(linkPathName.c_str (), linkTargetPath.data(), linkTargetPath.size()) != -1) {
+ const string targetPathStr (linkTargetPath.data());
+ const size_t lastSlashPos = targetPathStr.find_last_of ('/');
+ const size_t secondLastSlashPos = targetPathStr.find_last_of ('/', lastSlashPos-1);
+ path = string ("/dev/") + targetPathStr.substr (secondLastSlashPos+1, lastSlashPos-secondLastSlashPos-1);
+ }
+ }
+ }
+ }
+
#elif defined (TC_MACOSX)
string pathStr = StringConverter::StripTrailingNumber (StringConverter::ToSingle (Path));
path = pathStr.substr (0, pathStr.size() - 1);
@@ -80,10 +106,13 @@ namespace VeraCrypt
#elif defined (TC_FREEBSD)
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/Mutex.cpp b/src/Platform/Unix/Mutex.cpp
index a6b61de6..b69a5c6c 100644
--- a/src/Platform/Unix/Mutex.cpp
+++ b/src/Platform/Unix/Mutex.cpp
@@ -3,9 +3,9 @@
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
diff --git a/src/Platform/Unix/Pipe.cpp b/src/Platform/Unix/Pipe.cpp
index f427ae63..b05acd7c 100644
--- a/src/Platform/Unix/Pipe.cpp
+++ b/src/Platform/Unix/Pipe.cpp
@@ -3,9 +3,9 @@
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
diff --git a/src/Platform/Unix/Pipe.h b/src/Platform/Unix/Pipe.h
index 72af91bd..eb79d9dd 100644
--- a/src/Platform/Unix/Pipe.h
+++ b/src/Platform/Unix/Pipe.h
@@ -3,9 +3,9 @@
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
diff --git a/src/Platform/Unix/Poller.cpp b/src/Platform/Unix/Poller.cpp
index 6b845631..25d2ba71 100644
--- a/src/Platform/Unix/Poller.cpp
+++ b/src/Platform/Unix/Poller.cpp
@@ -3,9 +3,9 @@
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
diff --git a/src/Platform/Unix/Poller.h b/src/Platform/Unix/Poller.h
index 054fe75e..a46c0359 100644
--- a/src/Platform/Unix/Poller.h
+++ b/src/Platform/Unix/Poller.h
@@ -3,9 +3,9 @@
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
diff --git a/src/Platform/Unix/Process.cpp b/src/Platform/Unix/Process.cpp
index 92a8f478..46b14a1e 100644
--- a/src/Platform/Unix/Process.cpp
+++ b/src/Platform/Unix/Process.cpp
@@ -3,9 +3,9 @@
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
@@ -29,9 +29,9 @@ 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
stringstream dbg;
@@ -52,35 +52,15 @@ 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)
{
@@ -138,9 +118,8 @@ namespace VeraCrypt
throw_sys_if (fcntl (errPipe.GetReadFD(), F_SETFL, O_NONBLOCK) == -1);
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 ();
@@ -189,14 +168,14 @@ namespace VeraCrypt
throw_sys_if (waitRes == -1);
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());
}
catch (...) { }
diff --git a/src/Platform/Unix/Process.h b/src/Platform/Unix/Process.h
index d19d5737..bb8482f2 100644
--- a/src/Platform/Unix/Process.h
+++ b/src/Platform/Unix/Process.h
@@ -3,9 +3,9 @@
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
diff --git a/src/Platform/Unix/SyncEvent.cpp b/src/Platform/Unix/SyncEvent.cpp
index 10bbc0c9..0336164b 100644
--- a/src/Platform/Unix/SyncEvent.cpp
+++ b/src/Platform/Unix/SyncEvent.cpp
@@ -3,9 +3,9 @@
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
diff --git a/src/Platform/Unix/System.h b/src/Platform/Unix/System.h
index 30384907..7225dae2 100644
--- a/src/Platform/Unix/System.h
+++ b/src/Platform/Unix/System.h
@@ -3,9 +3,9 @@
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
diff --git a/src/Platform/Unix/SystemException.cpp b/src/Platform/Unix/SystemException.cpp
index be051cc0..428edfe7 100644
--- a/src/Platform/Unix/SystemException.cpp
+++ b/src/Platform/Unix/SystemException.cpp
@@ -3,9 +3,9 @@
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
diff --git a/src/Platform/Unix/SystemInfo.cpp b/src/Platform/Unix/SystemInfo.cpp
index c3e3ab38..f09674aa 100644
--- a/src/Platform/Unix/SystemInfo.cpp
+++ b/src/Platform/Unix/SystemInfo.cpp
@@ -3,9 +3,9 @@
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
@@ -23,8 +23,10 @@ namespace VeraCrypt
#elif defined (TC_MACOSX)
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
# error GetPlatformName() undefined
diff --git a/src/Platform/Unix/SystemLog.cpp b/src/Platform/Unix/SystemLog.cpp
index 88027e40..72221375 100644
--- a/src/Platform/Unix/SystemLog.cpp
+++ b/src/Platform/Unix/SystemLog.cpp
@@ -3,9 +3,9 @@
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
diff --git a/src/Platform/Unix/Thread.cpp b/src/Platform/Unix/Thread.cpp
index 2d9fae09..099c4658 100644
--- a/src/Platform/Unix/Thread.cpp
+++ b/src/Platform/Unix/Thread.cpp
@@ -3,9 +3,9 @@
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
diff --git a/src/Platform/Unix/Time.cpp b/src/Platform/Unix/Time.cpp
index e98cea69..356dde74 100644
--- a/src/Platform/Unix/Time.cpp
+++ b/src/Platform/Unix/Time.cpp
@@ -3,9 +3,9 @@
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/