From 0b5732e263fa439906b298cdcab8f2dba3f93ce4 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 5 May 2011 10:08:53 -0700 Subject: [PATCH] remap: change the mode argument from a boolean to a character Instead of taking a boolean value for get/put, pass a character; this allows us to extend the number of possibilities in the future. Signed-off-by: H. Peter Anvin --- tftpd/remap.c | 21 ++++++++------------- tftpd/remap.h | 2 +- tftpd/tftpd.c | 3 ++- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/tftpd/remap.c b/tftpd/remap.c index cdb9062..1e7abe7 100644 --- a/tftpd/remap.c +++ b/tftpd/remap.c @@ -30,14 +30,13 @@ #define RULE_EXIT 0x04 /* Exit after matching this rule */ #define RULE_RESTART 0x08 /* Restart at the top after matching this rule */ #define RULE_ABORT 0x10 /* Terminate processing with an error */ -#define RULE_GETONLY 0x20 /* Applicable to GET only */ -#define RULE_PUTONLY 0x40 /* Applicable to PUT only */ -#define RULE_INVERSE 0x80 /* Execute if regex *doesn't* match */ +#define RULE_INVERSE 0x20 /* Execute if regex *doesn't* match */ struct rule { struct rule *next; int nrule; int rule_flags; + char rule_mode; regex_t rx; const char *pattern; }; @@ -221,15 +220,13 @@ static int parseline(char *line, struct rule *r, int lineno) case 'i': rxflags |= REG_ICASE; break; - case 'G': - r->rule_flags |= RULE_GETONLY; - break; - case 'P': - r->rule_flags |= RULE_PUTONLY; - break; case '~': r->rule_flags |= RULE_INVERSE; break; + case 'G': + case 'P': + r->rule_mode = *p; + break; default: syslog(LOG_ERR, "Remap command \"%s\" on line %d contains invalid char \"%c\"", @@ -329,7 +326,7 @@ void freerules(struct rule *r) /* Execute a rule set on a string; returns a malloc'd new string. */ char *rewrite_string(const char *input, const struct rule *rules, - int is_put, match_pattern_callback macrosub, + char mode, match_pattern_callback macrosub, const char **errmsg) { char *current = tfstrdup(input); @@ -348,10 +345,8 @@ char *rewrite_string(const char *input, const struct rule *rules, } for (ruleptr = rules; ruleptr; ruleptr = ruleptr->next) { - if (((ruleptr->rule_flags & RULE_GETONLY) && is_put) || - ((ruleptr->rule_flags & RULE_PUTONLY) && !is_put)) { + if (ruleptr->rule_mode && ruleptr->rule_mode != mode) continue; /* Rule not applicable, try next */ - } if (!deadman--) { syslog(LOG_WARNING, diff --git a/tftpd/remap.h b/tftpd/remap.h index 3830b5c..69ca08d 100644 --- a/tftpd/remap.h +++ b/tftpd/remap.h @@ -35,7 +35,7 @@ struct rule *parserulefile(FILE *); void freerules(struct rule *); /* Execute a rule set on a string; returns a malloc'd new string. */ -char *rewrite_string(const char *, const struct rule *, int, +char *rewrite_string(const char *, const struct rule *, char, match_pattern_callback, const char **); #endif /* WITH_REGEX */ diff --git a/tftpd/tftpd.c b/tftpd/tftpd.c index 69ff121..bdbea6d 100644 --- a/tftpd/tftpd.c +++ b/tftpd/tftpd.c @@ -1388,7 +1388,8 @@ static char *rewrite_access(char *filename, int mode, const char **msg) { if (rewrite_rules) { char *newname = - rewrite_string(filename, rewrite_rules, mode != RRQ, + rewrite_string(filename, rewrite_rules, + mode != RRQ ? 'P' : 'G', rewrite_macros, msg); filename = newname; } -- 2.11.4.GIT