]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/findlib/makepath.c
Update doc
[bacula/bacula] / bacula / src / findlib / makepath.c
index 74324fc108a32682741d3a7e96fc61fcea38b82e..69ef9c9e97f942989f83567131ebddc606bdadcd 100644 (file)
@@ -90,7 +90,7 @@ cleanup(struct saved_cwd *cwd)
    (indicating success) and will set *CREATED_DIR_P to zero.  */
 
 static int
-make_dir(void *jcr, const char *dir, const char *dirpath, mode_t mode, int *created_dir_p)
+make_dir(JCR *jcr, const char *dir, const char *dirpath, mode_t mode, int *created_dir_p)
 {
   int fail = 0;
   int created_dir;
@@ -130,6 +130,18 @@ make_dir(void *jcr, const char *dir, const char *dirpath, mode_t mode, int *crea
   return fail;
 }
 
+/* return non-zero if path is absolute or zero if relative. */
+  
+int
+isAbsolute(const char *path)
+{
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
+    return path[1] == ':' || *path == '/' || *path == '\\';     /* drivespec:/blah is absolute */
+#else
+    return *path == '/';
+#endif   
+}
+    
 /* Ensure that the directory ARGPATH exists.
    Remove any trailing slashes from ARGPATH before calling this function.
 
@@ -154,7 +166,7 @@ make_dir(void *jcr, const char *dir, const char *dirpath, mode_t mode, int *crea
 
 int
 make_path(
-          void *jcr,
+          JCR *jcr,
           const char *argpath,
           int mode,
           int parent_mode,
@@ -200,6 +212,12 @@ make_path(
         re_protect = 0;
       }
 
+#if defined(HAVE_CYGWIN)
+      /* Because of silly Win32 security, we allow everything */
+      tmp_mode = S_IRWXUGO;
+      re_protect = 0;
+#endif
+
       /* If we can record the current working directory, we may be able
         to do the chdir optimization.  */
       cwd.do_chdir = !save_cwd(&cwd);
@@ -207,7 +225,7 @@ make_path(
       /* If we've saved the cwd and DIRPATH is an absolute pathname,
          we must chdir to `/' in order to enable the chdir optimization.
          So if chdir ("/") fails, turn off the optimization.  */
-      if (cwd.do_chdir && *dirpath == '/' && chdir ("/") < 0) {
+      if (cwd.do_chdir && isAbsolute(dirpath) && (chdir("/") < 0)) {
         cwd.do_chdir = 0;
       }
 
@@ -253,7 +271,7 @@ make_path(
 #endif
                  ) {
                 /* Note, if we are restoring as NON-root, this may not be fatal */
-                 Jmsg(jcr, M_WARNING, 0, _("Cannot change owner and/or group of %s: ERR=%s\n"),
+                 Jmsg(jcr, M_ERROR, 0, _("Cannot change owner and/or group of %s: ERR=%s\n"),
                      quote(dirpath), strerror(errno));
              }
               Dmsg0(300, "Chown done.\n");
@@ -342,7 +360,7 @@ make_path(
           Dmsg2(300, "Reset parent mode=%o dir=%s\n", parent_mode, dirpath);
          if (chmod(dirpath, parent_mode)) {
               Jmsg(jcr, M_WARNING, 0, _("Cannot change permissions of %s: ERR=%s\n"),
-                    quote (dirpath), strerror(errno));
+                    quote(dirpath), strerror(errno));
          }
       }
   } else {