Lines 637-644
Link Here
|
637 |
* in seconds after previous message is logged. After each flush, |
637 |
* in seconds after previous message is logged. After each flush, |
638 |
* we move to the next interval until we reach the largest. |
638 |
* we move to the next interval until we reach the largest. |
639 |
*/ |
639 |
*/ |
640 |
int repeatinterval[] = { 30, 60 }; /* # of secs before flush */ |
640 |
time_t repeatinterval[] = { 30, 60 }; /* # of secs before flush */ |
641 |
#define MAXREPEAT ((sizeof(repeatinterval) / sizeof(repeatinterval[0])) - 1) |
641 |
#define MAXREPEAT ((int) ((sizeof(repeatinterval) / sizeof(repeatinterval[0])) - 1)) |
642 |
#define REPEATTIME(f) ((f)->f_time + repeatinterval[(f)->f_repeatcount]) |
642 |
#define REPEATTIME(f) ((f)->f_time + repeatinterval[(f)->f_repeatcount]) |
643 |
#define BACKOFF(f) { if (++(f)->f_repeatcount > MAXREPEAT) \ |
643 |
#define BACKOFF(f) { if (++(f)->f_repeatcount > MAXREPEAT) \ |
644 |
(f)->f_repeatcount = MAXREPEAT; \ |
644 |
(f)->f_repeatcount = MAXREPEAT; \ |
Lines 730-735
Link Here
|
730 |
int MarkInterval = 20 * 60; /* interval between marks in seconds */ |
730 |
int MarkInterval = 20 * 60; /* interval between marks in seconds */ |
731 |
int MarkSeq = 0; /* mark sequence number */ |
731 |
int MarkSeq = 0; /* mark sequence number */ |
732 |
int NoFork = 0; /* don't fork - don't run in daemon mode */ |
732 |
int NoFork = 0; /* don't fork - don't run in daemon mode */ |
|
|
733 |
int DisableDNS = 0; /* don't look up IP addresses of incoming messages */ |
733 |
int AcceptRemote = 0; /* receive messages that come via UDP */ |
734 |
int AcceptRemote = 0; /* receive messages that come via UDP */ |
734 |
char **StripDomains = NULL; /* these domains may be stripped before writing logs */ |
735 |
char **StripDomains = NULL; /* these domains may be stripped before writing logs */ |
735 |
char **LocalHosts = NULL; /* these hosts are logged with their hostname */ |
736 |
char **LocalHosts = NULL; /* these hosts are logged with their hostname */ |
Lines 743-749
Link Here
|
743 |
char **crunch_list(char *list); |
744 |
char **crunch_list(char *list); |
744 |
int usage(void); |
745 |
int usage(void); |
745 |
void untty(void); |
746 |
void untty(void); |
746 |
void printchopped(const char *hname, char *msg, int len, int fd); |
747 |
void printchopped(const char *hname, char *msg, size_t len, int fd); |
747 |
void printline(const char *hname, char *msg); |
748 |
void printline(const char *hname, char *msg); |
748 |
void printsys(char *msg); |
749 |
void printsys(char *msg); |
749 |
void logmsg(int pri, char *msg, const char *from, int flags); |
750 |
void logmsg(int pri, char *msg, const char *from, int flags); |
Lines 786-792
Link Here
|
786 |
int len, num_fds; |
787 |
int len, num_fds; |
787 |
#else /* __GLIBC__ */ |
788 |
#else /* __GLIBC__ */ |
788 |
#ifndef TESTING |
789 |
#ifndef TESTING |
789 |
size_t len; |
790 |
socklen_t len; |
790 |
#endif |
791 |
#endif |
791 |
int num_fds; |
792 |
int num_fds; |
792 |
#endif /* __GLIBC__ */ |
793 |
#endif /* __GLIBC__ */ |
Lines 829-835
Link Here
|
829 |
funix[i] = -1; |
830 |
funix[i] = -1; |
830 |
} |
831 |
} |
831 |
|
832 |
|
832 |
while ((ch = getopt(argc, argv, "a:dhf:l:m:np:rs:v")) != EOF) |
833 |
while ((ch = getopt(argc, argv, "a:dhf:l:m:np:rs:vx")) != EOF) |
833 |
switch((char)ch) { |
834 |
switch((char)ch) { |
834 |
case 'a': |
835 |
case 'a': |
835 |
if (nfunix < MAXFUNIX) |
836 |
if (nfunix < MAXFUNIX) |
Lines 877-882
Link Here
|
877 |
case 'v': |
878 |
case 'v': |
878 |
printf("syslogd %s.%s\n", VERSION, PATCHLEVEL); |
879 |
printf("syslogd %s.%s\n", VERSION, PATCHLEVEL); |
879 |
exit (0); |
880 |
exit (0); |
|
|
881 |
case 'x': |
882 |
DisableDNS = 1; |
883 |
break; |
880 |
case '?': |
884 |
case '?': |
881 |
default: |
885 |
default: |
882 |
usage(); |
886 |
usage(); |
Lines 890-900
Link Here
|
890 |
dprintf("Checking pidfile.\n"); |
894 |
dprintf("Checking pidfile.\n"); |
891 |
if (!check_pid(PidFile)) |
895 |
if (!check_pid(PidFile)) |
892 |
{ |
896 |
{ |
|
|
897 |
signal (SIGTERM, doexit); |
893 |
if (fork()) { |
898 |
if (fork()) { |
894 |
/* |
899 |
/* |
895 |
* Parent process |
900 |
* Parent process |
896 |
*/ |
901 |
*/ |
897 |
signal (SIGTERM, doexit); |
|
|
898 |
sleep(300); |
902 |
sleep(300); |
899 |
/* |
903 |
/* |
900 |
* Not reached unless something major went wrong. 5 |
904 |
* Not reached unless something major went wrong. 5 |
Lines 906-911
Link Here
|
906 |
*/ |
910 |
*/ |
907 |
exit(1); |
911 |
exit(1); |
908 |
} |
912 |
} |
|
|
913 |
signal (SIGTERM, SIG_DFL); |
909 |
num_fds = getdtablesize(); |
914 |
num_fds = getdtablesize(); |
910 |
for (i= 0; i < num_fds; i++) |
915 |
for (i= 0; i < num_fds; i++) |
911 |
(void) close(i); |
916 |
(void) close(i); |
Lines 1074-1082
Link Here
|
1074 |
(fd_set *) NULL, (struct timeval *) NULL); |
1079 |
(fd_set *) NULL, (struct timeval *) NULL); |
1075 |
if ( restart ) |
1080 |
if ( restart ) |
1076 |
{ |
1081 |
{ |
|
|
1082 |
restart = 0; |
1077 |
dprintf("\nReceived SIGHUP, reloading syslogd.\n"); |
1083 |
dprintf("\nReceived SIGHUP, reloading syslogd.\n"); |
1078 |
init(); |
1084 |
init(); |
1079 |
restart = 0; |
|
|
1080 |
continue; |
1085 |
continue; |
1081 |
} |
1086 |
} |
1082 |
if (nfds == 0) { |
1087 |
if (nfds == 0) { |
Lines 1145-1152
Link Here
|
1145 |
dprintf("INET socket error: %d = %s.\n", \ |
1150 |
dprintf("INET socket error: %d = %s.\n", \ |
1146 |
errno, strerror(errno)); |
1151 |
errno, strerror(errno)); |
1147 |
logerror("recvfrom inet"); |
1152 |
logerror("recvfrom inet"); |
1148 |
/* should be harmless now that we set |
1153 |
/* should be harmless */ |
1149 |
* BSDCOMPAT on the socket */ |
|
|
1150 |
sleep(10); |
1154 |
sleep(10); |
1151 |
} |
1155 |
} |
1152 |
} |
1156 |
} |
Lines 1174-1180
Link Here
|
1174 |
|
1178 |
|
1175 |
int usage() |
1179 |
int usage() |
1176 |
{ |
1180 |
{ |
1177 |
fprintf(stderr, "usage: syslogd [-drvh] [-l hostlist] [-m markinterval] [-n] [-p path]\n" \ |
1181 |
fprintf(stderr, "usage: syslogd [-drvxh] [-l hostlist] [-m markinterval] [-n] [-p path]\n" \ |
1178 |
" [-s domainlist] [-f conffile]\n"); |
1182 |
" [-s domainlist] [-f conffile]\n"); |
1179 |
exit(1); |
1183 |
exit(1); |
1180 |
} |
1184 |
} |
Lines 1232-1248
Link Here
|
1232 |
close(fd); |
1236 |
close(fd); |
1233 |
return -1; |
1237 |
return -1; |
1234 |
} |
1238 |
} |
1235 |
if (should_use_so_bsdcompat()) { |
|
|
1236 |
/* We need to enable BSD compatibility. Otherwise an attacker |
1237 |
* could flood our log files by sending us tons of ICMP errors. |
1238 |
*/ |
1239 |
if (setsockopt(fd, SOL_SOCKET, SO_BSDCOMPAT, \ |
1240 |
(char *) &on, sizeof(on)) < 0) { |
1241 |
logerror("setsockopt(BSDCOMPAT), suspending inet"); |
1242 |
close(fd); |
1243 |
return -1; |
1244 |
} |
1245 |
} |
1246 |
if (bind(fd, (struct sockaddr *) &sin, sizeof(sin)) < 0) { |
1239 |
if (bind(fd, (struct sockaddr *) &sin, sizeof(sin)) < 0) { |
1247 |
logerror("bind, suspending inet"); |
1240 |
logerror("bind, suspending inet"); |
1248 |
close(fd); |
1241 |
close(fd); |
Lines 1254-1283
Link Here
|
1254 |
crunch_list(list) |
1249 |
crunch_list(list) |
1255 |
char *list; |
1250 |
char *list; |
1256 |
{ |
1251 |
{ |
1257 |
int count, i; |
1252 |
int i, m, n; |
1258 |
char *p, *q; |
1253 |
char *p, *q; |
1259 |
char **result = NULL; |
1254 |
char **result = NULL; |
1260 |
|
1255 |
|
1261 |
p = list; |
1256 |
p = list; |
1262 |
|
1257 |
|
1263 |
/* strip off trailing delimiters */ |
1258 |
/* strip off trailing delimiters */ |
1264 |
while (p[strlen(p)-1] == LIST_DELIMITER) { |
1259 |
while (*p && p[strlen(p)-1] == LIST_DELIMITER) |
1265 |
count--; |
|
|
1266 |
p[strlen(p)-1] = '\0'; |
1260 |
p[strlen(p)-1] = '\0'; |
1267 |
} |
|
|
1268 |
/* cut off leading delimiters */ |
1261 |
/* cut off leading delimiters */ |
1269 |
while (p[0] == LIST_DELIMITER) { |
1262 |
while (p[0] == LIST_DELIMITER) |
1270 |
count--; |
|
|
1271 |
p++; |
1263 |
p++; |
1272 |
} |
|
|
1273 |
|
1264 |
|
1274 |
/* count delimiters to calculate elements */ |
1265 |
/* count delimiters to calculate the number of elements */ |
1275 |
for (count=i=0; p[i]; i++) |
1266 |
for (n = i = 0; p[i]; i++) |
1276 |
if (p[i] == LIST_DELIMITER) count++; |
1267 |
if (p[i] == LIST_DELIMITER) n++; |
1277 |
|
1268 |
|
1278 |
if ((result = (char **)malloc(sizeof(char *) * count+2)) == NULL) { |
1269 |
if ((result = (char **)malloc(sizeof(char *) * (n + 2))) == NULL) { |
1279 |
printf ("Sorry, can't get enough memory, exiting.\n"); |
1270 |
printf ("Sorry, can't get enough memory, exiting.\n"); |
1280 |
exit(0); |
1271 |
exit(1); |
1281 |
} |
1272 |
} |
1282 |
|
1273 |
|
1283 |
/* |
1274 |
/* |
Lines 1285-1314
Link Here
|
1285 |
* characters are different from any delimiters, |
1276 |
* characters are different from any delimiters, |
1286 |
* so we don't have to care about this. |
1277 |
* so we don't have to care about this. |
1287 |
*/ |
1278 |
*/ |
1288 |
count = 0; |
1279 |
m = 0; |
1289 |
while ((q=strchr(p, LIST_DELIMITER))) { |
1280 |
while ((q = strchr(p, LIST_DELIMITER)) && m < n) { |
1290 |
result[count] = (char *) malloc((q - p + 1) * sizeof(char)); |
1281 |
result[m] = (char *) malloc((q - p + 1) * sizeof(char)); |
1291 |
if (result[count] == NULL) { |
1282 |
if (result[m] == NULL) { |
1292 |
printf ("Sorry, can't get enough memory, exiting.\n"); |
1283 |
printf ("Sorry, can't get enough memory, exiting.\n"); |
1293 |
exit(0); |
1284 |
exit(1); |
1294 |
} |
1285 |
} |
1295 |
strncpy(result[count], p, q - p); |
1286 |
memcpy(result[m], p, q - p); |
1296 |
result[count][q - p] = '\0'; |
1287 |
result[m][q - p] = '\0'; |
1297 |
p = q; p++; |
1288 |
p = q; p++; |
1298 |
count++; |
1289 |
m++; |
1299 |
} |
1290 |
} |
1300 |
if ((result[count] = \ |
1291 |
if ((result[m] = strdup(p)) == NULL) { |
1301 |
(char *)malloc(sizeof(char) * strlen(p) + 1)) == NULL) { |
|
|
1302 |
printf ("Sorry, can't get enough memory, exiting.\n"); |
1292 |
printf ("Sorry, can't get enough memory, exiting.\n"); |
1303 |
exit(0); |
1293 |
exit(1); |
1304 |
} |
1294 |
} |
1305 |
strcpy(result[count],p); |
1295 |
result[++m] = NULL; |
1306 |
result[++count] = NULL; |
|
|
1307 |
|
1296 |
|
1308 |
#if 0 |
1297 |
#if 0 |
1309 |
count=0; |
1298 |
m = 0; |
1310 |
while (result[count]) |
1299 |
while (result[m]) |
1311 |
dprintf ("#%d: %s\n", count, StripDomains[count++]); |
1300 |
dprintf ("#%d: %s\n", m, result[m++]); |
1312 |
#endif |
1301 |
#endif |
1313 |
return result; |
1302 |
return result; |
1314 |
} |
1303 |
} |
Lines 1346-1352
Link Here
|
1346 |
void printchopped(hname, msg, len, fd) |
1335 |
void printchopped(hname, msg, len, fd) |
1347 |
const char *hname; |
1336 |
const char *hname; |
1348 |
char *msg; |
1337 |
char *msg; |
1349 |
int len; |
1338 |
size_t len; |
1350 |
int fd; |
1339 |
int fd; |
1351 |
{ |
1340 |
{ |
1352 |
auto int ptlngth; |
1341 |
auto int ptlngth; |
Lines 1446-1451
Link Here
|
1446 |
while ((c = *p++) && q < &line[sizeof(line) - 4]) { |
1435 |
while ((c = *p++) && q < &line[sizeof(line) - 4]) { |
1447 |
if (c == '\n') |
1436 |
if (c == '\n') |
1448 |
*q++ = ' '; |
1437 |
*q++ = ' '; |
|
|
1438 |
#if 0 |
1449 |
else if (c < 040) { |
1439 |
else if (c < 040) { |
1450 |
*q++ = '^'; |
1440 |
*q++ = '^'; |
1451 |
*q++ = c ^ 0100; |
1441 |
*q++ = c ^ 0100; |
Lines 1454-1460
Link Here
|
1454 |
*q++ = '0' + ((c & 0300) >> 6); |
1444 |
*q++ = '0' + ((c & 0300) >> 6); |
1455 |
*q++ = '0' + ((c & 0070) >> 3); |
1445 |
*q++ = '0' + ((c & 0070) >> 3); |
1456 |
*q++ = '0' + (c & 0007); |
1446 |
*q++ = '0' + (c & 0007); |
1457 |
} else |
1447 |
} |
|
|
1448 |
#endif |
1449 |
else |
1458 |
*q++ = c; |
1450 |
*q++ = c; |
1459 |
} |
1451 |
} |
1460 |
*q = '\0'; |
1452 |
*q = '\0'; |
Lines 1929-1935
Link Here
|
1929 |
/* is this slot used? */ |
1921 |
/* is this slot used? */ |
1930 |
if (ut.ut_name[0] == '\0') |
1922 |
if (ut.ut_name[0] == '\0') |
1931 |
continue; |
1923 |
continue; |
1932 |
if (ut.ut_type == LOGIN_PROCESS) |
1924 |
if (ut.ut_type != USER_PROCESS) |
1933 |
continue; |
1925 |
continue; |
1934 |
if (!(strcmp (ut.ut_name,"LOGIN"))) /* paranoia */ |
1926 |
if (!(strcmp (ut.ut_name,"LOGIN"))) /* paranoia */ |
1935 |
continue; |
1927 |
continue; |
Lines 2013-2019
Link Here
|
2013 |
dprintf("Malformed from address.\n"); |
2005 |
dprintf("Malformed from address.\n"); |
2014 |
return ("???"); |
2006 |
return ("???"); |
2015 |
} |
2007 |
} |
2016 |
hp = gethostbyaddr((char *) &f->sin_addr, sizeof(struct in_addr), \ |
2008 |
if (DisableDNS) |
|
|
2009 |
hp = 0; |
2010 |
else |
2011 |
hp = gethostbyaddr((char *) &f->sin_addr, sizeof(struct in_addr), \ |
2017 |
f->sin_family); |
2012 |
f->sin_family); |
2018 |
if (hp == 0) { |
2013 |
if (hp == 0) { |
2019 |
dprintf("Host name for your address (%s) unknown.\n", |
2014 |
dprintf("Host name for your address (%s) unknown.\n", |