(I have a patch below.)

The workaround with NetBSD's restore(8) simply was to add a restore option 
(-M) that told restore never to set the file flags (via chflags(2)) and 
just write the specification for the setting the flag using mtree spec 
format. Then the admin could choose to run mtree later to set the flags 
using that generated specification.

But if the file already has immutable set before any restore, you may be 
out of luck.

Just for those who don't know about this with BSD: a security level can be 
set which stops even root from turning off these flags and the security 
level can't be lowered by root either. The only way is too reboot the 
computer and make sure it boots up without the security level raised (boot 
first into single user at physical console for example).

Another option which was only mentioned very briefly in this thread is to 
try what FreeBSD's restore(8) does (but NetBSD does not appear to do).

If the link(2) fails, then assume that maybe there is a file flag 
preventing this and then do (from FreeBSD's sbin/restore/utilities.c):

        if (stat(existing, &s) == 0 && s.st_flags != 0 &&
            chflags(existing, 0) == 0) {
                ret = link(existing, new);
                chflags(existing, s.st_flags);
        }


Here is an untested patch (or at least an idea :) that should help those 
who don't use raised securelevel. This patch needs some debug output for 
both chflags introduced here.

Index: src/findlib/create_file.c
===================================================================
RCS file: /cvsroot/bacula/bacula/src/findlib/create_file.c,v
retrieving revision 1.56
diff -u -r1.56 create_file.c
--- src/findlib/create_file.c   21 Nov 2006 20:14:46 -0000      1.56
+++ src/findlib/create_file.c   12 Dec 2006 21:08:11 -0000
@@ -288,10 +288,32 @@
       case FT_LNKSAVED:                  /* Hard linked, file already saved */
          Dmsg2(130, "Hard link %s => %s\n", attr->ofname, attr->olname);
          if (link(attr->olname, attr->ofname) != 0) {
+
+#ifdef HAVE_CHFLAGS
+      /*
+            * If using BSD user flags, maybe has a file flag
+            * preventing this. So attempt to disable, retry link,
+            * and reset flags.
+            * Note that BSD securelevel may prevent disabling flag.
+       */
+
+            struct stat s;
+
+            if (stat(attr->ofname, &s) == 0 && s.st_flags != 0 &&
+               chflags(attr->ofname, 0) == 0) {
+                   if (link(attr->olname, attr->ofname) != 0) {
+#endif /* HAVE_CHFLAGS */
             berrno be;
             Qmsg3(jcr, M_ERROR, 0, _("Could not hard link %s -> %s: ERR=%s\n"),
                   attr->ofname, attr->olname, be.strerror());
             return CF_ERROR;
+#ifdef HAVE_CHFLAGS
+                   }
+                   if (chflags(attr->ofname, s.st_flags) < 0) {
+                       /* add debugging here */
+                   }
+#endif /* HAVE_CHFLAGS */
+
          }
          return CF_CREATED;
 #endif

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users

Reply via email to