diff options
author | Oleg Safiullin <form@cvs.openbsd.org> | 2009-01-29 21:50:11 +0000 |
---|---|---|
committer | Oleg Safiullin <form@cvs.openbsd.org> | 2009-01-29 21:50:11 +0000 |
commit | acdcfa87b77e045144bec3e56d7cd8360bcf2e3d (patch) | |
tree | 949b10a0b020266998739f3410027fe4acc39c2c /usr.sbin | |
parent | ffd9e167097620bb10be8a6bf0e276b6708e3514 (diff) |
better parsing of .forward files
ok gilles@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/smtpd/forward.c | 63 |
1 files changed, 44 insertions, 19 deletions
diff --git a/usr.sbin/smtpd/forward.c b/usr.sbin/smtpd/forward.c index 8798509b3a4..5af8f4725fa 100644 --- a/usr.sbin/smtpd/forward.c +++ b/usr.sbin/smtpd/forward.c @@ -1,4 +1,4 @@ -/* $OpenBSD: forward.c,v 1.10 2009/01/08 19:17:31 jacekm Exp $ */ +/* $OpenBSD: forward.c,v 1.11 2009/01/29 21:50:10 form Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -40,12 +40,13 @@ forwards_get(struct aliaseslist *aliases, char *username) FILE *fp; struct alias alias; struct alias *aliasp; - char pathname[MAXPATHLEN]; - char *buf, *lbuf; + char pathname[MAXPATHLEN]; + char *buf, *lbuf, *p, *cp; size_t len; struct stat sb; struct passwd *pw; size_t nbaliases = 0; + int quoted; pw = safe_getpwnam(username); if (pw == NULL) @@ -85,31 +86,55 @@ forwards_get(struct aliaseslist *aliases, char *username) buf = lbuf; } - log_debug("\tforward: %s", buf); - if (! alias_parse(&alias, buf)) { - log_debug("bad entry in ~/.forward"); + /* ignore empty lines and comments */ + if (buf[0] == '#' || buf[0] == '\0') continue; - } - if (alias.type == ALIAS_INCLUDE) { - log_debug("includes are forbidden in ~/.forward"); - continue; - } - aliasp = calloc(1, sizeof(struct alias)); - if (aliasp == NULL) - fatal("calloc"); - *aliasp = alias; - TAILQ_INSERT_HEAD(aliases, aliasp, entry); - nbaliases++; + quoted = 0; + cp = buf; + do { + /* skip whitespace */ + while (isspace(*cp)) + cp++; + + /* parse line */ + for (p = cp; *p != '\0'; p++) { + if (*p == ',' && !quoted) { + *p++ = '\0'; + break; + } else if (*p == '"') + quoted = !quoted; + } + buf = cp; + cp = p; + + log_debug("\tforward: %s", buf); + if (! alias_parse(&alias, buf)) { + log_debug("bad entry in ~/.forward"); + continue; + } + + if (alias.type == ALIAS_INCLUDE) { + log_debug( + "includes are forbidden in ~/.forward"); + continue; + } + aliasp = calloc(1, sizeof(struct alias)); + if (aliasp == NULL) + fatal("calloc"); + *aliasp = alias; + TAILQ_INSERT_HEAD(aliases, aliasp, entry); + nbaliases++; + } while (*cp != '\0'); } free(lbuf); fclose(fp); - return nbaliases; + return (nbaliases); bad: log_debug("+ forward file error, probably bad perms/mode"); if (fp != NULL) fclose(fp); - return 0; + return (0); } |