2001-09-24 21:55:47 +04:00
|
|
|
/* $NetBSD: diag.c,v 1.7 2001/09/24 17:55:47 atatat Exp $ */
|
1997-10-10 01:20:16 +04:00
|
|
|
|
1996-11-26 19:48:08 +03:00
|
|
|
/*
|
|
|
|
* Routines to report various classes of problems. Each report is decorated
|
|
|
|
* with the current context (file name and line number), if available.
|
1999-07-03 16:30:16 +04:00
|
|
|
*
|
1996-11-26 19:48:08 +03:00
|
|
|
* tcpd_warn() reports a problem and proceeds.
|
1999-07-03 16:30:16 +04:00
|
|
|
*
|
1996-11-26 19:48:08 +03:00
|
|
|
* tcpd_jump() reports a problem and jumps.
|
1999-07-03 16:30:16 +04:00
|
|
|
*
|
1996-11-26 19:48:08 +03:00
|
|
|
* Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
|
|
|
|
*/
|
|
|
|
|
1997-10-10 01:20:16 +04:00
|
|
|
#include <sys/cdefs.h>
|
1996-11-26 19:48:08 +03:00
|
|
|
#ifndef lint
|
1997-10-10 01:20:16 +04:00
|
|
|
#if 0
|
1996-11-26 19:48:08 +03:00
|
|
|
static char sccsid[] = "@(#) diag.c 1.1 94/12/28 17:42:20";
|
1997-10-10 01:20:16 +04:00
|
|
|
#else
|
2001-09-24 21:55:47 +04:00
|
|
|
__RCSID("$NetBSD: diag.c,v 1.7 2001/09/24 17:55:47 atatat Exp $");
|
1997-10-10 01:20:16 +04:00
|
|
|
#endif
|
1996-11-26 19:48:08 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* System libraries */
|
|
|
|
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <setjmp.h>
|
2001-09-24 21:55:47 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
1996-11-26 19:48:08 +03:00
|
|
|
|
|
|
|
/* Local stuff */
|
|
|
|
|
|
|
|
#include "tcpd.h"
|
|
|
|
#include "mystdarg.h"
|
|
|
|
|
|
|
|
struct tcpd_context tcpd_context;
|
|
|
|
jmp_buf tcpd_buf;
|
|
|
|
|
2000-10-04 20:24:49 +04:00
|
|
|
static void tcpd_diag __P((int, char *, char *, va_list))
|
|
|
|
__attribute__((__format__(__printf__, 3, 0)));
|
1997-10-10 01:20:16 +04:00
|
|
|
|
1996-11-26 19:48:08 +03:00
|
|
|
/* tcpd_diag - centralize error reporter */
|
|
|
|
|
|
|
|
static void tcpd_diag(severity, tag, format, ap)
|
|
|
|
int severity;
|
|
|
|
char *tag;
|
|
|
|
char *format;
|
|
|
|
va_list ap;
|
|
|
|
{
|
|
|
|
char fmt[BUFSIZ];
|
2000-10-04 20:24:49 +04:00
|
|
|
char buf[BUFSIZ];
|
2001-09-24 21:55:47 +04:00
|
|
|
int i, o, oerrno;
|
1996-11-26 19:48:08 +03:00
|
|
|
|
2001-09-24 21:55:47 +04:00
|
|
|
/* save errno in case we need it */
|
|
|
|
oerrno = errno;
|
|
|
|
|
|
|
|
/* contruct the tag for the log entry */
|
1996-11-26 19:48:08 +03:00
|
|
|
if (tcpd_context.file)
|
2001-09-24 21:55:47 +04:00
|
|
|
(void)snprintf(buf, sizeof buf, "%s: %s, line %d: ",
|
2000-10-04 20:24:49 +04:00
|
|
|
tag, tcpd_context.file, tcpd_context.line);
|
1996-11-26 19:48:08 +03:00
|
|
|
else
|
2001-09-24 21:55:47 +04:00
|
|
|
(void)snprintf(buf, sizeof buf, "%s: ", tag);
|
|
|
|
|
|
|
|
/* change % to %% in tag before appending the format */
|
|
|
|
for (i = 0, o = 0; buf[i] != '\0'; ) {
|
|
|
|
if (buf[i] == '%') {
|
|
|
|
fmt[o] = '%';
|
|
|
|
if (o < sizeof(fmt) - 1)
|
|
|
|
o++;
|
|
|
|
}
|
|
|
|
fmt[o] = buf[i++];
|
|
|
|
if (o < sizeof(fmt) - 1)
|
|
|
|
o++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* append format and force null termination */
|
|
|
|
fmt[o] = '\0';
|
|
|
|
strncat(fmt, format, sizeof(fmt) - o);
|
|
|
|
fmt[sizeof(fmt) - 1] = '\0';
|
|
|
|
|
|
|
|
errno = oerrno;
|
|
|
|
vsyslog(severity, fmt, ap);
|
1996-11-26 19:48:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* tcpd_warn - report problem of some sort and proceed */
|
|
|
|
|
|
|
|
void VARARGS(tcpd_warn, char *, format)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
VASTART(ap, char *, format);
|
|
|
|
tcpd_diag(LOG_ERR, "warning", format, ap);
|
|
|
|
VAEND(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* tcpd_jump - report serious problem and jump */
|
|
|
|
|
|
|
|
void VARARGS(tcpd_jump, char *, format)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
VASTART(ap, char *, format);
|
|
|
|
tcpd_diag(LOG_ERR, "error", format, ap);
|
|
|
|
VAEND(ap);
|
|
|
|
longjmp(tcpd_buf, AC_ERROR);
|
|
|
|
}
|