summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd/forward.c
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2009-03-03 23:23:53 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2009-03-03 23:23:53 +0000
commitb62af95fa98188118939cff3b1d5d942bb20b934 (patch)
treefb0389cc8e695b71ba659ed6ac76f105754b924f /usr.sbin/smtpd/forward.c
parent7e32d8837264f3c4f2103da7b0027e3dad040339 (diff)
Fix a long standing issue where ~/.forward files were opened by user _smtpd
causing them not to be handled when a user's homedir is set to mode 0700. I still need to do some cleanup and make sure it works as it should, but this diff provides better behavior than what we had.
Diffstat (limited to 'usr.sbin/smtpd/forward.c')
-rw-r--r--usr.sbin/smtpd/forward.c35
1 files changed, 3 insertions, 32 deletions
diff --git a/usr.sbin/smtpd/forward.c b/usr.sbin/smtpd/forward.c
index ac2757a95fb..fb5decbdd45 100644
--- a/usr.sbin/smtpd/forward.c
+++ b/usr.sbin/smtpd/forward.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: forward.c,v 1.12 2009/02/22 11:44:29 form Exp $ */
+/* $OpenBSD: forward.c,v 1.13 2009/03/03 23:23:52 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -35,43 +35,20 @@
#include "smtpd.h"
int
-forwards_get(struct aliaseslist *aliases, char *username)
+forwards_get(int fd, struct aliaseslist *aliases)
{
FILE *fp;
struct alias alias;
struct alias *aliasp;
- 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)
- return 0;
-
- if (! bsnprintf(pathname, sizeof(pathname), "%s/.forward", pw->pw_dir))
- return 0;
-
- fp = fopen(pathname, "r");
+ fp = fdopen(fd, "r");
if (fp == NULL)
return 0;
- log_debug("+ opening forward file %s", pathname);
- /* make sure ~/ is not writable by anyone but owner */
- if (stat(pw->pw_dir, &sb) == -1)
- goto bad;
- if (sb.st_uid != pw->pw_uid || sb.st_mode & (S_IWGRP|S_IWOTH))
- goto bad;
-
- /* make sure ~/.forward is not writable by anyone but owner */
- if (fstat(fileno(fp), &sb) == -1)
- goto bad;
- if (sb.st_uid != pw->pw_uid || sb.st_mode & (S_IWGRP|S_IWOTH))
- goto bad;
-
lbuf = NULL;
while ((buf = fgetln(fp, &len))) {
if (buf[len - 1] == '\n')
@@ -130,10 +107,4 @@ forwards_get(struct aliaseslist *aliases, char *username)
free(lbuf);
fclose(fp);
return (nbaliases);
-
-bad:
- log_debug("+ forward file error, probably bad perms/mode");
- if (fp != NULL)
- fclose(fp);
- return (0);
}