diff options
author | Eric Faurot <eric@cvs.openbsd.org> | 2013-07-19 11:14:09 +0000 |
---|---|---|
committer | Eric Faurot <eric@cvs.openbsd.org> | 2013-07-19 11:14:09 +0000 |
commit | e69f8efeb851880afaf846c6c6f9ab4f0fb25226 (patch) | |
tree | 33347af75abf372ce6faa6f682a058b17ae70346 /usr.sbin/smtpd | |
parent | 6fff6905b9aa3bc12806712cb01ed4cbeb444ea7 (diff) |
Get rid of env->sc_pw and env->sc_pwqueue. Early queue initialization
now happens in queue_init(), and backends take the queue passwd as
parameter in their init function.
Remove useless SMTPD_FILTER_USER while there.
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r-- | usr.sbin/smtpd/control.c | 7 | ||||
-rw-r--r-- | usr.sbin/smtpd/lka.c | 5 | ||||
-rw-r--r-- | usr.sbin/smtpd/mda.c | 7 | ||||
-rw-r--r-- | usr.sbin/smtpd/mfa.c | 8 | ||||
-rw-r--r-- | usr.sbin/smtpd/mta.c | 8 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue.c | 11 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue_backend.c | 28 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue_fsqueue.c | 8 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue_null.c | 6 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue_ram.c | 6 | ||||
-rw-r--r-- | usr.sbin/smtpd/scheduler.c | 8 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtp.c | 7 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpctl.c | 15 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.c | 37 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 10 |
15 files changed, 80 insertions, 91 deletions
diff --git a/usr.sbin/smtpd/control.c b/usr.sbin/smtpd/control.c index 5006f50c6c3..891a8096567 100644 --- a/usr.sbin/smtpd/control.c +++ b/usr.sbin/smtpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.86 2013/07/19 07:49:08 eric Exp $ */ +/* $OpenBSD: control.c,v 1.87 2013/07/19 11:14:08 eric Exp $ */ /* * Copyright (c) 2012 Gilles Chehade <gilles@poolp.org> @@ -188,7 +188,8 @@ control(void) purge_config(PURGE_EVERYTHING); - pw = env->sc_pw; + if ((pw = getpwnam(SMTPD_USER)) == NULL) + fatalx("unknown user " SMTPD_USER); if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) fatal("control: socket"); @@ -225,7 +226,7 @@ control(void) stat_backend = env->sc_stat; stat_backend->init(); - if (chroot(pw->pw_dir) == -1) + if (chroot(PATH_CHROOT) == -1) fatal("control: chroot"); if (chdir("/") == -1) fatal("control: chdir(\"/\")"); diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c index 9c76bacffcc..ab5f7b99c27 100644 --- a/usr.sbin/smtpd/lka.c +++ b/usr.sbin/smtpd/lka.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka.c,v 1.153 2013/07/19 07:49:08 eric Exp $ */ +/* $OpenBSD: lka.c,v 1.154 2013/07/19 11:14:08 eric Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -589,7 +589,8 @@ lka(void) purge_config(PURGE_EVERYTHING); - pw = env->sc_pw; + if ((pw = getpwnam(SMTPD_USER)) == NULL) + fatalx("unknown user " SMTPD_USER); config_process(PROC_LKA); diff --git a/usr.sbin/smtpd/mda.c b/usr.sbin/smtpd/mda.c index 9a6b74551ca..647d56e0a75 100644 --- a/usr.sbin/smtpd/mda.c +++ b/usr.sbin/smtpd/mda.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mda.c,v 1.92 2013/07/19 07:49:08 eric Exp $ */ +/* $OpenBSD: mda.c,v 1.93 2013/07/19 11:14:08 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -507,9 +507,10 @@ mda(void) purge_config(PURGE_EVERYTHING); - pw = env->sc_pw; + if ((pw = getpwnam(SMTPD_USER)) == NULL) + fatalx("unknown user " SMTPD_USER); - if (chroot(pw->pw_dir) == -1) + if (chroot(PATH_CHROOT) == -1) fatal("mda: chroot"); if (chdir("/") == -1) fatal("mda: chdir(\"/\")"); diff --git a/usr.sbin/smtpd/mfa.c b/usr.sbin/smtpd/mfa.c index 2e2e4e53ef2..244704f4f3f 100644 --- a/usr.sbin/smtpd/mfa.c +++ b/usr.sbin/smtpd/mfa.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mfa.c,v 1.77 2013/07/19 07:49:08 eric Exp $ */ +/* $OpenBSD: mfa.c,v 1.78 2013/07/19 11:14:08 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -227,10 +227,8 @@ mfa(void) purge_config(PURGE_EVERYTHING); - if ((env->sc_pw = getpwnam(SMTPD_FILTER_USER)) == NULL) - if ((env->sc_pw = getpwnam(SMTPD_USER)) == NULL) - fatalx("unknown user " SMTPD_USER); - pw = env->sc_pw; + if ((pw = getpwnam(SMTPD_USER)) == NULL) + fatalx("unknown user " SMTPD_USER); config_process(PROC_MFA); diff --git a/usr.sbin/smtpd/mta.c b/usr.sbin/smtpd/mta.c index e8f74b0463e..55da6744b39 100644 --- a/usr.sbin/smtpd/mta.c +++ b/usr.sbin/smtpd/mta.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mta.c,v 1.160 2013/07/19 07:49:08 eric Exp $ */ +/* $OpenBSD: mta.c,v 1.161 2013/07/19 11:14:08 eric Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -430,8 +430,10 @@ mta(void) purge_config(PURGE_EVERYTHING); - pw = env->sc_pw; - if (chroot(pw->pw_dir) == -1) + if ((pw = getpwnam(SMTPD_USER)) == NULL) + fatalx("unknown user " SMTPD_USER); + + if (chroot(PATH_CHROOT) == -1) fatal("mta: chroot"); if (chdir("/") == -1) fatal("mta: chdir(\"/\")"); diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c index 6bebc5d7340..f0088ec61a3 100644 --- a/usr.sbin/smtpd/queue.c +++ b/usr.sbin/smtpd/queue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue.c,v 1.149 2013/07/19 07:49:08 eric Exp $ */ +/* $OpenBSD: queue.c,v 1.150 2013/07/19 11:14:08 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -540,12 +540,11 @@ queue(void) } purge_config(PURGE_EVERYTHING); - if (env->sc_pwqueue) { - free(env->sc_pw); - env->sc_pw = env->sc_pwqueue; - } - pw = env->sc_pw; + if ((pw = getpwnam(SMTPD_QUEUE_USER)) == NULL) + if ((pw = getpwnam(SMTPD_USER)) == NULL) + fatalx("unknown user " SMTPD_USER); + if (chroot(PATH_SPOOL) == -1) fatal("queue: chroot"); if (chdir("/") == -1) diff --git a/usr.sbin/smtpd/queue_backend.c b/usr.sbin/smtpd/queue_backend.c index 5fc1cd1994d..bed293ef237 100644 --- a/usr.sbin/smtpd/queue_backend.c +++ b/usr.sbin/smtpd/queue_backend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue_backend.c,v 1.44 2013/05/24 17:03:14 eric Exp $ */ +/* $OpenBSD: queue_backend.c,v 1.45 2013/07/19 11:14:08 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@poolp.org> @@ -23,6 +23,7 @@ #include <sys/stat.h> #include <ctype.h> +#include <err.h> #include <errno.h> #include <event.h> #include <fcntl.h> @@ -92,7 +93,14 @@ queue_message_incoming_path(uint32_t msgid, char *buf, size_t len) int queue_init(const char *name, int server) { - int r; + struct passwd *pwq; + int r; + + pwq = getpwnam(SMTPD_QUEUE_USER); + if (pwq == NULL) + pwq = getpwnam(SMTPD_USER); + if (pwq == NULL) + errx(1, "unknown user %s", SMTPD_USER); if (!strcmp(name, "fs")) backend = &queue_backend_fs; @@ -106,7 +114,21 @@ queue_init(const char *name, int server) return (0); } - r = backend->init(server); + if (server) { + if (ckdir(PATH_SPOOL, 0711, 0, 0, 1) == 0) + errx(1, "error in spool directory setup"); + if (ckdir(PATH_SPOOL PATH_OFFLINE, 01777, 0, 0, 1) == 0) + errx(1, "error in offline directory setup"); + if (ckdir(PATH_SPOOL PATH_PURGE, 0700, pwq->pw_uid, 0, 1) == 0) + errx(1, "error in purge directory setup"); + + mvpurge(PATH_SPOOL PATH_TEMPORARY, PATH_SPOOL PATH_PURGE); + + if (ckdir(PATH_SPOOL PATH_TEMPORARY, 0700, pwq->pw_uid, 0, 1) == 0) + errx(1, "error in purge directory setup"); + } + + r = backend->init(pwq, server); log_trace(TRACE_QUEUE, "queue-backend: queue_init(%i) -> %i", server, r); diff --git a/usr.sbin/smtpd/queue_fsqueue.c b/usr.sbin/smtpd/queue_fsqueue.c index 85e6e233c2e..bce2608c100 100644 --- a/usr.sbin/smtpd/queue_fsqueue.c +++ b/usr.sbin/smtpd/queue_fsqueue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue_fsqueue.c,v 1.62 2013/05/24 17:03:14 eric Exp $ */ +/* $OpenBSD: queue_fsqueue.c,v 1.63 2013/07/19 11:14:08 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@poolp.org> @@ -62,7 +62,7 @@ static void fsqueue_envelope_incoming_path(uint64_t, char *, size_t); static int fsqueue_envelope_dump(char *, char *, size_t, int, int); -static int fsqueue_init(int); +static int fsqueue_init(struct passwd *, int); static int fsqueue_message(enum queue_op, uint32_t *); static int fsqueue_envelope(enum queue_op , uint64_t *, char *, size_t); @@ -527,7 +527,7 @@ again: } static int -fsqueue_init(int server) +fsqueue_init(struct passwd *pwq, int server) { unsigned int n; char *paths[] = { PATH_QUEUE, PATH_CORRUPT }; @@ -543,7 +543,7 @@ fsqueue_init(int server) if (strlcat(path, paths[n], sizeof(path)) >= sizeof(path)) errx(1, "path too long %s%s", PATH_SPOOL, paths[n]); - if (ckdir(path, 0700, env->sc_pwqueue->pw_uid, 0, server) == 0) + if (ckdir(path, 0700, pwq->pw_uid, 0, server) == 0) ret = 0; } diff --git a/usr.sbin/smtpd/queue_null.c b/usr.sbin/smtpd/queue_null.c index e6f1ed279e9..e60b5f42dcc 100644 --- a/usr.sbin/smtpd/queue_null.c +++ b/usr.sbin/smtpd/queue_null.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue_null.c,v 1.2 2013/05/24 17:03:14 eric Exp $ */ +/* $OpenBSD: queue_null.c,v 1.3 2013/07/19 11:14:08 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> @@ -40,7 +40,7 @@ #include "smtpd.h" #include "log.h" -static int queue_null_init(int); +static int queue_null_init(struct passwd *, int); static int queue_null_message(enum queue_op, uint32_t *); static int queue_null_envelope(enum queue_op , uint64_t *, char *, size_t); @@ -53,7 +53,7 @@ struct queue_backend queue_backend_null = { static int devnull; static int -queue_null_init(int server) +queue_null_init(struct passwd *pw, int server) { devnull = open("/dev/null", O_WRONLY, 0777); diff --git a/usr.sbin/smtpd/queue_ram.c b/usr.sbin/smtpd/queue_ram.c index 55b3c3fd08d..12cf6c83842 100644 --- a/usr.sbin/smtpd/queue_ram.c +++ b/usr.sbin/smtpd/queue_ram.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue_ram.c,v 1.3 2013/05/24 17:03:14 eric Exp $ */ +/* $OpenBSD: queue_ram.c,v 1.4 2013/07/19 11:14:08 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> @@ -40,7 +40,7 @@ #include "smtpd.h" #include "log.h" -static int queue_ram_init(int); +static int queue_ram_init(struct passwd *, int); static int queue_ram_message(enum queue_op, uint32_t *); static int queue_ram_envelope(enum queue_op , uint64_t *, char *, size_t); @@ -65,7 +65,7 @@ struct qr_message { static struct tree messages; static int -queue_ram_init(int server) +queue_ram_init(struct passwd *pw, int server) { tree_init(&messages); diff --git a/usr.sbin/smtpd/scheduler.c b/usr.sbin/smtpd/scheduler.c index 1c09faf562e..60bc64c71c2 100644 --- a/usr.sbin/smtpd/scheduler.c +++ b/usr.sbin/smtpd/scheduler.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scheduler.c,v 1.29 2013/07/19 07:49:08 eric Exp $ */ +/* $OpenBSD: scheduler.c,v 1.30 2013/07/19 11:14:08 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -337,14 +337,16 @@ scheduler(void) purge_config(PURGE_EVERYTHING); + if ((pw = getpwnam(SMTPD_USER)) == NULL) + fatalx("unknown user " SMTPD_USER); + config_process(PROC_SCHEDULER); fdlimit(1.0); backend->init(); - pw = env->sc_pw; - if (chroot(pw->pw_dir) == -1) + if (chroot(PATH_CHROOT) == -1) fatal("scheduler: chroot"); if (chdir("/") == -1) fatal("scheduler: chdir(\"/\")"); diff --git a/usr.sbin/smtpd/smtp.c b/usr.sbin/smtpd/smtp.c index 7b64c21d101..5ac4d840019 100644 --- a/usr.sbin/smtpd/smtp.c +++ b/usr.sbin/smtpd/smtp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtp.c,v 1.126 2013/07/19 07:49:08 eric Exp $ */ +/* $OpenBSD: smtp.c,v 1.127 2013/07/19 11:14:08 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -247,9 +247,10 @@ smtp(void) purge_config(PURGE_EVERYTHING); - pw = env->sc_pw; + if ((pw = getpwnam(SMTPD_USER)) == NULL) + fatalx("unknown user " SMTPD_USER); - if (chroot(pw->pw_dir) == -1) + if (chroot(PATH_CHROOT) == -1) fatal("smtp: chroot"); if (chdir("/") == -1) fatal("smtp: chdir(\"/\")"); diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c index d0ee54a419e..ea1926fc129 100644 --- a/usr.sbin/smtpd/smtpctl.c +++ b/usr.sbin/smtpd/smtpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpctl.c,v 1.104 2013/05/24 17:03:14 eric Exp $ */ +/* $OpenBSD: smtpctl.c,v 1.105 2013/07/19 11:14:08 eric Exp $ */ /* * Copyright (c) 2006 Gilles Chehade <gilles@poolp.org> @@ -102,19 +102,6 @@ setup_env(struct smtpd *smtpd) bzero(smtpd, sizeof (*smtpd)); env = smtpd; - if ((env->sc_pw = getpwnam(SMTPD_USER)) == NULL) - errx(1, "unknown user %s", SMTPD_USER); - if ((env->sc_pw = pw_dup(env->sc_pw)) == NULL) - err(1, NULL); - - env->sc_pwqueue = getpwnam(SMTPD_QUEUE_USER); - if (env->sc_pwqueue) - env->sc_pwqueue = pw_dup(env->sc_pwqueue); - else - env->sc_pwqueue = pw_dup(env->sc_pw); - if (env->sc_pwqueue == NULL) - err(1, NULL); - if (!queue_init("fs", 0)) errx(1, "invalid directory permissions"); } diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c index cdc25f7d10f..aa733ccf225 100644 --- a/usr.sbin/smtpd/smtpd.c +++ b/usr.sbin/smtpd/smtpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.c,v 1.192 2013/07/04 07:04:07 gilles Exp $ */ +/* $OpenBSD: smtpd.c,v 1.193 2013/07/19 11:14:08 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -588,7 +588,6 @@ main(int argc, char *argv[]) struct event ev_sigchld; struct event ev_sighup; struct timeval tv; - struct passwd *pwq; env = &smtpd; @@ -715,33 +714,6 @@ main(int argc, char *argv[]) if (geteuid()) errx(1, "need root privileges"); - if ((env->sc_pw = getpwnam(SMTPD_USER)) == NULL) - errx(1, "unknown user %s", SMTPD_USER); - if ((env->sc_pw = pw_dup(env->sc_pw)) == NULL) - err(1, NULL); - - env->sc_pwqueue = getpwnam(SMTPD_QUEUE_USER); - if (env->sc_pwqueue) - pwq = env->sc_pwqueue = pw_dup(env->sc_pwqueue); - else - pwq = env->sc_pwqueue = pw_dup(env->sc_pw); - if (env->sc_pwqueue == NULL) - err(1, NULL); - - if (ckdir(PATH_SPOOL, 0711, 0, 0, 1) == 0) - errx(1, "error in spool directory setup"); - if (ckdir(PATH_SPOOL PATH_OFFLINE, 01777, 0, 0, 1) == 0) - errx(1, "error in offline directory setup"); - if (ckdir(PATH_SPOOL PATH_PURGE, 0700, pwq->pw_uid, 0, 1) == 0) - errx(1, "error in purge directory setup"); - if (ckdir(PATH_SPOOL PATH_TEMPORARY, 0700, pwq->pw_uid, 0, 1) == 0) - errx(1, "error in purge directory setup"); - - mvpurge(PATH_SPOOL PATH_INCOMING, PATH_SPOOL PATH_PURGE); - - if (ckdir(PATH_SPOOL PATH_INCOMING, 0700, pwq->pw_uid, 0, 1) == 0) - errx(1, "error in incoming directory setup"); - if (!queue_init(backend_queue, 1)) errx(1, "could not initialize queue backend"); @@ -913,6 +885,7 @@ child_add(pid_t pid, int type, const char *title) static void purge_task(int fd, short ev, void *arg) { + struct passwd *pw; DIR *d; int n; uid_t uid; @@ -934,12 +907,14 @@ purge_task(int fd, short ev, void *arg) log_warn("warn: purge_task: fork"); break; case 0: + if ((pw = getpwnam(SMTPD_USER)) == NULL) + fatalx("unknown user " SMTPD_USER); if (chroot(PATH_SPOOL PATH_PURGE) == -1) fatal("smtpd: chroot"); if (chdir("/") == -1) fatal("smtpd: chdir"); - uid = env->sc_pw->pw_uid; - gid = env->sc_pw->pw_gid; + uid = pw->pw_uid; + gid = pw->pw_gid; if (setgroups(1, &gid) || setresgid(gid, gid, gid) || setresuid(uid, uid, uid)) diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 48289ad8faa..cec8ebfd036 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.414 2013/07/19 08:12:19 eric Exp $ */ +/* $OpenBSD: smtpd.h,v 1.415 2013/07/19 11:14:08 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -49,7 +49,6 @@ #define SMTPD_QUEUE_MAXINTERVAL (4 * 60 * 60) #define SMTPD_QUEUE_EXPIRY (4 * 24 * 60 * 60) #define SMTPD_USER "_smtpd" -#define SMTPD_FILTER_USER "_smtpf" #define SMTPD_QUEUE_USER "_smtpq" #define SMTPD_SOCKET "/var/run/smtpd.sock" #ifndef SMTPD_NAME @@ -62,6 +61,7 @@ #define PATH_SMTPCTL "/usr/sbin/smtpctl" +#define PATH_CHROOT "/var/empty" #define PATH_SPOOL "/var/spool/smtpd" #define PATH_OFFLINE "/offline" #define PATH_PURGE "/purge" @@ -551,8 +551,6 @@ struct smtpd { int sc_qexpire; #define MAX_BOUNCE_WARN 4 time_t sc_bounce_warn[MAX_BOUNCE_WARN]; - struct passwd *sc_pw; - struct passwd *sc_pwqueue; char sc_hostname[SMTPD_MAXHOSTNAMELEN]; struct stat_backend *sc_stat; struct compress_backend *sc_comp; @@ -769,8 +767,10 @@ enum queue_op { QOP_CORRUPT, }; +struct passwd; + struct queue_backend { - int (*init)(int); + int (*init)(struct passwd *, int); int (*message)(enum queue_op, uint32_t *); int (*envelope)(enum queue_op, uint64_t *, char *, size_t); }; |