]> git.sur5r.net Git - bacula/bacula/commitdiff
Allow restore as non-root
authorKern Sibbald <kern@sibbald.com>
Tue, 25 Mar 2003 20:35:36 +0000 (20:35 +0000)
committerKern Sibbald <kern@sibbald.com>
Tue, 25 Mar 2003 20:35:36 +0000 (20:35 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@395 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/kernstodo
bacula/src/filed/win32/winservice.cpp
bacula/src/findlib/attribs.c
bacula/src/findlib/create_file.c
bacula/src/findlib/makepath.c
bacula/src/findlib/save-cwd.c

index b143903f8fd1227752543c0f72db48c835f1d994..6cb668b54109edee36390f1242fffe828320f603 100644 (file)
@@ -1,5 +1,5 @@
                  Kern's ToDo List
-                 13 March 2003 
+                  25 March 2003 
 
 Documentation to do: (a little bit at a time)
 - Document running a test version.
index d5ffc4c8f46a76c1196eb2c198e6d34fbb59f9a0..91e30b234606176cef10c1c472b40857e2e81d2f 100755 (executable)
@@ -71,6 +71,11 @@ bacService::bacService()
    } else {
       g_platform_id = osversioninfo.dwPlatformId;
    }
+   if (osversioninfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS &&
+       osversioninfo.dwMinorVersion == 0) {
+       /* Running Win95 so no GetFileAttributesEx available */
+       NoGetFileAttributesEx = 1;
+   }
 }
 
 
@@ -336,15 +341,6 @@ bacService::BaculaServiceMain()
          break;
       }
 
-      /* Test for GetFileAttributesEx which is not in Win95 */
-      if (GetProcAddress(kerneldll, "GetFileAttributesEx") == NULL) {
-          NoGetFileAttributesEx = 1;
-          /*****FIXME***** remove after testing */
-          MessageBox(NULL, "winserv NoGetFileAttributesEx", "Bacula", MB_OK);
-      } else { 
-          MessageBox(NULL, "winserv Got GetFileAttributesEx", "Bacula", MB_OK);
-      }
-
       // And find the RegisterServiceProcess function
       DWORD (*RegisterService)(DWORD, DWORD);
       RegisterService = (DWORD (*)(DWORD, DWORD))
index 3d8576761683eb3e50ad8b21ca3313711cc2c948..97823977c6dd4e357bbca668e51011e6e2054660 100755 (executable)
@@ -170,6 +170,8 @@ int set_attributes(void *jcr, char *fname, char *ofile, char *lname,
                   char *attribsEx, int *ofd)
 {
    struct utimbuf ut;   
+   mode_t old_mask;
+   int stat = 1;
 
 #ifdef HAVE_CYGWIN
    if (set_win32_attributes(jcr, fname, ofile, lname, type, stream,
@@ -183,6 +185,7 @@ int set_attributes(void *jcr, char *fname, char *ofile, char *lname,
     */
 #endif
 
+   old_mask = umask(0);
    if (*ofd != -1) {
       close(*ofd);                   /* first close file */
       *ofd = -1;
@@ -194,21 +197,21 @@ int set_attributes(void *jcr, char *fname, char *ofile, char *lname,
    /* ***FIXME**** optimize -- don't do if already correct */
    if (type == FT_LNK) {
       if (lchown(ofile, statp->st_uid, statp->st_gid) < 0) {
-         Jmsg2(jcr, M_ERROR, 0, "Unable to set file owner %s: ERR=%s\n",
+         Jmsg2(jcr, M_WARNING, 0, "Unable to set file owner %s: ERR=%s\n",
            ofile, strerror(errno));
-        return 0;
+        stat = 0;
       }
    } else {
       if (chown(ofile, statp->st_uid, statp->st_gid) < 0) {
-         Jmsg2(jcr, M_ERROR, 0, "Unable to set file owner %s: ERR=%s\n",
+         Jmsg2(jcr, M_WARNING, 0, "Unable to set file owner %s: ERR=%s\n",
            ofile, strerror(errno));
-        return 0;
+        stat = 0;
       }
    }
    if (chmod(ofile, statp->st_mode) < 0) {
       Jmsg2(jcr, M_ERROR, 0, "Unable to set file modes %s: ERR=%s\n",
         ofile, strerror(errno));
-      return 0;
+      stat = 0;
    }
 
    /*
@@ -217,9 +220,10 @@ int set_attributes(void *jcr, char *fname, char *ofile, char *lname,
    if (utime(ofile, &ut) < 0) {
       Jmsg2(jcr, M_ERROR, 0, "Unable to set file times %s: ERR=%s\n",
         ofile, strerror(errno));
-      return 0;
+      stat = 0;
    }
-   return 1;
+   umask(old_mask);
+   return stat;
 }
 
 
index e8d76730693022338b15a19d2da210056be19f6b..8c503d14a775901c0f33fdf461281a50670da24c 100644 (file)
@@ -149,6 +149,7 @@ int create_file(void *jcr, char *fname, char *ofile, char *lname,
         stat = !make_path(jcr, ofile, parent_mode, parent_mode, uid, gid, 1, NULL);
         if (stat == 0) {
             Dmsg1(0, "Could not make path. %s\n", ofile);
+            Jmsg1(jcr, M_ERROR, 0, _("Could not make path. %s\n"), ofile);
            return CF_ERROR;
         }
       
index 53fa1cce300774115f98eedca1731c4f9be4faae..827b24072393ea2f24cf23b000b98ef5cd40d2fe 100644 (file)
@@ -73,8 +73,9 @@ cleanup(struct saved_cwd *cwd)
    if (cwd->do_chdir) {
       int _fail = restore_cwd(cwd, NULL, NULL);
       free_cwd(cwd);
-      if (_fail)
+      if (_fail) {
         return 1;
+      }
    }
    return 0;
 }
@@ -93,9 +94,11 @@ make_dir(void *jcr, const char *dir, const char *dirpath, mode_t mode, int *crea
 {
   int fail = 0;
   int created_dir;
+  int save_errno;
 
   Dmsg2(300, "make_dir mode=%o dir=%s\n", mode, dir);
   created_dir = (mkdir(dir, mode) == 0);
+  save_errno = errno;
 
   if (!created_dir) {
       struct stat stats;
@@ -110,7 +113,7 @@ make_dir(void *jcr, const char *dir, const char *dirpath, mode_t mode, int *crea
 
       if (stat(dir, &stats)) {
           Jmsg(jcr, M_ERROR, 0, "Cannot create directory %s: %s\n", 
-                 dirpath, strerror(errno));
+                 dirpath, strerror(save_errno));
          fail = 1;
       } else if (!S_ISDIR(stats.st_mode)) {
           Jmsg(jcr, M_ERROR, 0, "%s exists but is not a directory\n", quote(dirpath));
@@ -177,7 +180,7 @@ make_path(
       char *dirpath;
 
       /* Temporarily relax umask in case it's overly restrictive.  */
-      mode_t oldmask = umask (0);
+      mode_t oldmask = umask(0);
 
       /* Make a copy of ARGPATH that we can scribble NULs on.  */
       dirpath = (char *)alloca(strlen(argpath) + 1);
@@ -188,15 +191,13 @@ make_path(
         or should have set[ug]id or sticky bits set and we are setting
         their owners, we need to fix their permissions after making them.  */
       if (((parent_mode & WX_USR) != WX_USR)
-         || ((owner != (uid_t) -1 || group != (gid_t) -1)
-             && (parent_mode & (S_ISUID | S_ISGID | S_ISVTX)) != 0))
-       {
-         tmp_mode = S_IRWXU;
-         re_protect = 1;
-       }
-      else {
-         tmp_mode = parent_mode;
-         re_protect = 0;
+         || ((owner != (uid_t)-1 || group != (gid_t)-1)
+             && (parent_mode & (S_ISUID | S_ISGID | S_ISVTX)) != 0)) {
+        tmp_mode = S_IRWXU;
+        re_protect = 1;
+      } else {
+        tmp_mode = parent_mode;
+        re_protect = 0;
       }
 
       /* If we can record the current working directory, we may be able
@@ -244,27 +245,22 @@ make_path(
 
          if (newly_created_dir) {
               Dmsg0(300, "newly_created_dir\n");
-             if (verbose_fmt_string) {
-                Jmsg(jcr, M_ERROR, 0, verbose_fmt_string, quote(dirpath));
-             }
 
-             if ((owner != (uid_t) -1 || group != (gid_t) -1)
-                 && chown (basename_dir, owner, group)
+             if ((owner != (uid_t)-1 || group != (gid_t)-1)
+                 && chown(basename_dir, owner, group)
 #if defined(AFS) && defined (EPERM)
                  && errno != EPERM
 #endif
                  ) {
-                 Jmsg(jcr, M_ERROR, 0, "Cannot change owner and/or group of %s: %s\n",
-                     quote (dirpath), strerror(errno));
-                umask(oldmask);
-                cleanup(&cwd);
-                return 1;
+                /* 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: %s\n",
+                     quote(dirpath), strerror(errno));
              }
               Dmsg0(300, "Chown done.\n");
 
              if (re_protect) {
                 struct ptr_list *pnew = (struct ptr_list *)
-                   alloca (sizeof (struct ptr_list));
+                   alloca(sizeof (struct ptr_list));
                 pnew->dirname_end = slash;
                 pnew->next = leading_dirs;
                 leading_dirs = pnew;
@@ -278,7 +274,7 @@ make_path(
             stat and mkdir process O(n^2) file name components.  */
          if (cwd.do_chdir && chdir(basename_dir) < 0) {
               Jmsg(jcr, M_ERROR, 0, "Cannot chdir to directory, %s: %s\n",
-                    quote (dirpath), strerror(errno));
+                    quote(dirpath), strerror(errno));
              umask(oldmask);
              cleanup(&cwd);
              return 1;
@@ -307,22 +303,17 @@ make_path(
       }
 
       /* Done creating directories.  Restore original umask.  */
-      umask (oldmask);
+      umask(oldmask);
 
-      if (verbose_fmt_string != NULL) {
-        Jmsg(jcr, M_ERROR, 0, verbose_fmt_string, dirpath);
-      }
-
-      if (owner != (uid_t) -1 || group != (gid_t) -1) {
+      if (owner != (uid_t)-1 || group != (gid_t)-1) {
          if (chown(basename_dir, owner, group)
 #ifdef AFS
              && errno != EPERM
 #endif
              )
            {
-              Jmsg(jcr, M_ERROR, 0, "Cannot change owner and/or group of %s: %s\n",
-                    quote (dirpath), strerror(errno));
-             retval = 1;
+              Jmsg(jcr, M_WARNING, 0, "Cannot change owner and/or group of %s: %s\n",
+                    quote(dirpath), strerror(errno));
            }
       }
 
@@ -335,13 +326,13 @@ make_path(
          Dmsg1(300, "Final chmod mode=%o\n", mode);
       }
       if ((mode & ~S_IRWXUGO) && chmod(basename_dir, mode)) {
-          Jmsg(jcr, M_ERROR, 0, "Cannot change permissions of %s: %s\n", 
+          Jmsg(jcr, M_WARNING, 0, "Cannot change permissions of %s: %s\n", 
             quote(dirpath), strerror(errno));
-         retval = 1;
       }
 
-     if (cleanup(&cwd))
+     if (cleanup(&cwd)) {
        return 1;
+     }
 
       /* If the mode for leading directories didn't include owner "wx"
         privileges, we have to reset their protections to the correct
@@ -350,9 +341,8 @@ make_path(
           *(p->dirname_end) = '\0';
           Dmsg2(300, "Reset parent mode=%o dir=%s\n", parent_mode, dirpath);
          if (chmod(dirpath, parent_mode)) {
-              Jmsg(jcr, M_ERROR, 0, "Cannot change permissions of %s: %s\n",
+              Jmsg(jcr, M_WARNING, 0, "Cannot change permissions of %s: %s\n",
                     quote (dirpath), strerror(errno));
-             retval = 1;
          }
       }
   } else {
@@ -373,21 +363,18 @@ make_path(
             On System V, users can give away files with chown and then not
              be able to chmod them.  So don't give files away.  */
 
-         if ((owner != (uid_t) -1 || group != (gid_t) -1)
+         if ((owner != (uid_t)-1 || group != (gid_t)-1)
              && chown(dirpath, owner, group)
 #ifdef AFS
              && errno != EPERM
 #endif
-             )
-           {
-              Jmsg(jcr, M_ERROR, 0, "Cannot change owner and/or group of %s: %s\n",
+             ) {
+              Jmsg(jcr, M_WARNING, 0, "Cannot change owner and/or group of %s: %s\n",
                     quote(dirpath), strerror(errno));
-             retval = 1;
            }
          if (chmod(dirpath, mode)) {
-              Jmsg(jcr, M_ERROR, 0, "Cannot change permissions of %s: %s\n",
+              Jmsg(jcr, M_WARNING, 0, "Cannot change permissions of %s: %s\n",
                                 quote(dirpath), strerror(errno));
-             retval = 1;
          }
           Dmsg2(300, "pathexists chmod mode=%o dir=%s\n", mode, dirpath);
       }
index 89746eec86f7d31037e1ba0f28d93340e0d634c5..d5f8184dbb6a7d76d20cbf1cd53a65e109c0ff3e 100644 (file)
@@ -33,7 +33,7 @@
    called, but doing so is ok. Otherwise, return zero.  */
 
 int
-save_cwd (struct saved_cwd *cwd)
+save_cwd(struct saved_cwd *cwd)
 {
   static int have_working_fchdir = 1;
 
@@ -51,7 +51,7 @@ save_cwd (struct saved_cwd *cwd)
 # if __sun__ || sun
       /* On SunOS 4, fchdir returns EINVAL if accounting is enabled,
         so we have to fall back to chdir.  */
-      if (fchdir (cwd->desc)) {
+      if (fchdir(cwd->desc)) {
          if (errno == EINVAL) {
              close(cwd->desc);
              cwd->desc = -1;
@@ -108,8 +108,10 @@ restore_cwd(const struct saved_cwd *cwd, const char *dest, const char *from)
 void
 free_cwd(struct saved_cwd *cwd)
 {
-  if (cwd->desc >= 0)
+  if (cwd->desc >= 0) {
      close(cwd->desc);
-  if (cwd->name)
+  }
+  if (cwd->name) {
      free_pool_memory(cwd->name);
+  }
 }