aboutsummaryrefslogtreecommitdiff
path: root/iauth/a_log.c
blob: 5307cfe19f09b6c57994e7525aecbe4f10e931ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/************************************************************************
 *   IRC - Internet Relay Chat, iauth/a_log.c
 *   Copyright (C) 1998 Christophe Kalt
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 1, or (at your option)
 *   any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef lint
static  char rcsid[] = "@(#)$Id: a_log.c,v 1.6 1999/02/21 00:33:45 kalt Exp $";
#endif

#include "os.h"
#include "a_defines.h"
#define A_LOG_C
#include "a_externs.h"
#undef A_LOG_C

static FILE	*debug = NULL, *authlog = NULL;

void
init_filelogs()
{
#if defined(IAUTH_DEBUG)
	if (debug)
		fclose(debug);
	debug = fopen(IAUTHDBG_PATH, "w");
# if defined(USE_SYSLOG)
	if (!debug)
		syslog(LOG_ERR, "Failed to open \"%s\" for writing",
		       IAUTHDBG_PATH);
# endif
#endif /* IAUTH_DEBUG */
	if (authlog)
		fclose(authlog);
	authlog = fopen(FNAME_AUTHLOG, "a");
#if defined(USE_SYSLOG)
	if (!authlog)
		syslog(LOG_NOTICE, "Failed to open \"%s\" for writing",
		       FNAME_AUTHLOG);
#endif
}

void
init_syslog()
{
#if defined(USE_SYSLOG)
	openlog("iauth", LOG_PID|LOG_NDELAY, LOG_FACILITY);
#endif
}

#if ! USE_STDARG
void
sendto_log(flags, slflag, pattern, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)
int flags, slflag;
char    *pattern, *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9, *p10;
#else
void
vsendto_log(int flags, int slflag, char *pattern, va_list va)
#endif
{
	char	logbuf[4096];

	logbuf[0] = '>';
#if ! USE_STDARG
	sprintf(logbuf+1, pattern, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
#else
	vsprintf(logbuf+1, pattern, va);
#endif

#if defined(USE_SYSLOG)
	if (slflag)
		syslog(slflag, logbuf+1);
#endif

	strcat(logbuf, "\n");

#if defined(IAUTH_DEBUG)
	if ((flags & ALOG_DALL) && (flags & debuglevel) && debug)
	    {
		fprintf(debug, logbuf+1);
		fflush(debug);
	    }
#endif
	if (authlog && (flags & ALOG_FLOG))
	    {
		fprintf(authlog, "%s: %s", myctime(time(NULL)), logbuf+1);
		fflush(authlog);
	    }
	if (flags & ALOG_IRCD)
	    {
		write(0, logbuf, strlen(logbuf));
#if defined(IAUTH_DEBUG)
		if ((ALOG_DSPY & debuglevel) && debug)
		    {
			fprintf(debug, "To ircd: %s", logbuf+1);
			fflush(debug);
		    }
#endif
	    }
}

#if USE_STDARG
void
sendto_log(int flags, int slflag, char *pattern, ...)
{
        va_list va;
        va_start(va, pattern);
        vsendto_log(flags, slflag, pattern, va);
        va_end(va);
}
#endif