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