2
Copyright (C) 2006 Andreas Gruenbacher <agruen@suse.de>, SuSE Linux AG.
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Lesser General Public
6
License as published by the Free Software Foundation; either
7
version 2.1 of the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Lesser General Public License for more details.
14
You should have received a copy of the GNU Lesser General Public License
15
along with this manual. If not, see <http://www.gnu.org/licenses/>.
26
#include "attr/libattr.h"
27
#define ERROR_CONTEXT_MACROS
28
#include "error_context.h"
30
#define ATTR_CONF "/etc/xattr.conf"
33
struct attr_action *next;
38
static struct attr_action *attr_actions;
41
free_attr_actions(void)
43
struct attr_action *tmp;
45
while (attr_actions) {
46
tmp = attr_actions->next;
47
free(attr_actions->pattern);
54
attr_parse_attr_conf(struct error_context *ctx)
56
char *text = NULL, *t;
57
size_t size_guess = 4096, len;
60
struct attr_action *new;
67
if ((file = fopen(ATTR_CONF, "r")) == NULL) {
73
text = malloc(size_guess + 1);
77
len = fread(text, 1, size_guess, file);
93
t += strspn(t, " \t\n");
94
len = strcspn(t, " \t\n#");
98
t += strcspn(t, "\n");
100
} else if (t[len] == 0)
102
else if (t[len] == '\n')
104
pattern = strndup(t, len);
109
t += strspn(t, " \t");
110
len = strcspn(t, " \t\n#");
111
if (len == 4 && !strncmp(t, "skip", 4))
112
action = ATTR_ACTION_SKIP;
113
else if (len == 11 && !strncmp(t, "permissions", 11))
114
action = ATTR_ACTION_PERMISSIONS;
118
t += strspn(t, " \t");
119
if (*t != '#' && *t != '\n')
122
new = malloc(sizeof(struct attr_action));
125
new->next = attr_actions;
126
new->pattern = pattern;
127
new->action = action;
130
t += strcspn(t, "\n");
139
const char *q = quote (ctx, ATTR_CONF);
140
error (ctx, "%s", q);
153
attr_copy_action(const char *name, struct error_context *ctx)
155
struct attr_action *action = attr_actions;
157
if (!attr_parse_attr_conf(ctx)) {
158
for (action = attr_actions; action; action = action->next) {
159
if (!fnmatch(action->pattern, name, 0))
160
return action->action;