xref: /freebsd/contrib/tcp_wrappers/diag.c (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1  /*
2   * Routines to report various classes of problems. Each report is decorated
3   * with the current context (file name and line number), if available.
4   *
5   * tcpd_warn() reports a problem and proceeds.
6   *
7   * tcpd_jump() reports a problem and jumps.
8   *
9   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
10   */
11 
12 #ifndef lint
13 static char sccsid[] = "@(#) diag.c 1.1 94/12/28 17:42:20";
14 #endif
15 
16 /* System libraries */
17 
18 #include <syslog.h>
19 #include <stdio.h>
20 #include <setjmp.h>
21 
22 /* Local stuff */
23 
24 #include "tcpd.h"
25 #include "mystdarg.h"
26 
27 struct tcpd_context tcpd_context;
28 jmp_buf tcpd_buf;
29 
30 /* tcpd_diag - centralize error reporter */
31 
32 static void tcpd_diag(int severity, char *tag, char *format, va_list ap)
33 {
34     char    fmt[BUFSIZ];
35 
36     if (tcpd_context.file)
37 	sprintf(fmt, "%s: %s, line %d: %s",
38 		tag, tcpd_context.file, tcpd_context.line, format);
39     else
40 	sprintf(fmt, "%s: %s", tag, format);
41     vsyslog(severity, fmt, ap);
42 }
43 
44 /* tcpd_warn - report problem of some sort and proceed */
45 
46 void    VARARGS(tcpd_warn, char *, format)
47 {
48     va_list ap;
49 
50     VASTART(ap, char *, format);
51     tcpd_diag(LOG_WARNING, "warning", format, ap);
52     VAEND(ap);
53 }
54 
55 /* tcpd_jump - report serious problem and jump */
56 
57 void    VARARGS(tcpd_jump, char *, format)
58 {
59     va_list ap;
60 
61     VASTART(ap, char *, format);
62     tcpd_diag(LOG_ERR, "error", format, ap);
63     VAEND(ap);
64     longjmp(tcpd_buf, AC_ERROR);
65 }
66