Commit cec83dca cec83dcab0f70d789b977ab53be8d0e391ad11f2 by Sergey Poznyakoff

* comsat/action.c, comsat/comsat.c, imap4d/auth_gsasl.c,

imap4d/auth_gss.c, imap4d/authenticate.c, imap4d/bye.c,
imap4d/close.c, imap4d/imap4d.c, imap4d/login.c, imap4d/search.c,
imap4d/signal.c, imap4d/starttls.c, imap4d/util.c, maidag/lmtp.c,
maidag/maidag.c, maidag/script.c, mail.local/main.c,
mail.local/script.c, pop3d/apop.c, pop3d/bulletin.c,
pop3d/extra.c, pop3d/lock.c, pop3d/logindelay.c, pop3d/pop3d.c,
pop3d/quit.c, pop3d/signal.c, pop3d/user.c, libsieve/util.c: Use
mu_diag_output instead of syslog.

* sieve/sieve.c: New option --no-program-name, for testsuite.
* sieve/testsuite/lib/sieve.exp: Call sieve with the
--no-program-name option.

* mailbox/cfg_lexer.c, mailbox/cfg_parser.y: Improve debugging.
* mailbox/diag.c: New file.
* mailbox/gdebug.c (mu_debug_level_from_string): New function.
* mailbox/muerror.c (mu_verror, mu_error): Rewrite using mu_diag
functions.
* mailbox/syslog.c (mu_diag_level_to_syslog): New function.
(mu_diag_syslog_printer): New function.

* mh/mh_argp.c (mh_argp_parse): Set prigram name using
mu_set_program_name.
* mh/mh_init.c (mu_error_printer): No longer needed.
* movemail/movemail.c (movemail_error_printer): No longer needed.

* include/mailutils/Makefile.am (pkginclude_HEADERS): Add diag.h
* include/mailutils/diag.h: New file.
* include/mailutils/cfg.h (mu_cfg_lexer_t): Take mu_debug_t as its
second argument.
* include/mailutils/error.h: Include diag.h
(mu_program_name,mu_set_program_name): Remove. Already declared in
diag.h.
(mu_error_set_print): Deprecated.

* mailbox/Makefile.am (libmailutils_la_SOURCES): Add diag.c
1 parent a3a31df1
2007-11-29 Sergey Poznyakoff <gray@gnu.org.ua>
* comsat/action.c, comsat/comsat.c, imap4d/auth_gsasl.c,
imap4d/auth_gss.c, imap4d/authenticate.c, imap4d/bye.c,
imap4d/close.c, imap4d/imap4d.c, imap4d/login.c, imap4d/search.c,
imap4d/signal.c, imap4d/starttls.c, imap4d/util.c, maidag/lmtp.c,
maidag/maidag.c, maidag/script.c, mail.local/main.c,
mail.local/script.c, pop3d/apop.c, pop3d/bulletin.c,
pop3d/extra.c, pop3d/lock.c, pop3d/logindelay.c, pop3d/pop3d.c,
pop3d/quit.c, pop3d/signal.c, pop3d/user.c, libsieve/util.c: Use
mu_diag_output instead of syslog.
* sieve/sieve.c: New option --no-program-name, for testsuite.
* sieve/testsuite/lib/sieve.exp: Call sieve with the
--no-program-name option.
* mailbox/cfg_lexer.c, mailbox/cfg_parser.y: Improve debugging.
* mailbox/diag.c: New file.
* mailbox/gdebug.c (mu_debug_level_from_string): New function.
* mailbox/muerror.c (mu_verror, mu_error): Rewrite using mu_diag
functions.
* mailbox/syslog.c (mu_diag_level_to_syslog): New function.
(mu_diag_syslog_printer): New function.
* mh/mh_argp.c (mh_argp_parse): Set prigram name using
mu_set_program_name.
* mh/mh_init.c (mu_error_printer): No longer needed.
* movemail/movemail.c (movemail_error_printer): No longer needed.
* include/mailutils/Makefile.am (pkginclude_HEADERS): Add diag.h
* include/mailutils/diag.h: New file.
* include/mailutils/cfg.h (mu_cfg_lexer_t): Take mu_debug_t as its
second argument.
* include/mailutils/error.h: Include diag.h
(mu_program_name,mu_set_program_name): Remove. Already declared in
diag.h.
(mu_error_set_print): Deprecated.
* mailbox/Makefile.am (libmailutils_la_SOURCES): Add diag.c
2007-11-28 Sergey Poznyakoff <gray@gnu.org.ua>
III. Use mu_debug_t for diagnostics in cfg framework.
......
......@@ -293,27 +293,27 @@ action_exec (FILE *tty, int line, int argc, char **argv)
if (argc == 0)
{
syslog (LOG_ERR, _("%s:.biffrc:%d: No arguments for exec"), username, line);
mu_diag_output (MU_DIAG_ERROR, _("%s:.biffrc:%d: No arguments for exec"), username, line);
return;
}
if (argv[0][0] != '/')
{
syslog (LOG_ERR, _("%s:.biffrc:%d: Not an absolute pathname"),
mu_diag_output (MU_DIAG_ERROR, _("%s:.biffrc:%d: Not an absolute pathname"),
username, line);
return;
}
if (stat (argv[0], &stb))
{
syslog (LOG_ERR, _("%s:.biffrc:%d: cannot stat %s: %s"),
mu_diag_output (MU_DIAG_ERROR, _("%s:.biffrc:%d: cannot stat %s: %s"),
username, line, argv[0], strerror (errno));
return;
}
if (stb.st_mode & (S_ISUID|S_ISGID))
{
syslog (LOG_ERR, _("%s:.biffrc:%d: will not execute set[ug]id programs"),
mu_diag_output (MU_DIAG_ERROR, _("%s:.biffrc:%d: will not execute set[ug]id programs"),
username, line);
return;
}
......@@ -327,7 +327,7 @@ action_exec (FILE *tty, int line, int argc, char **argv)
dup2 (fileno (tty), 2);
fclose (tty);
execv (argv[0], argv);
syslog (LOG_ERR, _("Cannot execute %s: %s"), argv[0], strerror (errno));
mu_diag_output (MU_DIAG_ERROR, _("Cannot execute %s: %s"), argv[0], strerror (errno));
exit (0);
}
}
......@@ -345,7 +345,7 @@ open_rc (const char *filename, FILE *tty)
{
if (stb.st_uid != pw->pw_uid)
{
syslog (LOG_NOTICE, _("%s's %s is not owned by %s"),
mu_diag_output (MU_DIAG_NOTICE, _("%s's %s is not owned by %s"),
username, filename, username);
return NULL;
}
......@@ -353,7 +353,7 @@ open_rc (const char *filename, FILE *tty)
{
fprintf (tty, "%s\r\n",
_("Warning: your .biffrc has wrong permissions"));
syslog (LOG_NOTICE, _("%s's %s has wrong permissions"),
mu_diag_output (MU_DIAG_NOTICE, _("%s's %s has wrong permissions"),
username, filename);
return NULL;
}
......@@ -418,7 +418,7 @@ run_user_action (FILE *tty, const char *cr, mu_message_t msg)
{
fprintf (tty, _(".biffrc:%d: unknown keyword"), line);
fprintf (tty, "\r\n");
syslog (LOG_ERR, _("%s:.biffrc:%d: unknown keyword %s"),
mu_diag_output (MU_DIAG_ERROR, _("%s:.biffrc:%d: unknown keyword %s"),
username, line, argv[0]);
break;
}
......
......@@ -209,7 +209,13 @@ main (int argc, char **argv)
/* Set up error messaging */
openlog ("gnu-comsat", LOG_PID, log_facility);
mu_error_set_print (mu_syslog_error_printer);
{
mu_debug_t debug;
mu_diag_get_debug (&debug);
mu_debug_set_print (debug, mu_diag_syslog_printer, NULL);
}
if (config_file)
read_config (config_file);
......@@ -227,10 +233,10 @@ main (int argc, char **argv)
static RETSIGTYPE
sig_hup (int sig)
{
syslog (LOG_NOTICE, _("Restarting"));
mu_diag_output (MU_DIAG_NOTICE, _("Restarting"));
if (xargv[0][0] != '/')
syslog (LOG_ERR, _("Cannot restart: program must be invoked using absolute pathname"));
mu_diag_output (MU_DIAG_ERROR, _("Cannot restart: program must be invoked using absolute pathname"));
else
execvp (xargv[0], xargv);
......@@ -290,7 +296,7 @@ comsat_daemon (int port)
fd = socket (PF_INET, SOCK_DGRAM, 0);
if (fd == -1)
{
syslog (LOG_CRIT, "socket: %m");
mu_diag_output (MU_DIAG_CRIT, "socket: %m");
exit (1);
}
......@@ -301,11 +307,11 @@ comsat_daemon (int port)
if (bind (fd, (struct sockaddr *) &local_sin, sizeof local_sin) < 0)
{
syslog (LOG_CRIT, "bind: %m");
mu_diag_output (MU_DIAG_CRIT, "bind: %m");
exit (1);
}
syslog (LOG_NOTICE, _("GNU comsat started"));
mu_diag_output (MU_DIAG_NOTICE, _("GNU comsat started"));
last_request_time = last_overflow_time = time (NULL);
while (1)
......@@ -319,7 +325,7 @@ comsat_daemon (int port)
if (rc == -1)
{
if (errno != EINTR)
syslog (LOG_ERR, "select: %m");
mu_diag_output (MU_DIAG_ERROR, "select: %m");
continue;
}
......@@ -332,7 +338,7 @@ comsat_daemon (int port)
unsigned delay;
delay = overflow_delay_time << (overflow_count + 1);
syslog (LOG_NOTICE,
mu_diag_output (MU_DIAG_NOTICE,
ngettext ("Too many requests: pausing for %u second",
"Too many requests: pausing for %u seconds",
delay),
......@@ -382,18 +388,18 @@ comsat_main (int fd)
{
if (errno == EINTR)
return 0;
syslog (LOG_ERR, "recvfrom: %m");
mu_diag_output (MU_DIAG_ERROR, "recvfrom: %m");
return 1;
}
if (acl_match (&sin_from))
{
syslog (LOG_ALERT, _("DENIED attempt to connect from %s"),
mu_diag_output (MU_DIAG_ALERT, _("DENIED attempt to connect from %s"),
inet_ntoa (sin_from.sin_addr));
return 1;
}
syslog (LOG_INFO,
mu_diag_output (MU_DIAG_INFO,
ngettext ("Received %d byte from %s",
"Received %d bytes from %s", rdlen),
rdlen, inet_ntoa (sin_from.sin_addr));
......@@ -404,7 +410,7 @@ comsat_main (int fd)
p = strchr (buffer, '@');
if (!p)
{
syslog (LOG_ERR, _("Malformed input: %s"), buffer);
mu_diag_output (MU_DIAG_ERROR, _("Malformed input: %s"), buffer);
return 1;
}
*p++ = 0;
......@@ -421,7 +427,7 @@ comsat_main (int fd)
if (pid == -1)
{
syslog (LOG_ERR, "fork: %m");
mu_diag_output (MU_DIAG_ERROR, "fork: %m");
return 1;
}
......@@ -537,7 +543,7 @@ find_user (const char *name, char *tty)
if (strncmp (ftty, PATH_TTY_PFX, strlen (PATH_TTY_PFX)))
{
/* An attempt to break security... */
syslog (LOG_ALERT, _("Bad line name in utmp record: %s"), ftty);
mu_diag_output (MU_DIAG_ALERT, _("Bad line name in utmp record: %s"), ftty);
return NOT_HERE;
}
......@@ -545,7 +551,7 @@ find_user (const char *name, char *tty)
{
if (!S_ISCHR (statb.st_mode))
{
syslog (LOG_ALERT, _("Not a character device: %s"), ftty);
mu_diag_output (MU_DIAG_ALERT, _("Not a character device: %s"), ftty);
return NOT_HERE;
}
......@@ -578,7 +584,7 @@ change_user (const char *user)
pw = getpwnam (user);
if (!pw)
{
syslog (LOG_CRIT, _("No such user: %s"), user);
mu_diag_output (MU_DIAG_CRIT, _("No such user: %s"), user);
exit (1);
}
......@@ -598,7 +604,7 @@ mailbox_path (const char *user)
if (!auth)
{
syslog (LOG_ALERT, _("User nonexistent: %s"), user);
mu_diag_output (MU_DIAG_ALERT, _("User nonexistent: %s"), user);
return NULL;
}
......
......@@ -36,7 +36,7 @@ create_gsasl_stream (mu_stream_t *newstr, mu_stream_t transport, int flags)
rc = mu_gsasl_stream_create (newstr, transport, sess_ctx, flags);
if (rc)
{
syslog (LOG_ERR, _("cannot create SASL stream: %s"),
mu_diag_output (MU_DIAG_ERROR, _("cannot create SASL stream: %s"),
mu_strerror (rc));
return RESP_NO;
}
......@@ -46,7 +46,7 @@ create_gsasl_stream (mu_stream_t *newstr, mu_stream_t transport, int flags)
const char *p;
if (mu_stream_strerror (*newstr, &p))
p = mu_strerror (rc);
syslog (LOG_ERR, _("cannot open SASL input stream: %s"), p);
mu_diag_output (MU_DIAG_ERROR, _("cannot open SASL input stream: %s"), p);
return RESP_NO;
}
......@@ -87,7 +87,7 @@ auth_gsasl (struct imap4d_command *command,
rc = gsasl_server_start (ctx, auth_type, &sess_ctx);
if (rc != GSASL_OK)
{
syslog (LOG_NOTICE, _("SASL gsasl_server_start: %s"),
mu_diag_output (MU_DIAG_NOTICE, _("SASL gsasl_server_start: %s"),
gsasl_strerror(rc));
return 0;
}
......@@ -103,7 +103,7 @@ auth_gsasl (struct imap4d_command *command,
if (rc != GSASL_OK)
{
syslog (LOG_NOTICE, _("GSASL error: %s"), gsasl_strerror (rc));
mu_diag_output (MU_DIAG_NOTICE, _("GSASL error: %s"), gsasl_strerror (rc));
free (output);
return RESP_NO;
}
......@@ -116,7 +116,7 @@ auth_gsasl (struct imap4d_command *command,
if (*username == NULL)
{
syslog (LOG_NOTICE, _("GSASL %s: cannot get username"), auth_type);
mu_diag_output (MU_DIAG_NOTICE, _("GSASL %s: cannot get username"), auth_type);
return RESP_NO;
}
......@@ -306,7 +306,7 @@ auth_gsasl_init ()
rc = gsasl_init (&ctx);
if (rc != GSASL_OK)
{
syslog (LOG_NOTICE, _("cannot initialize libgsasl: %s"),
mu_diag_output (MU_DIAG_NOTICE, _("cannot initialize libgsasl: %s"),
gsasl_strerror (rc));
}
......
......@@ -68,7 +68,7 @@ display_status_1 (char *m, OM_uint32 code, int type)
msg.length = strlen (msg.value);
}
syslog (LOG_ERR, _("GSS-API error %s (%s): %.*s"),
mu_diag_output (MU_DIAG_ERROR, _("GSS-API error %s (%s): %.*s"),
m, type == GSS_C_GSS_CODE ? _("major") : _("minor"),
(int) msg.length, (char *) msg.value);
......@@ -251,7 +251,7 @@ auth_gssapi (struct imap4d_command *command,
mech = sec_level >> 24;
if ((mech & SUPPORTED_P_MECH) == 0)
{
syslog (LOG_NOTICE,
mu_diag_output (MU_DIAG_NOTICE,
_("Client requested unsupported protection mechanism (%d)"),
mech);
gss_release_buffer (&min_stat, &outbuf);
......@@ -265,7 +265,7 @@ auth_gssapi (struct imap4d_command *command,
*username = malloc (outbuf.length - 4 + 1);
if (!*username)
{
syslog (LOG_NOTICE, _("Not enough memory"));
mu_diag_output (MU_DIAG_NOTICE, _("Not enough memory"));
gss_release_buffer (&min_stat, &outbuf);
maj_stat = gss_delete_sec_context (&min_stat, &context, &outbuf);
gss_release_buffer (&min_stat, &outbuf);
......@@ -294,7 +294,7 @@ auth_gssapi (struct imap4d_command *command,
if (baduser)
{
syslog (LOG_NOTICE, _("GSSAPI user %s is NOT authorized as %s"),
mu_diag_output (MU_DIAG_NOTICE, _("GSSAPI user %s is NOT authorized as %s"),
(char *) client_name.value, *username);
maj_stat = gss_delete_sec_context (&min_stat, &context, &outbuf);
gss_release_buffer (&min_stat, &outbuf);
......@@ -304,7 +304,7 @@ auth_gssapi (struct imap4d_command *command,
}
else
{
syslog (LOG_NOTICE, _("GSSAPI user %s is authorized as %s"),
mu_diag_output (MU_DIAG_NOTICE, _("GSSAPI user %s is authorized as %s"),
(char *) client_name.value, *username);
}
......
......@@ -134,7 +134,7 @@ imap4d_authenticate (struct imap4d_command *command, char *arg)
util_chdir (homedir);
namespace_init (homedir);
syslog (LOG_INFO, _("User `%s' logged in"), adata.username);
mu_diag_output (MU_DIAG_INFO, _("User `%s' logged in"), adata.username);
return util_finish (command, RESP_OK,
"%s authentication successful", auth_type);
......
......@@ -41,41 +41,41 @@ imap4d_bye0 (int reason, struct imap4d_command *command)
{
case ERR_NO_MEM:
util_out (RESP_BYE, "Server terminating no more resources.");
syslog (LOG_ERR, _("Out of memory"));
mu_diag_output (MU_DIAG_ERROR, _("Out of memory"));
break;
case ERR_SIGNAL:
syslog (LOG_ERR, _("Quitting on signal"));
mu_diag_output (MU_DIAG_ERROR, _("Quitting on signal"));
exit (status);
case ERR_TIMEOUT:
util_out (RESP_BYE, "Session timed out");
if (state == STATE_NONAUTH)
syslog (LOG_INFO, _("Session timed out for no user"));
mu_diag_output (MU_DIAG_INFO, _("Session timed out for no user"));
else
syslog (LOG_INFO, _("Session timed out for user: %s"), auth_data->name);
mu_diag_output (MU_DIAG_INFO, _("Session timed out for user: %s"), auth_data->name);
break;
case ERR_NO_OFILE:
syslog (LOG_INFO, _("No socket to send to"));
mu_diag_output (MU_DIAG_INFO, _("No socket to send to"));
break;
case ERR_MAILBOX_CORRUPTED:
syslog (LOG_ERR, _("Mailbox modified by third party"));
mu_diag_output (MU_DIAG_ERROR, _("Mailbox modified by third party"));
break;
case OK:
util_out (RESP_BYE, "Session terminating.");
if (state == STATE_NONAUTH)
syslog (LOG_INFO, _("Session terminating"));
mu_diag_output (MU_DIAG_INFO, _("Session terminating"));
else
syslog (LOG_INFO, _("Session terminating for user: %s"), auth_data->name);
mu_diag_output (MU_DIAG_INFO, _("Session terminating for user: %s"), auth_data->name);
status = EXIT_SUCCESS;
break;
default:
util_out (RESP_BYE, "Quitting (reason unknown)");
syslog (LOG_ERR, _("Quitting (numeric reason %d)"), reason);
mu_diag_output (MU_DIAG_ERROR, _("Quitting (numeric reason %d)"), reason);
break;
}
......
......@@ -36,7 +36,7 @@ imap4d_close (struct imap4d_command *command, char *arg MU_ARG_UNUSED)
status = mu_mailbox_flush (mbox, 1);
if (status)
{
syslog (LOG_ERR,
mu_diag_output (MU_DIAG_ERROR,
_("flushing mailbox failed: %s"), mu_strerror (status));
msg = "flushing mailbox failed";
}
......@@ -47,7 +47,7 @@ imap4d_close (struct imap4d_command *command, char *arg MU_ARG_UNUSED)
status = mu_mailbox_close (mbox);
if (status)
{
syslog (LOG_ERR, _("closing mailbox failed: %s"), mu_strerror (status));
mu_diag_output (MU_DIAG_ERROR, _("closing mailbox failed: %s"), mu_strerror (status));
msg = "closing mailbox failed";
}
mu_mailbox_destroy (&mbox);
......
......@@ -272,7 +272,12 @@ main (int argc, char **argv)
/* Redirect any stdout error from the library to syslog, they
should not go to the client. */
mu_error_set_print (mu_syslog_error_printer);
{
mu_debug_t debug;
mu_diag_get_debug (&debug);
mu_debug_set_print (debug, mu_diag_syslog_printer, NULL);
}
umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */
......@@ -317,17 +322,17 @@ imap4d_mainloop (int fd, FILE *infile, FILE *outfile)
struct sockaddr_in cs;
int len = sizeof cs;
syslog (LOG_INFO, _("Incoming connection opened"));
mu_diag_output (MU_DIAG_INFO, _("Incoming connection opened"));
if (getpeername (fd, (struct sockaddr *) &cs, &len) < 0)
syslog (LOG_ERR, _("Cannot obtain IP address of client: %s"),
mu_diag_output (MU_DIAG_ERROR, _("Cannot obtain IP address of client: %s"),
strerror (errno));
else
syslog (LOG_INFO, _("Connect from %s"), inet_ntoa (cs.sin_addr));
mu_diag_output (MU_DIAG_INFO, _("Connect from %s"), inet_ntoa (cs.sin_addr));
text = "IMAP4rev1";
}
else
{
syslog (LOG_INFO, _("Started in debugging mode"));
mu_diag_output (MU_DIAG_INFO, _("Started in debugging mode"));
text = "IMAP4rev1 Debugging mode";
}
......@@ -392,7 +397,7 @@ imap4d_daemon (unsigned int maxchildren, unsigned int port)
listenfd = socket (PF_INET, SOCK_STREAM, 0);
if (listenfd == -1)
{
syslog (LOG_ERR, "socket: %s", strerror (errno));
mu_diag_output (MU_DIAG_ERROR, "socket: %s", strerror (errno));
exit (1);
}
size = 1; /* Use size here to avoid making a new variable. */
......@@ -405,23 +410,23 @@ imap4d_daemon (unsigned int maxchildren, unsigned int port)
if (bind (listenfd, (struct sockaddr *) &server, size) == -1)
{
syslog (LOG_ERR, "bind: %s", strerror (errno));
mu_diag_output (MU_DIAG_ERROR, "bind: %s", strerror (errno));
exit (1);
}
if (listen (listenfd, 128) == -1)
{
syslog (LOG_ERR, "listen: %s", strerror (errno));
mu_diag_output (MU_DIAG_ERROR, "listen: %s", strerror (errno));
exit (1);
}
syslog (LOG_INFO, _("GNU imap4d started"));
mu_diag_output (MU_DIAG_INFO, _("GNU imap4d started"));
for (;;)
{
if (children > maxchildren)
{
syslog (LOG_ERR, _("Too many children (%s)"),
mu_diag_output (MU_DIAG_ERROR, _("Too many children (%s)"),
mu_umaxtostr (0, children));
pause ();
continue;
......@@ -432,13 +437,13 @@ imap4d_daemon (unsigned int maxchildren, unsigned int port)
{
if (errno == EINTR)
continue;
syslog (LOG_ERR, "accept: %s", strerror (errno));
mu_diag_output (MU_DIAG_ERROR, "accept: %s", strerror (errno));
exit (1);
}
pid = fork ();
if (pid == -1)
syslog (LOG_ERR, "fork: %s", strerror (errno));
mu_diag_output (MU_DIAG_ERROR, "fork: %s", strerror (errno));
else if (pid == 0) /* Child. */
{
int status;
......
......@@ -44,7 +44,7 @@ imap4d_login (struct imap4d_command *command, char *arg)
if (auth_data == NULL)
{
syslog (LOG_INFO, _("User `%s': nonexistent"), username);
mu_diag_output (MU_DIAG_INFO, _("User `%s': nonexistent"), username);
return util_finish (command, RESP_NO, "User name or passwd rejected");
}
......@@ -52,7 +52,7 @@ imap4d_login (struct imap4d_command *command, char *arg)
openlog ("gnu-imap4d", LOG_PID, log_facility);
if (rc)
{
syslog (LOG_INFO, _("Login failed: %s"), username);
mu_diag_output (MU_DIAG_INFO, _("Login failed: %s"), username);
return util_finish (command, RESP_NO, "User name or passwd rejected");
}
......@@ -67,7 +67,7 @@ imap4d_login (struct imap4d_command *command, char *arg)
util_chdir (homedir);
namespace_init (homedir);
syslog (LOG_INFO, _("User `%s' logged in (source: %s)"), username,
mu_diag_output (MU_DIAG_INFO, _("User `%s' logged in (source: %s)"), username,
auth_data->source);
return util_finish (command, RESP_OK, "Completed");
}
......
......@@ -583,7 +583,7 @@ parse_equiv_key (struct parsebuf *pb)
if (!node)
{
/* shouldn't happen? */
syslog(LOG_CRIT, _("%s:%d: INTERNAL ERROR (please report)"),
mu_diag_output (MU_DIAG_CRIT, _("%s:%d: INTERNAL ERROR (please report)"),
__FILE__, __LINE__);
abort ();
}
......@@ -706,7 +706,7 @@ parse_simple_key (struct parsebuf *pb)
break;
default:
syslog(LOG_CRIT, _("%s:%d: INTERNAL ERROR (please report)"),
mu_diag_output (MU_DIAG_CRIT, _("%s:%d: INTERNAL ERROR (please report)"),
__FILE__, __LINE__);
abort (); /* should never happen */
}
......@@ -782,7 +782,7 @@ search_run (struct parsebuf *pb)
evaluate_node (pb->tree, pb, &value);
if (value.type != value_number)
{
syslog(LOG_CRIT, _("%s:%d: INTERNAL ERROR (please report)"),
mu_diag_output (MU_DIAG_CRIT, _("%s:%d: INTERNAL ERROR (please report)"),
__FILE__, __LINE__);
abort (); /* should never happen */
}
......
......@@ -39,11 +39,11 @@ imap4d_sigchld (int signo)
RETSIGTYPE
imap4d_signal (int signo)
{
syslog (LOG_CRIT, _("Got signal %s"), strsignal (signo));
mu_diag_output (MU_DIAG_CRIT, _("Got signal %s"), strsignal (signo));
/* Master process. */
if (util_is_master ())
{
syslog (LOG_CRIT, _("MASTER: exiting on signal"));
mu_diag_output (MU_DIAG_CRIT, _("MASTER: exiting on signal"));
exit (1); /* abort(); */
}
......
......@@ -53,7 +53,7 @@ imap4d_starttls (struct imap4d_command *command, char *arg)
}
else
{
syslog (LOG_ERR, _("Session terminated"));
mu_diag_output (MU_DIAG_ERROR, _("Session terminated"));
util_bye ();
exit (0);
}
......
......@@ -361,7 +361,7 @@ util_send (const char *format, ...)
imap4d_bye (ERR_NO_MEM);
if (mu_gocs_daemon.transcript)
syslog (LOG_DEBUG, "sent: %s", buf);
mu_diag_output (MU_DIAG_DEBUG, "sent: %s", buf);
status = mu_stream_sequential_write (ostream, buf, strlen (buf));
free (buf);
......@@ -415,7 +415,7 @@ util_out (int rc, const char *format, ...)
imap4d_bye (ERR_NO_MEM);
if (mu_gocs_daemon.transcript)
syslog (LOG_DEBUG, "sent: %s", buf);
mu_diag_output (MU_DIAG_DEBUG, "sent: %s", buf);
status = mu_stream_sequential_write (ostream, buf, strlen (buf));
free (buf);
......@@ -456,7 +456,7 @@ util_finish (struct imap4d_command *command, int rc, const char *format, ...)
free (tempbuf);
if (mu_gocs_daemon.transcript)
syslog (LOG_DEBUG, "sent: %s\r\n", buf);
mu_diag_output (MU_DIAG_DEBUG, "sent: %s\r\n", buf);
mu_stream_sequential_write (ostream, buf, strlen (buf));
free (buf);
......@@ -507,7 +507,7 @@ imap4d_readline (void)
rc = mu_stream_sequential_readline (istream, buffer, sizeof (buffer), &sz);
if (sz == 0)
{
syslog (LOG_INFO, _("Unexpected eof on input"));
mu_diag_output (MU_DIAG_INFO, _("Unexpected eof on input"));
imap4d_bye (ERR_NO_OFILE);
}
else if (rc)
......@@ -516,7 +516,7 @@ imap4d_readline (void)
if (mu_stream_strerror (istream, &p))
p = strerror (errno);
syslog (LOG_INFO, _("Error reading from input file: %s"), p);
mu_diag_output (MU_DIAG_INFO, _("Error reading from input file: %s"), p);
imap4d_bye (ERR_NO_OFILE);
}
alarm (0);
......@@ -578,7 +578,7 @@ imap4d_readline (void)
}
while (number > 0 || (total && line[total - 1] != '\n'));
if (mu_gocs_daemon.transcript)
syslog (LOG_DEBUG, "recv: %s", line);
mu_diag_output (MU_DIAG_DEBUG, "recv: %s", line);
return line;
}
......@@ -1003,7 +1003,7 @@ util_localname ()
}
if (status)
{
syslog (LOG_CRIT, _("Cannot find out my own hostname"));
mu_diag_output (MU_DIAG_CRIT, _("Cannot find out my own hostname"));
exit (1);
}
......@@ -1150,7 +1150,7 @@ util_wait_input (int timeout)
status = mu_stream_wait (istream, &wflags, &tv);
if (status)
{
syslog (LOG_ERR, _("Cannot poll input stream: %s"),
mu_diag_output (MU_DIAG_ERROR, _("Cannot poll input stream: %s"),
mu_strerror(status));
return -1;
}
......@@ -1184,7 +1184,7 @@ imap4d_init_tls_server ()
{
const char *p;
mu_stream_strerror (stream, &p);
syslog (LOG_ERR, _("Cannot open TLS stream: %s"), p);
mu_diag_output (MU_DIAG_ERROR, _("Cannot open TLS stream: %s"), p);
return 0;
}
......
......@@ -41,6 +41,7 @@ pkginclude_HEADERS = \
cfg.h\
daemon.h\
debug.h\
diag.h\
envelope.h\
errno.h\
error.h\
......
......@@ -33,7 +33,7 @@ typedef struct mu_cfg_node mu_cfg_node_t;
typedef struct mu_cfg_locus mu_cfg_locus_t;
typedef struct mu_cfg_tree mu_cfg_tree_t;
typedef int (*mu_cfg_lexer_t) (void *ptr);
typedef int (*mu_cfg_lexer_t) (void *ptr, mu_debug_t dbg);
typedef void *(*mu_cfg_alloc_t) (size_t size);
typedef void (*mu_cfg_free_t) (void *ptr);
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2005, 2007 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
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifndef _MAILUTILS_DIAG_H
#define _MAILUTILS_DIAG_H
#include <stdarg.h>
#include <mailutils/types.h>
#include <mailutils/debug.h>
#ifdef __cplusplus
extern "C" {
#endif
extern const char *mu_program_name;
#define MU_DIAG_EMERG 0
#define MU_DIAG_ALERT 1
#define MU_DIAG_CRIT 2
#define MU_DIAG_ERROR 3
#define MU_DIAG_ERR MU_DIAG_ERROR
#define MU_DIAG_WARNING 4
#define MU_DIAG_NOTICE 5
#define MU_DIAG_INFO 6
#define MU_DIAG_DEBUG 7
void mu_set_program_name (const char *);
void mu_diag_init (void);
void mu_diag_get_debug (mu_debug_t *);
void mu_diag_set_debug (mu_debug_t);
void mu_diag_vprintf (int, const char *, va_list);
void mu_diag_printf (int, const char *, ...) MU_PRINTFLIKE(2,3);
void mu_diag_voutput (int, const char *, va_list);
void mu_diag_output (int, const char *, ...) MU_PRINTFLIKE(2,3);
int mu_diag_syslog_printer (void *, size_t, const char *);
int mu_diag_stderr_printer (void *, size_t, const char *);
int mu_diag_level_to_syslog (int level);
const char *mu_diag_level_to_string (int level);
#ifdef __cplusplus
}
#endif
#endif
......@@ -22,6 +22,7 @@
#include <stdarg.h>
#include <mailutils/types.h>
#include <mailutils/diag.h>
#ifdef __cplusplus
extern "C" {
......@@ -29,12 +30,9 @@ extern "C" {
typedef int (*mu_error_pfn_t) (const char *fmt, va_list ap);
extern const char *mu_program_name;
extern void mu_set_program_name (const char *name);
extern int mu_verror (const char *fmt, va_list ap);
extern int mu_error (const char *fmt, ...) MU_PRINTFLIKE(1,2);
extern void mu_error_set_print (mu_error_pfn_t);
extern void mu_error_set_print (mu_error_pfn_t) __attribute__((deprecated));
int mu_default_error_printer (const char *fmt, va_list ap);
int mu_syslog_error_printer (const char *fmt, va_list ap);
......
......@@ -277,10 +277,14 @@ int
_sieve_default_parse_error (void *unused, const char *filename, int lineno,
const char *fmt, va_list ap)
{
mu_debug_t debug;
mu_diag_get_debug (&debug);
if (filename)
fprintf (stderr, "%s:%d: ", filename, lineno);
vfprintf (stderr, fmt, ap);
fprintf (stderr, "\n");
mu_debug_set_locus (debug, filename, lineno);
mu_diag_vprintf (MU_DIAG_ERROR, fmt, ap);
mu_diag_printf (MU_DIAG_ERROR, "\n");
mu_debug_set_locus (debug, NULL, 0);
return 0;
}
......
......@@ -255,9 +255,9 @@ lmtp_reply (FILE *fp, char *code, char *enh, char *fmt, ...)
if (mu_gocs_daemon.transcript)
{
if (enh)
syslog (LOG_INFO, "LMTP reply: %s %s %s", code, enh, str);
mu_diag_output (MU_DIAG_INFO, "LMTP reply: %s %s %s", code, enh, str);
else
syslog (LOG_INFO, "LMTP reply: %s %s", code, str);
mu_diag_output (MU_DIAG_INFO, "LMTP reply: %s %s", code, str);
}
if (!str)
......@@ -738,7 +738,7 @@ lmtp_loop (FILE *in, FILE *out)
trimnl (buf);
if (mu_gocs_daemon.transcript)
syslog (LOG_INFO, "LMTP recieve: %s", buf);
mu_diag_output (MU_DIAG_INFO, "LMTP recieve: %s", buf);
if (next_state != state_none)
{
......@@ -767,11 +767,11 @@ log_connection (all_addr_t *addr, socklen_t addrlen)
switch (addr->sa.sa_family)
{
case PF_UNIX:
syslog (LOG_INFO, _("connect from socket"));
mu_diag_output (MU_DIAG_INFO, _("connect from socket"));
break;
case PF_INET:
syslog (LOG_INFO, _("connect from %s"), inet_ntoa (addr->s_in.sin_addr));
mu_diag_output (MU_DIAG_INFO, _("connect from %s"), inet_ntoa (addr->s_in.sin_addr));
}
}
......@@ -841,7 +841,7 @@ lmtp_daemon (char *urlstr)
pid = fork ();
if (pid == -1)
syslog (LOG_ERR, "fork: %s", strerror (errno));
mu_diag_output (MU_DIAG_ERROR, "fork: %s", strerror (errno));
else if (pid == 0) /* Child. */
{
int status;
......
......@@ -260,14 +260,7 @@ struct mu_cfg_param maidag_cfg_param[] = {
static int
_sieve_debug_printer (void *unused, const char *fmt, va_list ap)
{
if (log_to_stderr)
{
fprintf (stderr, "DEBUG: ");
vfprintf (stderr, fmt, ap);
fputc ('\n', stderr);
}
else
vsyslog (LOG_DEBUG, fmt, ap);
mu_diag_vprintf (MU_DIAG_DEBUG, fmt, ap);
return 0;
}
......@@ -277,8 +270,13 @@ _sieve_action_log (void *user_name,
mu_message_t msg,
const char *action, const char *fmt, va_list ap)
{
char *text = NULL;
int pfx = 0;
mu_debug_t debug;
mu_diag_get_debug (&debug);
mu_debug_set_locus (debug, locus->source_file, locus->source_line);
mu_diag_printf (MU_DIAG_NOTICE, _("(user %s) "), (char*) user_name);
if (message_id_header)
{
mu_header_t hdr = NULL;
......@@ -287,67 +285,42 @@ _sieve_action_log (void *user_name,
if (mu_header_aget_value (hdr, message_id_header, &val) == 0
|| mu_header_aget_value (hdr, MU_HEADER_MESSAGE_ID, &val) == 0)
{
asprintf (&text, _("%s:%lu: %s on msg %s"),
locus->source_file,
(unsigned long) locus->source_line,
action, val);
pfx = 1;
mu_diag_printf (MU_DIAG_NOTICE, _("%s on msg %s"), action, val);
free (val);
}
}
if (text == NULL)
if (!pfx)
{
size_t uid = 0;
mu_message_get_uid (msg, &uid);
asprintf (&text, _("%s:%lu: %s on msg uid %d"),
locus->source_file,
(unsigned long) locus->source_line,
action, uid);
mu_diag_printf (MU_DIAG_NOTICE, _("%s on msg uid %d"), action, uid);
}
if (fmt && strlen (fmt))
{
char *diag = NULL;
vasprintf (&diag, fmt, ap);
if (log_to_stderr)
fprintf (stderr, _("(user %s) %s: %s"), (char*) user_name,
text, diag);
else
syslog (LOG_NOTICE, _("(user %s) %s: %s"), (char*) user_name,
text, diag);
free (diag);
mu_diag_printf (MU_DIAG_NOTICE, "; ");
mu_diag_vprintf (MU_DIAG_NOTICE, fmt, ap);
}
else if (log_to_stderr)
fprintf (stderr, _("(user %s) %s"), (char*) user_name, text);
else
syslog (LOG_NOTICE, _("(user %s) %s"), (char*) user_name, text);
free (text);
if (log_to_stderr)
fputc ('\n', stderr);
mu_diag_printf (MU_DIAG_NOTICE, "\n");
mu_debug_set_locus (debug, NULL, 0);
}
static int
_sieve_parse_error (void *user_name, const char *filename, int lineno,
const char *fmt, va_list ap)
{
char *text;
vasprintf (&text, fmt, ap);
mu_debug_t debug;
mu_diag_get_debug (&debug);
if (filename)
{
char *loc;
asprintf (&loc, "%s:%d: ", filename, lineno);
if (log_to_stderr)
fprintf (stderr, "%s: %s", loc, text);
else
syslog (LOG_ERR, "%s: %s", loc, text);
free (loc);
}
else if (log_to_stderr)
fprintf (stderr, _("(user %s) %s"), (char*)user_name, text);
else
syslog (LOG_ERR, _("(user %s) %s"), (char*)user_name, text);
free (text);
if (log_to_stderr)
fputc ('\n', stderr);
mu_debug_set_locus (debug, filename, lineno);
mu_diag_printf (MU_DIAG_ERROR, _("(user %s) "), (char*) user_name);
mu_diag_vprintf (MU_DIAG_ERROR, fmt, ap);
mu_diag_printf (MU_DIAG_ERROR, "\n");
mu_debug_set_locus (debug, NULL, 0);
return 0;
}
......@@ -364,7 +337,7 @@ sieve_test (struct mu_auth_data *auth, mu_mailbox_t mbx)
if (access (progfile, R_OK))
{
if (debug_level > 2)
syslog (LOG_DEBUG, _("Access to %s failed: %m"), progfile);
mu_diag_output (MU_DIAG_DEBUG, _("Access to %s failed: %m"), progfile);
}
else
{
......@@ -456,8 +429,11 @@ main (int argc, char *argv[])
if (!log_to_stderr)
{
openlog ("mail.local", LOG_PID, log_facility);
mu_error_set_print (mu_syslog_error_printer);
mu_debug_t debug;
openlog ("maidag", LOG_PID, log_facility);
mu_diag_get_debug (&debug);
mu_debug_set_print (debug, mu_diag_syslog_printer, NULL);
}
argc -= arg_index;
......
......@@ -92,7 +92,7 @@ mda_catch_body (void *data, mu_mailbox_t mbox)
if (access (md->progfile, R_OK))
{
if (debug_level > 2)
syslog (LOG_DEBUG, _("Access to %s failed: %m"), md->progfile);
mu_diag_output (MU_DIAG_DEBUG, _("Access to %s failed: %m"), md->progfile);
}
else
{
......
......@@ -270,7 +270,7 @@ struct mu_cfg_param mail_local_cfg_param[] = {
static int
_sieve_debug_printer (void *unused, const char *fmt, va_list ap)
{
vsyslog (LOG_DEBUG, fmt, ap);
mu_diag_vprintf (MU_DIAG_DEBUG, fmt, ap);
return 0;
}
......@@ -280,8 +280,13 @@ _sieve_action_log (void *user_name,
mu_message_t msg,
const char *action, const char *fmt, va_list ap)
{
char *text = NULL;
int pfx = 0;
mu_debug_t debug;
mu_diag_get_debug (&debug);
mu_debug_set_locus (debug, locus->source_file, locus->source_line);
mu_diag_printf (MU_DIAG_NOTICE, _("(user %s) "), (char*) user_name);
if (message_id_header)
{
mu_header_t hdr = NULL;
......@@ -290,52 +295,42 @@ _sieve_action_log (void *user_name,
if (mu_header_aget_value (hdr, message_id_header, &val) == 0
|| mu_header_aget_value (hdr, MU_HEADER_MESSAGE_ID, &val) == 0)
{
asprintf (&text, _("%s:%lu: %s on msg %s"),
locus->source_file,
(unsigned long) locus->source_line,
action, val);
pfx = 1;
mu_diag_printf (MU_DIAG_NOTICE, _("%s on msg %s"), action, val);
free (val);
}
}
if (text == NULL)
if (!pfx)
{
size_t uid = 0;
mu_message_get_uid (msg, &uid);
asprintf (&text, _("%s:%lu: %s on msg uid %d"),
locus->source_file,
(unsigned long) locus->source_line,
action, uid);
mu_diag_printf (MU_DIAG_NOTICE, _("%s on msg uid %d"), action, uid);
}
if (fmt && strlen (fmt))
{
char *diag = NULL;
vasprintf (&diag, fmt, ap);
syslog (LOG_NOTICE, _("(user %s) %s: %s"),
(char*) user_name, text, diag);
free (diag);
mu_diag_printf (MU_DIAG_NOTICE, "; ");
mu_diag_vprintf (MU_DIAG_NOTICE, fmt, ap);
}
else
syslog (LOG_NOTICE, _("(user %s) %s"), (char*) user_name, text);
free (text);
mu_diag_printf (MU_DIAG_NOTICE, "\n");
mu_debug_set_locus (debug, NULL, 0);
}
static int
_sieve_parse_error (void *user_name, const char *filename, int lineno,
const char *fmt, va_list ap)
{
char *text;
vasprintf (&text, fmt, ap);
mu_debug_t debug;
mu_diag_get_debug (&debug);
if (filename)
{
char *loc;
asprintf (&loc, "%s:%d: ", filename, lineno);
syslog (LOG_ERR, "%s: %s", loc, text);
free (loc);
}
else
syslog (LOG_ERR, _("(user %s) %s"), (char*)user_name, text);
free (text);
mu_debug_set_locus (debug, filename, lineno);
mu_diag_printf (MU_DIAG_NOTICE, _("(user %s) "), (char*) user_name);
mu_diag_vprintf (MU_DIAG_NOTICE, fmt, ap);
mu_diag_printf (MU_DIAG_NOTICE, "\n");
mu_debug_set_locus (debug, NULL, 0);
return 0;
}
......@@ -372,8 +367,11 @@ main (int argc, char *argv[])
if (uid == 0)
{
mu_debug_t debug;
openlog ("mail.local", LOG_PID, log_facility);
mu_error_set_print (mu_syslog_error_printer);
mu_diag_get_debug (&debug);
mu_debug_set_print (debug, mu_diag_syslog_printer, NULL);
}
if (debug_flags)
......@@ -462,7 +460,7 @@ sieve_test (struct mu_auth_data *auth, mu_mailbox_t mbx)
if (access (progfile, R_OK))
{
if (debug_level > 2)
syslog (LOG_DEBUG, _("Access to %s failed: %m"), progfile);
mu_diag_output (MU_DIAG_DEBUG, _("Access to %s failed: %m"), progfile);
}
else
{
......
......@@ -92,7 +92,7 @@ mda_catch_body (void *data, mu_mailbox_t mbox)
if (access (md->progfile, R_OK))
{
if (debug_level > 2)
syslog (LOG_DEBUG, _("Access to %s failed: %m"), md->progfile);
mu_diag_output (MU_DIAG_DEBUG, _("Access to %s failed: %m"), md->progfile);
}
else
{
......
......@@ -51,6 +51,7 @@ libmailutils_la_SOURCES = \
debug.c\
cfg_lexer.c\
cfg_parser.c\
diag.c\
envelope.c\
fgetpwent.c\
file_stream.c\
......
......@@ -197,18 +197,54 @@ copy_string (struct lexer_data *p)
return cbuf_finish (p);
}
#define LEX_DEBUG(tok, arg1, arg2) \
do \
{ \
if (mu_debug_check_level (dbg, MU_DEBUG_TRACE2)) \
{ \
mu_debug_set_locus (dbg, \
mu_cfg_locus.file, mu_cfg_locus.line); \
mu_cfg_format_error (dbg, MU_DEBUG_TRACE2, "TOKEN %s \"%s\" \"%s\"", \
tok, \
arg1 ? arg1 : "", \
arg2 ? arg2 : ""); \
} \
} \
while (0)
int
default_lexer (void *dp)
default_lexer (void *dp, mu_debug_t dbg)
{
struct lexer_data *p = dp;
char *save_start;
char *tag, *label;
extern int mu_cfg_yydebug;
again:
skipws (p);
if (*p->curp == '#'
|| (*p->curp == '/' && p->curp[1] == '/'))
if (*p->curp == '#')
{
const char *start = ++p->curp;
skipline (p);
if (strncmp (start, "debug=", 6) == 0)
{
size_t lev;
if (p->curp[0] == '\n')
{
mu_cfg_locus.line++;
*p->curp++ = 0;
}
if (mu_debug_level_from_string (start + 6, &lev, dbg) == 0)
{
mu_debug_set_level (dbg, lev);
mu_cfg_yydebug = lev & MU_DEBUG_LEVEL_MASK (MU_DEBUG_TRACE1);
}
}
goto again;
}
if (*p->curp == '/' && p->curp[1] == '/')
{
skipline (p);
goto again;
......@@ -240,17 +276,22 @@ again:
}
if (*p->curp == 0)
return 0;
{
LEX_DEBUG ("EOF", NULL, NULL);
return 0;
}
if (*p->curp == '"' || *p->curp == '\'')
{
mu_cfg_yylval.string = copy_string (p);
LEX_DEBUG ("STRING", mu_cfg_yylval.string, NULL);
return MU_CFG_STRING_TOKEN;
}
if (mu_cfg_tie_in)
{
mu_cfg_yylval.string = copy_alpha (p);
LEX_DEBUG ("STRING", mu_cfg_yylval.string, NULL);
return MU_CFG_STRING_TOKEN;
}
......@@ -259,12 +300,14 @@ again:
p->curp++;
memset (&mu_cfg_yylval.node, 0, sizeof mu_cfg_yylval.node);
mu_cfg_yylval.node.locus = mu_cfg_locus;
LEX_DEBUG ("END", NULL, NULL);
return MU_CFG_END_TOKEN;
}
if (*p->curp == ';')
{
p->curp++;
LEX_DEBUG ("EOL", NULL, NULL);
return MU_CFG_EOL_TOKEN;
}
......@@ -273,6 +316,7 @@ again:
if (*p->curp == '"')
{
mu_cfg_yylval.string = tag;
LEX_DEBUG ("STRING", mu_cfg_yylval.string, NULL);
return MU_CFG_STRING_TOKEN;
}
......@@ -290,6 +334,7 @@ again:
mu_cfg_yylval.node.tag_name = tag;
mu_cfg_yylval.node.locus = mu_cfg_locus;
mu_cfg_yylval.node.tag_label = label;
LEX_DEBUG ("START", tag, label);
return MU_CFG_START_TOKEN;
}
else
......@@ -297,6 +342,7 @@ again:
p->curp = save_start;
mu_cfg_yylval.string = tag;
}
LEX_DEBUG ("STRING", mu_cfg_yylval.string, NULL);
return MU_CFG_STRING_TOKEN;
}
......@@ -688,7 +734,6 @@ _mu_parse_config (const char *file, const char *progname,
struct lexer_data data;
struct stat st;
int fd;
extern int mu_cfg_yydebug;
int rc;
mu_cfg_tree_t *parse_tree;
......@@ -716,12 +761,6 @@ _mu_parse_config (const char *file, const char *progname,
close (fd);
data.curp = data.buffer;
if (mu_cfg_parser_verbose > 1
|| strncmp (data.curp, "#debug", 6) == 0)
mu_cfg_yydebug = 1;
else
mu_cfg_yydebug = 0;
/* Parse configuration */
mu_cfg_locus.file = (char*) file;
mu_cfg_locus.line = 1;
......
......@@ -52,7 +52,7 @@ yyerror (char *s)
static int
yylex ()
{
return _mu_cfg_lexer (_mu_cfg_lexer_data);
return _mu_cfg_lexer (_mu_cfg_lexer_data, _mu_cfg_debug);
}
static mu_cfg_node_t *
......@@ -129,7 +129,29 @@ mu_cfg_perror (const mu_cfg_locus_t *loc, const char *fmt, ...)
_mu_cfg_vperror (_mu_cfg_debug, loc, fmt, ap);
va_end (ap);
}
#define node_type_str(t) (((t) == mu_cfg_node_tag) ? "tag" : "param")
static void
debug_print_node (mu_cfg_node_t *node)
{
if (mu_debug_check_level (_mu_cfg_debug, MU_DEBUG_TRACE0))
{
mu_debug_set_locus (_mu_cfg_debug,
node->locus.file, node->locus.line);
if (node->type == mu_cfg_node_undefined)
/* Stay on the safe side */
mu_cfg_format_error (_mu_cfg_debug, MU_DEBUG_ERROR,
"unknown statement type!");
else
mu_cfg_format_error (_mu_cfg_debug, MU_DEBUG_TRACE0,
"statement: %s, name: %s, label: %s",
node_type_str (node->type),
node->tag_name ? node->tag_name : "(null)",
node->tag_label ? node->tag_label : "(null)");
}
}
%}
%token MU_CFG_EOL_TOKEN
......@@ -161,12 +183,14 @@ input : taglist
taglist : tag
{
$$.head = $$.tail = $1;
debug_print_node ($1);
}
| taglist tag
{
$$ = $1;
$$.tail->next = $2;
$$.tail = $2;
debug_print_node ($2);
}
;
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2005, 2007 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
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <syslog.h>
#include <string.h>
#include <mailutils/diag.h>
#include <mailutils/nls.h>
#include <mailutils/errno.h>
const char *mu_program_name;
mu_debug_t mu_diag_debug;
void
mu_set_program_name (const char *name)
{
const char *progname;
if (!name)
progname = name;
else
{
progname = strrchr (name, '/');
if (progname)
progname++;
else
progname = name;
if (strlen (progname) > 3 && memcmp (progname, "lt-", 3) == 0)
progname += 3;
}
mu_program_name = progname;
}
void
mu_diag_init ()
{
if (!mu_diag_debug)
{
int rc = mu_debug_create (&mu_diag_debug, NULL);
if (rc)
{
fprintf (stderr,
_("cannot initialize debug object for diagnostics: %s\n"),
mu_strerror (rc));
/* That's a fatal error */
abort ();
}
mu_debug_set_print (mu_diag_debug, mu_diag_stderr_printer, NULL);
}
}
void
mu_diag_get_debug (mu_debug_t *pdebug)
{
mu_diag_init ();
*pdebug = mu_diag_debug;
}
void
mu_diag_set_debug (mu_debug_t debug)
{
if (mu_diag_debug)
mu_debug_destroy (&mu_diag_debug, NULL);
mu_diag_debug = debug;
}
void
mu_diag_vprintf (int level, const char *fmt, va_list ap)
{
mu_diag_init ();
mu_debug_vprintf (mu_diag_debug, level, fmt, ap);
}
void
mu_diag_printf (int level, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
mu_diag_vprintf (level, fmt, ap);
va_end (ap);
}
void
mu_diag_voutput (int level, const char *fmt, va_list ap)
{
mu_diag_init ();
mu_debug_vprintf (mu_diag_debug, level, fmt, ap);
mu_debug_printf (mu_diag_debug, level, "\n");
}
void
mu_diag_output (int level, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
mu_diag_voutput (level, fmt, ap);
va_end (ap);
}
const char *
mu_diag_level_to_string (int level)
{
switch (level)
{
case MU_DIAG_EMERG:
return _("Emergency");
case MU_DIAG_ALERT:
return _("Alert");
case MU_DIAG_CRIT:
return _("Critical");
case MU_DIAG_ERROR:
return _("Error");
case MU_DIAG_WARNING:
return _("Warning");
case MU_DIAG_NOTICE:
return _("Notice");
case MU_DIAG_INFO:
return _("Info");
case MU_DIAG_DEBUG:
return _("Debug");
}
return _("Unknown");
}
int
mu_diag_stderr_printer (void *data, size_t level, const char *buf)
{
if (mu_program_name)
fprintf (stderr, "%s: ", mu_program_name);
if (level != MU_DIAG_ERROR)
fprintf (stderr, "%s: ", mu_diag_level_to_string (level));
fputs (buf, stderr);
return 0;
}
......@@ -32,6 +32,8 @@
#include <mailutils/errno.h>
#include <mailutils/argcv.h>
#include <mailutils/debug.h>
#include <mailutils/cfg.h>
#include <mailutils/nls.h>
int mu_debug_line_info = 0;
......@@ -97,6 +99,68 @@ decode_debug_level (const char *p, int *lev)
}
int
mu_debug_level_from_string (const char *string, size_t *plev, mu_debug_t debug)
{
char *p, *q;
unsigned level = MU_DEBUG_INHERIT;
if (isdigit (*p))
{
level = strtoul (p, &q, 0);
if (*q)
{
mu_cfg_format_error (debug, MU_DEBUG_ERROR,
_("invalid debugging specification `%s': "
"expected levels or number after `=', "
"but found `%s'"),
string, p);
return MU_ERR_FAILURE;
}
}
else
{
for (q = strtok (p, ","); q; q = strtok (NULL, ","))
{
int flag;
int revert = 0;
int upto = 0;
if (*q == '!')
{
q++;
revert = 1;
}
if (*q == '<')
{
q++;
upto = 1;
}
if (decode_debug_level (q, &flag))
mu_cfg_format_error (debug, MU_DEBUG_ERROR,
_("invalid debugging level `%s'"),
q);
else if (revert)
{
if (upto)
level &= ~MU_DEBUG_LEVEL_UPTO (flag);
else
level &= ~MU_DEBUG_LEVEL_MASK (flag);
}
else
{
if (upto)
level |= MU_DEBUG_LEVEL_UPTO (flag);
else
level |= MU_DEBUG_LEVEL_MASK (flag);
}
}
}
*plev = level;
return 0;
}
int
mu_global_debug_from_string (const char *string, const char *errpfx)
{
int rc;
......@@ -119,6 +183,7 @@ mu_global_debug_from_string (const char *string, const char *errpfx)
if (*p == '=')
{
/* FIXME: Use mu_debug_level_from_string */
char *q;
*p++ = 0;
......
......@@ -26,23 +26,28 @@
#include <string.h>
#include <mailutils/error.h>
const char *mu_program_name;
/* Historic shortcuts for mu_diag_ functions */
void
mu_set_program_name (const char *name)
int
mu_verror (const char *fmt, va_list ap)
{
char *progname = strrchr (name, '/');
if (progname)
progname++;
else
progname = name;
if (strlen (progname) > 3 && memcmp (progname, "lt-", 3) == 0)
progname += 3;
mu_diag_voutput (MU_DIAG_ERROR, fmt, ap);
return 0;
}
mu_program_name = progname;
int
mu_error (const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
mu_verror (fmt, ap);
va_end (ap);
return 0;
}
/* Compatibility layer */
int
mu_default_error_printer (const char *fmt, va_list ap)
{
......@@ -66,32 +71,46 @@ mu_syslog_error_printer (const char *fmt, va_list ap)
return 0;
}
static mu_error_pfn_t mu_error_printer = mu_default_error_printer;
int
mu_verror (const char *fmt, va_list ap)
{
if (mu_error_printer)
return (*mu_error_printer) (fmt, ap);
return 0;
}
int
mu_error (const char *fmt, ...)
static void
compat_error_printer0 (mu_error_pfn_t pfn, const char *fmt, ...)
{
int status;
va_list ap;
if (!mu_error_printer)
return 0;
va_start (ap, fmt);
status = (*mu_error_printer) (fmt, ap);
pfn (fmt, ap);
va_end (ap);
return status;
}
static int
compat_error_printer (void *data, size_t level, const char *buf)
{
if (!data)
mu_diag_stderr_printer (NULL, level, buf);
else
{
int len = strlen (buf);
if (len > 0 && buf[len-1] == '\n')
len--;
compat_error_printer0 (data, "%-.*s", len, buf);
}
return 0;
}
void
mu_error_set_print (mu_error_pfn_t pfn)
{
mu_error_printer = pfn;
mu_debug_t debug;
mu_diag_get_debug (&debug);
mu_debug_set_print (debug, compat_error_printer, NULL);
mu_debug_set_data (debug, pfn, NULL, NULL);
#if 0
{
static int warned;
if (!warned)
{
warned = 1;
mu_diag_output ("this program uses mu_error_set_print, which is deprecated");
}
#endif
}
......
......@@ -19,6 +19,7 @@
#endif
#include <syslog.h>
#include <string.h>
#include <mailutils/diag.h>
struct kw_int
{
......@@ -104,5 +105,47 @@ mu_syslog_priority_to_string (int n)
return n_to_syslog (kw_prio, n);
}
int
mu_diag_level_to_syslog (int level)
{
switch (level)
{
case MU_DIAG_EMERG:
return LOG_EMERG;
case MU_DIAG_ALERT:
return LOG_ALERT;
case MU_DIAG_CRIT:
return LOG_CRIT;
case MU_DIAG_ERROR:
return LOG_ERR;
case MU_DIAG_WARNING:
return LOG_WARNING;
case MU_DIAG_NOTICE:
return LOG_NOTICE;
case MU_DIAG_INFO:
return LOG_INFO;
case MU_DIAG_DEBUG:
return LOG_DEBUG;
}
return LOG_EMERG;
}
int
mu_diag_syslog_printer (void *data, size_t level, const char *buf)
{
int len = strlen (buf);
if (len > 0 && buf[len-1] == '\n')
len--;
syslog (mu_diag_level_to_syslog (level), "%-.*s", len, buf);
return 0;
}
int log_facility = LOG_FACILITY;
......
......@@ -111,18 +111,11 @@ mh_argp_parse (int *pargc, char **pargv[],
{
struct argp argp;
struct mh_argp_data data;
char *p;
const char *val;
int index;
int extra = 0;
program_invocation_name = (*pargv)[0];
p = strrchr ((*pargv)[0], '/');
if (p)
program_invocation_short_name = p+1;
else
program_invocation_short_name = program_invocation_name;
mu_set_program_name ((*pargv)[0]);
mh_init ();
memset (&argp, 0, sizeof (argp));
......
......@@ -39,23 +39,12 @@ char mh_list_format[] =
"%<(zero)%17(friendly{from})%>"
" %{subject}%<{body}<<%{body}>>%>";
static int
mu_error_printer (const char *fmt, va_list ap)
{
fprintf (stderr, "%s: ", program_invocation_short_name);
vfprintf (stderr, fmt, ap);
fprintf (stderr, "\n");
return 0;
}
void
mh_init ()
{
/* Register all mailbox and mailer formats */
mu_register_all_formats ();
mu_error_set_print (mu_error_printer);
/* Read user's profile */
mh_read_profile ();
}
......
......@@ -95,17 +95,6 @@ static const char *movemail_capa[] = {
NULL
};
int
movemail_error_printer (const char *fmt, va_list ap)
{
int n;
n = fprintf (stderr, "%s: ", program_invocation_short_name);
n += vfprintf (stderr, fmt, ap);
fputc ('\n', stderr);
return n + 1;
}
void
die (mu_mailbox_t mbox, char *msg, int status)
{
......@@ -290,8 +279,6 @@ main (int argc, char **argv)
/* argument parsing */
mu_error_set_print (movemail_error_printer);
#ifdef WITH_TLS
mu_gocs_register ("tls", mu_tls_module_init);
#endif
......
......@@ -53,7 +53,7 @@ pop3d_apopuser (const char *user)
int rc = mu_dbm_open (APOP_PASSFILE, &db, MU_STREAM_READ, 0600);
if (rc)
{
syslog (LOG_ERR, _("Unable to open APOP db: %s"),
mu_diag_output (MU_DIAG_ERROR, _("Unable to open APOP db: %s"),
mu_strerror (errno));
return NULL;
}
......@@ -71,7 +71,7 @@ pop3d_apopuser (const char *user)
mu_dbm_close (db);
if (rc)
{
syslog (LOG_ERR, _("Cannot fetch APOP data: %s"), mu_strerror (errno));
mu_diag_output (MU_DIAG_ERROR, _("Cannot fetch APOP data: %s"), mu_strerror (errno));
return NULL;
}
password = calloc (MU_DATUM_SIZE(data) + 1, sizeof (*password));
......@@ -93,14 +93,14 @@ pop3d_apopuser (const char *user)
if (mu_check_perm (APOP_PASSFILE, 0600))
{
syslog (LOG_INFO, _("Bad permissions on APOP password file"));
mu_diag_output (MU_DIAG_INFO, _("Bad permissions on APOP password file"));
return NULL;
}
apop_file = fopen (APOP_PASSFILE, "r");
if (apop_file == NULL)
{
syslog (LOG_INFO, _("Unable to open APOP password file %s"),
mu_diag_output (MU_DIAG_INFO, _("Unable to open APOP password file %s"),
strerror (errno));
return NULL;
}
......@@ -160,7 +160,7 @@ pop3d_apop (const char *arg)
user = pop3d_cmd (arg);
if (strlen (user) > (POP_MAXCMDLEN - APOP_DIGEST))
{
syslog (LOG_INFO, _("User name too long: %s"), user);
mu_diag_output (MU_DIAG_INFO, _("User name too long: %s"), user);
free (user);
return ERR_BAD_ARGS;
}
......@@ -169,7 +169,7 @@ pop3d_apop (const char *arg)
password = pop3d_apopuser (user);
if (password == NULL)
{
syslog (LOG_INFO, _("Password for `%s' not found in the database"),
mu_diag_output (MU_DIAG_INFO, _("Password for `%s' not found in the database"),
user);
free (user);
free (user_digest);
......@@ -193,7 +193,7 @@ pop3d_apop (const char *arg)
if (strcmp (user_digest, buf))
{
syslog (LOG_INFO, _("APOP failed for `%s'"), user);
mu_diag_output (MU_DIAG_INFO, _("APOP failed for `%s'"), user);
free (user);
free (user_digest);
return ERR_BAD_LOGIN;
......
......@@ -184,7 +184,7 @@ read_bulletin_db (size_t *pnum)
n = *(long*)MU_DATUM_PTR (data);
if (n >= 0)
{
syslog (LOG_INFO,
mu_diag_output (MU_DIAG_INFO,
_("assuming bulletin database is in qpopper format"));
*pnum = n;
rc = 0;
......@@ -280,7 +280,7 @@ deliver_pending_bulletins ()
mu_error (_("Cannot count bulletins: %s"), mu_strerror (rc));
else
{
syslog (LOG_DEBUG,
mu_diag_output (MU_DIAG_DEBUG,
"user %s, last bulletin %lu, total bulletins %lu",
username, (unsigned long) lastnum, (unsigned long) total);
......@@ -289,7 +289,7 @@ deliver_pending_bulletins ()
size_t i;
size_t count = total - lastnum;
syslog (LOG_INFO,
mu_diag_output (MU_DIAG_INFO,
ngettext ("user %s: delivering %lu pending bulletin",
"user %s: delivering %lu pending bulletins",
count),
......
......@@ -103,34 +103,34 @@ pop3d_abquit (int reason)
{
case ERR_NO_MEM:
pop3d_outf ("-ERR Out of memory, quitting\r\n");
syslog (LOG_ERR, _("Out of memory"));
mu_diag_output (MU_DIAG_ERROR, _("Out of memory"));
break;
case ERR_SIGNAL:
syslog (LOG_ERR, _("Quitting on signal"));
mu_diag_output (MU_DIAG_ERROR, _("Quitting on signal"));
break;
case ERR_TIMEOUT:
pop3d_outf ("-ERR Session timed out\r\n");
if (state == TRANSACTION)
syslog (LOG_INFO, _("Session timed out for user: %s"), username);
mu_diag_output (MU_DIAG_INFO, _("Session timed out for user: %s"), username);
else
syslog (LOG_INFO, _("Session timed out for no user"));
mu_diag_output (MU_DIAG_INFO, _("Session timed out for no user"));
break;
case ERR_NO_OFILE:
syslog (LOG_INFO, _("No socket to send to"));
mu_diag_output (MU_DIAG_INFO, _("No socket to send to"));
break;
case ERR_MBOX_SYNC:
syslog (LOG_ERR, _("Mailbox was updated by other party: %s"), username);
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:
pop3d_outf ("-ERR Quitting (reason unknown)\r\n");
syslog (LOG_ERR, _("Quitting (numeric reason %d)"), reason);
mu_diag_output (MU_DIAG_ERROR, _("Quitting (numeric reason %d)"), reason);
break;
}
......@@ -166,7 +166,7 @@ pop3d_init_tls_server ()
{
const char *p;
mu_stream_strerror (stream, &p);
syslog (LOG_ERR, _("cannot open TLS stream: %s"), p);
mu_diag_output (MU_DIAG_ERROR, _("cannot open TLS stream: %s"), p);
return 0;
}
......@@ -217,7 +217,7 @@ pop3d_outf (const char *fmt, ...)
pop3d_abquit (ERR_NO_MEM);
if (mu_gocs_daemon.transcript)
syslog (LOG_DEBUG, "sent: %s", buf);
mu_diag_output (MU_DIAG_DEBUG, "sent: %s", buf);
rc = mu_stream_sequential_write (ostream, buf, strlen (buf));
free (buf);
......@@ -227,7 +227,7 @@ pop3d_outf (const char *fmt, ...)
if (mu_stream_strerror (ostream, &p))
p = strerror (errno);
syslog (LOG_ERR, _("Write failed: %s"), p);
mu_diag_output (MU_DIAG_ERROR, _("Write failed: %s"), p);
pop3d_abquit (ERR_NO_OFILE);
}
}
......@@ -250,17 +250,17 @@ pop3d_readline (char *buffer, size_t size)
if (mu_stream_strerror (ostream, &p))
p = strerror (errno);
syslog (LOG_ERR, _("Read failed: %s"), p);
mu_diag_output (MU_DIAG_ERROR, _("Read failed: %s"), p);
pop3d_abquit (ERR_NO_OFILE);
}
else if (nbytes == 0)
{
syslog (LOG_ERR, _("unexpected eof on input"));
mu_diag_output (MU_DIAG_ERROR, _("unexpected eof on input"));
pop3d_abquit (ERR_NO_OFILE);
}
if (mu_gocs_daemon.transcript)
syslog (LOG_DEBUG, "recv: %s", buffer);
mu_diag_output (MU_DIAG_DEBUG, "recv: %s", buffer);
/* Caller should not free () this ... should we strdup() then? */
return buffer;
......
......@@ -33,7 +33,7 @@ pop3d_lock ()
mu_locker_set_flags (lock, MU_LOCKER_PID);
if ((status = mu_locker_lock (lock)))
{
syslog (LOG_NOTICE, _("Locking mailbox `%s' failed: %s"),
mu_diag_output (MU_DIAG_NOTICE, _("Locking mailbox `%s' failed: %s"),
name ? name : "?", mu_strerror(status));
return ERR_MBOX_LOCK;
}
......
......@@ -27,9 +27,9 @@ open_stat_db (DBM_FILE *db, int mode)
if (rc)
{
if (rc == -1)
syslog (LOG_INFO, _("Bad permissions on statistics db"));
mu_diag_output (MU_DIAG_INFO, _("Bad permissions on statistics db"));
else
syslog (LOG_ERR, _("Unable to open statistics db: %s"),
mu_diag_output (MU_DIAG_ERROR, _("Unable to open statistics db: %s"),
mu_strerror (rc));
}
return rc;
......@@ -59,7 +59,7 @@ check_login_delay (char *username)
rc = mu_dbm_fetch (db, key, &data);
if (rc)
{
syslog (LOG_ERR, _("Can't fetch login delay data: %s"),
mu_diag_output (MU_DIAG_ERROR, _("Can't fetch login delay data: %s"),
mu_strerror (rc));
mu_dbm_close (db);
return 0;
......@@ -67,7 +67,7 @@ check_login_delay (char *username)
if (MU_DATUM_SIZE(data) > sizeof (text) - 1)
{
syslog (LOG_ERR, _("Invalid entry for '%s': wrong timestamp size"),
mu_diag_output (MU_DIAG_ERROR, _("Invalid entry for '%s': wrong timestamp size"),
username);
mu_dbm_close (db);
return 0;
......@@ -80,7 +80,7 @@ check_login_delay (char *username)
prev_time = strtoul (text, &p, 0);
if (*p)
{
syslog (LOG_ERR, _("Malformed timestamp for '%s': %s"),
mu_diag_output (MU_DIAG_ERROR, _("Malformed timestamp for '%s': %s"),
username, text);
return 0;
}
......
......@@ -315,7 +315,12 @@ main (int argc, char **argv)
openlog ("gnu-pop3d", LOG_PID, log_facility);
/* Redirect any stdout error from the library to syslog, they
should not go to the client. */
mu_error_set_print (mu_syslog_error_printer);
{
mu_debug_t debug;
mu_diag_get_debug (&debug);
mu_debug_set_print (debug, mu_diag_syslog_printer, NULL);
}
umask (S_IROTH | S_IWOTH | S_IXOTH); /* 007 */
......@@ -374,22 +379,22 @@ pop3d_daemon_init (void)
void
pop3d_log_connection (int fd)
{
syslog (LOG_INFO, _("Incoming connection opened"));
mu_diag_output (MU_DIAG_INFO, _("Incoming connection opened"));
/* log information on the connecting client */
if (debug_mode)
{
syslog (LOG_INFO, _("Started in debugging mode"));
mu_diag_output (MU_DIAG_INFO, _("Started in debugging mode"));
}
else
{
struct sockaddr_in cs;
int len = sizeof cs;
if (getpeername (fd, (struct sockaddr*)&cs, &len) < 0)
syslog (LOG_ERR, _("Cannot obtain IP address of client: %s"),
mu_diag_output (MU_DIAG_ERROR, _("Cannot obtain IP address of client: %s"),
strerror (errno));
else
syslog (LOG_INFO, _("connect from %s"), inet_ntoa (cs.sin_addr));
mu_diag_output (MU_DIAG_INFO, _("connect from %s"), inet_ntoa (cs.sin_addr));
}
}
......@@ -513,7 +518,7 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile)
status = pop3d_stls (arg);
if (status)
{
syslog (LOG_ERR, _("Session terminated"));
mu_diag_output (MU_DIAG_ERROR, _("Session terminated"));
break;
}
}
......@@ -576,7 +581,7 @@ pop3d_daemon (unsigned int maxchildren, unsigned int port)
listenfd = socket (PF_INET, SOCK_STREAM, 0);
if (listenfd == -1)
{
syslog (LOG_ERR, "socket: %s", strerror(errno));
mu_diag_output (MU_DIAG_ERROR, "socket: %s", strerror(errno));
exit (EXIT_FAILURE);
}
size = 1; /* Use size here to avoid making a new variable. */
......@@ -589,24 +594,24 @@ pop3d_daemon (unsigned int maxchildren, unsigned int port)
if (bind (listenfd, (struct sockaddr *)&server, size) == -1)
{
syslog (LOG_ERR, "bind: %s", strerror (errno));
mu_diag_output (MU_DIAG_ERROR, "bind: %s", strerror (errno));
exit (EXIT_FAILURE);
}
if (listen (listenfd, 128) == -1)
{
syslog (LOG_ERR, "listen: %s", strerror (errno));
mu_diag_output (MU_DIAG_ERROR, "listen: %s", strerror (errno));
exit (EXIT_FAILURE);
}
syslog (LOG_INFO, _("GNU pop3d started"));
mu_diag_output (MU_DIAG_INFO, _("GNU pop3d started"));
for (;;)
{
process_cleanup ();
if (children > maxchildren)
{
syslog (LOG_ERR, _("too many children (%s)"),
mu_diag_output (MU_DIAG_ERROR, _("too many children (%s)"),
mu_umaxtostr (0, children));
pause ();
continue;
......@@ -617,14 +622,14 @@ pop3d_daemon (unsigned int maxchildren, unsigned int port)
{
if (errno == EINTR)
continue;
syslog (LOG_ERR, "accept: %s", strerror (errno));
mu_diag_output (MU_DIAG_ERROR, "accept: %s", strerror (errno));
continue;
/*exit (EXIT_FAILURE);*/
}
pid = fork ();
if (pid == -1)
syslog(LOG_ERR, "fork: %s", strerror (errno));
mu_diag_output (MU_DIAG_ERROR, "fork: %s", strerror (errno));
else if (pid == 0) /* Child. */
{
int status;
......
......@@ -44,10 +44,10 @@ pop3d_quit (const char *arg)
if (mu_mailbox_close (mbox) != 0)
err = ERR_FILE;
mu_mailbox_destroy (&mbox);
syslog (LOG_INFO, _("Session ended for user: %s"), username);
mu_diag_output (MU_DIAG_INFO, _("Session ended for user: %s"), username);
}
else
syslog (LOG_INFO, _("Session ended for no user"));
mu_diag_output (MU_DIAG_INFO, _("Session ended for no user"));
state = UPDATE;
update_login_delay (username);
......
......@@ -51,12 +51,12 @@ pop3d_signal (int signo)
{
int code;
syslog (LOG_CRIT, _("Got signal %s"), strsignal (signo));
mu_diag_output (MU_DIAG_CRIT, _("Got signal %s"), strsignal (signo));
/* Master process. */
if (pop3d_is_master ())
{
syslog (LOG_CRIT, _("MASTER: exiting on signal"));
mu_diag_output (MU_DIAG_CRIT, _("MASTER: exiting on signal"));
exit (EXIT_FAILURE);
}
......
......@@ -25,12 +25,12 @@ pop3d_begin_session ()
{
int status;
syslog (LOG_INFO, _("POP3 login: user `%s', source %s"),
auth_data->name, auth_data->source);
mu_diag_output (MU_DIAG_INFO, _("POP3 login: user `%s', source %s"),
auth_data->name, auth_data->source);
if (check_login_delay (auth_data->name))
{
syslog (LOG_INFO,
mu_diag_output (MU_DIAG_INFO,
_("User `%s' tried to log in within the minimum allowed delay"),
auth_data->name);
state = AUTHORIZATION;
......@@ -77,7 +77,7 @@ pop3d_begin_session ()
size_t total = 0;
mu_mailbox_get_url (mbox, &url);
mu_mailbox_messages_count (mbox, &total);
syslog (LOG_INFO,
mu_diag_output (MU_DIAG_INFO,
ngettext ("User `%s' logged in with mailbox `%s' (%s message)",
"User `%s' logged in with mailbox `%s' (%s messages)",
(unsigned long) total),
......@@ -131,7 +131,7 @@ pop3d_user (const char *arg)
tmp = pop3d_apopuser (arg);
if (tmp != NULL)
{
syslog (LOG_INFO, _("APOP user %s tried to log in with USER"), arg);
mu_diag_output (MU_DIAG_INFO, _("APOP user %s tried to log in with USER"), arg);
free (tmp);
return ERR_BAD_LOGIN;
}
......@@ -141,7 +141,7 @@ pop3d_user (const char *arg)
if (auth_data == NULL)
{
syslog (LOG_INFO, _("User `%s': nonexistent"), arg);
mu_diag_output (MU_DIAG_INFO, _("User `%s': nonexistent"), arg);
return ERR_BAD_LOGIN;
}
......@@ -150,14 +150,14 @@ pop3d_user (const char *arg)
if (rc)
{
syslog (LOG_INFO, _("User `%s': authentication failed"), arg);
mu_diag_output (MU_DIAG_INFO, _("User `%s': authentication failed"), arg);
mu_auth_data_destroy (&auth_data);
return ERR_BAD_LOGIN;
}
}
else if (strcasecmp (cmd, "QUIT") == 0)
{
syslog (LOG_INFO, _("Possible probe of account `%s'"), arg);
mu_diag_output (MU_DIAG_INFO, _("Possible probe of account `%s'"), arg);
free (cmd);
return pop3d_quit (pass);
}
......
......@@ -62,6 +62,7 @@ N_("Debug flags:\n\
#define D_DEFAULT "TPt"
#define ARG_LINE_INFO 257
#define ARG_NO_PROGRAM_NAME 258
static struct argp_option options[] =
{
......@@ -94,6 +95,9 @@ static struct argp_option options[] =
{"email", 'e', N_("ADDRESS"), 0,
N_("Override user email address"), 0},
{"no-program-name", ARG_NO_PROGRAM_NAME, NULL, 0,
N_("Do not prefix diagnostic messages with the program name"), 0},
{0}
};
......@@ -159,6 +163,13 @@ set_debug_level (mu_debug_t debug, const char *arg)
}
}
int
mu_compat_printer (void *data, size_t level, const char *buf)
{
fputs (buf, stderr);
return 0;
}
static error_t
parser (int key, char *arg, struct argp_state *state)
{
......@@ -213,6 +224,14 @@ parser (int key, char *arg, struct argp_state *state)
case ARG_LINE_INFO:
sieve_print_locus = is_true_p (arg);
break;
case ARG_NO_PROGRAM_NAME:
{
mu_debug_t debug;
mu_diag_get_debug (&debug);
mu_debug_set_print (debug, mu_compat_printer, NULL);
}
break;
case ARGP_KEY_ARG:
if (script)
......@@ -290,70 +309,38 @@ static const char *sieve_argp_capa[] =
};
static int
sieve_stderr_debug_printer (void *unused, const char *fmt, va_list ap)
{
vfprintf (stderr, fmt, ap);
return 0;
}
static int
sieve_syslog_debug_printer (void *unused, const char *fmt, va_list ap)
_sieve_debug_printer (void *unused, const char *fmt, va_list ap)
{
vsyslog (LOG_DEBUG, fmt, ap);
mu_diag_vprintf (MU_DIAG_DEBUG, fmt, ap);
return 0;
}
static void
stdout_action_log (void *unused,
const mu_sieve_locus_t *locus, size_t msgno, mu_message_t msg,
_sieve_action_log (void *unused,
const mu_sieve_locus_t *locus, size_t msgno,
mu_message_t msg,
const char *action, const char *fmt, va_list ap)
{
size_t uid = 0;
mu_message_get_uid (msg, &uid);
mu_debug_t debug;
if (sieve_print_locus)
fprintf (stdout, _("%s:%lu: %s on msg uid %lu"),
locus->source_file, (unsigned long) locus->source_line,
action, (unsigned long) uid);
else
fprintf (stdout, _("%s on msg uid %lu"), action, (unsigned long) uid);
if (fmt && strlen (fmt))
{
fprintf (stdout, ": ");
vfprintf (stdout, fmt, ap);
mu_diag_get_debug (&debug);
mu_debug_set_locus (debug, locus->source_file, locus->source_line);
}
fprintf (stdout, "\n");
}
static void
syslog_action_log (void *unused,
const mu_sieve_locus_t *locus, size_t msgno, mu_message_t msg,
const char *action, const char *fmt, va_list ap)
{
size_t uid = 0;
char *text = NULL;
mu_message_get_uid (msg, &uid);
if (sieve_print_locus)
asprintf (&text, _("%s:%lu: %s on msg uid %lu"),
locus->source_file, (unsigned long) locus->source_line,
action, (unsigned long) uid);
else
asprintf (&text, _("%s on msg uid %lu"), action, (unsigned long) uid);
mu_diag_printf (MU_DIAG_NOTICE, _("%s on msg uid %d"), action, uid);
if (fmt && strlen (fmt))
{
char *diag = NULL;
asprintf (&diag, fmt, ap);
syslog (LOG_NOTICE, "%s: %s", text, diag);
free (diag);
mu_diag_printf (MU_DIAG_NOTICE, ": ");
mu_diag_vprintf (MU_DIAG_NOTICE, fmt, ap);
}
else
syslog (LOG_NOTICE, "%s", text);
free (text);
mu_diag_printf (MU_DIAG_NOTICE, "\n");
if (sieve_print_locus)
mu_debug_set_locus (debug, NULL, 0);
}
int
......@@ -396,18 +383,16 @@ main (int argc, char *argv[])
if (log_facility)
{
mu_debug_t debug;
mu_diag_get_debug (&debug);
openlog ("sieve", LOG_PID, log_facility);
mu_error_set_print (mu_syslog_error_printer);
mu_sieve_set_debug (mach, sieve_syslog_debug_printer);
if (verbose)
mu_sieve_set_logger (mach, syslog_action_log);
}
else
{
mu_sieve_set_debug (mach, sieve_stderr_debug_printer);
if (verbose)
mu_sieve_set_logger (mach, stdout_action_log);
mu_debug_set_print (debug, mu_diag_syslog_printer, NULL);
}
mu_sieve_set_debug (mach, _sieve_debug_printer);
if (verbose)
mu_sieve_set_logger (mach, _sieve_action_log);
rc = mu_sieve_compile (mach, script);
if (rc)
......
......@@ -34,6 +34,7 @@ proc sieve_test {args} {
set default ""
set sw [list "--verbose" \
"--line-info=no" \
"--no-program-name" \
"-M sendmail:$top_builddir/examples/mta" \
"--email foobar@nonexistent.net"]
set reuse_spool 0
......