diff options
Diffstat (limited to 'src/Platform/Unix')
-rw-r--r-- | src/Platform/Unix/Directory.cpp | 2 | ||||
-rw-r--r-- | src/Platform/Unix/File.cpp | 2 | ||||
-rw-r--r-- | src/Platform/Unix/FilesystemPath.cpp | 2 | ||||
-rw-r--r-- | src/Platform/Unix/Mutex.cpp | 2 | ||||
-rw-r--r-- | src/Platform/Unix/Pipe.cpp | 2 | ||||
-rw-r--r-- | src/Platform/Unix/Pipe.h | 2 | ||||
-rw-r--r-- | src/Platform/Unix/Poller.cpp | 2 | ||||
-rw-r--r-- | src/Platform/Unix/Poller.h | 2 | ||||
-rw-r--r-- | src/Platform/Unix/Process.cpp | 65 | ||||
-rw-r--r-- | src/Platform/Unix/Process.h | 4 | ||||
-rw-r--r-- | src/Platform/Unix/SyncEvent.cpp | 2 | ||||
-rw-r--r-- | src/Platform/Unix/System.h | 2 | ||||
-rw-r--r-- | src/Platform/Unix/SystemException.cpp | 2 | ||||
-rw-r--r-- | src/Platform/Unix/SystemInfo.cpp | 2 | ||||
-rw-r--r-- | src/Platform/Unix/SystemLog.cpp | 2 | ||||
-rw-r--r-- | src/Platform/Unix/Thread.cpp | 2 | ||||
-rw-r--r-- | src/Platform/Unix/Time.cpp | 2 |
17 files changed, 81 insertions, 18 deletions
diff --git a/src/Platform/Unix/Directory.cpp b/src/Platform/Unix/Directory.cpp index 50de000b..c27af26a 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-2017 IDRIX + and all other portions of this file are Copyright (c) 2013-2025 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 207efb4e..9c35a2e5 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-2017 IDRIX + and all other portions of this file are Copyright (c) 2013-2025 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/FilesystemPath.cpp b/src/Platform/Unix/FilesystemPath.cpp index 1230c2aa..90965448 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-2017 IDRIX + and all other portions of this file are Copyright (c) 2013-2025 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/Mutex.cpp b/src/Platform/Unix/Mutex.cpp index b69a5c6c..6441ee93 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-2017 IDRIX + and all other portions of this file are Copyright (c) 2013-2025 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 b05acd7c..41ebb506 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-2017 IDRIX + and all other portions of this file are Copyright (c) 2013-2025 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 eb79d9dd..b0bf0409 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-2017 IDRIX + and all other portions of this file are Copyright (c) 2013-2025 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 25d2ba71..66ba0ff5 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-2017 IDRIX + and all other portions of this file are Copyright (c) 2013-2025 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 a46c0359..8ae6e7ae 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-2017 IDRIX + and all other portions of this file are Copyright (c) 2013-2025 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 46b14a1e..395d4bc9 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-2017 IDRIX + and all other portions of this file are Copyright (c) 2013-2025 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. */ @@ -26,14 +26,75 @@ #include "Platform/Unix/Poller.h" namespace VeraCrypt { - string Process::Execute (const string &processName, const list <string> &arguments, int timeOut, ProcessExecFunctor *execFunctor, const Buffer *inputData) + + bool Process::IsExecutable(const std::string& path) { + struct stat sb; + if (stat(path.c_str(), &sb) == 0) { + return S_ISREG(sb.st_mode) && (sb.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)); + } + return false; + } + + // Find executable in system paths + std::string Process::FindSystemBinary(const char* name, std::string& errorMsg) { + if (!name) { + errno = EINVAL; // Invalid argument + errorMsg = "Invalid input: name or paths is NULL"; + return ""; + } + + // Default system directories to search for executables +#ifdef TC_MACOSX + const char* defaultDirs[] = {"/usr/local/bin", "/usr/bin", "/bin", "/user/sbin", "/sbin"}; +#elif TC_FREEBSD + const char* defaultDirs[] = {"/sbin", "/bin", "/usr/sbin", "/usr/bin", "/usr/local/sbin", "/usr/local/bin"}; +#elif TC_OPENBSD + const char* defaultDirs[] = {"/sbin", "/bin", "/usr/sbin", "/usr/bin", "/usr/X11R6/bin", "/usr/local/sbin", "/usr/local/bin"}; +#else + const char* defaultDirs[] = {"/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin", "/sbin", "/bin"}; +#endif + const size_t defaultDirCount = sizeof(defaultDirs) / sizeof(defaultDirs[0]); + + std::string currentPath(name); + + // If path doesn't start with '/', prepend default directories + if (currentPath[0] != '/') { + for (size_t i = 0; i < defaultDirCount; ++i) { + std::string combinedPath = std::string(defaultDirs[i]) + "/" + currentPath; + if (IsExecutable(combinedPath)) { + return combinedPath; + } + } + } else if (IsExecutable(currentPath)) { + return currentPath; + } + + // Prepare error message + errno = ENOENT; // No such file or directory + errorMsg = std::string(name) + " not found in system directories"; + return ""; + } + + string Process::Execute (const string &processNameArg, const list <string> &arguments, int timeOut, ProcessExecFunctor *execFunctor, const Buffer *inputData) { char *args[32]; if (array_capacity (args) <= (arguments.size() + 1)) throw ParameterTooLarge (SRC_POS); + // if execFunctor is null and processName is not absolute path, find it in system paths + string processName; + if (!execFunctor && (processNameArg[0] != '/')) + { + std::string errorMsg; + processName = FindSystemBinary(processNameArg.c_str(), errorMsg); + if (processName.empty()) + throw SystemException(SRC_POS, errorMsg); + } + else + processName = processNameArg; + #if 0 stringstream dbg; dbg << "exec " << processName; foreach (const string &at, arguments) diff --git a/src/Platform/Unix/Process.h b/src/Platform/Unix/Process.h index bb8482f2..83215956 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-2017 IDRIX + and all other portions of this file are Copyright (c) 2013-2025 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. */ @@ -30,8 +30,10 @@ namespace VeraCrypt public: Process (); virtual ~Process (); + static bool IsExecutable(const std::string& path); + static std::string FindSystemBinary(const char* name, std::string& errorMsg); static string Execute (const string &processName, const list <string> &arguments, int timeOut = -1, ProcessExecFunctor *execFunctor = nullptr, const Buffer *inputData = nullptr); protected: diff --git a/src/Platform/Unix/SyncEvent.cpp b/src/Platform/Unix/SyncEvent.cpp index 0336164b..f186e555 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-2017 IDRIX + and all other portions of this file are Copyright (c) 2013-2025 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 7225dae2..b6a6f092 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-2017 IDRIX + and all other portions of this file are Copyright (c) 2013-2025 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 428edfe7..b29e0370 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-2017 IDRIX + and all other portions of this file are Copyright (c) 2013-2025 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 f09674aa..530d3b4b 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-2017 IDRIX + and all other portions of this file are Copyright (c) 2013-2025 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/SystemLog.cpp b/src/Platform/Unix/SystemLog.cpp index 72221375..95b20074 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-2017 IDRIX + and all other portions of this file are Copyright (c) 2013-2025 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 099c4658..febf9ab2 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-2017 IDRIX + and all other portions of this file are Copyright (c) 2013-2025 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 356dde74..055938f9 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-2017 IDRIX + and all other portions of this file are Copyright (c) 2013-2025 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. */ |