summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/backupstore/BackupStoreConfigVerify.cpp8
-rw-r--r--lib/common/BoxPortsAndFiles.h23
-rw-r--r--lib/common/Guards.h6
-rw-r--r--lib/win32/emu.cpp70
-rw-r--r--lib/win32/emu.h4
5 files changed, 83 insertions, 28 deletions
diff --git a/lib/backupstore/BackupStoreConfigVerify.cpp b/lib/backupstore/BackupStoreConfigVerify.cpp
index 6fa05d06..784adfb8 100644
--- a/lib/backupstore/BackupStoreConfigVerify.cpp
+++ b/lib/backupstore/BackupStoreConfigVerify.cpp
@@ -35,7 +35,13 @@ static const ConfigurationVerifyKey verifyrootkeys[] =
{"AccountDatabase", 0, ConfigTest_Exists, 0},
{"TimeBetweenHousekeeping", 0, ConfigTest_Exists | ConfigTest_IsInt, 0},
{"ExtendedLogging", "no", ConfigTest_IsBool, 0}, // make value "yes" to enable in config file
- {"RaidFileConf", BOX_FILE_RAIDFILE_DEFAULT_CONFIG, ConfigTest_LastEntry, 0}
+
+ #ifdef WIN32
+ {"RaidFileConf", "", ConfigTest_LastEntry, 0}
+ #else
+ {"RaidFileConf", BOX_FILE_RAIDFILE_DEFAULT_CONFIG, ConfigTest_LastEntry, 0}
+ #endif
+
};
const ConfigurationVerify BackupConfigFileVerify =
diff --git a/lib/common/BoxPortsAndFiles.h b/lib/common/BoxPortsAndFiles.h
index 562c6724..a6ca9f6d 100644
--- a/lib/common/BoxPortsAndFiles.h
+++ b/lib/common/BoxPortsAndFiles.h
@@ -14,20 +14,27 @@
// Backup store daemon
-#define BOX_PORT_BBSTORED (BOX_PORT_BASE+1)
-#define BOX_FILE_BBSTORED_DEFAULT_CONFIG "/etc/box/bbstored.conf"
+#define BOX_PORT_BBSTORED (BOX_PORT_BASE+1)
+
// directory within the RAIDFILE root for the backup store daemon
-#define BOX_RAIDFILE_ROOT_BBSTORED "backup"
+#define BOX_RAIDFILE_ROOT_BBSTORED "backup"
-// Backup client daemon
+// configuration file paths
#ifdef WIN32
-#define BOX_FILE_BBACKUPD_DEFAULT_CONFIG "C:\\Program Files\\Box Backup\\bbackupd.conf"
+ // no default config file path, use these macros to call
+ // GetDefaultConfigFilePath() instead.
+
+ #define BOX_GET_DEFAULT_BBACKUPD_CONFIG_FILE \
+ GetDefaultConfigFilePath("bbackupd.conf").c_str()
+ #define BOX_GET_DEFAULT_RAIDFILE_CONFIG_FILE \
+ GetDefaultConfigFilePath("raidfile.conf").c_str()
+ #define BOX_GET_DEFAULT_BBSTORED_CONFIG_FILE \
+ GetDefaultConfigFilePath("bbstored.conf").c_str()
#else
#define BOX_FILE_BBACKUPD_DEFAULT_CONFIG "/etc/box/bbackupd.conf"
-#endif
-
-// RaidFile conf location default
#define BOX_FILE_RAIDFILE_DEFAULT_CONFIG "/etc/box/raidfile.conf"
+#define BOX_FILE_BBSTORED_DEFAULT_CONFIG "/etc/box/bbstored.conf"
+#endif
// Default name of the named pipe
#define BOX_NAMED_PIPE_NAME L"\\\\.\\pipe\\boxbackup"
diff --git a/lib/common/Guards.h b/lib/common/Guards.h
index fbcfedaf..d2fb84e0 100644
--- a/lib/common/Guards.h
+++ b/lib/common/Guards.h
@@ -32,13 +32,13 @@ template <int flags = O_RDONLY | O_BINARY, int mode = (S_IRUSR | S_IWUSR | S_IRG
class FileHandleGuard
{
public:
- FileHandleGuard(const char *filename)
- : mOSFileHandle(::open(filename, flags, mode))
+ FileHandleGuard(const std::string& rFilename)
+ : mOSFileHandle(::open(rFilename.c_str(), flags, mode))
{
if(mOSFileHandle < 0)
{
BOX_ERROR("FileHandleGuard: failed to open file '" <<
- filename << "': " << strerror(errno));
+ rFilename << "': " << strerror(errno));
THROW_EXCEPTION(CommonException, OSFileOpenError)
}
}
diff --git a/lib/win32/emu.cpp b/lib/win32/emu.cpp
index 4224d62e..1a6b0e79 100644
--- a/lib/win32/emu.cpp
+++ b/lib/win32/emu.cpp
@@ -218,6 +218,44 @@ bool EnableBackupRights( void )
}
}
+// forward declaration
+char* ConvertFromWideString(const WCHAR* pString, unsigned int codepage);
+
+// --------------------------------------------------------------------------
+//
+// Function
+// Name: GetDefaultConfigFilePath(std::string name)
+// Purpose: Calculates the default configuration file name,
+// by using the directory location of the currently
+// executing program, and appending the provided name.
+// In case of fire, returns an empty string.
+// Created: 26th May 2007
+//
+// --------------------------------------------------------------------------
+std::string GetDefaultConfigFilePath(const std::string& rName)
+{
+ WCHAR exePathWide[MAX_PATH];
+ GetModuleFileNameW(NULL, exePathWide, MAX_PATH-1);
+
+ char* exePathUtf8 = ConvertFromWideString(exePathWide, CP_UTF8);
+ if (exePathUtf8 == NULL)
+ {
+ return "";
+ }
+
+ std::string configfile = exePathUtf8;
+ delete [] exePathUtf8;
+
+ // make the default config file name,
+ // based on the program path
+ configfile = configfile.substr(0,
+ configfile.rfind('\\'));
+ configfile += "\\";
+ configfile += rName;
+
+ return configfile;
+}
+
// --------------------------------------------------------------------------
//
// Function
@@ -1252,15 +1290,15 @@ BOOL AddEventSource
// Work out the executable file name, to register ourselves
// as the event source
- char cmd[MAX_PATH];
- if (GetModuleFileName(NULL, cmd, sizeof(cmd)-1) == 0)
+ WCHAR cmd[MAX_PATH];
+ DWORD len = GetModuleFileNameW(NULL, cmd, MAX_PATH);
+
+ if (len == 0)
{
::syslog(LOG_ERR, "Failed to get the program file name: %s",
GetErrorMessage(GetLastError()).c_str());
return FALSE;
}
- cmd[sizeof(cmd)-1] = 0;
- std::string exepath(cmd);
// Create the event source as a subkey of the log.
@@ -1282,12 +1320,12 @@ BOOL AddEventSource
// Set the name of the message file.
- if (RegSetValueEx(hk, // subkey handle
- "EventMessageFile", // value name
- 0, // must be zero
- REG_EXPAND_SZ, // value type
- (LPBYTE) exepath.c_str(), // pointer to value data
- (DWORD) (exepath.size()))) // data size
+ if (RegSetValueExW(hk, // subkey handle
+ L"EventMessageFile", // value name
+ 0, // must be zero
+ REG_EXPAND_SZ, // value type
+ (LPBYTE)cmd, // pointer to value data
+ len*sizeof(WCHAR))) // data size
{
::syslog(LOG_ERR, "Failed to set the event message file: %s",
GetErrorMessage(GetLastError()).c_str());
@@ -1315,12 +1353,12 @@ BOOL AddEventSource
// Set the category message file and number of categories.
- if (RegSetValueEx(hk, // subkey handle
- "CategoryMessageFile", // value name
- 0, // must be zero
- REG_EXPAND_SZ, // value type
- (LPBYTE) exepath.c_str(), // pointer to value data
- (DWORD) (exepath.size()))) // data size
+ if (RegSetValueExW(hk, // subkey handle
+ L"CategoryMessageFile", // value name
+ 0, // must be zero
+ REG_EXPAND_SZ, // value type
+ (LPBYTE)cmd, // pointer to value data
+ len*sizeof(WCHAR))) // data size
{
::syslog(LOG_ERR, "Failed to set the category message file: "
"%s", GetErrorMessage(GetLastError()).c_str());
diff --git a/lib/win32/emu.h b/lib/win32/emu.h
index 1f078c14..8ab74130 100644
--- a/lib/win32/emu.h
+++ b/lib/win32/emu.h
@@ -377,6 +377,10 @@ bool ConvertFromUtf8 (const std::string& rSource, std::string& rDest,
bool ConvertUtf8ToConsole(const char* pString, std::string& rDest);
bool ConvertConsoleToUtf8(const char* pString, std::string& rDest);
+// Utility function which returns a default config file name,
+// based on the path of the current executable.
+std::string GetDefaultConfigFilePath(const std::string& rName);
+
// GetErrorMessage() returns a system error message, like strerror()
// but for Windows error codes.
std::string GetErrorMessage(DWORD errorCode);