* Copyright (C) 1996-2001 Andrew Tridgell <tridge@samba.org>
* Copyright (C) 1996 Paul Mackerras
* Copyright (C) 2002 Martin Pool
- * Copyright (C) 2003-2013 Wayne Davison
+ * Copyright (C) 2003-2022 Wayne Davison
*
* 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
*/
#include "rsync.h"
+#include "ifuncs.h"
extern int am_server;
extern int am_sender;
+extern int am_generator;
extern int eol_nulls;
extern int io_error;
+extern int xfer_dirs;
+extern int recurse;
extern int local_server;
extern int prune_empty_dirs;
extern int ignore_perishable;
+extern int relative_paths;
extern int delete_mode;
extern int delete_excluded;
extern int cvs_exclude;
extern int sanitize_paths;
extern int protocol_version;
+extern int trust_sender_args;
extern int module_id;
extern char curr_dir[MAXPATHLEN];
filter_rule_list filter_list = { .debug_type = "" };
filter_rule_list cvs_filter_list = { .debug_type = " [global CVS]" };
filter_rule_list daemon_filter_list = { .debug_type = " [daemon]" };
+filter_rule_list implied_filter_list = { .debug_type = " [implied]" };
+
+int saw_xattr_filter = 0;
+int trust_sender_args = 0;
+int trust_sender_filter = 0;
/* Need room enough for ":MODS " prefix plus some room to grow. */
#define MAX_RULE_PREFIX (16)
static int mergelist_cnt = 0;
static int mergelist_size = 0;
+#define LOCAL_RULE 1
+#define REMOTE_RULE 2
+static uchar cur_elide_value = REMOTE_RULE;
+
/* Each filter_list_struct describes a singly-linked list by keeping track
* of both the head and tail pointers. The list is slightly unusual in that
* a parent-dir's content can be appended to the end of the local list in a
static void teardown_mergelist(filter_rule *ex)
{
+ int j;
+
+ if (!ex->u.mergelist)
+ return;
+
if (DEBUG_GTE(FILTER, 2)) {
rprintf(FINFO, "[%s] deactivating mergelist #%d%s\n",
who_am_i(), mergelist_cnt - 1,
ex->u.mergelist->debug_type);
}
- /* We should deactivate mergelists in LIFO order. */
- assert(mergelist_cnt > 0);
- assert(ex == mergelist_parents[mergelist_cnt - 1]);
-
- /* The parent_dirscan filters should have been freed. */
- assert(ex->u.mergelist->parent_dirscan_head == NULL);
-
free(ex->u.mergelist->debug_type);
free(ex->u.mergelist);
- mergelist_cnt--;
+
+ for (j = 0; j < mergelist_cnt; j++) {
+ if (mergelist_parents[j] == ex) {
+ mergelist_parents[j] = NULL;
+ break;
+ }
+ }
+ while (mergelist_cnt && mergelist_parents[mergelist_cnt-1] == NULL)
+ mergelist_cnt--;
}
static void free_filter(filter_rule *ex)
{
+ if (ex->rflags & FILTRULE_PERDIR_MERGE)
+ teardown_mergelist(ex);
free(ex->pattern);
free(ex);
}
-static void free_filters(filter_rule *head)
+static void free_filters(filter_rule *ent)
{
- filter_rule *rev_head = NULL;
-
- /* Reverse the list so we deactivate mergelists in the proper LIFO
- * order. */
- while (head) {
- filter_rule *next = head->next;
- head->next = rev_head;
- rev_head = head;
- head = next;
- }
-
- while (rev_head) {
- filter_rule *prev = rev_head->next;
- /* Tear down mergelists here, not in free_filter, so that we
- * affect only real filter lists and not temporarily allocated
- * filters. */
- if (rev_head->rflags & FILTRULE_PERDIR_MERGE)
- teardown_mergelist(rev_head);
- free_filter(rev_head);
- rev_head = prev;
+ while (ent) {
+ filter_rule *next = ent->next;
+ free_filter(ent);
+ ent = next;
}
}
{
const char *cp;
unsigned int pre_len, suf_len, slash_cnt = 0;
+ char *mention_rule_suffix;
- if (DEBUG_GTE(FILTER, 2)) {
- rprintf(FINFO, "[%s] add_rule(%s%.*s%s)%s\n",
+ if (DEBUG_GTE(FILTER, 1) && pat_len && (pat[pat_len-1] == ' ' || pat[pat_len-1] == '\t'))
+ mention_rule_suffix = " -- CAUTION: trailing whitespace!";
+ else
+ mention_rule_suffix = DEBUG_GTE(FILTER, 2) ? "" : NULL;
+ if (mention_rule_suffix) {
+ rprintf(FINFO, "[%s] add_rule(%s%.*s%s)%s%s\n",
who_am_i(), get_rule_prefix(rule, pat, 0, NULL),
- (int)pat_len, pat,
- (rule->rflags & FILTRULE_DIRECTORY) ? "/" : "",
- listp->debug_type);
+ (int)pat_len, pat, (rule->rflags & FILTRULE_DIRECTORY) ? "/" : "",
+ listp->debug_type, mention_rule_suffix);
}
/* These flags also indicate that we're reading a list that
} else
suf_len = 0;
- if (!(rule->pattern = new_array(char, pre_len + pat_len + suf_len + 1)))
- out_of_memory("add_rule");
+ rule->pattern = new_array(char, pre_len + pat_len + suf_len + 1);
if (pre_len) {
memcpy(rule->pattern, dirbuf + module_dirlen, pre_len);
for (cp = rule->pattern; cp < rule->pattern + pre_len; cp++) {
slash_cnt++;
}
}
+ rule->elide = 0;
strlcpy(rule->pattern + pre_len, pat, pat_len + 1);
pat_len += pre_len;
if (suf_len) {
* add it again. */
for (i = 0; i < mergelist_cnt; i++) {
filter_rule *ex = mergelist_parents[i];
- const char *s = strrchr(ex->pattern, '/');
+ const char *s;
+ if (!ex)
+ continue;
+ s = strrchr(ex->pattern, '/');
if (s)
s++;
else
}
}
- if (!(lp = new_array(filter_rule_list, 1)))
- out_of_memory("add_rule");
- lp->head = lp->tail = lp->parent_dirscan_head = NULL;
+ lp = new_array0(filter_rule_list, 1);
if (asprintf(&lp->debug_type, " [per-dir %s]", cp) < 0)
out_of_memory("add_rule");
rule->u.mergelist = lp;
if (mergelist_cnt == mergelist_size) {
mergelist_size += 5;
- mergelist_parents = realloc_array(mergelist_parents,
- filter_rule *,
- mergelist_size);
- if (!mergelist_parents)
- out_of_memory("add_rule");
+ mergelist_parents = realloc_array(mergelist_parents, filter_rule *, mergelist_size);
}
if (DEBUG_GTE(FILTER, 2)) {
rprintf(FINFO, "[%s] activating mergelist #%d%s\n",
}
}
-static void clear_filter_list(filter_rule_list *listp)
+/* If the wildcards failed, the remote shell might give us a file matching the literal
+ * wildcards. Since "*" & "?" already match themselves, this just needs to deal with
+ * failed "[foo]" idioms.
+ */
+static void maybe_add_literal_brackets_rule(filter_rule const *based_on, int arg_len)
+{
+ filter_rule *rule;
+ const char *arg = based_on->pattern, *cp;
+ char *p;
+ int cnt = 0;
+
+ if (arg_len < 0)
+ arg_len = strlen(arg);
+
+ for (cp = arg; *cp; cp++) {
+ if (*cp == '\\' && cp[1]) {
+ cp++;
+ } else if (*cp == '[')
+ cnt++;
+ }
+ if (!cnt)
+ return;
+
+ rule = new0(filter_rule);
+ rule->rflags = based_on->rflags;
+ rule->u.slash_cnt = based_on->u.slash_cnt;
+ p = rule->pattern = new_array(char, arg_len + cnt + 1);
+ for (cp = arg; *cp; ) {
+ if (*cp == '\\' && cp[1]) {
+ *p++ = *cp++;
+ } else if (*cp == '[')
+ *p++ = '\\';
+ *p++ = *cp++;
+ }
+ *p++ = '\0';
+
+ rule->next = implied_filter_list.head;
+ implied_filter_list.head = rule;
+ if (DEBUG_GTE(FILTER, 3)) {
+ rprintf(FINFO, "[%s] add_implied_include(%s%s)\n", who_am_i(), rule->pattern,
+ rule->rflags & FILTRULE_DIRECTORY ? "/" : "");
+ }
+}
+
+static char *partial_string_buf = NULL;
+static int partial_string_len = 0;
+void implied_include_partial_string(const char *s_start, const char *s_end)
+{
+ partial_string_len = s_end - s_start;
+ if (partial_string_len <= 0 || partial_string_len >= MAXPATHLEN) { /* too-large should be impossible... */
+ partial_string_len = 0;
+ return;
+ }
+ if (!partial_string_buf)
+ partial_string_buf = new_array(char, MAXPATHLEN);
+ memcpy(partial_string_buf, s_start, partial_string_len);
+}
+
+void free_implied_include_partial_string()
{
- if (listp->tail) {
- /* Truncate any inherited items from the local list. */
- listp->tail->next = NULL;
- /* Now free everything that is left. */
- free_filters(listp->head);
+ if (partial_string_buf) {
+ if (partial_string_len)
+ add_implied_include("", 0);
+ free(partial_string_buf);
+ partial_string_buf = NULL;
+ }
+ partial_string_len = 0; /* paranoia */
+}
+
+/* Each arg the client sends to the remote sender turns into an implied include
+ * that the receiver uses to validate the file list from the sender. */
+void add_implied_include(const char *arg, int skip_daemon_module)
+{
+ int arg_len, saw_wild = 0, saw_live_open_brkt = 0, backslash_cnt = 0;
+ int slash_cnt = 0;
+ const char *cp;
+ char *p;
+ if (trust_sender_args)
+ return;
+ if (partial_string_len) {
+ arg_len = strlen(arg);
+ if (partial_string_len + arg_len >= MAXPATHLEN) {
+ partial_string_len = 0;
+ return; /* Should be impossible... */
+ }
+ memcpy(partial_string_buf + partial_string_len, arg, arg_len + 1);
+ partial_string_len = 0;
+ arg = partial_string_buf;
+ }
+ if (skip_daemon_module) {
+ if ((cp = strchr(arg, '/')) != NULL)
+ arg = cp + 1;
+ else
+ arg = "";
+ }
+ if (relative_paths) {
+ if ((cp = strstr(arg, "/./")) != NULL)
+ arg = cp + 3;
+ } else if ((cp = strrchr(arg, '/')) != NULL) {
+ arg = cp + 1;
+ }
+ if (*arg == '.' && arg[1] == '\0')
+ arg++;
+ arg_len = strlen(arg);
+ if (arg_len) {
+ char *new_pat;
+ if (strpbrk(arg, "*[?")) {
+ /* We need to add room to escape backslashes if wildcard chars are present. */
+ for (cp = arg; (cp = strchr(cp, '\\')) != NULL; cp++)
+ arg_len++;
+ saw_wild = 1;
+ }
+ arg_len++; /* Leave room for the prefixed slash */
+ p = new_pat = new_array(char, arg_len + 1);
+ *p++ = '/';
+ slash_cnt++;
+ for (cp = arg; *cp; ) {
+ switch (*cp) {
+ case '\\':
+ if (cp[1] == ']') {
+ if (!saw_wild)
+ cp++; /* A \] in a non-wild filter causes a problem, so drop the \ . */
+ } else if (!strchr("*[?", cp[1])) {
+ backslash_cnt++;
+ if (saw_wild)
+ *p++ = '\\';
+ }
+ *p++ = *cp++;
+ break;
+ case '/':
+ if (p[-1] == '/') { /* This is safe because of the initial slash. */
+ if (*++cp == '\0') {
+ slash_cnt--;
+ p--;
+ }
+ } else if (cp[1] == '\0') {
+ cp++;
+ } else {
+ slash_cnt++;
+ *p++ = *cp++;
+ }
+ break;
+ case '.':
+ if (p[-1] == '/') {
+ if (cp[1] == '/') {
+ cp += 2;
+ if (!*cp) {
+ slash_cnt--;
+ p--;
+ }
+ } else if (cp[1] == '\0') {
+ cp++;
+ slash_cnt--;
+ p--;
+ } else
+ *p++ = *cp++;
+ } else
+ *p++ = *cp++;
+ break;
+ case '[':
+ saw_live_open_brkt = 1;
+ *p++ = *cp++;
+ break;
+ default:
+ *p++ = *cp++;
+ break;
+ }
+ }
+ *p = '\0';
+ arg_len = p - new_pat;
+ if (!arg_len)
+ free(new_pat);
+ else {
+ filter_rule *rule = new0(filter_rule);
+ rule->rflags = FILTRULE_INCLUDE + (saw_wild ? FILTRULE_WILD : 0);
+ rule->u.slash_cnt = slash_cnt;
+ arg = rule->pattern = new_pat;
+ if (!implied_filter_list.head)
+ implied_filter_list.head = implied_filter_list.tail = rule;
+ else {
+ rule->next = implied_filter_list.head;
+ implied_filter_list.head = rule;
+ }
+ if (DEBUG_GTE(FILTER, 3))
+ rprintf(FINFO, "[%s] add_implied_include(%s)\n", who_am_i(), arg);
+ if (saw_live_open_brkt)
+ maybe_add_literal_brackets_rule(rule, arg_len);
+ if (relative_paths && slash_cnt) {
+ int sub_slash_cnt = slash_cnt;
+ while ((p = strrchr(new_pat, '/')) != NULL && p != new_pat) {
+ filter_rule const *ent;
+ filter_rule *R_rule;
+ int found = 0;
+ *p = '\0';
+ for (ent = implied_filter_list.head; ent; ent = ent->next) {
+ if (ent != rule && strcmp(ent->pattern, new_pat) == 0) {
+ found = 1;
+ break;
+ }
+ }
+ if (found) {
+ *p = '/';
+ break; /* We added all parent dirs already */
+ }
+ R_rule = new0(filter_rule);
+ R_rule->rflags = FILTRULE_INCLUDE | FILTRULE_DIRECTORY;
+ /* Check if our sub-path has wildcards or escaped backslashes */
+ if (saw_wild && strpbrk(new_pat, "*[?\\"))
+ R_rule->rflags |= FILTRULE_WILD;
+ R_rule->pattern = strdup(new_pat);
+ R_rule->u.slash_cnt = --sub_slash_cnt;
+ R_rule->next = implied_filter_list.head;
+ implied_filter_list.head = R_rule;
+ if (DEBUG_GTE(FILTER, 3)) {
+ rprintf(FINFO, "[%s] add_implied_include(%s/)\n",
+ who_am_i(), R_rule->pattern);
+ }
+ if (saw_live_open_brkt)
+ maybe_add_literal_brackets_rule(R_rule, -1);
+ }
+ for (p = new_pat; sub_slash_cnt < slash_cnt; sub_slash_cnt++) {
+ p += strlen(p);
+ *p = '/';
+ }
+ }
+ }
+ }
+
+ if (recurse || xfer_dirs) {
+ /* Now create a rule with an added "/" & "**" or "*" at the end */
+ filter_rule *rule = new0(filter_rule);
+ rule->rflags = FILTRULE_INCLUDE | FILTRULE_WILD;
+ if (recurse)
+ rule->rflags |= FILTRULE_WILD2;
+ /* We must leave enough room for / * * \0. */
+ if (!saw_wild && backslash_cnt) {
+ /* We are appending a wildcard, so now the backslashes need to be escaped. */
+ p = rule->pattern = new_array(char, arg_len + backslash_cnt + 3 + 1);
+ for (cp = arg; *cp; ) { /* Note that arg_len != 0 because backslash_cnt > 0 */
+ if (*cp == '\\')
+ *p++ = '\\';
+ *p++ = *cp++;
+ }
+ } else {
+ p = rule->pattern = new_array(char, arg_len + 3 + 1);
+ if (arg_len) {
+ memcpy(p, arg, arg_len);
+ p += arg_len;
+ }
+ }
+ *p++ = '/';
+ *p++ = '*';
+ if (recurse)
+ *p++ = '*';
+ *p = '\0';
+ rule->u.slash_cnt = slash_cnt + 1;
+ rule->next = implied_filter_list.head;
+ implied_filter_list.head = rule;
+ if (DEBUG_GTE(FILTER, 3))
+ rprintf(FINFO, "[%s] add_implied_include(%s)\n", who_am_i(), rule->pattern);
+ if (saw_live_open_brkt)
+ maybe_add_literal_brackets_rule(rule, p - rule->pattern);
}
+}
+
+/* This frees any non-inherited items, leaving just inherited items on the list. */
+static void pop_filter_list(filter_rule_list *listp)
+{
+ filter_rule *inherited;
+
+ if (!listp->tail)
+ return;
+
+ inherited = listp->tail->next;
+
+ /* Truncate any inherited items from the local list. */
+ listp->tail->next = NULL;
+ /* Now free everything that is left. */
+ free_filters(listp->head);
- listp->head = listp->tail = NULL;
+ listp->head = inherited;
+ listp->tail = NULL;
}
/* This returns an expanded (absolute) filename for the merge-file name if
fn_len = clean_fname(fn, CFN_COLLAPSE_DOT_DOT_DIRS);
}
- /* If the name isn't in buf yet, it's wasn't absolute. */
+ /* If the name isn't in buf yet, it wasn't absolute. */
if (fn != buf) {
int d_len = dirbuf_len - prefix_skip;
if (d_len + fn_len >= MAXPATHLEN) {
strlcpy(y, save, MAXPATHLEN);
while ((*x++ = *y++) != '/') {}
}
- /* Save current head for freeing when the mergelist becomes inactive. */
- lp->parent_dirscan_head = lp->head;
parent_dirscan = False;
if (DEBUG_GTE(FILTER, 2)) {
rprintf(FINFO, "[%s] completed parent_dirscan for mergelist #%d%s\n",
push = (struct local_filter_state *)new_array(char,
sizeof (struct local_filter_state)
+ (mergelist_cnt-1) * sizeof (filter_rule_list));
- if (!push)
- out_of_memory("push_local_filters");
push->mergelist_cnt = mergelist_cnt;
for (i = 0; i < mergelist_cnt; i++) {
- memcpy(&push->mergelists[i], mergelist_parents[i]->u.mergelist,
- sizeof (filter_rule_list));
+ filter_rule *ex = mergelist_parents[i];
+ if (!ex)
+ continue;
+ memcpy(&push->mergelists[i], ex->u.mergelist, sizeof (filter_rule_list));
}
/* Note: parse_filter_file() might increase mergelist_cnt, so keep
* this loop separate from the above loop. */
for (i = 0; i < mergelist_cnt; i++) {
filter_rule *ex = mergelist_parents[i];
- filter_rule_list *lp = ex->u.mergelist;
+ filter_rule_list *lp;
+ if (!ex)
+ continue;
+ lp = ex->u.mergelist;
if (DEBUG_GTE(FILTER, 2)) {
rprintf(FINFO, "[%s] pushing mergelist #%d%s\n",
for (i = mergelist_cnt; i-- > 0; ) {
filter_rule *ex = mergelist_parents[i];
- filter_rule_list *lp = ex->u.mergelist;
+ filter_rule_list *lp;
+ if (!ex)
+ continue;
+ lp = ex->u.mergelist;
if (DEBUG_GTE(FILTER, 2)) {
rprintf(FINFO, "[%s] popping mergelist #%d%s\n",
who_am_i(), i, lp->debug_type);
}
- clear_filter_list(lp);
-
- if (i >= old_mergelist_cnt) {
- /* This mergelist does not exist in the state to be
- * restored. Free its parent_dirscan list to clean up
- * any per-dir mergelists defined there so we don't
- * crash trying to restore nonexistent state for them
- * below. (Counterpart to setup_merge_file call in
- * push_local_filters. Must be done here, not in
- * free_filter, for LIFO order.) */
+ pop_filter_list(lp);
+ if (i >= old_mergelist_cnt && lp->head) {
+ /* This mergelist does not exist in the state to be restored, but it
+ * still has inherited rules. This can sometimes happen if a per-dir
+ * merge file calls setup_merge_file() in push_local_filters() and that
+ * leaves some inherited rules that aren't in the pushed list state. */
if (DEBUG_GTE(FILTER, 2)) {
rprintf(FINFO, "[%s] freeing parent_dirscan filters of mergelist #%d%s\n",
who_am_i(), i, ex->u.mergelist->debug_type);
}
- free_filters(lp->parent_dirscan_head);
- lp->parent_dirscan_head = NULL;
+ pop_filter_list(lp);
}
}
- /* If we cleaned things up properly, the only still-active mergelists
- * should be those with a state to be restored. */
- assert(mergelist_cnt == old_mergelist_cnt);
+ if (!pop)
+ return; /* No state to restore. */
- if (!pop) {
- /* No state to restore. */
- return;
- }
-
- for (i = 0; i < mergelist_cnt; i++) {
- memcpy(mergelist_parents[i]->u.mergelist, &pop->mergelists[i],
- sizeof (filter_rule_list));
+ for (i = 0; i < old_mergelist_cnt; i++) {
+ filter_rule *ex = mergelist_parents[i];
+ if (!ex)
+ continue;
+ memcpy(ex->u.mergelist, &pop->mergelists[i], sizeof (filter_rule_list));
}
free(pop);
filt_array[cur_depth] = push_local_filters(dname, dlen);
}
-static int rule_matches(const char *fname, filter_rule *ex, int name_is_dir)
+static int rule_matches(const char *fname, filter_rule *ex, int name_flags)
{
int slash_handling, str_cnt = 0, anchored_match = 0;
int ret_match = ex->rflags & FILTRULE_NEGATE ? 0 : 1;
const char *strings[16]; /* more than enough */
const char *name = fname + (*fname == '/');
- if (!*name)
+ if (!*name || ex->elide == cur_elide_value)
+ return 0;
+
+ if (!(name_flags & NAME_IS_XATTR) ^ !(ex->rflags & FILTRULE_XATTR))
return 0;
if (!ex->u.slash_cnt && !(ex->rflags & FILTRULE_WILD2)) {
strings[str_cnt++] = "/";
}
strings[str_cnt++] = name;
- if (name_is_dir) {
+ if (name_flags & NAME_IS_DIR) {
/* Allow a trailing "/"+"***" to match the directory. */
if (ex->rflags & FILTRULE_WILD3_SUFFIX)
strings[str_cnt++] = "/";
static void report_filter_result(enum logcode code, char const *name,
filter_rule const *ent,
- int name_is_dir, const char *type)
+ int name_flags, const char *type)
{
+ int log_level = am_sender || am_generator ? 1 : 3;
+
/* If a trailing slash is present to match only directories,
* then it is stripped out by add_rule(). So as a special
- * case we add it back in here. */
-
- if (DEBUG_GTE(FILTER, 1)) {
+ * case we add it back in the log output. */
+ if (DEBUG_GTE(FILTER, log_level)) {
static char *actions[2][2]
= { {"show", "hid"}, {"risk", "protect"} };
const char *w = who_am_i();
+ const char *t = name_flags & NAME_IS_XATTR ? "xattr"
+ : name_flags & NAME_IS_DIR ? "directory"
+ : "file";
rprintf(code, "[%s] %sing %s %s because of pattern %s%s%s\n",
- w, actions[*w!='s'][!(ent->rflags & FILTRULE_INCLUDE)],
- name_is_dir ? "directory" : "file", name, ent->pattern,
+ w, actions[*w=='g'][!(ent->rflags & FILTRULE_INCLUDE)],
+ t, name, ent->pattern,
ent->rflags & FILTRULE_DIRECTORY ? "/" : "", type);
}
}
+/* This function is used to check if a file should be included/excluded
+ * from the list of files based on its name and type etc. The value of
+ * filter_level is set to either SERVER_FILTERS or ALL_FILTERS. */
+int name_is_excluded(const char *fname, int name_flags, int filter_level)
+{
+ if (daemon_filter_list.head && check_filter(&daemon_filter_list, FLOG, fname, name_flags) < 0) {
+ if (!(name_flags & NAME_IS_XATTR))
+ errno = ENOENT;
+ return 1;
+ }
+
+ if (filter_level != ALL_FILTERS)
+ return 0;
+
+ if (filter_list.head && check_filter(&filter_list, FINFO, fname, name_flags) < 0)
+ return 1;
+
+ return 0;
+}
+
+int check_server_filter(filter_rule_list *listp, enum logcode code, const char *name, int name_flags)
+{
+ int ret;
+ cur_elide_value = LOCAL_RULE;
+ ret = check_filter(listp, code, name, name_flags);
+ cur_elide_value = REMOTE_RULE;
+ return ret;
+}
+
/* Return -1 if file "name" is defined to be excluded by the specified
* exclude list, 1 if it is included, and 0 if it was not matched. */
int check_filter(filter_rule_list *listp, enum logcode code,
- const char *name, int name_is_dir)
+ const char *name, int name_flags)
{
filter_rule *ent;
if (ignore_perishable && ent->rflags & FILTRULE_PERISHABLE)
continue;
if (ent->rflags & FILTRULE_PERDIR_MERGE) {
- int rc = check_filter(ent->u.mergelist, code, name,
- name_is_dir);
+ int rc = check_filter(ent->u.mergelist, code, name, name_flags);
if (rc)
return rc;
continue;
}
if (ent->rflags & FILTRULE_CVS_IGNORE) {
- int rc = check_filter(&cvs_filter_list, code, name,
- name_is_dir);
+ int rc = check_filter(&cvs_filter_list, code, name, name_flags);
if (rc)
return rc;
continue;
}
- if (rule_matches(name, ent, name_is_dir)) {
- report_filter_result(code, name, ent, name_is_dir,
- listp->debug_type);
+ if (rule_matches(name, ent, name_flags)) {
+ report_filter_result(code, name, ent, name_flags, listp->debug_type);
return ent->rflags & FILTRULE_INCLUDE ? 1 : -1;
}
}
if (!*s)
return NULL;
- if (!(rule = new0(filter_rule)))
- out_of_memory("parse_rule_tok");
+ rule = new0(filter_rule);
/* Inherit from the template. Don't inherit FILTRULES_SIDES; we check
* that later. */
}
switch (ch) {
case ':':
+ trust_sender_filter = 1;
rule->rflags |= FILTRULE_PERDIR_MERGE
- | FILTRULE_FINISH_SETUP;
+ | FILTRULE_FINISH_SETUP;
/* FALL THROUGH */
case '.':
rule->rflags |= FILTRULE_MERGE_FILE;
goto invalid;
rule->rflags |= FILTRULE_WORD_SPLIT;
break;
+ case 'x':
+ rule->rflags |= FILTRULE_XATTR;
+ saw_xattr_filter = 1;
+ break;
}
}
if (*s)
return rule;
}
-static char default_cvsignore[] =
- /* These default ignored items come from the CVS manual. */
- "RCS SCCS CVS CVS.adm RCSLOG cvslog.* tags TAGS"
- " .make.state .nse_depinfo *~ #* .#* ,* _$* *$"
- " *.old *.bak *.BAK *.orig *.rej .del-*"
- " *.a *.olb *.o *.obj *.so *.exe"
- " *.Z *.elc *.ln core"
- /* The rest we added to suit ourself. */
- " .svn/ .git/ .hg/ .bzr/";
-
static void get_cvs_excludes(uint32 rflags)
{
static int initialized = 0;
return;
initialized = 1;
- parse_filter_str(&cvs_filter_list, default_cvsignore,
+ parse_filter_str(&cvs_filter_list, default_cvsignore(),
rule_template(rflags | (protocol_version >= 30 ? FILTRULE_PERISHABLE : 0)),
0);
"[%s] clearing filter list%s\n",
who_am_i(), listp->debug_type);
}
- clear_filter_list(listp);
+ pop_filter_list(listp);
+ listp->head = NULL;
goto free_continue;
}
const char *name;
filter_rule *excl_self;
- if (!(excl_self = new0(filter_rule)))
- out_of_memory("parse_filter_str");
+ excl_self = new0(filter_rule);
/* Find the beginning of the basename and add an exclude for it. */
for (name = pat + pat_len; name > pat && name[-1] != '/'; name--) {}
add_rule(listp, name, (pat + pat_len) - name, excl_self, 0);
}
if (rule->rflags & FILTRULE_EXCLUDE_SELF)
*op++ = 'e';
+ if (rule->rflags & FILTRULE_XATTR)
+ *op++ = 'x';
if (rule->rflags & FILTRULE_SENDER_SIDE
&& (!for_xfer || protocol_version >= 29))
*op++ = 's';
static void send_rules(int f_out, filter_rule_list *flp)
{
- filter_rule *ent, *prev = NULL;
+ filter_rule *ent;
for (ent = flp->head; ent; ent = ent->next) {
unsigned int len, plen, dlen;
* merge files as an optimization (since they can only have
* include/exclude rules). */
if (ent->rflags & FILTRULE_SENDER_SIDE)
- elide = am_sender ? 1 : -1;
+ elide = am_sender ? LOCAL_RULE : REMOTE_RULE;
if (ent->rflags & FILTRULE_RECEIVER_SIDE)
- elide = elide ? 0 : am_sender ? -1 : 1;
+ elide = elide ? 0 : am_sender ? REMOTE_RULE : LOCAL_RULE;
else if (delete_excluded && !elide
&& (!(ent->rflags & FILTRULE_PERDIR_MERGE)
|| ent->rflags & FILTRULE_NO_PREFIXES))
- elide = am_sender ? 1 : -1;
- if (elide < 0) {
- if (prev)
- prev->next = ent->next;
- else
- flp->head = ent->next;
- } else
- prev = ent;
- if (elide > 0)
+ elide = am_sender ? LOCAL_RULE : REMOTE_RULE;
+ ent->elide = elide;
+ if (elide == LOCAL_RULE)
continue;
if (ent->rflags & FILTRULE_CVS_IGNORE
&& !(ent->rflags & FILTRULE_MERGE_FILE)) {
if (dlen)
write_byte(f_out, '/');
}
- flp->tail = prev;
}
/* This is only called by the client. */
char line[BIGPATHBUFLEN];
int xflags = protocol_version >= 29 ? 0 : XFLG_OLD_PREFIXES;
int receiver_wants_list = prune_empty_dirs
- || (delete_mode
- && (!delete_excluded || protocol_version >= 29));
+ || (delete_mode && (!delete_excluded || protocol_version >= 29));
unsigned int len;
if (!local_server && (am_sender || receiver_wants_list)) {