17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
37c478bd9Sstevel@tonic-gate * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate */
57c478bd9Sstevel@tonic-gate
67c478bd9Sstevel@tonic-gate /*
77c478bd9Sstevel@tonic-gate * Routines to report various classes of problems. Each report is decorated
87c478bd9Sstevel@tonic-gate * with the current context (file name and line number), if available.
9*1da57d55SToomas Soome *
107c478bd9Sstevel@tonic-gate * tcpd_warn() reports a problem and proceeds.
11*1da57d55SToomas Soome *
127c478bd9Sstevel@tonic-gate * tcpd_jump() reports a problem and jumps.
13*1da57d55SToomas Soome *
147c478bd9Sstevel@tonic-gate * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
157c478bd9Sstevel@tonic-gate */
167c478bd9Sstevel@tonic-gate
177c478bd9Sstevel@tonic-gate #ifndef lint
187c478bd9Sstevel@tonic-gate static char sccsid[] = "@(#) diag.c 1.1 94/12/28 17:42:20";
197c478bd9Sstevel@tonic-gate #endif
207c478bd9Sstevel@tonic-gate
217c478bd9Sstevel@tonic-gate /* System libraries */
227c478bd9Sstevel@tonic-gate
237c478bd9Sstevel@tonic-gate #include <syslog.h>
247c478bd9Sstevel@tonic-gate #include <stdio.h>
257c478bd9Sstevel@tonic-gate #include <setjmp.h>
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Local stuff */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate #include "tcpd.h"
307c478bd9Sstevel@tonic-gate #include "mystdarg.h"
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate struct tcpd_context tcpd_context;
337c478bd9Sstevel@tonic-gate jmp_buf tcpd_buf;
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate /* tcpd_diag - centralize error reporter */
367c478bd9Sstevel@tonic-gate
tcpd_diag(severity,tag,format,ap)377c478bd9Sstevel@tonic-gate static void tcpd_diag(severity, tag, format, ap)
387c478bd9Sstevel@tonic-gate int severity;
397c478bd9Sstevel@tonic-gate char *tag;
407c478bd9Sstevel@tonic-gate char *format;
417c478bd9Sstevel@tonic-gate va_list ap;
427c478bd9Sstevel@tonic-gate {
437c478bd9Sstevel@tonic-gate char fmt[BUFSIZ];
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate if (tcpd_context.file)
467c478bd9Sstevel@tonic-gate sprintf(fmt, "%s: %s, line %d: %s",
477c478bd9Sstevel@tonic-gate tag, tcpd_context.file, tcpd_context.line, format);
487c478bd9Sstevel@tonic-gate else
497c478bd9Sstevel@tonic-gate sprintf(fmt, "%s: %s", tag, format);
507c478bd9Sstevel@tonic-gate vsyslog(severity, fmt, ap);
517c478bd9Sstevel@tonic-gate }
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate /* tcpd_warn - report problem of some sort and proceed */
547c478bd9Sstevel@tonic-gate
VARARGS(tcpd_warn,char *,format)557c478bd9Sstevel@tonic-gate void VARARGS(tcpd_warn, char *, format)
567c478bd9Sstevel@tonic-gate {
577c478bd9Sstevel@tonic-gate va_list ap;
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate VASTART(ap, char *, format);
607c478bd9Sstevel@tonic-gate tcpd_diag(LOG_ERR, "warning", format, ap);
617c478bd9Sstevel@tonic-gate VAEND(ap);
627c478bd9Sstevel@tonic-gate }
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate /* tcpd_jump - report serious problem and jump */
657c478bd9Sstevel@tonic-gate
VARARGS(tcpd_jump,char *,format)667c478bd9Sstevel@tonic-gate void VARARGS(tcpd_jump, char *, format)
677c478bd9Sstevel@tonic-gate {
687c478bd9Sstevel@tonic-gate va_list ap;
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate VASTART(ap, char *, format);
717c478bd9Sstevel@tonic-gate tcpd_diag(LOG_ERR, "error", format, ap);
727c478bd9Sstevel@tonic-gate VAEND(ap);
737c478bd9Sstevel@tonic-gate longjmp(tcpd_buf, AC_ERROR);
747c478bd9Sstevel@tonic-gate }
75