]> arthur.barton.de Git - bup.git/commitdiff
Don't try to restore read-only chattr(1) attributes.
authorRob Browning <rlb@defaultvalue.org>
Sat, 11 Jun 2011 16:39:23 +0000 (11:39 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sun, 14 Oct 2012 20:02:30 +0000 (15:02 -0500)
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Zoran Zaric <zz@zoranzaric.de>
config/configure
lib/bup/_helpers.c

index fce0ddea948048a1f7fe8063476c4e46e1fddc0e..6f339399fdd3005850636811e6b6ae323b200ee3 100755 (executable)
@@ -58,6 +58,8 @@ AC_CHECK_HEADERS unistd.h
 # For FS_IOC_GETFLAGS and FS_IOC_SETFLAGS.
 AC_CHECK_HEADERS linux/fs.h
 AC_CHECK_HEADERS sys/ioctl.h
+# For attr related flags like EXT2_COMPR_FL.
+AC_CHECK_HEADERS ext2fs/ext2_fs.h
 
 AC_CHECK_FUNCS utimensat 
 AC_CHECK_FUNCS utimes
index f58243017f029f9ba821a8e0205c4f7fca9cbbc1..04a3bb9ce9a928ac3154a7d95a1f88202143efce 100644 (file)
 #ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
+#ifdef HAVE_EXT2FS_EXT2_FS_H
+#include <ext2fs/ext2_fs.h>
+#endif
+
+#if defined(FS_IOC_GETFLAGS) && defined(FS_IOC_SETFLAGS) \
+    && defined(HAVE_EXT2FS_EXT2_FS_H)
+#define BUP_HAVE_FILE_ATTRS 1
+#endif
 
 static int istty2 = 0;
 
@@ -639,7 +647,7 @@ static PyObject *fadvise_done(PyObject *self, PyObject *args)
 }
 
 
-#ifdef FS_IOC_GETFLAGS
+#ifdef BUP_HAVE_FILE_ATTRS
 static PyObject *bup_get_linux_file_attr(PyObject *self, PyObject *args)
 {
     int rc;
@@ -665,10 +673,10 @@ static PyObject *bup_get_linux_file_attr(PyObject *self, PyObject *args)
     close(fd);
     return Py_BuildValue("k", attr);
 }
-#endif /* def FS_IOC_GETFLAGS */
+#endif /* def BUP_HAVE_FILE_ATTRS */
 
 
-#ifdef FS_IOC_SETFLAGS
+#ifdef BUP_HAVE_FILE_ATTRS
 static PyObject *bup_set_linux_file_attr(PyObject *self, PyObject *args)
 {
     int rc;
@@ -683,6 +691,14 @@ static PyObject *bup_set_linux_file_attr(PyObject *self, PyObject *args)
     if (fd == -1)
         return PyErr_SetFromErrnoWithFilename(PyExc_OSError, path);
 
+    // Restrict attr to modifiable flags acdeijstuADST -- see
+    // chattr(1) and the e2fsprogs source.  Letter to flag mapping is
+    // in pf.c flags_array[].
+    attr &= EXT2_APPEND_FL | EXT2_COMPR_FL | EXT2_NODUMP_FL | EXT4_EXTENTS_FL
+    | EXT2_IMMUTABLE_FL | EXT3_JOURNAL_DATA_FL | EXT2_SECRM_FL | EXT2_NOTAIL_FL
+    | EXT2_UNRM_FL | EXT2_NOATIME_FL | EXT2_DIRSYNC_FL | EXT2_SYNC_FL
+    | EXT2_TOPDIR_FL;
+
     rc = ioctl(fd, FS_IOC_SETFLAGS, &attr);
     if (rc == -1)
     {
@@ -693,7 +709,7 @@ static PyObject *bup_set_linux_file_attr(PyObject *self, PyObject *args)
     close(fd);
     return Py_BuildValue("O", Py_None);
 }
-#endif /* def FS_IOC_SETFLAGS */
+#endif /* def BUP_HAVE_FILE_ATTRS */
 
 
 #if defined(HAVE_UTIMENSAT) || defined(HAVE_FUTIMES) || defined(HAVE_LUTIMES)
@@ -994,11 +1010,11 @@ static PyMethodDef helper_methods[] = {
        "open() the given filename for read with O_NOATIME if possible" },
     { "fadvise_done", fadvise_done, METH_VARARGS,
        "Inform the kernel that we're finished with earlier parts of a file" },
-#ifdef FS_IOC_GETFLAGS
+#ifdef BUP_HAVE_FILE_ATTRS
     { "get_linux_file_attr", bup_get_linux_file_attr, METH_VARARGS,
       "Return the Linux attributes for the given file." },
 #endif
-#ifdef FS_IOC_SETFLAGS
+#ifdef BUP_HAVE_FILE_ATTRS
     { "set_linux_file_attr", bup_set_linux_file_attr, METH_VARARGS,
       "Set the Linux attributes for the given file." },
 #endif