1161754Sru/*	$OpenBSD: log.c,v 1.8 2006/03/16 19:32:46 deraadt Exp $	*/
288276Smarkm/*	$NetBSD: log.c,v 1.4 1994/12/24 17:56:28 cgd Exp $	*/
388276Smarkm
4331722Seadler/*
57527Sjkh * Copyright (c) 1983, 1993
67527Sjkh *	The Regents of the University of California.  All rights reserved.
77527Sjkh *
87527Sjkh * Redistribution and use in source and binary forms, with or without
97527Sjkh * modification, are permitted provided that the following conditions
107527Sjkh * are met:
117527Sjkh * 1. Redistributions of source code must retain the above copyright
127527Sjkh *    notice, this list of conditions and the following disclaimer.
137527Sjkh * 2. Redistributions in binary form must reproduce the above copyright
147527Sjkh *    notice, this list of conditions and the following disclaimer in the
157527Sjkh *    documentation and/or other materials provided with the distribution.
16161754Sru * 3. Neither the name of the University nor the names of its contributors
177527Sjkh *    may be used to endorse or promote products derived from this software
187527Sjkh *    without specific prior written permission.
197527Sjkh *
207527Sjkh * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
217527Sjkh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
227527Sjkh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
237527Sjkh * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
247527Sjkh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
257527Sjkh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
267527Sjkh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
277527Sjkh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
287527Sjkh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
297527Sjkh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
307527Sjkh * SUCH DAMAGE.
317527Sjkh */
327527Sjkh
3388276Smarkm#include <sys/cdefs.h>
3488276Smarkm__FBSDID("$FreeBSD$");
3588276Smarkm
367527Sjkh#ifndef lint
3728365Scharnier#if 0
387527Sjkhstatic char sccsid[] = "@(#)log.c	8.1 (Berkeley) 6/6/93";
39161754Srustatic const char rcsid[] = "$OpenBSD: log.c,v 1.8 2006/03/16 19:32:46 deraadt Exp $";
4028365Scharnier#endif
417527Sjkh#endif /* not lint */
427527Sjkh
437527Sjkh#include "tip.h"
447527Sjkh
4588276Smarkm#ifdef ACULOG
467527Sjkhstatic	FILE *flog = NULL;
477527Sjkh
487527Sjkh/*
497527Sjkh * Log file maintenance routines
507527Sjkh */
5128365Scharniervoid
52161754Srulogent(char *group, char *num, char *acu, char *message)
537527Sjkh{
547527Sjkh	char *user, *timestamp;
557527Sjkh	struct passwd *pwd;
5637262Sbde	time_t t;
577527Sjkh
587527Sjkh	if (flog == NULL)
597527Sjkh		return;
607527Sjkh	if (flock(fileno(flog), LOCK_EX) < 0) {
6188276Smarkm		perror("flock");
627527Sjkh		return;
637527Sjkh	}
6488276Smarkm	if ((user = getlogin()) == NOSTR) {
657527Sjkh		if ((pwd = getpwuid(getuid())) == NOPWD)
667527Sjkh			user = "???";
677527Sjkh		else
687527Sjkh			user = pwd->pw_name;
6988276Smarkm	}
707527Sjkh	t = time(0);
717527Sjkh	timestamp = ctime(&t);
727527Sjkh	timestamp[24] = '\0';
737527Sjkh	fprintf(flog, "%s (%s) <%s, %s, %s> %s\n",
747527Sjkh		user, timestamp, group,
7588276Smarkm#ifdef PRISTINE
767527Sjkh		"",
777527Sjkh#else
787527Sjkh		num,
797527Sjkh#endif
807527Sjkh		acu, message);
817527Sjkh	(void) fflush(flog);
827527Sjkh	(void) flock(fileno(flog), LOCK_UN);
837527Sjkh}
847527Sjkh
8528365Scharniervoid
86161754Sruloginit(void)
877527Sjkh{
887527Sjkh	flog = fopen(value(LOG), "a");
897527Sjkh	if (flog == NULL)
907527Sjkh		fprintf(stderr, "can't open log file %s.\r\n", value(LOG));
917527Sjkh}
927527Sjkh#endif
93