static int sleepcmd(FILE *input, BSOCK *UA_sock);
-#define CONFIG_FILE "./bconsole.conf" /* default configuration file */
+#define CONFIG_FILE "bconsole.conf" /* default configuration file */
static void usage()
{
extern URES res_all;
#endif
-#define CONFIG_FILE "./bacula-dir.conf" /* default configuration file */
+#define CONFIG_FILE "bacula-dir.conf" /* default configuration file */
static void usage()
{
JOB *job;
int i;
JCR *jcr = ua->jcr;
+ char *escaped_bsr_name = NULL;
+ char *escaped_where_name = NULL;
memset(&rx, 0, sizeof(rx));
rx.path = get_pool_memory(PM_FNAME);
goto bail_out;
}
+ escaped_bsr_name = escape_filename(jcr->RestoreBootstrap);
+ escaped_where_name = escape_filename(rx.where);
+
/* Build run command */
if (rx.where) {
if (!acl_access_ok(ua, Where_ACL, rx.where)) {
bsendmsg(ua, _("Forbidden \"where\" specified.\n"));
goto bail_out;
}
+
Mmsg(ua->cmd,
"run job=\"%s\" client=\"%s\" storage=\"%s\" bootstrap=\"%s\""
" where=\"%s\" files=%d catalog=\"%s\"",
job->name(), rx.ClientName, rx.store?rx.store->name():"",
- jcr->RestoreBootstrap, rx.where, rx.selected_files, ua->catalog->name());
+ escaped_bsr_name ? escaped_bsr_name : jcr->RestoreBootstrap,
+ escaped_where_name ? escaped_where_name : rx.where,
+ rx.selected_files, ua->catalog->name());
} else {
Mmsg(ua->cmd,
"run job=\"%s\" client=\"%s\" storage=\"%s\" bootstrap=\"%s\""
" files=%d catalog=\"%s\"",
job->name(), rx.ClientName, rx.store?rx.store->name():"",
- jcr->RestoreBootstrap, rx.selected_files, ua->catalog->name());
+ escaped_bsr_name ? escaped_bsr_name : jcr->RestoreBootstrap,
+ rx.selected_files, ua->catalog->name());
+ }
+
+ if (escaped_bsr_name != NULL) {
+ bfree(escaped_bsr_name);
+ }
+
+ if (escaped_where_name != NULL) {
+ bfree(escaped_where_name);
}
+
if (find_arg(ua, NT_("yes")) > 0) {
pm_strcat(ua->cmd, " yes"); /* pass it on to the run command */
}
return 1;
bail_out:
+ if (escaped_bsr_name != NULL) {
+ bfree(escaped_bsr_name);
+ }
+
+ if (escaped_where_name != NULL) {
+ bfree(escaped_where_name);
+ }
+
free_rx(&rx);
return 0;
bool no_signals = false;
-#define CONFIG_FILE "./bacula-fd.conf" /* default config file */
+#define CONFIG_FILE "bacula-fd.conf" /* default config file */
char *configfile = NULL;
static bool foreground = false;
/* Separate pathname and filename */
for (q=p=f=ofile; *p; p++) {
- if (*p == '/') {
- f = q; /* possible filename */
- }
#ifdef HAVE_WIN32
- if (*p == '\\') { /* strip backslashes on Win32 */
- continue;
+ if (*p == '\\' || *p == '/') {
+ f = q;
+ if (p[1] == '\\' || p[1] == '/') {
+ p++;
+ }
}
*q++ = *p; /* copy data */
#else
+ if (*p == '/') {
+ f = q; /* possible filename */
+ }
q++;
#endif
}
}
/* Skip over leading slashes. */
+#if defined(HAVE_WIN32)
+ while (*slash == '/' || *slash == '\\')
+ slash++;
+#else
while (*slash == '/')
slash++;
-
+#endif
while (1) {
int newly_created_dir;
int fail;
/* slash points to the leftmost unprocessed component of dirpath. */
basename_dir = slash;
+#if defined(HAVE_WIN32)
+ slash = strpbrk(slash, ":/\\");
+ if (slash == NULL) {
+ break;
+ }
+#else
slash = strchr (slash, '/');
if (slash == NULL) {
break;
}
+#endif
/* If we're *not* doing chdir before each mkdir, then we have to refer
to the target using the full (multi-component) directory name. */
/* Avoid unnecessary calls to `stat' when given
pathnames containing multiple adjacent slashes. */
- while (*slash == '/')
- slash++;
+#if defined(HAVE_WIN32)
+ while (*slash == '/' || *slash == '\\')
+ slash++;
+#else
+ while (*slash == '/')
+ slash++;
+#endif
} /* end while (1) */
if (!cwd.do_chdir) {
{
Mmsg(name, "%s/%s.%s.%d.tmp", working_directory, my_name, what, Id);
}
+
+char *escape_filename(const char *file_path)
+{
+ if (file_path == NULL || strpbrk(file_path, "\"\\") == NULL) {
+ return NULL;
+ }
+
+ char *escaped_path = (char *)bmalloc(2 * (strlen(file_path) + 1));
+ char *cur_char = escaped_path;
+
+ while (*file_path) {
+ if (*file_path == '\\' || *file_path == '"') {
+ *cur_char++ = '\\';
+ }
+
+ *cur_char++ = *file_path++;
+ }
+
+ *cur_char = '\0';
+
+ return escaped_path;
+}
+
+
#include "bacula.h"
+#if defined(HAVE_WIN32)
+#include "shlobj.h"
+#else
+#define MAX_PATH 1024
+#endif
+
/* Each daemon has a slightly different set of
* resources, so it will define the following
* global values.
extern RES **res_head;
#if defined(_MSC_VER)
-// work around visual studio name manling preventing external linkage since res_all
+// work around visual studio name mangling preventing external linkage since res_all
// is declared as a different type when instantiated.
extern "C" CURES res_all;
#else
/* Forward referenced subroutines */
static void scan_types(LEX *lc, MSGS *msg, int dest, char *where, char *cmd);
-
+static const char *get_default_configdir();
+static bool find_config_file(const char *config_file, char *full_path);
/* Common Resource definitions */
if (items[i].handler == store_bit) {
*(int *)(items[i].value) |= items[i].code;
} else if (items[i].handler == store_bool) {
- *(bool *)(items[i].value) = items[i].default_value;
+ *(bool *)(items[i].value) = items[i].default_value != 0;
} else if (items[i].handler == store_pint ||
items[i].handler == store_int) {
*(int *)(items[i].value) = items[i].default_value;
RES_ITEM *items = NULL;
int level = 0;
+ char *full_path = (char *)alloca(MAX_PATH);
+
+ if (find_config_file(cf, full_path)) {
+ cf = full_path;
+ }
+
/* Make two passes. The first builds the name symbol table,
* and the second picks up the items.
*/
return 1;
}
+const char *get_default_configdir()
+{
+#if defined(HAVE_WIN32)
+#define DEFAULT_CONFIGDIR "C:\\Documents and Settings\\All Users\\Application Data\\Bacula"
+
+ HRESULT hr;
+ static char szConfigDir[MAX_PATH + 1] = { 0 };
+
+ if (szConfigDir[0] == '\0') {
+ hr = SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, 0, szConfigDir);
+
+ if (SUCCEEDED(hr)) {
+ bstrncat(szConfigDir, "\\Bacula", sizeof(szConfigDir));
+ } else {
+ bstrncpy(szConfigDir, DEFAULT_CONFIGDIR, sizeof(szConfigDir));
+ }
+ }
+ return szConfigDir;
+#else
+ return "/etc/bacula";
+#endif
+}
+
+bool
+find_config_file(const char *config_file, char *full_path)
+{
+#if defined(HAVE_WIN32)
+ if (strpbrk(config_file, ":/\\") != NULL) {
+ return false;
+ }
+#else
+ if (strchr(config_file, '/') != NULL) {
+ return false;
+ }
+#endif
+
+ struct stat st;
+
+ if (stat(config_file, &st) == 0) {
+ return false;
+ }
+
+ const char *config_dir = get_default_configdir();
+ size_t dir_length = strlen(config_dir);
+ size_t file_length = strlen(config_file);
+
+ if ((dir_length + 1 + file_length + 1) > MAX_PATH) {
+ return false;
+ }
+
+ memcpy(full_path, config_dir, dir_length + 1);
+
+ if (full_path[dir_length - 1] != '/' &&
+ full_path[dir_length - 1] != '\\') {
+ full_path[dir_length++] = '/';
+ }
+
+ memcpy(&full_path[dir_length], config_file, file_length + 1);
+
+ return true;
+}
+
/*********************************************************************
*
* Free configuration resources
#endif
void read_state_file(char *dir, const char *progname, int port);
int bstrerror(int errnum, char *buf, size_t bufsiz);
+char *escape_filename(const char *file_path);
/* bnet.c */
int32_t bnet_recv (BSOCK *bsock);