]> git.sur5r.net Git - bacula/bacula/commitdiff
Change daemons and utilities so that if -c is omitted from the command line AND there...
authorRobert Nelson <robertn@the-nelsons.org>
Tue, 24 Oct 2006 23:28:49 +0000 (23:28 +0000)
committerRobert Nelson <robertn@the-nelsons.org>
Tue, 24 Oct 2006 23:28:49 +0000 (23:28 +0000)
Fixed restore on Windows so that backslashes as path separators works.

Add missing query.sql file to Windows installer.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3572 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/console/console.c
bacula/src/dird/dird.c
bacula/src/dird/ua_restore.c
bacula/src/filed/filed.c
bacula/src/findlib/create_file.c
bacula/src/findlib/makepath.c
bacula/src/lib/bsys.c
bacula/src/lib/parse_conf.c
bacula/src/lib/protos.h

index 8bae25bde3f8556c5645a5fab3f755d0d2bdc2fc..331f50ccc871253daddc08b2bb636dc7033db972 100644 (file)
@@ -90,7 +90,7 @@ static int timecmd(FILE *input, BSOCK *UA_sock);
 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()
 {
index df1efeb84806ee3a6eac385c74a781ed401e370f..b8d6491c2d4a5ad9665c6614b7d989bafc46359c 100644 (file)
@@ -70,7 +70,7 @@ extern "C" { // work around visual compiler mangling variables
 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()
 {
index 1ae783b8ee9e3830a12706266799d2d7c0974246..090c78bbaef78cb1d84a958afb6c07fb56aad1f6 100644 (file)
@@ -68,6 +68,8 @@ int restore_cmd(UAContext *ua, const char *cmd)
    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);
@@ -166,24 +168,40 @@ int restore_cmd(UAContext *ua, const char *cmd)
       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 */
    }
@@ -194,6 +212,14 @@ int restore_cmd(UAContext *ua, const char *cmd)
    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;
 
index 2a2ccb9d9751206cfcfbe9ea983250ee4191d81d..fe898e04466c32377506c373902b0a96c9099680 100644 (file)
@@ -36,7 +36,7 @@ CLIENT *me;                           /* my resource */
 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;
index c494ba8f1ea5da0d97983fe46424e0767fc6bde6..3f845c1508e491b3a7956659d527f0663399b989 100644 (file)
@@ -348,15 +348,18 @@ static int separate_path_and_file(JCR *jcr, char *fname, char *ofile)
 
    /* 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
    }
index 2ca799fadffc8ad3d26271e0115a3f66d75e97fd..dbb873b2baaeb0837483fc4cc38e0cc8bfc9a326 100644 (file)
@@ -255,9 +255,13 @@ make_path(
       }
 
       /* 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;
@@ -265,10 +269,17 @@ make_path(
           /* 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.  */
@@ -327,8 +338,13 @@ make_path(
 
           /* 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) {
index a4dc7231aabdb5f9e060da4c8806bbaa395a8405..2869a3fa299e22d46c8f1067351b475c07e75fb2 100644 (file)
@@ -744,3 +744,27 @@ void make_unique_filename(POOLMEM **name, int Id, char *what)
 {
    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;
+}
+
+
index d5a0ceafdaf23a1176312376a7600da13ca2f07f..fb18ada83cf6efb0b66cd25ad1c01ec874bfcaf3 100755 (executable)
 
 #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.
@@ -60,7 +66,7 @@ extern RES_TABLE resources[];
 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
@@ -73,7 +79,8 @@ extern brwlock_t res_lock;            /* resource lock */
 
 /* 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 */
 
@@ -193,7 +200,7 @@ void init_resource(int type, RES_ITEM *items, int pass)
          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;
@@ -768,6 +775,12 @@ parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error, int err_type)
    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.
     */
@@ -895,6 +908,68 @@ parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error, int err_type)
    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
index d0ddd5326e87ed1c8692b5371cd15b88b0a52d79..7d93cfd6389e392acebb722514d519a0b2a44da8 100644 (file)
@@ -62,6 +62,7 @@ long long int strtoll            (const char *ptr, char **endptr, int base);
 #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);