Prepare for implementing extended attribute support.

This patch adds *xattr() stubs in case extended attribute support is
not present and implements the *attrat() family of functions.  Based
on the patch by Pavel Raiskup <pavel@raiskup.cz> for gnulib.

* acinclude.m4 (TAR_HEADERS_ATTR_XATTR_H): New defun.
* configure.ac: Call TAR_HEADERS_ATTR_XATTR_H
* lib/Makefile.am: Add xattr-at.[ch], distribute attr-xattr.in.h
[!TAR_COND_XATTR_H]: Build attr/xattr.h
* lib/attr-xattr.in.h: New file.
* lib/xattr-at.c: New file.
* lib/xattr-at.h: New file.
This commit is contained in:
Sergey Poznyakoff
2012-11-18 19:20:46 +02:00
parent 643a8844a5
commit b997c90f9e
11 changed files with 534 additions and 2 deletions

51
tests/capabs_raw01.at Normal file
View File

@@ -0,0 +1,51 @@
# Process this file with autom4te to create testsuite. -*- Autotest -*-
#
# Test suite for GNU tar.
# Copyright (C) 2012 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Test description: Test if file capabilities are archived/restored correctly
# using just the default xattr support (capabilities are stored/restored in
# binary format -> system dependant).
AT_SETUP([capabilities: binary store/restore])
AT_KEYWORDS([xattrs capabilities capabs_raw01])
AT_TAR_CHECK([
AT_PRIVILEGED_PREREQ
AT_XATTRS_PREREQ
AT_CAPABILITIES_UTILS_PREREQ
mkdir dir
genfile --file dir/file
setcap "= cap_chown=ei" dir/file
# archive whole directory including binary xattrs
tar --xattrs -cf archive.tar dir
# clear the directory
rm -rf dir
# restore _all_ xattrs (not just the user.* domain)
tar --xattrs --xattrs-include='*' -xf archive.tar
getcap dir/file
],
[0],
[dir/file = cap_chown+ei
])
AT_CLEANUP

47
tests/xattr01.at Normal file
View File

@@ -0,0 +1,47 @@
# Process this file with autom4te to create testsuite. -*- Autotest -*-
#
# Test suite for GNU tar.
# Copyright (C) 2011 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Test description:
#
# This is basic test for support of extended attributes.
AT_SETUP([xattrs: basic functionality])
AT_KEYWORDS([xattrs xattr01])
AT_TAR_CHECK([
AT_XATTRS_PREREQ
mkdir dir
genfile --file dir/file
setfattr -n user.test -v OurDirValue dir
setfattr -n user.test -v OurFileValue dir/file
tar --xattrs -cf archive.tar dir
rm -rf dir
tar --xattrs -xf archive.tar
getfattr -h -d dir | grep -v -e '^#' -e ^$
getfattr -h -d dir/file | grep -v -e '^#' -e ^$
],
[0],
[user.test="OurDirValue"
user.test="OurFileValue"
])
AT_CLEANUP

55
tests/xattr02.at Normal file
View File

@@ -0,0 +1,55 @@
# Process this file with autom4te to create testsuite. -*- Autotest -*-
#
# Test suite for GNU tar.
# Copyright (C) 2011 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Test description:
#
# Cooperation of the '-C' option and storing/restoring extended attributes.
AT_SETUP([xattrs: change directory with -C option])
AT_KEYWORDS([xattrs xattr02])
AT_TAR_CHECK([
AT_XATTRS_PREREQ
mkdir dir
mkdir dir/subdir
mkdir dir/subdir/subsubdir
genfile --file dir/file1
genfile --file dir/subdir/file2
setfattr -n user.test -v OurFile1Value dir/file1
setfattr -n user.test -v OurFile2Value dir/subdir/file2
setfattr -n user.test -v OurDirValue dir/subdir/subsubdir
tar --xattrs -cf archive.tar -C dir file1 -C subdir file2 subsubdir
rm -rf dir
tar --xattrs -xf archive.tar
getfattr -h -d file1 | grep -v -e '^#' -e ^$
getfattr -h -d file2 | grep -v -e '^#' -e ^$
getfattr -h -d subsubdir | grep -v -e '^#' -e ^$
],
[0],
[user.test="OurFile1Value"
user.test="OurFile2Value"
user.test="OurDirValue"
])
AT_CLEANUP

56
tests/xattr03.at Normal file
View File

@@ -0,0 +1,56 @@
# Process this file with autom4te to create testsuite. -*- Autotest -*-
#
# Test suite for GNU tar.
# Copyright (C) 2012 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Test description:
#
# Setup of the trusted.* domain under privileged user.
AT_SETUP([xattrs: trusted.* attributes])
AT_KEYWORDS([xattrs xattr03])
AT_TAR_CHECK([
AT_PRIVILEGED_PREREQ
AT_XATTRS_PREREQ
mkdir dir
mkdir dir/subdir
mkdir dir/subdir/subsubdir
genfile --file dir/file1
genfile --file dir/subdir/file2
setfattr -n trusted.test -v OurFile1Value dir/file1
setfattr -n trusted.test -v OurFile2Value dir/subdir/file2
setfattr -n trusted.test -v OurDirValue dir/subdir/subsubdir
tar --xattrs -cf archive.tar -C dir file1 -C subdir file2 subsubdir
rm -rf dir
tar --xattrs --xattrs-include=trusted* -xf archive.tar
getfattr -mtrusted. -d file1 | grep -v -e '^#' -e ^$
getfattr -mtrusted. -d file2 | grep -v -e '^#' -e ^$
getfattr -mtrusted. -d subsubdir | grep -v -e '^#' -e ^$
],
[0],
[trusted.test="OurFile1Value"
trusted.test="OurFile2Value"
trusted.test="OurDirValue"
])
AT_CLEANUP

48
tests/xattr04.at Normal file
View File

@@ -0,0 +1,48 @@
# Process this file with autom4te to create testsuite. -*- Autotest -*-
#
# Test suite for GNU tar.
# Copyright (C) 2012 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Test description: Test for the regression caused by tar update from 1.23 to
# 1.26, Red Hat xattr patch was not ready for open->openat conversion.
#
# Related commit 4bde4f3. See the bug: https://bugzilla.redhat.com/717684
AT_SETUP([xattrs: s/open/openat/ regression])
AT_KEYWORDS([xattrs xattr04])
AT_TAR_CHECK([
AT_XATTRS_PREREQ
mkdir dir
mkdir output
genfile --file dir/file
setfattr -n user.test -v value dir/file
# archive whole directory including binary xattrs
tar --xattrs -cf archive.tar -C dir .
tar --xattrs -xf archive.tar -C output
ret=$?
getfattr -h -d output/file | grep -v -e '^#' -e ^$
exit $ret
],
[0],
[user.test="value"
])
AT_CLEANUP