190792Sgshapiro/*
2261370Sgshapiro * Copyright (c) 2000-2001 Proofpoint, Inc. and its suppliers.
390792Sgshapiro *      All rights reserved.
490792Sgshapiro *
590792Sgshapiro * By using this file, you agree to the terms and conditions set
690792Sgshapiro * forth in the LICENSE file which can be found at the top level of
790792Sgshapiro * the sendmail distribution.
890792Sgshapiro */
990792Sgshapiro
1090792Sgshapiro#include <sm/gen.h>
11266711SgshapiroSM_RCSID("@(#)$Id: syslogio.c,v 1.30 2013-11-22 20:51:43 ca Exp $")
1290792Sgshapiro#include <stdlib.h>
1390792Sgshapiro#include <unistd.h>
1490792Sgshapiro#include <fcntl.h>
1590792Sgshapiro#include <syslog.h>
1690792Sgshapiro#include <errno.h>
1790792Sgshapiro#ifdef SM_RPOOL
1890792Sgshapiro# include <sm/rpool.h>
1990792Sgshapiro#endif /* SM_RPOOL */
2090792Sgshapiro#include <sm/io.h>
2190792Sgshapiro#include "local.h"
2290792Sgshapiro
2390792Sgshapiro/*
2490792Sgshapiro**  Overall:
2590792Sgshapiro**  This is a output file type that copies its output to the syslog daemon.
2690792Sgshapiro**  Each line of output is written as a separate syslog message.
2790792Sgshapiro**  The client is responsible for calling openlog() before writing to
2890792Sgshapiro**  any syslog file, and calling closelog() after all syslog output is complete.
2990792Sgshapiro**  The only state associated with a syslog file is 'int priority',
3090792Sgshapiro**  which we store in fp->f_ival.
3190792Sgshapiro*/
3290792Sgshapiro
3390792Sgshapiro/*
3490792Sgshapiro**  SM_SYSLOGOPEN -- open a file pointer to syslog
3590792Sgshapiro**
3690792Sgshapiro**	Parameters:
3790792Sgshapiro**		fp -- file pointer assigned for the open
3890792Sgshapiro**		info -- priority level of the syslog messages
3990792Sgshapiro**		flags -- not used
4090792Sgshapiro**		rpool -- ignored
4190792Sgshapiro**
4290792Sgshapiro**	Returns:
4390792Sgshapiro**		0 (zero) success always (see Overall)
4490792Sgshapiro*/
4590792Sgshapiro
4690792Sgshapiroint
4790792Sgshapirosm_syslogopen(fp, info, flags, rpool)
4890792Sgshapiro	SM_FILE_T *fp;
4990792Sgshapiro	const void *info;
5090792Sgshapiro	int flags;
5190792Sgshapiro	const void *rpool;
5290792Sgshapiro{
5390792Sgshapiro	int *priority = (int *)info;
5490792Sgshapiro
5590792Sgshapiro	fp->f_ival = *priority;
5690792Sgshapiro	return 0;
5790792Sgshapiro}
5890792Sgshapiro
5990792Sgshapiro/*
6090792Sgshapiro**  SM_SYSLOGREAD -- read function for syslog
6190792Sgshapiro**
6290792Sgshapiro**  This is a "stub" function (placeholder) that always returns an error.
6390792Sgshapiro**  It is an error to read syslog.
6490792Sgshapiro**
6590792Sgshapiro**	Parameters:
6690792Sgshapiro**		fp -- the file pointer
6790792Sgshapiro**		buf -- buffer to place the data read
6890792Sgshapiro**		n -- number of bytes to read
6990792Sgshapiro**
7090792Sgshapiro**	Returns:
7190792Sgshapiro**		-1 (error) always and sets errno
7290792Sgshapiro*/
7390792Sgshapiro
7490792Sgshapirossize_t
7590792Sgshapirosm_syslogread(fp, buf, n)
7690792Sgshapiro	SM_FILE_T *fp;
7790792Sgshapiro	char *buf;
7890792Sgshapiro	size_t n;
7990792Sgshapiro{
8090792Sgshapiro	/* an error to read */
8190792Sgshapiro	errno = ENODEV;
8290792Sgshapiro	return -1;
8390792Sgshapiro}
8490792Sgshapiro
8590792Sgshapiro/*
8690792Sgshapiro**  SM_SYSLOGWRITE -- write function for syslog
8790792Sgshapiro**
8890792Sgshapiro**  Send output to syslog.
8990792Sgshapiro**
9090792Sgshapiro**	Parameters:
9190792Sgshapiro**		fp -- the file pointer
9290792Sgshapiro**		buf -- buffer that the write data comes from
9390792Sgshapiro**		n -- number of bytes to write
9490792Sgshapiro**
9590792Sgshapiro**	Returns:
9690792Sgshapiro**		0 (zero) for success always
9790792Sgshapiro*/
9890792Sgshapiro
9990792Sgshapiro/*
10090792Sgshapiro**  XXX TODO: more work needs to be done to ensure that each line of output
10190792Sgshapiro**  XXX written to a syslog file is mapped to exactly one syslog message.
10290792Sgshapiro*/
10390792Sgshapirossize_t
10490792Sgshapirosm_syslogwrite(fp, buf, n)
10590792Sgshapiro	SM_FILE_T *fp;
10690792Sgshapiro	char const *buf;
10790792Sgshapiro	size_t n;
10890792Sgshapiro{
10990792Sgshapiro	syslog(fp->f_ival, "%s", buf);
11090792Sgshapiro	return 0;
11190792Sgshapiro}
11290792Sgshapiro
11390792Sgshapiro/*
11490792Sgshapiro**  SM_SYSLOGSEEK -- position the syslog file offset
11590792Sgshapiro**
11690792Sgshapiro**  This is a "stub" function (placeholder) that always returns an error.
11790792Sgshapiro**  It is an error to seek syslog.
11890792Sgshapiro**
11990792Sgshapiro**	Parameters:
12090792Sgshapiro**		fp -- the file pointer
12190792Sgshapiro**		offset -- the new offset position relative to 'whence'
12290792Sgshapiro**		whence -- flag indicating start of 'offset'
12390792Sgshapiro**
12490792Sgshapiro**	Returns:
12590792Sgshapiro**		-1 (error) always.
12690792Sgshapiro*/
12790792Sgshapiro
12890792Sgshapirooff_t
12990792Sgshapirosm_syslogseek(fp, offset, whence)
13090792Sgshapiro	SM_FILE_T *fp;
13190792Sgshapiro	off_t offset;
13290792Sgshapiro	int whence;
13390792Sgshapiro{
13490792Sgshapiro	errno = ENODEV;
13590792Sgshapiro	return -1;
13690792Sgshapiro}
13790792Sgshapiro
13890792Sgshapiro/*
13990792Sgshapiro**  SM_SYSLOGCLOSE -- close the syslog file pointer
14090792Sgshapiro**
14190792Sgshapiro**	Parameters:
14290792Sgshapiro**		fp -- the file pointer
14390792Sgshapiro**
14490792Sgshapiro**	Returns:
14590792Sgshapiro**		0 (zero) success always (see Overall)
14690792Sgshapiro**
14790792Sgshapiro*/
14890792Sgshapiro
14990792Sgshapiroint
15090792Sgshapirosm_syslogclose(fp)
15190792Sgshapiro	SM_FILE_T *fp;
15290792Sgshapiro{
15390792Sgshapiro	return 0;
15490792Sgshapiro}
15590792Sgshapiro
15690792Sgshapiro/*
15790792Sgshapiro**  SM_SYSLOGSETINFO -- set information for the file pointer
15890792Sgshapiro**
15990792Sgshapiro**	Parameters:
16090792Sgshapiro**		fp -- the file pointer being set
16190792Sgshapiro**		what -- what information is being set
16290792Sgshapiro**		valp -- information content being set to
16390792Sgshapiro**
16490792Sgshapiro**	Returns:
16590792Sgshapiro**		-1 on failure
16690792Sgshapiro**		0 (zero) on success
16790792Sgshapiro**
16890792Sgshapiro**	Side Effects:
16990792Sgshapiro**		Sets internal file pointer data
17090792Sgshapiro*/
17190792Sgshapiro
17290792Sgshapiroint
17390792Sgshapirosm_syslogsetinfo(fp, what, valp)
17490792Sgshapiro	SM_FILE_T *fp;
17590792Sgshapiro	int what;
17690792Sgshapiro	void *valp;
17790792Sgshapiro{
17890792Sgshapiro	switch (what)
17990792Sgshapiro	{
18090792Sgshapiro	  case SM_IO_SL_PRIO:
18190792Sgshapiro		fp->f_ival = *((int *)(valp));
18290792Sgshapiro		return 0;
18390792Sgshapiro	  default:
18490792Sgshapiro		errno = EINVAL;
18590792Sgshapiro		return -1;
18690792Sgshapiro	}
18790792Sgshapiro}
18890792Sgshapiro
18990792Sgshapiro/*
19090792Sgshapiro**  SM_SYSLOGGETINFO -- get information relating to the file pointer
19190792Sgshapiro**
19290792Sgshapiro**	Parameters:
19390792Sgshapiro**		fp -- the file pointer being queried
19490792Sgshapiro**		what -- the information type being queried
19590792Sgshapiro**		valp -- location to placed queried information
19690792Sgshapiro**
19790792Sgshapiro**	Returns:
19890792Sgshapiro**		0 (zero) on success
19990792Sgshapiro**		-1 on failure
20090792Sgshapiro**
20190792Sgshapiro**	Side Effects:
20290792Sgshapiro**		Fills in 'valp' with data.
20390792Sgshapiro*/
20490792Sgshapiro
20590792Sgshapiroint
20690792Sgshapirosm_sysloggetinfo(fp, what, valp)
20790792Sgshapiro	SM_FILE_T *fp;
20890792Sgshapiro	int what;
20990792Sgshapiro	void *valp;
21090792Sgshapiro{
21190792Sgshapiro	switch (what)
21290792Sgshapiro	{
21390792Sgshapiro	  case SM_IO_SL_PRIO:
21490792Sgshapiro		*((int *)(valp)) = fp->f_ival;
21590792Sgshapiro		return 0;
21690792Sgshapiro	  default:
21790792Sgshapiro		errno = EINVAL;
21890792Sgshapiro		return -1;
21990792Sgshapiro	}
22090792Sgshapiro}
221