Commit a1bf4e21 a1bf4e218255bf7b70cb5ef115e61064030666ba by Sergey Poznyakoff

* NEWS: Update.

* imap4d/bye.c, imap4d/starttls.c, imap4d/util.c: Use exit codes
from sysexits.h
* imap4d/imap4d.c: Use mu_set_signals to install signals.
Use exit codes from sysexits.h.
* imap4d/imap4d.h: Include sysexits.h and muaux.h
(ERR_TERMINATE): New define.
(imap4d_sigchld,imap4d_signal): Remove.
(imap4d_master_signal,imap4d_child_signal): New prototypes.
* imap4d/signal.c (imap4d_master_signal,imap4d_child_signal): New
functions.

* pop3d/pop3d.h Include sysexits.h and muaux.h
(ERR_TERMINATE): New define.
(pop3d_signal): Remove.
(pop3d_master_signal, pop3d_child_signal): New protos.
* pop3d/signal.c (pop3d_master_signal, pop3d_child_signal): New
functions.

* pop3d/extra.c, pop3d/popauth.c
* pop3d/pop3d.c: Use mu_set_signals to install signals.
Use exit codes from sysexits.h.

* include/mailutils/server.h (mu_m_server_set_strexit): New
prototype.
* include/mailutils/types.hin (MU_ARRAY_SIZE): New define.

* lib/Makefile.am (libmuaux_la_SOURCES): Add signal.c, strexit.c.
(noinst_HEADERS): Add muaux.h
* lib/muaux.h: New file.

* libsieve/extensions/spamd.c: Add NLS markers.

* mailbox/header.c (header_readline): Minor rewrite.
* mailbox/msrv.c (struct _mu_m_server): New member `strexit'.
(mu_m_server_begin): Call alloc_children.
(mu_m_server_restore_signals): New function.
(mu_m_server_end): Call mu_m_server_restore_signals.
(m_srv_conn): Reset signals in child branch.

* po/POTFILES.in: Update.
1 parent f3e3db45
2008-02-05 Sergey Poznyakoff <gray@gnu.org.ua>
* pop3d/extra.c (pop3d_readline): After a failed authorization
attempt many clients simply disconnect without issuing QUIT.
Do not count this as a protocol error.
* NEWS: Update.
* imap4d/bye.c, imap4d/starttls.c, imap4d/util.c: Use exit codes
from sysexits.h
......
GNU mailutils NEWS -- history of user-visible changes. 2008-02-04
Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007,
2008 Free Software Foundation, Inc.
See the end of file for copying conditions.
Please send mailutils bug reports to <bug-mailutils@gnu.org>.
......@@ -1026,7 +1027,8 @@ The first release.
----------------------------------------------------------------------
Copyright information:
Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007,
2008 Free Software Foundation, Inc.
Permission is granted to anyone to make or distribute verbatim copies
of this document as received, in any medium, provided that the
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2005,
2007 Free Software Foundation, Inc.
2007, 2008 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -28,7 +28,7 @@ imap4d_bye (int reason)
int
imap4d_bye0 (int reason, struct imap4d_command *command)
{
int status = EXIT_FAILURE;
int status = EX_SOFTWARE;
if (mbox)
{
......@@ -40,15 +40,22 @@ imap4d_bye0 (int reason, struct imap4d_command *command)
switch (reason)
{
case ERR_NO_MEM:
util_out (RESP_BYE, "Server terminating no more resources.");
util_out (RESP_BYE, "Server terminating: no more resources.");
mu_diag_output (MU_DIAG_ERROR, _("Out of memory"));
break;
case ERR_TERMINATE:
status = EX_OK;
util_out (RESP_BYE, "Server terminating on request.");
mu_diag_output (MU_DIAG_NOTICE, _("Terminating on request"));
break;
case ERR_SIGNAL:
mu_diag_output (MU_DIAG_ERROR, _("Quitting on signal"));
exit (status);
case ERR_TIMEOUT:
status = EX_TEMPFAIL;
util_out (RESP_BYE, "Session timed out");
if (state == STATE_NONAUTH)
mu_diag_output (MU_DIAG_INFO, _("Session timed out for no user"));
......@@ -57,20 +64,22 @@ imap4d_bye0 (int reason, struct imap4d_command *command)
break;
case ERR_NO_OFILE:
status = EX_IOERR;
mu_diag_output (MU_DIAG_INFO, _("No socket to send to"));
break;
case ERR_MAILBOX_CORRUPTED:
status = EX_OSERR;
mu_diag_output (MU_DIAG_ERROR, _("Mailbox modified by third party"));
break;
case OK:
status = EX_OK;
util_out (RESP_BYE, "Session terminating.");
if (state == STATE_NONAUTH)
mu_diag_output (MU_DIAG_INFO, _("Session terminating"));
else
mu_diag_output (MU_DIAG_INFO, _("Session terminating for user: %s"), auth_data->name);
status = EXIT_SUCCESS;
break;
default:
......@@ -79,7 +88,7 @@ imap4d_bye0 (int reason, struct imap4d_command *command)
break;
}
if (status == EXIT_SUCCESS && command)
if (status == EX_OK && command)
util_finish (command, RESP_OK, "Completed");
util_bye ();
......
......@@ -372,11 +372,11 @@ imap4d_mainloop (int fd, FILE *infile, FILE *outfile)
{
char *text;
int debug_mode = isatty (fd);
static int sigtab[] = { SIGILL, SIGBUS, SIGFPE, SIGSEGV, SIGSTOP, SIGPIPE,
SIGABRT, SIGINT, SIGQUIT, SIGTERM, SIGHUP, SIGALRM };
/* Reset hup to exit. */
signal (SIGHUP, imap4d_signal);
/* Timeout alarm. */
signal (SIGALRM, imap4d_signal);
/* Reset signals */
mu_set_signals (imap4d_child_signal, sigtab, MU_ARRAY_SIZE (sigtab));
util_setio (infile, outfile);
......@@ -393,7 +393,7 @@ imap4d_mainloop (int fd, FILE *infile, FILE *outfile)
else
{
util_flush_output ();
return EXIT_SUCCESS;
return 0;
}
/* Greetings. */
......@@ -411,7 +411,7 @@ imap4d_mainloop (int fd, FILE *infile, FILE *outfile)
util_flush_output ();
}
return EXIT_SUCCESS;
return 0;
}
int
......@@ -458,7 +458,9 @@ int
main (int argc, char **argv)
{
struct group *gr;
int status = EXIT_SUCCESS;
int status = 0;
static int sigtab[] = { SIGILL, SIGBUS, SIGFPE, SIGSEGV, SIGSTOP, SIGPIPE,
SIGABRT };
/* Native Language Support */
MU_APP_INIT_NLS ();
......@@ -490,10 +492,11 @@ main (int argc, char **argv)
/* FIXME mu_m_server_set_pidfile (); */
mu_m_server_set_default_port (server, 143);
mu_m_server_set_timeout (server, 1800); /* RFC2060: 30 minutes. */
mu_m_server_set_strexit (server, mu_strexit);
if (mu_app_init (&argp, imap4d_capa, imap4d_cfg_param,
argc, argv, 0, NULL, server))
exit (1);
exit (EX_CONFIG); /* FIXME: No way to discern from EX_USAGE? */
if (login_disabled)
imap4d_capability_add (IMAP_CAPA_LOGINDISABLED);
......@@ -514,32 +517,32 @@ main (int argc, char **argv)
{
/* Normal operation: */
/* First we want our group to be mail so we can access the spool. */
errno = 0;
gr = getgrnam ("mail");
if (gr == NULL)
{
perror (_("Error getting mail group"));
exit (1);
if (errno == 0 || errno == ENOENT)
{
mu_error (_("%s: No such group"), "mail");
exit (EX_CONFIG);
}
else
{
mu_error (_("Error getting mail group: %s"),
mu_strerror (errno));
exit (EX_OSERR);
}
}
if (setgid (gr->gr_gid) == -1)
{
perror (_("Error setting mail group"));
exit (1);
mu_error (_("Error setting mail group: %s"), mu_strerror (errno));
exit (EX_OSERR);
}
}
/* Set the signal handlers. */
signal (SIGINT, imap4d_signal);
signal (SIGQUIT, imap4d_signal);
signal (SIGILL, imap4d_signal);
signal (SIGBUS, imap4d_signal);
signal (SIGFPE, imap4d_signal);
signal (SIGSEGV, imap4d_signal);
signal (SIGTERM, imap4d_signal);
signal (SIGSTOP, imap4d_signal);
signal (SIGPIPE, imap4d_signal);
/*signal (SIGPIPE, SIG_IGN); */
signal (SIGABRT, imap4d_signal);
mu_set_signals (imap4d_master_signal, sigtab, MU_ARRAY_SIZE (sigtab));
/* Set up for syslog. */
openlog (MU_LOG_TAG (), LOG_PID, mu_log_facility);
......@@ -582,6 +585,6 @@ main (int argc, char **argv)
/* Close the syslog connection and exit. */
closelog ();
return status != 0;
return status ? EX_SOFTWARE : EX_OK;
}
......
......@@ -69,6 +69,7 @@
#ifdef HAVE_PATHS_H
# include <paths.h>
#endif
#include <sysexits.h>
#include "xalloc.h"
......@@ -101,6 +102,7 @@
#include <mu_asprintf.h>
#include <mu_umaxtostr.h>
#include <muaux.h>
#ifdef __cplusplus
extern "C" {
......@@ -142,6 +144,7 @@ struct imap4d_command
#define ERR_SIGNAL 4
#define ERR_TLS 5
#define ERR_MAILBOX_CORRUPTED 6
#define ERR_TERMINATE 7
/* Namespace numbers */
#define NS_PRIVATE 0
......@@ -243,8 +246,8 @@ extern size_t uid_to_msgno (size_t);
extern void imap4d_set_observer (mu_mailbox_t mbox);
/* Signal handling. */
extern RETSIGTYPE imap4d_sigchld (int);
extern RETSIGTYPE imap4d_signal (int);
extern RETSIGTYPE imap4d_master_signal (int);
extern RETSIGTYPE imap4d_child_signal (int);
extern int imap4d_bye (int);
extern int imap4d_bye0 (int reason, struct imap4d_command *command);
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2007 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 2001, 2002, 2007,
2008 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -22,18 +23,40 @@
/* Default signal handler to call the imap4d_bye() function */
RETSIGTYPE
imap4d_signal (int signo)
imap4d_master_signal (int signo)
{
mu_diag_output (MU_DIAG_CRIT, _("Got signal %s"), strsignal (signo));
/* Master process. */
if (util_is_master ())
int code;
mu_diag_output (MU_DIAG_CRIT, _("MASTER: exiting on signal (%s)"),
strsignal (signo));
switch (signo)
{
mu_diag_output (MU_DIAG_CRIT, _("MASTER: exiting on signal"));
exit (1); /* abort(); */
case SIGTERM:
case SIGHUP:
case SIGQUIT:
case SIGINT:
code = EX_OK;
break;
default:
code = EX_SOFTWARE;
break;
}
exit (code);
}
RETSIGTYPE
imap4d_child_signal (int signo)
{
mu_diag_output (MU_DIAG_CRIT, _("Got signal `%s'"), strsignal (signo));
switch (signo)
{
case SIGTERM:
case SIGHUP:
imap4d_bye (ERR_TERMINATE);
case SIGALRM:
imap4d_bye (ERR_TIMEOUT);
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2003, 2007 Free Software Foundation, Inc.
Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -55,7 +55,7 @@ imap4d_starttls (struct imap4d_command *command, char *arg)
{
mu_diag_output (MU_DIAG_ERROR, _("Session terminated"));
util_bye ();
exit (0);
exit (EX_OK);
}
return status;
......
......@@ -1007,7 +1007,7 @@ util_localname ()
if (status)
{
mu_diag_output (MU_DIAG_CRIT, _("Cannot find out my own hostname"));
exit (1);
exit (EX_OSERR);
}
hp = gethostbyname (name);
......
......@@ -106,6 +106,7 @@ void mu_m_server_set_default_address (mu_m_server_t srv, struct sockaddr *sa,
void mu_m_server_set_timeout (mu_m_server_t srv, time_t t);
void mu_m_server_set_mode (mu_m_server_t srv, int mode);
void mu_m_server_set_sigset (mu_m_server_t srv, sigset_t *sigset);
void mu_m_server_set_strexit (mu_m_server_t srv, const char *(*fun) (int));
int mu_m_server_mode (mu_m_server_t srv);
int mu_m_server_foreground (mu_m_server_t srv);
......
......@@ -118,6 +118,7 @@ typedef struct _mu_m_server *mu_m_server_t;
(MU_FOLDER_ATTRIBUTE_DIRECTORY|MU_FOLDER_ATTRIBUTE_FILE)
#define mu_offsetof(s,f) ((size_t)&((s*)0)->f)
#define MU_ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
#ifdef __cplusplus
}
......
## Process this file with GNU Automake to create Makefile.in
## Copyright (C) 1999, 2000, 2001, 2002, 2005,
## 2007 Free Software Foundation, Inc.
## 2007, 2008 Free Software Foundation, Inc.
##
## GNU Mailutils is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
......@@ -26,10 +26,13 @@ libmuaux_la_SOURCES += \
daemon.c\
mailcap.c\
mu_dbm.c\
signal.c\
strexit.c\
tcpwrap.c
noinst_HEADERS +=\
mailcap.h\
muaux.h\
mu_dbm.h\
mu_asprintf.h\
tcpwrap.h
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2008 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Mailutils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301 USA */
void mu_set_signals (RETSIGTYPE (*handler) (int signo), int *sigv, int sigc);
const char *mu_strexit (int code);
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
Copyright (C) 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
......@@ -32,6 +32,7 @@
#include <signal.h>
#include <mailutils/libsieve.h>
#include <mailutils/mu_auth.h>
#include <mailutils/nls.h>
#define DEFAULT_SPAMD_PORT 783
......@@ -319,20 +320,20 @@ spamd_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
if (got_sigpipe)
{
mu_sieve_error (mach, "remote side has closed connection");
mu_sieve_error (mach, _("remote side has closed connection"));
spamd_abort (mach, &stream, handler);
}
if (sscanf (buffer, "SPAMD/%18s %d %*s", version_str, &response) != 2)
{
mu_sieve_error (mach, "spamd responded with bad string '%s'", buffer);
mu_sieve_error (mach, _("spamd responded with bad string '%s'"), buffer);
spamd_abort (mach, &stream, handler);
}
decode_float (&version, version_str, 1);
if (version < 10)
{
mu_sieve_error (mach, "unsupported SPAMD version: %s", version_str);
mu_sieve_error (mach, _("unsupported SPAMD version: %s"), version_str);
spamd_abort (mach, &stream, handler);
}
......@@ -345,7 +346,8 @@ spamd_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
if (sscanf (buffer, "Spam: %5s ; %20s / %20s",
spam_str, score_str, threshold_str) != 3)
{
mu_sieve_error (mach, "spamd responded with bad Spam header '%s'", buffer);
mu_sieve_error (mach, _("spamd responded with bad Spam header '%s'"),
buffer);
spamd_abort (mach, &stream, handler);
}
......@@ -376,7 +378,8 @@ spamd_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
rc = mu_message_get_header (msg, &hdr);
if (rc)
{
mu_sieve_error (mach, "cannot get message header: %s", mu_strerror (rc));
mu_sieve_error (mach, _("cannot get message header: %s"),
mu_strerror (rc));
spamd_abort (mach, &stream, handler);
}
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2004, 2005,
2007 Free Software Foundation, Inc.
2007, 2008 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -1059,16 +1059,20 @@ header_readline (mu_stream_t is, char *buffer, size_t buflen,
buflen--; /* Account for the terminating nul */
mu_hdrent_fixup (header, ent);
strsize = MU_STR_SIZE (ent->nlen, ent->vlen) - ent_off;
start = MU_HDRENT_NAME (header, ent) + ent_off;
end = strchr (start, '\n');
if (end)
strsize = end - start + 1;
else
strsize = strlen (start);
{
size_t len = end - start + 1;
if (len < strsize)
strsize = len;
}
if (strsize < buflen)
buflen = strsize;
memcpy (buffer, MU_HDRENT_NAME (header, ent) + ent_off, buflen);
memcpy (buffer, start, buflen);
buffer[buflen] = 0;
mu_hdrent_unroll_fixup (header, ent);
if (pnread)
......
......@@ -105,6 +105,8 @@ struct _mu_m_server
sigset_t sigmask; /* A set of signals to handle by the
m-server. */
mu_sig_handler_t sigtab[NSIG]; /* Keeps old signal handlers. */
const char *(*strexit) (int); /* Convert integer exit code to textual
description. */
};
struct m_srv_config /* Configuration data for a single TCP server. */
......@@ -125,22 +127,12 @@ static mu_list_t m_server_list;
#define UNUSED_PID ((pid_t)-1)
static void
alloc_children (mu_m_server_t srv, size_t num)
alloc_children (mu_m_server_t srv)
{
int i;
size_t size = num * sizeof (srv->child_pid[0]);
size_t last;
size_t size = srv->max_children * sizeof (srv->child_pid[0]);
if (srv->child_pid)
{
srv->child_pid = realloc (srv->child_pid, size);
last = srv->max_children;
}
else
{
srv->child_pid = malloc (size);
last = 0;
}
if (!srv->child_pid)
{
......@@ -148,10 +140,8 @@ alloc_children (mu_m_server_t srv, size_t num)
abort ();
}
for (i = last; i < num; i++)
for (i = 0; i < srv->max_children; i++)
srv->child_pid[i] = UNUSED_PID;
srv->max_children = num;
}
static void
......@@ -160,8 +150,6 @@ register_child (mu_m_server_t msrv, pid_t pid)
int i;
msrv->num_children++;
if (!msrv->child_pid)
alloc_children (msrv, msrv->max_children);
for (i = 0; i < msrv->max_children; i++)
if (msrv->child_pid[i] == UNUSED_PID)
{
......@@ -226,7 +214,15 @@ m_server_cleanup (void *item, void *data)
int code = WEXITSTATUS (datp->status);
if (code == 0)
prio = MU_DIAG_DEBUG;
mu_diag_output (prio, "process %lu finished with code %d",
if (msrv->strexit)
mu_diag_output (prio,
_("process %lu finished with code %d (%s)"),
(unsigned long) datp->pid,
code,
msrv->strexit (code));
else
mu_diag_output (prio,
_("process %lu finished with code %d"),
(unsigned long) datp->pid,
code);
}
......@@ -361,7 +357,7 @@ mu_m_server_set_data (mu_m_server_t srv, void *data)
void
mu_m_server_set_max_children (mu_m_server_t srv, size_t num)
{
alloc_children (srv, num);
srv->max_children = num;
}
int
......@@ -379,6 +375,12 @@ mu_m_server_set_foreground (mu_m_server_t srv, int enable)
return 0;
}
void
mu_m_server_set_strexit (mu_m_server_t srv, const char *(*fun) (int))
{
srv->strexit = fun;
}
int
mu_m_server_get_srvlist (mu_m_server_t srv, mu_list_t *plist)
{
......@@ -507,6 +509,9 @@ mu_m_server_begin (mu_m_server_t msrv)
int i, rc;
size_t count = 0;
if (!msrv->child_pid)
alloc_children (msrv);
mu_list_count (msrv->srvlist, &count);
if (count == 0 && msrv->defaddr.len)
add_server (msrv, &msrv->defaddr.s.s_sa, msrv->defaddr.len, msrv->deftype);
......@@ -543,7 +548,7 @@ mu_m_server_begin (mu_m_server_t msrv)
}
void
mu_m_server_end (mu_m_server_t msrv)
mu_m_server_restore_signals (mu_m_server_t msrv)
{
int i;
......@@ -553,6 +558,12 @@ mu_m_server_end (mu_m_server_t msrv)
}
void
mu_m_server_end (mu_m_server_t msrv)
{
mu_m_server_restore_signals (msrv);
}
void
mu_m_server_destroy (mu_m_server_t *pmsrv)
{
mu_m_server_t msrv = *pmsrv;
......@@ -726,6 +737,7 @@ m_srv_conn (int fd, struct sockaddr *sa, int salen,
else if (pid == 0) /* Child. */
{
mu_ip_server_shutdown (srv); /* FIXME: does it harm for MU_IP_UDP? */
mu_m_server_restore_signals (pconf->msrv);
status = pconf->msrv->conn (fd, sa, salen, pconf->msrv->data, srv,
pconf->timeout, pconf->transcript);
closelog ();
......
......@@ -3,47 +3,61 @@
# Copyright (C) 2002, 2003, 2004, 2005, 2008 Free Software Foundation, Inc.
#
auth/pam.c
auth/ldap.c
auth/radius.c
auth/sql.c
auth/tls.c
auth/virtual.c
comsat/action.c
comsat/oldcfg.c
comsat/comsat.c
config/mailutils-config.c
dotlock/dotlock.c
frm/common.c
frm/frm.c
frm/from.c
guimb/collect.c
guimb/main.c
guimb/util.c
imap4d/auth_gsasl.c
imap4d/auth_gss.c
imap4d/authenticate.c
imap4d/bye.c
imap4d/close.c
imap4d/imap4d.c
imap4d/list.c
imap4d/login.c
imap4d/preauth.c
imap4d/search.c
imap4d/signal.c
imap4d/starttls.c
imap4d/util.c
lib/argp-help.c
lib/argp-parse.c
lib/getopt.c
lib/mailcap.c
lib/tcpwrap.c
lib/xmalloc.c
lib/strexit.c
libargp/auth.c
libargp/cmdline.c
libargp/common.c
libargp/compat.c
libargp/gsasl.c
libargp/mu_argp.c
libargp/muinit.c
libargp/pam.c
libargp/radius.c
libargp/sieve.c
libargp/sql.c
libargp/tls.c
libargp/virtdomain.c
libcfg/acl.c
libcfg/auth.c
libcfg/common.c
libcfg/gsasl.c
......@@ -55,14 +69,22 @@ libcfg/sieve.c
libcfg/sql.c
libcfg/tls.c
libcfg/virtdomain.c
libproto/imap/folder.c
libproto/mbox/mbox.c
libsieve/actions.c
libsieve/comparator.c
libsieve/extensions/list.c
libsieve/extensions/moderator.c
libsieve/extensions/spamd.c
libsieve/extensions/timestamp.c
libsieve/extensions/vacation.c
libsieve/actions.c
libsieve/comparator.c
libsieve/conf.c
libsieve/prog.c
libsieve/relational.c
libsieve/require.c
......@@ -71,11 +93,21 @@ libsieve/sieve.l
libsieve/sieve.y
libsieve/tests.c
libsieve/util.c
maidag/maidag.c
maidag/deliver.c
maidag/lmtp.c
maidag/maidag.c
maidag/mailquota.c
maidag/mailtmp.c
maidag/script.c
mail.local/mailquota.c
mail.local/main.c
mail.local/script.c
mail.remote/mail.remote.c
mail/alias.c
mail/alt.c
mail/cd.c
......@@ -102,16 +134,30 @@ mail/summary.c
mail/unalias.c
mail/util.c
mail/z.c
mailbox/cfg_driver.c
mailbox/cfg_format.c
mailbox/cfg_lexer.c
mailbox/cfg_parser.y
mailbox/debug.c
mailbox/diag.c
mailbox/errors
mailbox/file_stream.c
mailbox/filter_iconv.c
mailbox/gdebug.c
mailbox/gocs.c
mailbox/ipsrv.c
mailbox/message.c
mailbox/msrv.c
mailbox/mu_auth.c
mailbox/muerrno.c
mailbox/mutil.c
mailbox/parsedate.y
mailbox/registrar.c
mailbox/version.c
messages/messages.c
mh/anno.c
mh/fmtcheck.c
mh/folder.c
......@@ -141,22 +187,29 @@ mh/scan.c
mh/send.c
mh/whatnow.c
mh/whom.c
mimeview/mimetypes.l
mimeview/mimetypes.y
mimeview/mimeview.c
movemail/movemail.c
pop3d/apop.c
pop3d/bulletin.c
pop3d/extra.c
pop3d/lock.c
pop3d/logindelay.c
pop3d/pop3d.c
pop3d/popauth.c
pop3d/quit.c
pop3d/signal.c
pop3d/user.c
readmsg/readmsg.c
sieve/sieve.c
sql/mysql.c
sql/postgres.c
# EOF
......
......@@ -90,6 +90,8 @@ pop3d_cmd (const char *cmd)
int
pop3d_abquit (int reason)
{
int code;
/* Unlock spool */
if (state != AUTHORIZATION)
{
......@@ -102,52 +104,85 @@ pop3d_abquit (int reason)
switch (reason)
{
case ERR_NO_MEM:
code = EX_SOFTWARE;
pop3d_outf ("-ERR Out of memory, quitting\r\n");
mu_diag_output (MU_DIAG_ERROR, _("Out of memory"));
break;
case ERR_SIGNAL:
code = EX_SOFTWARE;
mu_diag_output (MU_DIAG_ERROR, _("Quitting on signal"));
break;
case ERR_TERMINATE:
code = EX_OK;
mu_diag_output (MU_DIAG_NOTICE, _("Terminating on request"));
break;
case ERR_TIMEOUT:
code = EX_TEMPFAIL;
pop3d_outf ("-ERR Session timed out\r\n");
if (state == TRANSACTION)
mu_diag_output (MU_DIAG_INFO, _("Session timed out for user: %s"), username);
mu_diag_output (MU_DIAG_INFO, _("Session timed out for user: %s"),
username);
else
mu_diag_output (MU_DIAG_INFO, _("Session timed out for no user"));
break;
case ERR_NO_IFILE:
code = EX_NOINPUT;
mu_diag_output (MU_DIAG_INFO, _("No input stream"));
break;
case ERR_NO_OFILE:
code = EX_IOERR;
mu_diag_output (MU_DIAG_INFO, _("No socket to send to"));
break;
case ERR_PROTO:
code = EX_PROTOCOL;
mu_diag_output (MU_DIAG_INFO, _("Remote protocol error"));
break;
case ERR_IO:
code = EX_IOERR;
mu_diag_output (MU_DIAG_INFO, _("I/O error"));
break;
case ERR_MBOX_SYNC:
mu_diag_output (MU_DIAG_ERROR, _("Mailbox was updated by other party: %s"), username);
code = EX_OSERR; /* FIXME: This could be EX_SOFTWARE as well? */
mu_diag_output (MU_DIAG_ERROR,
_("Mailbox was updated by other party: %s"),
username);
pop3d_outf
("-ERR [OUT-SYNC] Mailbox updated by other party or corrupt\r\n");
break;
default:
code = EX_SOFTWARE;
pop3d_outf ("-ERR Quitting (reason unknown)\r\n");
mu_diag_output (MU_DIAG_ERROR, _("Quitting (numeric reason %d)"), reason);
mu_diag_output (MU_DIAG_ERROR, _("Quitting (numeric reason %d)"),
reason);
break;
}
closelog ();
exit (EXIT_FAILURE);
exit (code);
}
void
pop3d_setio (FILE *in, FILE *out)
{
if (!in || !out)
if (!in)
pop3d_abquit (ERR_NO_IFILE);
if (!out)
pop3d_abquit (ERR_NO_OFILE);
setvbuf (in, NULL, _IOLBF, 0);
setvbuf (out, NULL, _IOLBF, 0);
if (mu_stdio_stream_create (&istream, in, MU_STREAM_NO_CLOSE)
|| mu_stdio_stream_create (&ostream, out, MU_STREAM_NO_CLOSE))
if (mu_stdio_stream_create (&istream, in, MU_STREAM_NO_CLOSE))
pop3d_abquit (ERR_NO_IFILE);
if (mu_stdio_stream_create (&ostream, out, MU_STREAM_NO_CLOSE))
pop3d_abquit (ERR_NO_OFILE);
}
......@@ -243,7 +278,7 @@ pop3d_outf (const char *fmt, ...)
if (mu_stream_strerror (ostream, &p))
p = strerror (errno);
mu_diag_output (MU_DIAG_ERROR, _("Write failed: %s"), p);
pop3d_abquit (ERR_NO_OFILE);
pop3d_abquit (ERR_IO);
}
}
......@@ -265,17 +300,21 @@ pop3d_readline (char *buffer, size_t size)
if (mu_stream_strerror (ostream, &p))
p = strerror (errno);
mu_diag_output (MU_DIAG_ERROR, _("Read failed: %s"), p);
pop3d_abquit (ERR_NO_OFILE);
pop3d_abquit (ERR_IO);
}
else if (nbytes == 0)
{
mu_diag_output (MU_DIAG_ERROR, _("unexpected eof on input"));
pop3d_abquit (ERR_NO_OFILE);
/* After a failed authorization attempt many clients simply disconnect
without issuing QUIT. We do not count this as a protocol error. */
if (state == AUTHORIZATION)
exit (EX_OK);
mu_diag_output (MU_DIAG_ERROR, _("Unexpected eof on input"));
pop3d_abquit (ERR_PROTO);
}
transcript ("recv", buffer);
/* Caller should not free () this ... should we strdup() then? */
return buffer;
}
......
......@@ -291,11 +291,10 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile)
{
int status = OK;
char buffer[512];
static int sigtab[] = { SIGILL, SIGBUS, SIGFPE, SIGSEGV, SIGSTOP, SIGPIPE,
SIGABRT, SIGINT, SIGQUIT, SIGTERM, SIGHUP, SIGALRM };
/* Reset hup to exit. */
signal (SIGHUP, pop3d_signal);
/* Timeout alarm. */
signal (SIGALRM, pop3d_signal);
mu_set_signals (pop3d_child_signal, sigtab, MU_ARRAY_SIZE (sigtab));
pop3d_setio (infile, outfile);
......@@ -443,7 +442,7 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile)
pop3d_bye ();
return (status != OK);
return status;
}
int
......@@ -461,6 +460,8 @@ main (int argc, char **argv)
{
struct group *gr;
int status = OK;
static int sigtab[] = { SIGILL, SIGBUS, SIGFPE, SIGSEGV, SIGSTOP, SIGPIPE,
SIGABRT };
/* Native Language Support */
MU_APP_INIT_NLS ();
......@@ -486,10 +487,11 @@ main (int argc, char **argv)
/* FIXME mu_m_server_set_pidfile (); */
mu_m_server_set_default_port (server, 110);
mu_m_server_set_timeout (server, 600);
mu_m_server_set_strexit (server, mu_strexit);
if (mu_app_init (&argp, pop3d_argp_capa, pop3d_cfg_param,
argc, argv, 0, NULL, server))
exit (1);
exit (EX_CONFIG); /* FIXME: No way to discern from EX_USAGE? */
if (expire == 0)
expire_on_exit = 1;
......@@ -506,31 +508,32 @@ main (int argc, char **argv)
}
else
{
errno = 0;
gr = getgrnam ("mail");
if (gr == NULL)
{
perror (_("Error getting mail group"));
exit (EXIT_FAILURE);
if (errno == 0 || errno == ENOENT)
{
mu_error (_("%s: No such group"), "mail");
exit (EX_CONFIG);
}
else
{
mu_error (_("Error getting mail group: %s"),
mu_strerror (errno));
exit (EX_OSERR);
}
}
if (setgid (gr->gr_gid) == -1)
{
perror (_("Error setting mail group"));
exit (EXIT_FAILURE);
mu_error (_("Error setting mail group: %s"), mu_strerror (errno));
exit (EX_OSERR);
}
}
/* Set the signal handlers. */
signal (SIGINT, pop3d_signal);
signal (SIGQUIT, pop3d_signal);
signal (SIGILL, pop3d_signal);
signal (SIGBUS, pop3d_signal);
signal (SIGFPE, pop3d_signal);
signal (SIGSEGV, pop3d_signal);
signal (SIGTERM, pop3d_signal);
signal (SIGSTOP, pop3d_signal);
signal (SIGPIPE, pop3d_signal);
signal (SIGABRT, pop3d_signal);
mu_set_signals (pop3d_master_signal, sigtab, MU_ARRAY_SIZE (sigtab));
/* Set up for syslog. */
openlog (MU_LOG_TAG (), LOG_PID, mu_log_facility);
......@@ -573,6 +576,6 @@ main (int argc, char **argv)
mu_error (_("Main loop status: %s"), mu_strerror (status));
/* Close the syslog connection and exit. */
closelog ();
return (OK != status);
return status ? EX_SOFTWARE : EX_OK;
}
......
......@@ -26,6 +26,7 @@
#include <mu_dbm.h>
#include <mu_asprintf.h>
#include <mu_umaxtostr.h>
#include <muaux.h>
/* The implementation */
#define IMPL "GNU POP3 Daemon"
......@@ -137,6 +138,7 @@ extern int expire_on_exit;
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <sysexits.h>
#include <mailutils/attribute.h>
#include <mailutils/body.h>
......@@ -198,13 +200,17 @@ extern int expire_on_exit;
#define ERR_NO_MEM 10
#define ERR_SIGNAL 11
#define ERR_FILE 12
#define ERR_NO_OFILE 13
#define ERR_TIMEOUT 14
#define ERR_UNKNOWN 15
#define ERR_MBOX_SYNC 16
#define ERR_TLS_ACTIVE 17
#define ERR_TLS_IO 18
#define ERR_LOGIN_DELAY 19
#define ERR_NO_IFILE 13
#define ERR_NO_OFILE 14
#define ERR_IO 15
#define ERR_PROTO 16
#define ERR_TIMEOUT 17
#define ERR_UNKNOWN 18
#define ERR_MBOX_SYNC 19
#define ERR_TLS_ACTIVE 20
#define ERR_TLS_IO 21
#define ERR_LOGIN_DELAY 22
#define ERR_TERMINATE 23
typedef struct mu_pop_server *mu_pop_server_t;
......@@ -244,7 +250,9 @@ extern int pop3d_retr (const char *);
extern int pop3d_rset (const char *);
extern void process_cleanup (void);
extern RETSIGTYPE pop3d_signal (int);
extern RETSIGTYPE pop3d_master_signal (int);
extern RETSIGTYPE pop3d_child_signal (int);
extern int pop3d_stat (const char *);
#ifdef WITH_TLS
extern int pop3d_stls (const char *);
......
......@@ -115,7 +115,7 @@ set_db_perms (struct argp_state *astate, char *opt, int *pperm)
if (*p)
{
argp_error (astate, _("Invalid octal number: %s"), opt);
exit (1);
exit (EX_USAGE);
}
}
*pperm = perm;
......@@ -205,7 +205,7 @@ main(int argc, char **argv)
mu_argp_init (program_version, NULL);
if (mu_app_init (&argp, popauth_argp_capa, NULL,
argc, argv, 0, NULL, &adata))
exit (1);
exit (EX_USAGE);
return (*ftab[adata.action]) (&adata);
}
......@@ -216,7 +216,7 @@ check_action (int action)
if (action != -1)
{
mu_error (_("You may not specify more than one `-aldp' option"));
exit (1);
exit (EX_USAGE);
}
}
......@@ -239,15 +239,16 @@ check_user_perm (int action, struct action_data *ap)
{
mu_error (_("Cannot create %s: %s"),
ap->input_name, mu_strerror (errno));
exit (1);
exit (EX_SOFTWARE);
}
mu_dbm_close (db);
mu_dbm_stat (ap->input_name, &sb);
}
else
{
mu_error (_("Cannot stat %s: %s"), ap->input_name, mu_strerror (errno));
exit (1);
mu_error (_("Cannot stat %s: %s"), ap->input_name,
mu_strerror (errno));
exit (EX_OSERR);
}
}
......@@ -258,17 +259,17 @@ check_user_perm (int action, struct action_data *ap)
if (ap->username)
{
mu_error (_("Only the file owner can use --username"));
exit (1);
exit (EX_USAGE);
}
if (action != ACT_CHPASS)
{
mu_error (_("Operation not allowed"));
exit (1);
exit (EX_USAGE);
}
pw = getpwuid (uid);
if (!pw)
exit (1);
exit (EX_OSERR);
ap->username = pw->pw_name;
return 1;
}
......@@ -451,7 +452,7 @@ fill_pass (struct action_data *ap)
free (ap->passwd);
p = getpass (_("Password:"));
if (!p)
exit (1);
exit (EX_DATAERR);
ap->passwd = strdup (p);
/* TRANSLATORS: Please try to format this string so that it has
the same length as the translation of 'Password:' above */
......@@ -598,5 +599,5 @@ popauth_version (FILE *stream, struct argp_state *state)
printf ("%s\n", argp_program_version);
printf (_("Database format: %s\n"), FORMAT);
printf (_("Database location: %s\n"), APOP_PASSFILE);
exit (EXIT_SUCCESS);
exit (EX_OK);
}
......
......@@ -19,23 +19,38 @@
#include "pop3d.h"
/* Default signal handler to call the pop3d_abquit() function */
RETSIGTYPE
pop3d_signal (int signo)
pop3d_master_signal (int signo)
{
int code;
mu_diag_output (MU_DIAG_CRIT, _("Got signal %s"), strsignal (signo));
/* Master process. */
if (pop3d_is_master ())
mu_diag_output (MU_DIAG_CRIT, _("MASTER: exiting on signal (%s)"),
strsignal (signo));
switch (signo)
{
mu_diag_output (MU_DIAG_CRIT, _("MASTER: exiting on signal"));
exit (EXIT_FAILURE);
case SIGTERM:
case SIGHUP:
case SIGQUIT:
case SIGINT:
code = EX_OK;
break;
default:
code = EX_SOFTWARE;
break;
}
exit (code);
}
RETSIGTYPE
pop3d_child_signal (int signo)
{
int code;
mu_diag_output (MU_DIAG_CRIT, _("Got signal `%s'"), strsignal (signo));
switch (signo)
{
case SIGALRM:
......@@ -46,6 +61,11 @@ pop3d_signal (int signo)
code = ERR_NO_OFILE;
break;
case SIGTERM:
case SIGHUP:
code = ERR_TERMINATE;
break;
default:
code = ERR_SIGNAL;
}
......