Mon Oct 12 13:30:35 CEST 1998: Martin Schulze <joey@infodrom.north.de>

Redirected some error output with regard to argument parsing to
      stderr.

  Mon Oct 12 14:02:51 CEST 1998: Martin Schulze <joey@infodrom.north.de>
      Applied patch provided vom Topi Miettinen with regard to the
      people from OpenBSD.  This provides the additional '-a'
      argument used for specifying additional UNIX domain sockets to
      listen to.  This is been used with chroot()'ed named's for
      example.

  Mon Oct 12 18:29:44 CEST 1998: Martin Schulze <joey@infodrom.north.de>
      Added `ftp' facility which was introduced in glibc version 2.
      It's #ifdef'ed so won't harm with older libraries.
This commit is contained in:
Joey Schulze 1998-10-12 16:36:18 +00:00
parent cf7e986344
commit 0e4915d405

111
syslogd.c
View File

@ -362,6 +362,21 @@ static char sccsid[] = "@(#)syslogd.c 5.27 (Berkeley) 10/10/88";
* will raise if it is initialized. Only after that one the * will raise if it is initialized. Only after that one the
* parent process may exit. Otherwise klogd might try to flush * parent process may exit. Otherwise klogd might try to flush
* its log cache while syslogd can't receive the messages yet. * its log cache while syslogd can't receive the messages yet.
*
* Mon Oct 12 13:30:35 CEST 1998: Martin Schulze <joey@infodrom.north.de>
* Redirected some error output with regard to argument parsing to
* stderr.
*
* Mon Oct 12 14:02:51 CEST 1998: Martin Schulze <joey@infodrom.north.de>
* Applied patch provided vom Topi Miettinen with regard to the
* people from OpenBSD. This provides the additional '-a'
* argument used for specifying additional UNIX domain sockets to
* listen to. This is been used with chroot()'ed named's for
* example.
*
* Mon Oct 12 18:29:44 CEST 1998: Martin Schulze <joey@infodrom.north.de>
* Added `ftp' facility which was introduced in glibc version 2.
* It's #ifdef'ed so won't harm with older libraries.
*/ */
@ -469,18 +484,23 @@ static char sccsid[] = "@(#)syslogd.c 5.27 (Berkeley) 10/10/88";
#define _PATH_LOG "/dev/log" #define _PATH_LOG "/dev/log"
#endif #endif
char *LogName = _PATH_LOG;
char *ConfFile = _PATH_LOGCONF; char *ConfFile = _PATH_LOGCONF;
char *PidFile = _PATH_LOGPID; char *PidFile = _PATH_LOGPID;
char ctty[] = _PATH_CONSOLE; char ctty[] = _PATH_CONSOLE;
char **parts; char **parts;
int inetm = 0, funix = -1; int inetm = 0;
static int debugging_on = 0; static int debugging_on = 0;
static int nlogs = -1; static int nlogs = -1;
static int restart = 0; static int restart = 0;
#define MAXFUNIX 20
int nfunix = 1;
char *funixn[MAXFUNIX] = { _PATH_LOG };
int funix[MAXFUNIX] = { -1, };
#define UNAMESZ 8 /* length of a login name */ #define UNAMESZ 8 /* length of a login name */
#define MAXUNAMES 20 /* maximum number of user names */ #define MAXUNAMES 20 /* maximum number of user names */
#define MAXFNAME 200 /* max file pathname length */ #define MAXFNAME 200 /* max file pathname length */
@ -617,6 +637,9 @@ struct code FacNames[] = {
{"syslog", LOG_SYSLOG}, {"syslog", LOG_SYSLOG},
{"user", LOG_USER}, {"user", LOG_USER},
{"uucp", LOG_UUCP}, {"uucp", LOG_UUCP},
#if defined(__GLIBC__) && __GLIBC__ >= 2
{"ftp", LOG_FTP},
#endif
{"local0", LOG_LOCAL0}, {"local0", LOG_LOCAL0},
{"local1", LOG_LOCAL1}, {"local1", LOG_LOCAL1},
{"local2", LOG_LOCAL2}, {"local2", LOG_LOCAL2},
@ -682,7 +705,7 @@ static void allocate_log(void);
void sighup_handler(); void sighup_handler();
#ifdef SYSLOG_UNIXAF #ifdef SYSLOG_UNIXAF
static int create_unix_socket(); static int create_unix_socket(const char *path);
#endif #endif
#ifdef SYSLOG_INET #ifdef SYSLOG_INET
static int create_inet_socket(); static int create_inet_socket();
@ -702,6 +725,14 @@ int main(argc, argv)
#endif #endif
int num_fds; int num_fds;
#endif /* __GLIBC__ */ #endif /* __GLIBC__ */
/*
* It took me quite some time to figure out so I guess I
* should better write it down. unixm is a list of file
* descriptors from which one can read(). This is contrary to
* readfds which is a list of file descriptors where activity
* is monitored by select() and from which one cannot read().
* -Joey
*/
fd_set unixm, readfds; fd_set unixm, readfds;
#ifndef TESTING #ifndef TESTING
@ -725,8 +756,19 @@ int main(argc, argv)
#ifndef TESTING #ifndef TESTING
chdir ("/"); chdir ("/");
#endif #endif
while ((ch = getopt(argc, argv, "dhf:l:m:np:rs:v")) != EOF) for (i = 1; i < nfunix; i++) {
funixn[i] = "";
funix[i] = -1;
}
while ((ch = getopt(argc, argv, "a:dhf:l:m:np:rs:v")) != EOF)
switch((char)ch) { switch((char)ch) {
case 'a':
if (nfunix < MAXFUNIX)
funixn[nfunix++] = optarg;
else
fprintf(stderr, "Out of descriptors, ignoring %s\n", optarg);
break;
case 'd': /* debug */ case 'd': /* debug */
Debug = 1; Debug = 1;
break; break;
@ -738,7 +780,7 @@ int main(argc, argv)
break; break;
case 'l': case 'l':
if (LocalHosts) { if (LocalHosts) {
printf ("Only one -l argument allowed," \ fprintf (stderr, "Only one -l argument allowed," \
"the first one is taken.\n"); "the first one is taken.\n");
break; break;
} }
@ -750,15 +792,15 @@ int main(argc, argv)
case 'n': /* don't fork */ case 'n': /* don't fork */
NoFork = 1; NoFork = 1;
break; break;
case 'p': /* path */ case 'p': /* path to regular log socket */
LogName = optarg; funixn[0] = optarg;
break; break;
case 'r': /* accept remote messages */ case 'r': /* accept remote messages */
AcceptRemote = 1; AcceptRemote = 1;
break; break;
case 's': case 's':
if (StripDomains) { if (StripDomains) {
printf ("Only one -s argument allowed," \ fprintf (stderr, "Only one -s argument allowed," \
"the first one is taken.\n"); "the first one is taken.\n");
break; break;
} }
@ -883,7 +925,6 @@ int main(argc, argv)
(void) signal(SIGALRM, domark); (void) signal(SIGALRM, domark);
(void) signal(SIGUSR1, Debug ? debug_switch : SIG_IGN); (void) signal(SIGUSR1, Debug ? debug_switch : SIG_IGN);
(void) alarm(TIMERINTVL); (void) alarm(TIMERINTVL);
(void) unlink(LogName);
/* Create a partial message table for all file descriptors. */ /* Create a partial message table for all file descriptors. */
num_fds = getdtablesize(); num_fds = getdtablesize();
@ -921,14 +962,12 @@ int main(argc, argv)
#ifdef SYSLOG_UNIXAF #ifdef SYSLOG_UNIXAF
#ifndef TESTING #ifndef TESTING
/* /*
* Add the Unix Domain Socket to the list of read * Add the Unix Domain Sockets to the list of read
* descriptors. * descriptors.
*/ */
if (funix >= 0) { for (i = 0; i < nfunix; i++) {
FD_SET(funix, &readfds); if (funix[i] != -1)
for (nfds= 0; nfds < FD_SETSIZE; ++nfds) FD_SET(funix[i], &readfds);
if ( FD_ISSET(nfds, &unixm) )
FD_SET(nfds, &readfds);
} }
#endif #endif
#endif #endif
@ -1024,21 +1063,20 @@ int main(argc, argv)
} }
} }
/* Accept a new unix connection */ /* Accept a new unix connection */
if (FD_ISSET(funix, &readfds)) { for (i = 0; i < nfunix; i++)
if (funix[i] != -1 && FD_ISSET(funix[i], &readfds)) {
len = sizeof(fromunix); len = sizeof(fromunix);
if ((fd = accept(funix, (struct sockaddr *) &fromunix,\ if ((fd = accept(funix[i], (struct sockaddr *) &fromunix,
&len)) >= 0) { &len)) >= 0) {
FD_SET(fd, &unixm); FD_SET(fd, &unixm);
dprintf("New UNIX connect assigned to fd: " \ dprintf("New UNIX connect assigned to fd: " \
"%d.\n", fd); "%d.\n", fd);
FD_SET(fd, &readfds); FD_SET(fd, &readfds);
} } else {
else {
dprintf("Error accepting UNIX connection: " \ dprintf("Error accepting UNIX connection: " \
"%d = %s.\n", errno, strerror(errno)); "%d = %s.\n", errno, strerror(errno));
} }
} }
#endif #endif
#ifdef SYSLOG_INET #ifdef SYSLOG_INET
@ -1100,21 +1138,27 @@ int usage()
} }
#ifdef SYSLOG_UNIXAF #ifdef SYSLOG_UNIXAF
static int create_unix_socket() static int create_unix_socket(const char *path)
{ {
struct sockaddr_un sunx; struct sockaddr_un sunx;
int fd; int fd;
char line[MAXLINE +1]; char line[MAXLINE +1];
if (path[0] == '\0')
return -1;
(void) unlink(path);
memset(&sunx, 0, sizeof(sunx));
sunx.sun_family = AF_UNIX; sunx.sun_family = AF_UNIX;
(void) strncpy(sunx.sun_path, LogName, sizeof(sunx.sun_path)); (void) strncpy(sunx.sun_path, path, sizeof(sunx.sun_path));
fd = socket(AF_UNIX, SOCK_STREAM, 0); fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0 || bind(fd, (struct sockaddr *) &sunx, if (fd < 0 || bind(fd, (struct sockaddr *) &sunx,
sizeof(sunx.sun_family)+strlen(sunx.sun_path)) < 0 || sizeof(sunx.sun_family)+strlen(sunx.sun_path)) < 0 ||
chmod(LogName, 0666) < 0 || listen(fd, 5) < 0) { chmod(path, 0666) < 0 || listen(fd, 5) < 0) {
(void) sprintf(line, "cannot create %s", LogName); (void) sprintf(line, "cannot create %s", path);
logerror(line); logerror(line);
dprintf("cannot create %s (%d).\n", LogName, errno); dprintf("cannot create %s (%d).\n", path, errno);
close(fd); close(fd);
#ifndef SYSV #ifndef SYSV
die(0); die(0);
@ -2029,6 +2073,7 @@ void die(sig)
register struct filed *f; register struct filed *f;
char buf[100]; char buf[100];
int lognum; int lognum;
int i;
for (lognum = 0; lognum <= nlogs; lognum++) { for (lognum = 0; lognum <= nlogs; lognum++) {
f = &Files[lognum]; f = &Files[lognum];
@ -2044,12 +2089,17 @@ void die(sig)
logmsg(LOG_SYSLOG|LOG_INFO, buf, LocalHostName, ADDDATE); logmsg(LOG_SYSLOG|LOG_INFO, buf, LocalHostName, ADDDATE);
} }
/* Close the sockets. */ /* Close the UNIX sockets. */
close(funix); for (i = 0; i < nfunix; i++)
if (funix[i] != -1)
close(funix[i]);
/* Close the inet socket. */
if (InetInuse) close(inetm); if (InetInuse) close(inetm);
/* Clean-up files. */ /* Clean-up files. */
(void) unlink(LogName); for (i = 0; i < nfunix; i++)
if (funixn[i] && funix[i] != -1)
(void)unlink(funixn[i]);
#ifndef TESTING #ifndef TESTING
(void) remove_pid(PidFile); (void) remove_pid(PidFile);
#endif #endif
@ -2219,8 +2269,9 @@ void init()
(void) fclose(cf); (void) fclose(cf);
#ifdef SYSLOG_UNIXAF #ifdef SYSLOG_UNIXAF
if (funix < 0) for (i = 0; i < nfunix; i++)
funix = create_unix_socket(); if ((funix[i] = create_unix_socket(funixn[i])) != -1)
dprintf("Opened UNIX socket `%s'.\n", funixn[i]);
#endif #endif
#ifdef SYSLOG_INET #ifdef SYSLOG_INET