Lines 173-179
static STAILQ_HEAD(, socklist) shead = STAILQ_HEAD
Link Here
|
173 |
|
173 |
|
174 |
#define IGN_CONS 0x001 /* don't print on console */ |
174 |
#define IGN_CONS 0x001 /* don't print on console */ |
175 |
#define SYNC_FILE 0x002 /* do fsync on file after printing */ |
175 |
#define SYNC_FILE 0x002 /* do fsync on file after printing */ |
176 |
#define ADDDATE 0x004 /* add a date to the message */ |
|
|
177 |
#define MARK 0x008 /* this message is a mark */ |
176 |
#define MARK 0x008 /* this message is a mark */ |
178 |
#define ISKERNEL 0x010 /* kernel generated message */ |
177 |
#define ISKERNEL 0x010 /* kernel generated message */ |
179 |
|
178 |
|
Lines 324-329
static int logflags = O_WRONLY|O_APPEND; /* flags
Link Here
|
324 |
static char bootfile[MAXLINE+1]; /* booted kernel file */ |
323 |
static char bootfile[MAXLINE+1]; /* booted kernel file */ |
325 |
|
324 |
|
326 |
static int RemoteAddDate; /* Always set the date on remote messages */ |
325 |
static int RemoteAddDate; /* Always set the date on remote messages */ |
|
|
326 |
static int RemoteHostname; /* Log remote hostname from the message */ |
327 |
|
327 |
|
328 |
static int UniquePriority; /* Only log specified priority? */ |
328 |
static int UniquePriority; /* Only log specified priority? */ |
329 |
static int LogFacPri; /* Put facility and priority in log message: */ |
329 |
static int LogFacPri; /* Put facility and priority in log message: */ |
Lines 352-358
static void domark(int);
Link Here
|
352 |
static void fprintlog(struct filed *, int, const char *); |
352 |
static void fprintlog(struct filed *, int, const char *); |
353 |
static void init(int); |
353 |
static void init(int); |
354 |
static void logerror(const char *); |
354 |
static void logerror(const char *); |
355 |
static void logmsg(int, const char *, const char *, int); |
355 |
static void logmsg(int, const char *, const char *, const char *, int); |
356 |
static void log_deadchild(pid_t, int, const char *); |
356 |
static void log_deadchild(pid_t, int, const char *); |
357 |
static void markit(void); |
357 |
static void markit(void); |
358 |
static int socksetup(struct peer *); |
358 |
static int socksetup(struct peer *); |
Lines 361-367
static int socklist_recv_sock(struct socklist *);
Link Here
|
361 |
static int socklist_recv_signal(struct socklist *); |
361 |
static int socklist_recv_signal(struct socklist *); |
362 |
static void sighandler(int); |
362 |
static void sighandler(int); |
363 |
static int skip_message(const char *, const char *, int); |
363 |
static int skip_message(const char *, const char *, int); |
364 |
static void printline(const char *, char *, int); |
364 |
static void parsemsg(const char *, char *); |
365 |
static void printsys(char *); |
365 |
static void printsys(char *); |
366 |
static int p_open(const char *, pid_t *); |
366 |
static int p_open(const char *, pid_t *); |
367 |
static void reapchild(int); |
367 |
static void reapchild(int); |
Lines 454-460
main(int argc, char *argv[])
Link Here
|
454 |
if (madvise(NULL, 0, MADV_PROTECT) != 0) |
454 |
if (madvise(NULL, 0, MADV_PROTECT) != 0) |
455 |
dprintf("madvise() failed: %s\n", strerror(errno)); |
455 |
dprintf("madvise() failed: %s\n", strerror(errno)); |
456 |
|
456 |
|
457 |
while ((ch = getopt(argc, argv, "468Aa:b:cCdf:Fkl:m:nNop:P:sS:Tuv")) |
457 |
while ((ch = getopt(argc, argv, "468Aa:b:cCdf:FHkl:m:nNop:P:sS:Tuv")) |
458 |
!= -1) |
458 |
!= -1) |
459 |
switch (ch) { |
459 |
switch (ch) { |
460 |
#ifdef INET |
460 |
#ifdef INET |
Lines 518-523
main(int argc, char *argv[])
Link Here
|
518 |
case 'F': /* run in foreground instead of daemon */ |
518 |
case 'F': /* run in foreground instead of daemon */ |
519 |
Foreground++; |
519 |
Foreground++; |
520 |
break; |
520 |
break; |
|
|
521 |
case 'H': |
522 |
RemoteHostname = 1; |
523 |
break; |
521 |
case 'k': /* keep remote kern fac */ |
524 |
case 'k': /* keep remote kern fac */ |
522 |
KeepKernFac = 1; |
525 |
KeepKernFac = 1; |
523 |
break; |
526 |
break; |
Lines 772-778
socklist_recv_sock(struct socklist *sl)
Link Here
|
772 |
socklen_t sslen; |
775 |
socklen_t sslen; |
773 |
const char *hname; |
776 |
const char *hname; |
774 |
char line[MAXLINE + 1]; |
777 |
char line[MAXLINE + 1]; |
775 |
int date, len; |
778 |
int len; |
776 |
|
779 |
|
777 |
sslen = sizeof(ss); |
780 |
sslen = sizeof(ss); |
778 |
len = recvfrom(sl->sl_socket, line, sizeof(line) - 1, 0, sa, &sslen); |
781 |
len = recvfrom(sl->sl_socket, line, sizeof(line) - 1, 0, sa, &sslen); |
Lines 786-795
socklist_recv_sock(struct socklist *sl)
Link Here
|
786 |
} |
789 |
} |
787 |
/* Received valid data. */ |
790 |
/* Received valid data. */ |
788 |
line[len] = '\0'; |
791 |
line[len] = '\0'; |
789 |
if (sl->sl_ss.ss_family == AF_LOCAL) { |
792 |
if (sl->sl_ss.ss_family == AF_LOCAL) |
790 |
hname = LocalHostName; |
793 |
hname = LocalHostName; |
791 |
date = 0; |
794 |
else { |
792 |
} else { |
|
|
793 |
hname = cvthname(sa); |
795 |
hname = cvthname(sa); |
794 |
unmapped(sa); |
796 |
unmapped(sa); |
795 |
if (validate(sa, hname) == 0) { |
797 |
if (validate(sa, hname) == 0) { |
Lines 796-804
socklist_recv_sock(struct socklist *sl)
Link Here
|
796 |
dprintf("Message from %s was ignored.", hname); |
798 |
dprintf("Message from %s was ignored.", hname); |
797 |
return (-1); |
799 |
return (-1); |
798 |
} |
800 |
} |
799 |
date = RemoteAddDate ? ADDDATE : 0; |
|
|
800 |
} |
801 |
} |
801 |
printline(hname, line, date); |
802 |
parsemsg(hname, line); |
802 |
|
803 |
|
803 |
return (0); |
804 |
return (0); |
804 |
} |
805 |
} |
Lines 836-842
usage(void)
Link Here
|
836 |
{ |
837 |
{ |
837 |
|
838 |
|
838 |
fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n", |
839 |
fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n", |
839 |
"usage: syslogd [-468ACcdFknosTuv] [-a allowed_peer]", |
840 |
"usage: syslogd [-468ACcdFHknosTuv] [-a allowed_peer]", |
840 |
" [-b bind_address] [-f config_file]", |
841 |
" [-b bind_address] [-f config_file]", |
841 |
" [-l [mode:]path] [-m mark_interval]", |
842 |
" [-l [mode:]path] [-m mark_interval]", |
842 |
" [-P pid_file] [-p log_socket]", |
843 |
" [-P pid_file] [-p log_socket]", |
Lines 845-872
usage(void)
Link Here
|
845 |
} |
846 |
} |
846 |
|
847 |
|
847 |
/* |
848 |
/* |
848 |
* Take a raw input line, decode the message, and print the message |
849 |
* Take a raw input line, extract PRI, TIMESTAMP and HOSTNAME from the message, |
849 |
* on the appropriate log files. |
850 |
* and print the message on the appropriate log files. |
850 |
*/ |
851 |
*/ |
851 |
static void |
852 |
static void |
852 |
printline(const char *hname, char *msg, int flags) |
853 |
parsemsg(const char *from, char *msg) |
853 |
{ |
854 |
{ |
854 |
char *p, *q; |
855 |
const char *timestamp; |
|
|
856 |
char *q; |
855 |
long n; |
857 |
long n; |
856 |
int c, pri; |
858 |
int i, c, pri, msglen; |
857 |
char line[MAXLINE + 1]; |
859 |
char line[MAXLINE + 1]; |
858 |
|
860 |
|
859 |
/* test for special codes */ |
861 |
/* Parse PRI. */ |
860 |
p = msg; |
862 |
if (msg[0] != '<' || !isdigit(msg[1])) { |
861 |
pri = DEFUPRI; |
863 |
dprintf("Invalid PRI from %s\n", from); |
862 |
if (*p == '<') { |
864 |
return; |
863 |
errno = 0; |
865 |
} |
864 |
n = strtol(p + 1, &q, 10); |
866 |
for (i = 2; i <= 4; i++) { |
865 |
if (*q == '>' && n >= 0 && n < INT_MAX && errno == 0) { |
867 |
if (msg[i] == '>') |
866 |
p = q + 1; |
868 |
break; |
867 |
pri = n; |
869 |
if (!isdigit(msg[i])) { |
|
|
870 |
dprintf("Invalid PRI header from %s\n", from); |
871 |
return; |
868 |
} |
872 |
} |
869 |
} |
873 |
} |
|
|
874 |
if (msg[i] != '>') { |
875 |
dprintf("Invalid PRI header from %s\n", from); |
876 |
return; |
877 |
} |
878 |
errno = 0; |
879 |
n = strtol(msg + 1, &q, 10); |
880 |
if (errno != 0 || *q != msg[i] || n < 0 || n >= INT_MAX) { |
881 |
dprintf("Invalid PRI %ld from %s: %s\n", |
882 |
n, from, strerror(errno)); |
883 |
return; |
884 |
} |
885 |
pri = n; |
870 |
if (pri &~ (LOG_FACMASK|LOG_PRIMASK)) |
886 |
if (pri &~ (LOG_FACMASK|LOG_PRIMASK)) |
871 |
pri = DEFUPRI; |
887 |
pri = DEFUPRI; |
872 |
|
888 |
|
Lines 878-886
static void
Link Here
|
878 |
if ((pri & LOG_FACMASK) == LOG_KERN && !KeepKernFac) |
894 |
if ((pri & LOG_FACMASK) == LOG_KERN && !KeepKernFac) |
879 |
pri = LOG_MAKEPRI(LOG_USER, LOG_PRI(pri)); |
895 |
pri = LOG_MAKEPRI(LOG_USER, LOG_PRI(pri)); |
880 |
|
896 |
|
|
|
897 |
/* |
898 |
* The TIMESTAMP field is the local time and is in the format of |
899 |
* "Mmm dd hh:mm:ss" (without the quote marks). |
900 |
* A single space character MUST follow the TIMESTAMP field. |
901 |
* |
902 |
* XXXGL: the check can be improved. |
903 |
*/ |
904 |
msg += i + 1; |
905 |
msglen = strlen(msg); |
906 |
if (msglen < MAXDATELEN || msg[3] != ' ' || msg[6] != ' ' || |
907 |
msg[9] != ':' || msg[12] != ':' || msg[15] != ' ') { |
908 |
dprintf("Invalid TIMESTAMP from %s: %s\n", from, msg); |
909 |
return; |
910 |
} |
911 |
|
912 |
if (!RemoteAddDate) |
913 |
timestamp = msg; |
914 |
else |
915 |
timestamp = NULL; |
916 |
msg += MAXDATELEN; |
917 |
msglen -= MAXDATELEN; |
918 |
|
919 |
/* |
920 |
* A single space character MUST also follow the HOSTNAME field. |
921 |
*/ |
922 |
for (i = 0; i < MIN(MAXHOSTNAMELEN, msglen); i++) { |
923 |
if (msg[i] == ' ') { |
924 |
if (RemoteHostname) |
925 |
from = msg; |
926 |
msg += i + 1; |
927 |
break; |
928 |
} |
929 |
/* |
930 |
* Support non RFC compliant messages, without hostname. |
931 |
*/ |
932 |
if (msg[i] == ':') |
933 |
break; |
934 |
} |
935 |
if (i == MIN(MAXHOSTNAMELEN, msglen)) { |
936 |
dprintf("Invalid HOSTNAME from %s: %s\n", from, msg); |
937 |
return; |
938 |
} |
939 |
|
881 |
q = line; |
940 |
q = line; |
882 |
|
941 |
while ((c = (unsigned char)*msg++) != '\0' && |
883 |
while ((c = (unsigned char)*p++) != '\0' && |
|
|
884 |
q < &line[sizeof(line) - 4]) { |
942 |
q < &line[sizeof(line) - 4]) { |
885 |
if (mask_C1 && (c & 0x80) && c < 0xA0) { |
943 |
if (mask_C1 && (c & 0x80) && c < 0xA0) { |
886 |
c &= 0x7F; |
944 |
c &= 0x7F; |
Lines 902-908
static void
Link Here
|
902 |
} |
960 |
} |
903 |
*q = '\0'; |
961 |
*q = '\0'; |
904 |
|
962 |
|
905 |
logmsg(pri, line, hname, flags); |
963 |
logmsg(pri, timestamp, line, from, 0); |
906 |
} |
964 |
} |
907 |
|
965 |
|
908 |
/* |
966 |
/* |
Lines 956-962
printsys(char *msg)
Link Here
|
956 |
long n; |
1014 |
long n; |
957 |
int flags, isprintf, pri; |
1015 |
int flags, isprintf, pri; |
958 |
|
1016 |
|
959 |
flags = ISKERNEL | SYNC_FILE | ADDDATE; /* fsync after write */ |
1017 |
flags = ISKERNEL | SYNC_FILE; /* fsync after write */ |
960 |
p = msg; |
1018 |
p = msg; |
961 |
pri = DEFSPRI; |
1019 |
pri = DEFSPRI; |
962 |
isprintf = 1; |
1020 |
isprintf = 1; |
Lines 977-983
printsys(char *msg)
Link Here
|
977 |
flags |= IGN_CONS; |
1035 |
flags |= IGN_CONS; |
978 |
if (pri &~ (LOG_FACMASK|LOG_PRIMASK)) |
1036 |
if (pri &~ (LOG_FACMASK|LOG_PRIMASK)) |
979 |
pri = DEFSPRI; |
1037 |
pri = DEFSPRI; |
980 |
logmsg(pri, p, LocalHostName, flags); |
1038 |
logmsg(pri, NULL, p, LocalHostName, flags); |
981 |
} |
1039 |
} |
982 |
|
1040 |
|
983 |
static time_t now; |
1041 |
static time_t now; |
Lines 1032-1042
skip_message(const char *name, const char *spec, i
Link Here
|
1032 |
* the priority. |
1090 |
* the priority. |
1033 |
*/ |
1091 |
*/ |
1034 |
static void |
1092 |
static void |
1035 |
logmsg(int pri, const char *msg, const char *from, int flags) |
1093 |
logmsg(int pri, const char *timestamp, const char *msg, const char *from, |
|
|
1094 |
int flags) |
1036 |
{ |
1095 |
{ |
1037 |
struct filed *f; |
1096 |
struct filed *f; |
1038 |
int i, fac, msglen, prilev; |
1097 |
int i, fac, msglen, prilev; |
1039 |
const char *timestamp; |
|
|
1040 |
char prog[NAME_MAX+1]; |
1098 |
char prog[NAME_MAX+1]; |
1041 |
char buf[MAXLINE+1]; |
1099 |
char buf[MAXLINE+1]; |
1042 |
|
1100 |
|
Lines 1043-1071
static void
Link Here
|
1043 |
dprintf("logmsg: pri %o, flags %x, from %s, msg %s\n", |
1101 |
dprintf("logmsg: pri %o, flags %x, from %s, msg %s\n", |
1044 |
pri, flags, from, msg); |
1102 |
pri, flags, from, msg); |
1045 |
|
1103 |
|
1046 |
/* |
|
|
1047 |
* Check to see if msg looks non-standard. |
1048 |
*/ |
1049 |
msglen = strlen(msg); |
1050 |
if (msglen < MAXDATELEN || msg[3] != ' ' || msg[6] != ' ' || |
1051 |
msg[9] != ':' || msg[12] != ':' || msg[15] != ' ') |
1052 |
flags |= ADDDATE; |
1053 |
|
1054 |
(void)time(&now); |
1104 |
(void)time(&now); |
1055 |
if (flags & ADDDATE) { |
1105 |
if (timestamp == NULL) |
1056 |
timestamp = ctime(&now) + 4; |
1106 |
timestamp = ctime(&now) + 4; |
1057 |
} else { |
|
|
1058 |
timestamp = msg; |
1059 |
msg += MAXDATELEN; |
1060 |
msglen -= MAXDATELEN; |
1061 |
} |
1062 |
|
1107 |
|
1063 |
/* skip leading blanks */ |
|
|
1064 |
while (isspace(*msg)) { |
1065 |
msg++; |
1066 |
msglen--; |
1067 |
} |
1068 |
|
1069 |
/* extract facility and priority level */ |
1108 |
/* extract facility and priority level */ |
1070 |
if (flags & MARK) |
1109 |
if (flags & MARK) |
1071 |
fac = LOG_NFACILITIES; |
1110 |
fac = LOG_NFACILITIES; |
Lines 1078-1084
static void
Link Here
|
1078 |
|
1117 |
|
1079 |
prilev = LOG_PRI(pri); |
1118 |
prilev = LOG_PRI(pri); |
1080 |
|
1119 |
|
1081 |
/* extract program name */ |
1120 |
/* Extract TAG part of the message (usually program name). */ |
1082 |
for (i = 0; i < NAME_MAX; i++) { |
1121 |
for (i = 0; i < NAME_MAX; i++) { |
1083 |
if (!isprint(msg[i]) || msg[i] == ':' || msg[i] == '[' || |
1122 |
if (!isprint(msg[i]) || msg[i] == ':' || msg[i] == '[' || |
1084 |
msg[i] == '/' || isspace(msg[i])) |
1123 |
msg[i] == '/' || isspace(msg[i])) |
Lines 1092-1099
static void
Link Here
|
1092 |
snprintf(buf, sizeof(buf), "%s: %s", |
1131 |
snprintf(buf, sizeof(buf), "%s: %s", |
1093 |
use_bootfile ? bootfile : "kernel", msg); |
1132 |
use_bootfile ? bootfile : "kernel", msg); |
1094 |
msg = buf; |
1133 |
msg = buf; |
1095 |
msglen = strlen(buf); |
|
|
1096 |
} |
1134 |
} |
|
|
1135 |
msglen = strlen(msg); |
1097 |
|
1136 |
|
1098 |
/* log the message to the particular outputs */ |
1137 |
/* log the message to the particular outputs */ |
1099 |
if (!Initialized) { |
1138 |
if (!Initialized) { |
Lines 1643-1649
logerror(const char *type)
Link Here
|
1643 |
(void)snprintf(buf, sizeof buf, "syslogd: %s", type); |
1682 |
(void)snprintf(buf, sizeof buf, "syslogd: %s", type); |
1644 |
errno = 0; |
1683 |
errno = 0; |
1645 |
dprintf("%s\n", buf); |
1684 |
dprintf("%s\n", buf); |
1646 |
logmsg(LOG_SYSLOG|LOG_ERR, buf, LocalHostName, ADDDATE); |
1685 |
logmsg(LOG_SYSLOG|LOG_ERR, NULL, buf, LocalHostName, 0); |
1647 |
recursed--; |
1686 |
recursed--; |
1648 |
} |
1687 |
} |
1649 |
|
1688 |
|
Lines 1987-1993
init(int signo)
Link Here
|
1987 |
} |
2026 |
} |
1988 |
} |
2027 |
} |
1989 |
|
2028 |
|
1990 |
logmsg(LOG_SYSLOG|LOG_INFO, "syslogd: restart", LocalHostName, ADDDATE); |
2029 |
logmsg(LOG_SYSLOG|LOG_INFO, NULL, "syslogd: restart", LocalHostName, 0); |
1991 |
dprintf("syslogd: restarted\n"); |
2030 |
dprintf("syslogd: restarted\n"); |
1992 |
/* |
2031 |
/* |
1993 |
* Log a change in hostname, but only on a restart. |
2032 |
* Log a change in hostname, but only on a restart. |
Lines 1996-2002
init(int signo)
Link Here
|
1996 |
(void)snprintf(hostMsg, sizeof(hostMsg), |
2035 |
(void)snprintf(hostMsg, sizeof(hostMsg), |
1997 |
"syslogd: hostname changed, \"%s\" to \"%s\"", |
2036 |
"syslogd: hostname changed, \"%s\" to \"%s\"", |
1998 |
oldLocalHostName, LocalHostName); |
2037 |
oldLocalHostName, LocalHostName); |
1999 |
logmsg(LOG_SYSLOG|LOG_INFO, hostMsg, LocalHostName, ADDDATE); |
2038 |
logmsg(LOG_SYSLOG|LOG_INFO, NULL, hostMsg, LocalHostName, 0); |
2000 |
dprintf("%s\n", hostMsg); |
2039 |
dprintf("%s\n", hostMsg); |
2001 |
} |
2040 |
} |
2002 |
/* |
2041 |
/* |
Lines 2006-2012
init(int signo)
Link Here
|
2006 |
if (signo == 0 && !use_bootfile) { |
2045 |
if (signo == 0 && !use_bootfile) { |
2007 |
(void)snprintf(bootfileMsg, sizeof(bootfileMsg), |
2046 |
(void)snprintf(bootfileMsg, sizeof(bootfileMsg), |
2008 |
"syslogd: kernel boot file is %s", bootfile); |
2047 |
"syslogd: kernel boot file is %s", bootfile); |
2009 |
logmsg(LOG_KERN|LOG_INFO, bootfileMsg, LocalHostName, ADDDATE); |
2048 |
logmsg(LOG_KERN|LOG_INFO, NULL, bootfileMsg, LocalHostName, 0); |
2010 |
dprintf("%s\n", bootfileMsg); |
2049 |
dprintf("%s\n", bootfileMsg); |
2011 |
} |
2050 |
} |
2012 |
} |
2051 |
} |
Lines 2315-2322
markit(void)
Link Here
|
2315 |
now = time((time_t *)NULL); |
2354 |
now = time((time_t *)NULL); |
2316 |
MarkSeq += TIMERINTVL; |
2355 |
MarkSeq += TIMERINTVL; |
2317 |
if (MarkSeq >= MarkInterval) { |
2356 |
if (MarkSeq >= MarkInterval) { |
2318 |
logmsg(LOG_INFO, "-- MARK --", |
2357 |
logmsg(LOG_INFO, NULL, "-- MARK --", LocalHostName, MARK); |
2319 |
LocalHostName, ADDDATE|MARK); |
|
|
2320 |
MarkSeq = 0; |
2358 |
MarkSeq = 0; |
2321 |
} |
2359 |
} |
2322 |
|
2360 |
|