Minor change.
* src/xattrs.c: Fix indentation. Fix copyleft statement, promote to GPLv3+. * src/xattrs.h: Likewise
This commit is contained in:
164
src/xattrs.c
164
src/xattrs.c
@@ -7,7 +7,7 @@
|
||||
|
||||
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 2, or (at your option) any later
|
||||
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
|
||||
@@ -100,58 +100,70 @@ int file_has_acl_at (int dirfd, char const *, struct stat const *);
|
||||
#undef AT_FUNC_POST_FILE_ARGS
|
||||
|
||||
/* convert unix permissions into an ACL ... needed due to "default" ACLs */
|
||||
static acl_t perms2acl (int perms)
|
||||
static acl_t
|
||||
perms2acl (int perms)
|
||||
{
|
||||
char val[] = "user::---,group::---,other::---";
|
||||
/* 0123456789 123456789 123456789 123456789 */
|
||||
|
||||
/* user */
|
||||
if (perms & 0400) val[ 6] = 'r';
|
||||
if (perms & 0200) val[ 7] = 'w';
|
||||
if (perms & 0100) val[ 8] = 'x';
|
||||
if (perms & 0400)
|
||||
val[6] = 'r';
|
||||
if (perms & 0200)
|
||||
val[7] = 'w';
|
||||
if (perms & 0100)
|
||||
val[8] = 'x';
|
||||
|
||||
/* group */
|
||||
if (perms & 0040) val[17] = 'r';
|
||||
if (perms & 0020) val[18] = 'w';
|
||||
if (perms & 0010) val[19] = 'x';
|
||||
if (perms & 0040)
|
||||
val[17] = 'r';
|
||||
if (perms & 0020)
|
||||
val[18] = 'w';
|
||||
if (perms & 0010)
|
||||
val[19] = 'x';
|
||||
|
||||
/* other */
|
||||
if (perms & 0004) val[28] = 'r';
|
||||
if (perms & 0002) val[29] = 'w';
|
||||
if (perms & 0001) val[30] = 'x';
|
||||
if (perms & 0004)
|
||||
val[28] = 'r';
|
||||
if (perms & 0002)
|
||||
val[29] = 'w';
|
||||
if (perms & 0001)
|
||||
val[30] = 'x';
|
||||
|
||||
return (acl_from_text (val));
|
||||
return acl_from_text (val);
|
||||
}
|
||||
|
||||
static char *skip_to_ext_fields (char *ptr)
|
||||
static char *
|
||||
skip_to_ext_fields (char *ptr)
|
||||
{
|
||||
ptr += strcspn (ptr, ":,\n"); /* skip tag name. Ie. user/group/default/mask */
|
||||
|
||||
if (*ptr != ':')
|
||||
return (ptr); /* error? no user/group field */
|
||||
return ptr; /* error? no user/group field */
|
||||
++ptr;
|
||||
|
||||
ptr += strcspn (ptr, ":,\n"); /* skip user/group name */
|
||||
|
||||
if (*ptr != ':')
|
||||
return (ptr); /* error? no perms field */
|
||||
return ptr; /* error? no perms field */
|
||||
++ptr;
|
||||
|
||||
ptr += strcspn (ptr, ":,\n"); /* skip perms */
|
||||
|
||||
if (*ptr != ':')
|
||||
return (ptr); /* no extra fields */
|
||||
return ptr; /* no extra fields */
|
||||
|
||||
return (ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* The POSIX draft allows extra fields after the three main ones. Star
|
||||
uses this to add a fourth field for user/group which is the numeric ID.
|
||||
We just skip all extra fields atm. */
|
||||
static const char *fixup_extra_acl_fields (const char *ptr)
|
||||
static const char *
|
||||
fixup_extra_acl_fields (const char *ptr)
|
||||
{
|
||||
char *src = (char *)ptr;
|
||||
char *dst = (char *)ptr;
|
||||
char *src = (char *) ptr;
|
||||
char *dst = (char *) ptr;
|
||||
|
||||
while (*src)
|
||||
{
|
||||
@@ -160,7 +172,8 @@ static const char *fixup_extra_acl_fields (const char *ptr)
|
||||
|
||||
src = skip_to_ext_fields (src);
|
||||
len = src - old;
|
||||
if (old != dst) memmove (dst, old, len);
|
||||
if (old != dst)
|
||||
memmove (dst, old, len);
|
||||
dst += len;
|
||||
|
||||
if (*src == ':') /* We have extra fields, skip them all */
|
||||
@@ -175,7 +188,8 @@ static const char *fixup_extra_acl_fields (const char *ptr)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static void xattrs__acls_set (struct tar_stat_info const *st,
|
||||
static void
|
||||
xattrs__acls_set (struct tar_stat_info const *st,
|
||||
char const *file_name, int type,
|
||||
const char *ptr, size_t len, bool def)
|
||||
{ /* "system.posix_acl_access" */
|
||||
@@ -195,7 +209,7 @@ static void xattrs__acls_set (struct tar_stat_info const *st,
|
||||
return; /* don't call acl functions unless we first hit an ACL, or
|
||||
--acls was passed explicitly */
|
||||
|
||||
if (acl == (acl_t)NULL)
|
||||
if (acl == (acl_t) NULL)
|
||||
{
|
||||
call_arg_warn ("acl_from_text", file_name);
|
||||
return;
|
||||
@@ -203,22 +217,25 @@ static void xattrs__acls_set (struct tar_stat_info const *st,
|
||||
|
||||
if (acl_set_file_at (chdir_fd, file_name, type, acl) == -1)
|
||||
/* warn even if filesystem does not support acls */
|
||||
WARNOPT (WARN_XATTR_WRITE, (0, errno,
|
||||
_("acl_set_file_at: Cannot set POSIX ACLs for file '%s'"), file_name));
|
||||
WARNOPT (WARN_XATTR_WRITE,
|
||||
(0, errno,
|
||||
_("acl_set_file_at: Cannot set POSIX ACLs for file '%s'"),
|
||||
file_name));
|
||||
|
||||
acl_free (acl);
|
||||
}
|
||||
|
||||
static void xattrs__acls_get_a (int parentfd, const char *file_name,
|
||||
static void
|
||||
xattrs__acls_get_a (int parentfd, const char *file_name,
|
||||
struct tar_stat_info *st,
|
||||
char **ret_ptr, size_t *ret_len)
|
||||
char **ret_ptr, size_t * ret_len)
|
||||
{ /* "system.posix_acl_access" */
|
||||
char *val = NULL;
|
||||
ssize_t len;
|
||||
acl_t acl;
|
||||
|
||||
if ((acl = acl_get_file_at (parentfd, file_name, ACL_TYPE_ACCESS))
|
||||
== (acl_t)NULL)
|
||||
== (acl_t) NULL)
|
||||
{
|
||||
if (errno != ENOTSUP)
|
||||
call_arg_warn ("acl_get_file_at", file_name);
|
||||
@@ -240,16 +257,17 @@ static void xattrs__acls_get_a (int parentfd, const char *file_name,
|
||||
acl_free (val);
|
||||
}
|
||||
|
||||
static void xattrs__acls_get_d (int parentfd, char const *file_name,
|
||||
static void
|
||||
xattrs__acls_get_d (int parentfd, char const *file_name,
|
||||
struct tar_stat_info *st,
|
||||
char **ret_ptr, size_t *ret_len)
|
||||
char **ret_ptr, size_t * ret_len)
|
||||
{ /* "system.posix_acl_default" */
|
||||
char *val = NULL;
|
||||
ssize_t len;
|
||||
acl_t acl;
|
||||
|
||||
if ((acl = acl_get_file_at (parentfd, file_name, ACL_TYPE_DEFAULT))
|
||||
== (acl_t)NULL)
|
||||
== (acl_t) NULL)
|
||||
{
|
||||
if (errno != ENOTSUP)
|
||||
call_arg_warn ("acl_get_file_at", file_name);
|
||||
@@ -272,7 +290,8 @@ static void xattrs__acls_get_d (int parentfd, char const *file_name,
|
||||
}
|
||||
#endif /* HAVE_POSIX_ACLS */
|
||||
|
||||
static void acls_one_line (const char *prefix, char delim,
|
||||
static void
|
||||
acls_one_line (const char *prefix, char delim,
|
||||
const char *aclstring, size_t len)
|
||||
{
|
||||
/* support both long and short text representation of posix acls */
|
||||
@@ -308,7 +327,8 @@ static void acls_one_line (const char *prefix, char delim,
|
||||
obstack_free (&stk, NULL);
|
||||
}
|
||||
|
||||
void xattrs_acls_get (int parentfd, char const *file_name,
|
||||
void
|
||||
xattrs_acls_get (int parentfd, char const *file_name,
|
||||
struct tar_stat_info *st, int fd, int xisfile)
|
||||
{
|
||||
if (acls_option > 0)
|
||||
@@ -337,7 +357,8 @@ void xattrs_acls_get (int parentfd, char const *file_name,
|
||||
}
|
||||
}
|
||||
|
||||
void xattrs_acls_set (struct tar_stat_info const *st,
|
||||
void
|
||||
xattrs_acls_set (struct tar_stat_info const *st,
|
||||
char const *file_name, char typeflag)
|
||||
{
|
||||
if ((acls_option > 0) && (typeflag != SYMTYPE))
|
||||
@@ -357,7 +378,8 @@ void xattrs_acls_set (struct tar_stat_info const *st,
|
||||
}
|
||||
}
|
||||
|
||||
static void mask_map_realloc (struct xattrs_mask_map *map)
|
||||
static void
|
||||
mask_map_realloc (struct xattrs_mask_map *map)
|
||||
{
|
||||
if (map->size == 0)
|
||||
{
|
||||
@@ -374,7 +396,8 @@ static void mask_map_realloc (struct xattrs_mask_map *map)
|
||||
}
|
||||
}
|
||||
|
||||
void xattrs_mask_add (const char *mask, bool incl)
|
||||
void
|
||||
xattrs_mask_add (const char *mask, bool incl)
|
||||
{
|
||||
struct xattrs_mask_map *mask_map = incl ? &xattrs_setup.incl
|
||||
: &xattrs_setup.excl;
|
||||
@@ -385,13 +408,15 @@ void xattrs_mask_add (const char *mask, bool incl)
|
||||
mask_map->masks[mask_map->used++] = mask;
|
||||
}
|
||||
|
||||
static void clear_mask_map (struct xattrs_mask_map *mask_map)
|
||||
static void
|
||||
clear_mask_map (struct xattrs_mask_map *mask_map)
|
||||
{
|
||||
if (mask_map->size)
|
||||
free (mask_map->masks);
|
||||
}
|
||||
|
||||
void xattrs_clear_setup ()
|
||||
void
|
||||
xattrs_clear_setup ()
|
||||
{
|
||||
clear_mask_map (&xattrs_setup.incl);
|
||||
clear_mask_map (&xattrs_setup.excl);
|
||||
@@ -399,7 +424,8 @@ void xattrs_clear_setup ()
|
||||
|
||||
/* get all xattrs from file given by FILE_NAME or FD (when non-zero). This
|
||||
includes all the user.*, security.*, system.*, etc. available domains */
|
||||
void xattrs_xattrs_get (int parentfd, char const *file_name,
|
||||
void
|
||||
xattrs_xattrs_get (int parentfd, char const *file_name,
|
||||
struct tar_stat_info *st, int fd)
|
||||
{
|
||||
if (xattrs_option > 0)
|
||||
@@ -414,12 +440,14 @@ void xattrs_xattrs_get (int parentfd, char const *file_name,
|
||||
static char *xatrs = NULL;
|
||||
ssize_t xret = -1;
|
||||
|
||||
if (!xatrs) xatrs = xmalloc (xsz);
|
||||
if (!xatrs)
|
||||
xatrs = xmalloc (xsz);
|
||||
|
||||
while (((fd == 0) ?
|
||||
((xret = llistxattrat (parentfd, file_name, xatrs, xsz)) == -1) :
|
||||
((xret = flistxattr (fd, xatrs, xsz)) == -1)) &&
|
||||
(errno == ERANGE))
|
||||
((xret =
|
||||
llistxattrat (parentfd, file_name, xatrs, xsz)) == -1) :
|
||||
((xret = flistxattr (fd, xatrs, xsz)) == -1))
|
||||
&& (errno == ERANGE))
|
||||
{
|
||||
xsz <<= 1;
|
||||
xatrs = xrealloc (xatrs, xsz);
|
||||
@@ -433,7 +461,8 @@ void xattrs_xattrs_get (int parentfd, char const *file_name,
|
||||
static ssize_t asz = 1024;
|
||||
static char *val = NULL;
|
||||
|
||||
if (!val) val = xmalloc (asz);
|
||||
if (!val)
|
||||
val = xmalloc (asz);
|
||||
|
||||
while (xret > 0)
|
||||
{
|
||||
@@ -466,10 +495,10 @@ void xattrs_xattrs_get (int parentfd, char const *file_name,
|
||||
}
|
||||
}
|
||||
|
||||
static void xattrs__fd_set (struct tar_stat_info const *st,
|
||||
static void
|
||||
xattrs__fd_set (struct tar_stat_info const *st,
|
||||
char const *file_name, char typeflag,
|
||||
const char *attr,
|
||||
const char *ptr, size_t len)
|
||||
const char *attr, const char *ptr, size_t len)
|
||||
{
|
||||
if (ptr)
|
||||
{
|
||||
@@ -485,7 +514,8 @@ static void xattrs__fd_set (struct tar_stat_info const *st,
|
||||
}
|
||||
|
||||
if (ret == -1)
|
||||
WARNOPT (WARN_XATTR_WRITE, (0, errno,
|
||||
WARNOPT (WARN_XATTR_WRITE,
|
||||
(0, errno,
|
||||
_("%s: Cannot set '%s' extended attribute for file '%s'"),
|
||||
sysname, attr, file_name));
|
||||
}
|
||||
@@ -493,7 +523,8 @@ static void xattrs__fd_set (struct tar_stat_info const *st,
|
||||
|
||||
/* lgetfileconat is called against FILE_NAME iff the FD parameter is set to
|
||||
zero, otherwise the fgetfileconat is used against correct file descriptor */
|
||||
void xattrs_selinux_get (int parentfd, char const *file_name,
|
||||
void
|
||||
xattrs_selinux_get (int parentfd, char const *file_name,
|
||||
struct tar_stat_info *st, int fd)
|
||||
{
|
||||
if (selinux_context_option > 0)
|
||||
@@ -513,7 +544,8 @@ void xattrs_selinux_get (int parentfd, char const *file_name,
|
||||
}
|
||||
}
|
||||
|
||||
void xattrs_selinux_set (struct tar_stat_info const *st,
|
||||
void
|
||||
xattrs_selinux_set (struct tar_stat_info const *st,
|
||||
char const *file_name, char typeflag)
|
||||
{
|
||||
if (selinux_context_option > 0)
|
||||
@@ -542,14 +574,16 @@ void xattrs_selinux_set (struct tar_stat_info const *st,
|
||||
}
|
||||
|
||||
if (ret == -1)
|
||||
WARNOPT (WARN_XATTR_WRITE, (0, errno,
|
||||
_("%s: Cannot set SELinux context for file '%s'"), sysname,
|
||||
file_name));
|
||||
WARNOPT (WARN_XATTR_WRITE,
|
||||
(0, errno,
|
||||
_("%s: Cannot set SELinux context for file '%s'"),
|
||||
sysname, file_name));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static bool xattrs_matches_mask (const char *kw, struct xattrs_mask_map *mm)
|
||||
static bool
|
||||
xattrs_matches_mask (const char *kw, struct xattrs_mask_map *mm)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -563,7 +597,8 @@ static bool xattrs_matches_mask (const char *kw, struct xattrs_mask_map *mm)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool xattrs_kw_included (const char *kw, bool archiving)
|
||||
static bool
|
||||
xattrs_kw_included (const char *kw, bool archiving)
|
||||
{
|
||||
if (xattrs_setup.incl.size)
|
||||
return xattrs_matches_mask (kw, &xattrs_setup.incl);
|
||||
@@ -576,7 +611,8 @@ static bool xattrs_kw_included (const char *kw, bool archiving)
|
||||
}
|
||||
}
|
||||
|
||||
static bool xattrs_kw_excluded (const char *kw, bool archiving)
|
||||
static bool
|
||||
xattrs_kw_excluded (const char *kw, bool archiving)
|
||||
{
|
||||
if (!xattrs_setup.excl.size)
|
||||
return false;
|
||||
@@ -587,7 +623,8 @@ static bool xattrs_kw_excluded (const char *kw, bool archiving)
|
||||
/* Check whether the xattr with keyword KW should be discarded from list of
|
||||
attributes that are going to be archived/excluded (set ARCHIVING=true for
|
||||
archiving, false for excluding) */
|
||||
static bool xattrs_masked_out (const char *kw, bool archiving)
|
||||
static bool
|
||||
xattrs_masked_out (const char *kw, bool archiving)
|
||||
{
|
||||
if (!xattrs_kw_included (kw, archiving))
|
||||
return true;
|
||||
@@ -595,9 +632,9 @@ static bool xattrs_masked_out (const char *kw, bool archiving)
|
||||
return xattrs_kw_excluded (kw, archiving);
|
||||
}
|
||||
|
||||
void xattrs_xattrs_set (struct tar_stat_info const *st,
|
||||
char const *file_name, char typeflag,
|
||||
int later_run)
|
||||
void
|
||||
xattrs_xattrs_set (struct tar_stat_info const *st,
|
||||
char const *file_name, char typeflag, int later_run)
|
||||
{
|
||||
if (xattrs_option > 0)
|
||||
{
|
||||
@@ -639,9 +676,11 @@ void xattrs_xattrs_set (struct tar_stat_info const *st,
|
||||
}
|
||||
}
|
||||
|
||||
void xattrs_print_char (struct tar_stat_info const *st, char *output)
|
||||
void
|
||||
xattrs_print_char (struct tar_stat_info const *st, char *output)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (verbose_option < 2)
|
||||
{
|
||||
*output = 0;
|
||||
@@ -672,7 +711,8 @@ void xattrs_print_char (struct tar_stat_info const *st, char *output)
|
||||
*output = '+';
|
||||
}
|
||||
|
||||
void xattrs_print (struct tar_stat_info const *st)
|
||||
void
|
||||
xattrs_print (struct tar_stat_info const *st)
|
||||
{
|
||||
if (verbose_option < 3)
|
||||
return;
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
#ifndef GUARD_XATTTRS_H
|
||||
#define GUARD_XATTTRS_H
|
||||
|
||||
/* Support for extended attributes.
|
||||
|
||||
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software
|
||||
@@ -10,7 +7,7 @@
|
||||
|
||||
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 2, or (at your option) any later
|
||||
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
|
||||
@@ -23,6 +20,8 @@
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef GUARD_XATTTRS_H
|
||||
#define GUARD_XATTTRS_H
|
||||
|
||||
/* Add include/exclude fnmatch pattern for xattr key domain. Set INCL parameter
|
||||
to true/false if you want to add include/exclude pattern */
|
||||
|
||||
Reference in New Issue
Block a user