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