diff options
author | Charles Longeau <chl@cvs.openbsd.org> | 2011-11-23 13:48:04 +0000 |
---|---|---|
committer | Charles Longeau <chl@cvs.openbsd.org> | 2011-11-23 13:48:04 +0000 |
commit | 23c8c1b7348659e6da6ee988df1422e263d59262 (patch) | |
tree | f5d8f21f603907958124096da4d5534225c8488b | |
parent | 6a3023b8680d9221f19f9c1b0c93d3594ed5fde9 (diff) |
Fix Segmentation Fault when launching mailq(8)
Bug reported by Mark Patruck <mark at wrapped.cx>
ok gilles@ eric@
-rw-r--r-- | usr.sbin/smtpd/smtpctl.c | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c index f71c96000c6..7d41c10a8e1 100644 --- a/usr.sbin/smtpd/smtpctl.c +++ b/usr.sbin/smtpd/smtpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpctl.c,v 1.71 2011/11/15 23:06:39 gilles Exp $ */ +/* $OpenBSD: smtpctl.c,v 1.72 2011/11/23 13:48:03 chl Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -41,6 +41,7 @@ #include "parser.h" void usage(void); +static void setup_env(struct smtpd *); static void show_sizes(void); static int show_command_output(struct imsg *); static int show_stats_output(struct imsg *); @@ -66,12 +67,30 @@ usage(void) exit(1); } +static void +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); + + env->sc_queue = queue_backend_lookup(QT_FS); + if (env->sc_queue == NULL) + errx(1, "could not find queue backend"); + + if (!env->sc_queue->init()) + errx(1, "invalid directory permissions"); +} + int main(int argc, char *argv[]) { struct sockaddr_un sun; struct parse_result *res = NULL; struct imsg imsg; + struct smtpd smtpd; int ctl_sock; int done = 0; int n, verbose = 0; @@ -82,26 +101,16 @@ main(int argc, char *argv[]) else if (strcmp(__progname, "mailq") == 0) { if (geteuid()) errx(1, "need root privileges"); + setup_env(&smtpd); show_queue(Q_QUEUE, 0); return 0; } else if (strcmp(__progname, "smtpctl") == 0) { - struct smtpd smtpd; /* check for root privileges */ if (geteuid()) errx(1, "need root privileges"); - bzero(&smtpd, sizeof (smtpd)); - env = &smtpd; - if ((env->sc_pw = getpwnam(SMTPD_USER)) == NULL) - errx(1, "unknown user %s", SMTPD_USER); - - env->sc_queue = queue_backend_lookup(QT_FS); - if (env->sc_queue == NULL) - errx(1, "could not find queue backend"); - - if (!env->sc_queue->init()) - errx(1, "invalid directory permissions"); + setup_env(&smtpd); if ((res = parse(argc - 1, argv + 1)) == NULL) exit(1); |