summaryrefslogtreecommitdiff
path: root/lib/common
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common')
-rw-r--r--lib/common/BannerText.cpp14
-rw-r--r--lib/common/BannerText.h43
-rw-r--r--lib/common/Box.h16
-rw-r--r--lib/common/BoxException.h3
-rw-r--r--lib/common/BoxPlatform.h4
-rw-r--r--lib/common/BoxPortsAndFiles.h.in2
-rw-r--r--lib/common/Configuration.cpp15
-rw-r--r--lib/common/Configuration.h1
-rw-r--r--lib/common/FileStream.h1
-rw-r--r--lib/common/InvisibleTempFileStream.cpp2
-rw-r--r--lib/common/MainHelper.h10
-rw-r--r--lib/common/NamedLock.cpp4
-rw-r--r--lib/common/Test.cpp142
-rw-r--r--lib/common/Test.h8
14 files changed, 110 insertions, 155 deletions
diff --git a/lib/common/BannerText.cpp b/lib/common/BannerText.cpp
new file mode 100644
index 00000000..9ec2c0d7
--- /dev/null
+++ b/lib/common/BannerText.cpp
@@ -0,0 +1,14 @@
+// --------------------------------------------------------------------------
+//
+// File
+// Name: BannerText.cpp
+// Purpose: Banner text for daemons and utilities
+// Created: 2018-08-16
+//
+// --------------------------------------------------------------------------
+
+#include "Box.h"
+
+#include "BannerText.h"
+
+#pragma message("Build signature: " BOX_BUILD_SIGNATURE)
diff --git a/lib/common/BannerText.h b/lib/common/BannerText.h
index 9ca0c11c..a2e412a8 100644
--- a/lib/common/BannerText.h
+++ b/lib/common/BannerText.h
@@ -14,9 +14,48 @@
# include "BoxVersion.h"
#endif
+// Already included by BoxPlatform.h:
+#include <stdint.h>
+
+// Yes, you need two function macros to stringify an expanded macro value.
+// https://stackoverflow.com/questions/5459868/concatenate-int-to-string-using-c-preprocessor
+#define BOX_STRINGIFY_HELPER(x) #x
+#define BOX_STRINGIFY(x) BOX_STRINGIFY_HELPER(x)
+
+// How to identify a 64-bit build: https://stackoverflow.com/a/687902/648162
+#if UINTPTR_MAX == (4294967295U)
+# define BOX_BUILD_BITS 32
+#elif UINTPTR_MAX == (18446744073709551615UL)
+# define BOX_BUILD_BITS 64
+#else
+# pragma message ("UINTPTR_MAX = " BOX_STRINGIFY(UINTPTR_MAX))
+# error Unknown architecture pointer size
+#endif
+
+#ifdef BOX_RELEASE_BUILD
+# define BOX_BUILD_TYPE Release
+#else
+# define BOX_BUILD_TYPE Debug
+#endif
+
+#define STRINGIFY1(x) #x
+#define STRINGIFY2(x) STRINGIFY1(x)
+#ifdef _MSC_VER
+# define BOX_COMPILER "MSVC " STRINGIFY2(_MSC_VER)
+#elif defined __GNUC__
+# define BOX_COMPILER "GCC " __VERSION__
+#elif defined __VERSION__
+// It might be an integer, not a string!
+# define BOX_COMPILER "Unknown " BOX_STRINGIFY(__VERSION__)
+#else
+# define BOX_COMPILER "Unknown"
+#endif
+
+#define BOX_BUILD_SIGNATURE BOX_COMPILER " " BOX_STRINGIFY(BOX_BUILD_BITS) "bit " BOX_STRINGIFY(BOX_BUILD_TYPE)
+
#define BANNER_TEXT(UtilityName) \
- "Box " UtilityName " v" BOX_VERSION ", (c) Ben Summers and " \
- "contributors 2003-2014"
+ "Box Backup " UtilityName " v" BOX_VERSION "\n" \
+ "(c) Ben Summers and contributors 2003-2020. Build type: " BOX_BUILD_SIGNATURE
#endif // BANNERTEXT__H
diff --git a/lib/common/Box.h b/lib/common/Box.h
index 8ce2a625..5f629790 100644
--- a/lib/common/Box.h
+++ b/lib/common/Box.h
@@ -39,7 +39,7 @@
#include "CommonException.h"
#include "Logging.h"
-#ifndef BOX_RELEASE_BUILD
+#ifndef BOX_RELEASE_BUILD // this is a debug build:
extern bool AssertFailuresToSyslog;
#define ASSERT_FAILS_TO_SYSLOG_ON {AssertFailuresToSyslog = true;}
void BoxDebugAssertFailed(const char *cond, const char *file, int line);
@@ -70,7 +70,7 @@
// Exception names
#define EXCEPTION_CODENAMES_EXTENDED
-#else
+#else // this is a release build:
#define ASSERT_FAILS_TO_SYSLOG_ON
#define ASSERT(cond)
@@ -80,19 +80,19 @@
// Box Backup builds release get extra information for exception logging
#define EXCEPTION_CODENAMES_EXTENDED
#define EXCEPTION_CODENAMES_EXTENDED_WITH_DESCRIPTION
+
+ #ifdef BOX_MEMORY_LEAK_TESTING
+ #error BOX_MEMORY_LEAK_TESTING should not already be defined in release builds!
+ #endif
#endif
-#if defined DEBUG_LEAKS
+#if defined DEBUG_LEAKS // optionally enable memory leak debugging even in release builds
#ifdef PLATFORM_DISABLE_MEM_LEAK_TESTING
#error Compiling with DEBUG_LEAKS enabled, but not supported on this platform
#else
#define BOX_MEMORY_LEAK_TESTING
#endif
-#elif defined BOX_RELEASE_BUILD
- #ifndef PLATFORM_DISABLE_MEM_LEAK_TESTING
- #define BOX_MEMORY_LEAK_TESTING
- #endif
-#endif // DEBUG_LEAKS || BOX_RELEASE_BUILD
+#endif // DEBUG_LEAKS
#ifdef BOX_MEMORY_LEAK_TESTING
// Memory leak testing
diff --git a/lib/common/BoxException.h b/lib/common/BoxException.h
index 361f04e8..e3a2268a 100644
--- a/lib/common/BoxException.h
+++ b/lib/common/BoxException.h
@@ -34,6 +34,9 @@ public:
private:
};
+#define EXCEPTION_IS_TYPE(exception_obj, type, subtype) \
+ (exception_obj.GetType() == type::ExceptionType && \
+ exception_obj.GetSubType() == type::subtype)
#endif // BOXEXCEPTION__H
diff --git a/lib/common/BoxPlatform.h b/lib/common/BoxPlatform.h
index f7c74bfc..c86573f6 100644
--- a/lib/common/BoxPlatform.h
+++ b/lib/common/BoxPlatform.h
@@ -48,6 +48,10 @@
#include <sys/types.h>
#endif
+// Need to define this before including stdint.h to ensure access to UINTPTR_MAX in C99:
+// https://stackoverflow.com/questions/986426/what-do-stdc-limit-macros-and-stdc-constant-macros-mean
+#define __STDC_LIMIT_MACROS
+
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#else
diff --git a/lib/common/BoxPortsAndFiles.h.in b/lib/common/BoxPortsAndFiles.h.in
index 8978cd4c..f63e614b 100644
--- a/lib/common/BoxPortsAndFiles.h.in
+++ b/lib/common/BoxPortsAndFiles.h.in
@@ -22,7 +22,7 @@
// default security level if SSLSecurityLevel is not specified: see
// https://github.com/boxbackup/boxbackup/wiki/WeakSSLCertificates
-const int BOX_DEFAULT_SSL_SECURITY_LEVEL = 1;
+const int BOX_DEFAULT_SSL_SECURITY_LEVEL = -1;
// configuration file paths
#ifdef WIN32
diff --git a/lib/common/Configuration.cpp b/lib/common/Configuration.cpp
index 8ce8d389..9860864a 100644
--- a/lib/common/Configuration.cpp
+++ b/lib/common/Configuration.cpp
@@ -470,6 +470,16 @@ int Configuration::GetKeyValueInt(const std::string& rKeyName) const
}
+int Configuration::GetKeyValueInt(const std::string& rKeyName, int default_value) const
+{
+ if(!KeyExists(rKeyName))
+ {
+ return default_value;
+ }
+ return GetKeyValueInt(rKeyName);
+}
+
+
// --------------------------------------------------------------------------
//
// Function
@@ -778,8 +788,7 @@ bool Configuration::Verify(const ConfigurationVerify &rVerify,
}
else if(pvkey->HasDefaultValue())
{
- mKeys[pvkey->Name()] =
- pvkey->DefaultValue();
+ mKeys[pvkey->Name()] = pvkey->DefaultValue();
}
}
@@ -922,5 +931,3 @@ bool Configuration::Verify(const ConfigurationVerify &rVerify,
return ok;
}
-
-
diff --git a/lib/common/Configuration.h b/lib/common/Configuration.h
index e6498e80..f9b5eb77 100644
--- a/lib/common/Configuration.h
+++ b/lib/common/Configuration.h
@@ -122,6 +122,7 @@ public:
bool KeyExists(const std::string& rKeyName) const;
const std::string &GetKeyValue(const std::string& rKeyName) const;
int GetKeyValueInt(const std::string& rKeyName) const;
+ int GetKeyValueInt(const std::string& rKeyName, int default_value) const;
uint32_t GetKeyValueUint32(const std::string& rKeyName) const;
bool GetKeyValueBool(const std::string& rKeyName) const;
std::vector<std::string> GetKeyNames() const;
diff --git a/lib/common/FileStream.h b/lib/common/FileStream.h
index 1426d8a2..26442212 100644
--- a/lib/common/FileStream.h
+++ b/lib/common/FileStream.h
@@ -42,6 +42,7 @@ public:
virtual pos_type BytesLeftToRead();
virtual void Write(const void *pBuffer, int NBytes,
int Timeout = IOStream::TimeOutInfinite);
+ using IOStream::Write;
virtual pos_type GetPosition() const;
virtual void Seek(IOStream::pos_type Offset, int SeekType);
virtual void Close();
diff --git a/lib/common/InvisibleTempFileStream.cpp b/lib/common/InvisibleTempFileStream.cpp
index 1a9d6d5a..d6d04489 100644
--- a/lib/common/InvisibleTempFileStream.cpp
+++ b/lib/common/InvisibleTempFileStream.cpp
@@ -31,7 +31,7 @@ InvisibleTempFileStream::InvisibleTempFileStream(const std::string& Filename,
#endif
{
#ifndef WIN32
- if(unlink(Filename.c_str()) != 0)
+ if(EMU_UNLINK(Filename.c_str()) != 0)
{
MEMLEAKFINDER_NOT_A_LEAK(this);
THROW_EXCEPTION(CommonException, OSFileOpenError)
diff --git a/lib/common/MainHelper.h b/lib/common/MainHelper.h
index 0303090e..f52607bf 100644
--- a/lib/common/MainHelper.h
+++ b/lib/common/MainHelper.h
@@ -16,13 +16,19 @@
# include "BoxVersion.h"
#endif
+#include "BannerText.h"
#include "BoxException.h"
#include "Logging.h"
#define MAINHELPER_START \
- if(argc == 2 && ::strcmp(argv[1], "--version") == 0) \
- { printf(BOX_VERSION "\n"); return 0; } \
+ /* need to init memleakfinder early because we already called MAINHELPER_SETUP_MEMORY_LEAK_EXIT_REPORT */ \
MEMLEAKFINDER_INIT \
+ if(argc == 2 && ::strcmp(argv[1], "--version") == 0) \
+ { \
+ printf("Version: " BOX_VERSION "\n"); \
+ printf("Build: " BOX_BUILD_SIGNATURE "\n"); \
+ return 0; \
+ } \
MEMLEAKFINDER_START \
try {
diff --git a/lib/common/NamedLock.cpp b/lib/common/NamedLock.cpp
index 8e672ff5..08d7c461 100644
--- a/lib/common/NamedLock.cpp
+++ b/lib/common/NamedLock.cpp
@@ -256,7 +256,7 @@ void NamedLock::ReleaseLock()
// Windows, and there we need to close the file before deleting it,
// otherwise the system won't let us delete it.
- if(::unlink(mFileName.c_str()) != 0)
+ if(EMU_UNLINK(mFileName.c_str()) != 0)
{
THROW_EMU_ERROR(
BOX_FILE_MESSAGE(mFileName, "Failed to delete lockfile"),
@@ -287,7 +287,7 @@ void NamedLock::ReleaseLock()
// On Windows we need to close the file before deleting it, otherwise
// the system won't let us delete it.
- if(::unlink(mFileName.c_str()) != 0)
+ if(EMU_UNLINK(mFileName.c_str()) != 0)
{
THROW_EMU_ERROR(
BOX_FILE_MESSAGE(mFileName, "Failed to delete lockfile"),
diff --git a/lib/common/Test.cpp b/lib/common/Test.cpp
index 2c51cd61..c6b28738 100644
--- a/lib/common/Test.cpp
+++ b/lib/common/Test.cpp
@@ -28,7 +28,7 @@
int num_tests_selected = 0;
int num_failures = 0;
-int old_failure_count = 0;
+static int old_failure_count = 0; // do not expose!
int first_fail_line;
std::string original_working_dir;
std::string first_fail_file;
@@ -97,6 +97,8 @@ bool setUp(const char* function_name)
if(StartsWith("TestDir", filename) ||
StartsWith("0_", filename) ||
filename == "accounts.txt" ||
+ filename == "bbackupd-data" ||
+ filename == "ca" ||
StartsWith("file", filename) ||
StartsWith("notifyran", filename) ||
StartsWith("notifyscript.tag", filename) ||
@@ -105,14 +107,16 @@ bool setUp(const char* function_name)
filename == "syncallowscript.control" ||
StartsWith("syncallowscript.notifyran.", filename) ||
filename == "test2.downloaded" ||
- EndsWith("testfile", filename))
+ EndsWith("testfile", filename) ||
+ filename == "tmp" ||
+ EndsWith(".qdbm", filename))
{
std::string filepath = std::string("testfiles\\") + filename;
int filetype = ObjectExists(filepath);
if(filetype == ObjectExists_File)
{
- if(::unlink(filepath.c_str()) != 0)
+ if(EMU_UNLINK(filepath.c_str()) != 0)
{
TEST_FAIL_WITH_MESSAGE(BOX_SYS_ERROR_MESSAGE("Failed to delete "
"test fixture file: unlink(\"" << filepath << "\")"));
@@ -201,7 +205,8 @@ bool setUp(const char* function_name)
"testfiles/restore* testfiles/bbackupd-data "
"testfiles/syncallowscript.control "
"testfiles/syncallowscript.notifyran.* "
- "testfiles/test2.downloaded"
+ "testfiles/test2.downloaded "
+ "testfiles/tmp "
) == 0);
TEST_THAT_THROWONFAIL(system("touch testfiles/accounts.txt") == 0);
#endif
@@ -382,133 +387,6 @@ int ReadPidFile(const char *pidFile)
return pid;
}
-int LaunchServer(const std::string& rCommandLine, const char *pidFile)
-{
- BOX_INFO("Starting server: " << rCommandLine);
-
-#ifdef WIN32
-
- PROCESS_INFORMATION procInfo;
-
- STARTUPINFO startInfo;
- startInfo.cb = sizeof(startInfo);
- startInfo.lpReserved = NULL;
- startInfo.lpDesktop = NULL;
- startInfo.lpTitle = NULL;
- startInfo.dwFlags = 0;
- startInfo.cbReserved2 = 0;
- startInfo.lpReserved2 = NULL;
-
- std::string cmd = ConvertPaths(rCommandLine);
- CHAR* tempCmd = strdup(cmd.c_str());
-
- DWORD result = CreateProcess
- (
- NULL, // lpApplicationName, naughty!
- tempCmd, // lpCommandLine
- NULL, // lpProcessAttributes
- NULL, // lpThreadAttributes
- false, // bInheritHandles
- 0, // dwCreationFlags
- NULL, // lpEnvironment
- NULL, // lpCurrentDirectory
- &startInfo, // lpStartupInfo
- &procInfo // lpProcessInformation
- );
-
- free(tempCmd);
-
- TEST_THAT_OR(result != 0,
- BOX_LOG_WIN_ERROR("Launch failed: " << rCommandLine);
- return -1;
- );
-
- CloseHandle(procInfo.hProcess);
- CloseHandle(procInfo.hThread);
-
- return WaitForServerStartup(pidFile, (int)procInfo.dwProcessId);
-
-#else // !WIN32
-
- TEST_THAT_OR(RunCommand(rCommandLine) == 0,
- TEST_FAIL_WITH_MESSAGE("Failed to start server: " << rCommandLine);
- return -1;
- )
-
- return WaitForServerStartup(pidFile, 0);
-
-#endif // WIN32
-}
-
-int WaitForServerStartup(const char *pidFile, int pidIfKnown)
-{
- #ifdef WIN32
- if (pidFile == NULL)
- {
- return pidIfKnown;
- }
- #else
- // on other platforms there is no other way to get
- // the PID, so a NULL pidFile doesn't make sense.
- ASSERT(pidFile != NULL);
- #endif
-
- // time for it to start up
- BOX_TRACE("Waiting for server to start");
-
- for (int i = 0; i < 15; i++)
- {
- if (TestFileNotEmpty(pidFile))
- {
- break;
- }
-
- if (pidIfKnown && !ServerIsAlive(pidIfKnown))
- {
- break;
- }
-
- ::sleep(1);
- }
-
- // on Win32 we can check whether the process is alive
- // without even checking the PID file
-
- if (pidIfKnown && !ServerIsAlive(pidIfKnown))
- {
- TEST_FAIL_WITH_MESSAGE("Server died!");
- return -1;
- }
-
- if (!TestFileNotEmpty(pidFile))
- {
- TEST_FAIL_WITH_MESSAGE("Server didn't save PID file");
- return -1;
- }
-
- BOX_TRACE("Server started");
-
- // wait a second for the pid to be written to the file
- ::sleep(1);
-
- // read pid file
- int pid = ReadPidFile(pidFile);
-
- // On Win32 we can check whether the PID in the pidFile matches
- // the one returned by the system, which it always should.
-
- if (pidIfKnown && pid != pidIfKnown)
- {
- BOX_ERROR("Server wrote wrong pid to file (" << pidFile <<
- "): expected " << pidIfKnown << " but found " <<
- pid);
- TEST_FAIL_WITH_MESSAGE("Server wrote wrong pid to file");
- return -1;
- }
-
- return pid;
-}
-
void TestRemoteProcessMemLeaksFunc(const char *filename,
const char* file, int line)
{
@@ -550,7 +428,7 @@ void TestRemoteProcessMemLeaksFunc(const char *filename,
}
// Delete it
- ::unlink(filename);
+ EMU_UNLINK(filename);
}
#endif
}
diff --git a/lib/common/Test.h b/lib/common/Test.h
index 32f8220d..35443c29 100644
--- a/lib/common/Test.h
+++ b/lib/common/Test.h
@@ -34,10 +34,13 @@
#define TEST_RETURN_COMMAND(actual, expected, command) TEST_EQUAL_LINE((expected << 8), actual, command);
#endif
+#define DEFAULT_BBSTORED_CONFIG_FILE "testfiles/bbstored.conf"
+#define DEFAULT_BBACKUPD_CONFIG_FILE "testfiles/bbackupd.conf"
+#define DEFAULT_S3_CACHE_DIR "testfiles/bbackupd-cache"
+
extern int num_failures;
extern int first_fail_line;
extern int num_tests_selected;
-extern int old_failure_count;
extern std::string first_fail_file;
extern std::string bbackupd_args, bbstored_args, bbackupquery_args, test_args;
extern std::list<std::string> run_only_named_tests;
@@ -217,6 +220,7 @@ int finish_test_suite();
bool TestFileExists(const char *Filename);
bool TestDirExists(const char *Filename);
+bool TestFileNotEmpty(const char *Filename);
// -1 if doesn't exist
int TestGetFileSize(const std::string& Filename);
@@ -224,8 +228,6 @@ std::string ConvertPaths(const std::string& rOriginal);
int RunCommand(const std::string& rCommandLine);
bool ServerIsAlive(int pid);
int ReadPidFile(const char *pidFile);
-int LaunchServer(const std::string& rCommandLine, const char *pidFile);
-int WaitForServerStartup(const char *pidFile, int pidIfKnown);
#define TestRemoteProcessMemLeaks(filename) \
TestRemoteProcessMemLeaksFunc(filename, __FILE__, __LINE__)