syslogd.c (fe291141486acf27ed1c8eed791ba9897f84c3f0) | syslogd.c (8cc248fb92bfae1e6ef4e2b48a0064377c4b3c11) |
---|---|
1/*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 1983, 1988, 1993, 1994 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 180 unchanged lines hidden (view full) --- 189#define SYNC_FILE 0x002 /* do fsync on file after printing */ 190#define MARK 0x008 /* this message is a mark */ 191#define ISKERNEL 0x010 /* kernel generated message */ 192 193/* Traditional syslog timestamp format. */ 194#define RFC3164_DATELEN 15 195#define RFC3164_DATEFMT "%b %e %H:%M:%S" 196 | 1/*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 1983, 1988, 1993, 1994 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 180 unchanged lines hidden (view full) --- 189#define SYNC_FILE 0x002 /* do fsync on file after printing */ 190#define MARK 0x008 /* this message is a mark */ 191#define ISKERNEL 0x010 /* kernel generated message */ 192 193/* Traditional syslog timestamp format. */ 194#define RFC3164_DATELEN 15 195#define RFC3164_DATEFMT "%b %e %H:%M:%S" 196 |
197/* 198 * FORMAT_BSD_LEGACY and FORMAT_RFC3164_STRICT are two variations of 199 * the RFC 3164 logging format. 200 */ 201#define IS_RFC3164_FORMAT (output_format == FORMAT_BSD_LEGACY || \ 202output_format == FORMAT_RFC3164_STRICT) 203 |
|
197static STAILQ_HEAD(, filed) fhead = 198 STAILQ_HEAD_INITIALIZER(fhead); /* Log files that we write to */ 199static struct filed consfile; /* Console */ 200 201/* 202 * Queue of about-to-be dead processes we should watch out for. 203 */ 204struct deadq_entry { --- 105 unchanged lines hidden (view full) --- 310static bool RemoteHostname; /* Log remote hostname from the message */ 311 312static bool UniquePriority; /* Only log specified priority? */ 313static int LogFacPri; /* Put facility and priority in log message: */ 314 /* 0=no, 1=numeric, 2=names */ 315static bool KeepKernFac; /* Keep remotely logged kernel facility */ 316static bool needdofsync = true; /* Are any file(s) waiting to be fsynced? */ 317static struct pidfh *pfh; | 204static STAILQ_HEAD(, filed) fhead = 205 STAILQ_HEAD_INITIALIZER(fhead); /* Log files that we write to */ 206static struct filed consfile; /* Console */ 207 208/* 209 * Queue of about-to-be dead processes we should watch out for. 210 */ 211struct deadq_entry { --- 105 unchanged lines hidden (view full) --- 317static bool RemoteHostname; /* Log remote hostname from the message */ 318 319static bool UniquePriority; /* Only log specified priority? */ 320static int LogFacPri; /* Put facility and priority in log message: */ 321 /* 0=no, 1=numeric, 2=names */ 322static bool KeepKernFac; /* Keep remotely logged kernel facility */ 323static bool needdofsync = true; /* Are any file(s) waiting to be fsynced? */ 324static struct pidfh *pfh; |
318static bool RFC3164OutputFormat = true; /* Use legacy format by default. */ | 325static enum { 326 FORMAT_BSD_LEGACY, /* default, RFC 3164 with legacy deviations */ 327 FORMAT_RFC3164_STRICT, /* compliant to RFC 3164 recommendataions */ 328 FORMAT_RFC5424, /* RFC 5424 format */ 329} output_format = FORMAT_BSD_LEGACY; |
319static int kq; /* kqueue(2) descriptor. */ 320 321struct iovlist; 322 323static bool allowaddr(char *); 324static void addpeer(const char *, const char *, mode_t); 325static void addsock(const char *, const char *, mode_t); 326static nvlist_t *cfline(const char *, const char *, const char *, const char *); --- 303 unchanged lines hidden (view full) --- 630 SecureMode = 1; 631 break; 632 case 'n': 633 resolve = false; 634 break; 635 case 'O': 636 if (strcmp(optarg, "bsd") == 0 || 637 strcmp(optarg, "rfc3164") == 0) | 330static int kq; /* kqueue(2) descriptor. */ 331 332struct iovlist; 333 334static bool allowaddr(char *); 335static void addpeer(const char *, const char *, mode_t); 336static void addsock(const char *, const char *, mode_t); 337static nvlist_t *cfline(const char *, const char *, const char *, const char *); --- 303 unchanged lines hidden (view full) --- 641 SecureMode = 1; 642 break; 643 case 'n': 644 resolve = false; 645 break; 646 case 'O': 647 if (strcmp(optarg, "bsd") == 0 || 648 strcmp(optarg, "rfc3164") == 0) |
638 RFC3164OutputFormat = true; | 649 output_format = FORMAT_BSD_LEGACY; 650 else if (strcmp(optarg, "rfc3164-strict") == 0) 651 output_format = FORMAT_RFC3164_STRICT; |
639 else if (strcmp(optarg, "syslog") == 0 || 640 strcmp(optarg, "rfc5424") == 0) | 652 else if (strcmp(optarg, "syslog") == 0 || 653 strcmp(optarg, "rfc5424") == 0) |
641 RFC3164OutputFormat = false; | 654 output_format = FORMAT_RFC5424; |
642 else 643 usage(); 644 break; 645 case 'o': 646 use_bootfile = true; 647 break; 648 case 'P': /* path for alt. PID */ 649 PidFile = optarg; --- 11 unchanged lines hidden (view full) --- 661 LogFacPri++; 662 break; 663 default: 664 usage(); 665 } 666 if ((argc -= optind) != 0) 667 usage(); 668 | 655 else 656 usage(); 657 break; 658 case 'o': 659 use_bootfile = true; 660 break; 661 case 'P': /* path for alt. PID */ 662 PidFile = optarg; --- 11 unchanged lines hidden (view full) --- 674 LogFacPri++; 675 break; 676 default: 677 usage(); 678 } 679 if ((argc -= optind) != 0) 680 usage(); 681 |
669 if (RFC3164OutputFormat && MaxForwardLen > 1024) | 682 if (IS_RFC3164_FORMAT && MaxForwardLen > 1024) |
670 errx(1, "RFC 3164 messages may not exceed 1024 bytes"); 671 672 pfh = pidfile_open(PidFile, 0600, &spid); 673 if (pfh == NULL) { 674 if (errno == EEXIST) 675 errx(1, "syslogd already running, pid: %d", spid); 676 warn("cannot open pid file"); 677 } --- 1310 unchanged lines hidden (view full) --- 1988 case F_FORW: 1989 /* Message forwarded over the network. */ 1990 iovlist_append(&il, "<"); 1991 snprintf(priority_number, sizeof(priority_number), "%d", 1992 f->f_prevpri); 1993 iovlist_append(&il, priority_number); 1994 iovlist_append(&il, ">"); 1995 iovlist_append(&il, timebuf); | 683 errx(1, "RFC 3164 messages may not exceed 1024 bytes"); 684 685 pfh = pidfile_open(PidFile, 0600, &spid); 686 if (pfh == NULL) { 687 if (errno == EEXIST) 688 errx(1, "syslogd already running, pid: %d", spid); 689 warn("cannot open pid file"); 690 } --- 1310 unchanged lines hidden (view full) --- 2001 case F_FORW: 2002 /* Message forwarded over the network. */ 2003 iovlist_append(&il, "<"); 2004 snprintf(priority_number, sizeof(priority_number), "%d", 2005 f->f_prevpri); 2006 iovlist_append(&il, priority_number); 2007 iovlist_append(&il, ">"); 2008 iovlist_append(&il, timebuf); |
1996 if (strcasecmp(hostname, LocalHostName) != 0) { | 2009 if (output_format == FORMAT_RFC3164_STRICT) { 2010 iovlist_append(&il, " "); 2011 iovlist_append(&il, hostname); 2012 } else if (strcasecmp(hostname, LocalHostName) != 0) { |
1997 iovlist_append(&il, " Forwarded from "); 1998 iovlist_append(&il, hostname); 1999 iovlist_append(&il, ":"); 2000 } 2001 iovlist_append(&il, " "); 2002 break; 2003 2004 case F_WALL: --- 82 unchanged lines hidden (view full) --- 2087 dprintf("Logging to %s", TypeNames[f->f_type]); 2088 f->f_time = now; 2089 f->f_prevcount = 0; 2090 if (f->f_type == F_UNUSED) { 2091 dprintf("\n"); 2092 return; 2093 } 2094 | 2013 iovlist_append(&il, " Forwarded from "); 2014 iovlist_append(&il, hostname); 2015 iovlist_append(&il, ":"); 2016 } 2017 iovlist_append(&il, " "); 2018 break; 2019 2020 case F_WALL: --- 82 unchanged lines hidden (view full) --- 2103 dprintf("Logging to %s", TypeNames[f->f_type]); 2104 f->f_time = now; 2105 f->f_prevcount = 0; 2106 if (f->f_type == F_UNUSED) { 2107 dprintf("\n"); 2108 return; 2109 } 2110 |
2095 if (RFC3164OutputFormat) | 2111 if (IS_RFC3164_FORMAT) |
2096 fprintlog_rfc3164(f, hostname, app_name, procid, msg, flags); 2097 else 2098 fprintlog_rfc5424(f, hostname, app_name, procid, msgid, 2099 structured_data, msg, flags); 2100} 2101 2102/* 2103 * Prints a message to a log file that the previously logged message was --- 106 unchanged lines hidden (view full) --- 2210 if (error) { 2211 dprintf("Host name for your address (%s) unknown\n", ip); 2212 return (ip); 2213 } 2214 hl = strlen(hname); 2215 if (hl > 0 && hname[hl-1] == '.') 2216 hname[--hl] = '\0'; 2217 /* RFC 5424 prefers logging FQDNs. */ | 2112 fprintlog_rfc3164(f, hostname, app_name, procid, msg, flags); 2113 else 2114 fprintlog_rfc5424(f, hostname, app_name, procid, msgid, 2115 structured_data, msg, flags); 2116} 2117 2118/* 2119 * Prints a message to a log file that the previously logged message was --- 106 unchanged lines hidden (view full) --- 2226 if (error) { 2227 dprintf("Host name for your address (%s) unknown\n", ip); 2228 return (ip); 2229 } 2230 hl = strlen(hname); 2231 if (hl > 0 && hname[hl-1] == '.') 2232 hname[--hl] = '\0'; 2233 /* RFC 5424 prefers logging FQDNs. */ |
2218 if (RFC3164OutputFormat) | 2234 if (IS_RFC3164_FORMAT) |
2219 trimdomain(hname, hl); 2220 return (hname); 2221} 2222 2223/* 2224 * Print syslogd errors some place. 2225 */ 2226void --- 367 unchanged lines hidden (view full) --- 2594 */ 2595 if (reload) 2596 (void)strlcpy(oldLocalHostName, LocalHostName, 2597 sizeof(oldLocalHostName)); 2598 if (gethostname(LocalHostName, sizeof(LocalHostName))) 2599 err(EX_OSERR, "gethostname() failed"); 2600 if ((p = strchr(LocalHostName, '.')) != NULL) { 2601 /* RFC 5424 prefers logging FQDNs. */ | 2235 trimdomain(hname, hl); 2236 return (hname); 2237} 2238 2239/* 2240 * Print syslogd errors some place. 2241 */ 2242void --- 367 unchanged lines hidden (view full) --- 2610 */ 2611 if (reload) 2612 (void)strlcpy(oldLocalHostName, LocalHostName, 2613 sizeof(oldLocalHostName)); 2614 if (gethostname(LocalHostName, sizeof(LocalHostName))) 2615 err(EX_OSERR, "gethostname() failed"); 2616 if ((p = strchr(LocalHostName, '.')) != NULL) { 2617 /* RFC 5424 prefers logging FQDNs. */ |
2602 if (RFC3164OutputFormat) | 2618 if (IS_RFC3164_FORMAT) |
2603 *p = '\0'; 2604 LocalDomain = p + 1; 2605 } else { 2606 LocalDomain = ""; 2607 } 2608 2609#ifndef WITH_CASPER 2610 /* --- 518 unchanged lines hidden (view full) --- 3129 if (host != NULL && *host != '*') { 3130 int hl; 3131 3132 strlcpy(f.f_host, host, sizeof(f.f_host)); 3133 hl = strlen(f.f_host); 3134 if (hl > 0 && f.f_host[hl-1] == '.') 3135 f.f_host[--hl] = '\0'; 3136 /* RFC 5424 prefers logging FQDNs. */ | 2619 *p = '\0'; 2620 LocalDomain = p + 1; 2621 } else { 2622 LocalDomain = ""; 2623 } 2624 2625#ifndef WITH_CASPER 2626 /* --- 518 unchanged lines hidden (view full) --- 3145 if (host != NULL && *host != '*') { 3146 int hl; 3147 3148 strlcpy(f.f_host, host, sizeof(f.f_host)); 3149 hl = strlen(f.f_host); 3150 if (hl > 0 && f.f_host[hl-1] == '.') 3151 f.f_host[--hl] = '\0'; 3152 /* RFC 5424 prefers logging FQDNs. */ |
3137 if (RFC3164OutputFormat) | 3153 if (IS_RFC3164_FORMAT) |
3138 trimdomain(f.f_host, hl); 3139 } 3140 3141 /* save program name if any */ 3142 if (prog != NULL && *prog != '*') 3143 strlcpy(f.f_program, prog, sizeof(f.f_program)); 3144 3145 /* scan through the list of selectors */ --- 687 unchanged lines hidden --- | 3154 trimdomain(f.f_host, hl); 3155 } 3156 3157 /* save program name if any */ 3158 if (prog != NULL && *prog != '*') 3159 strlcpy(f.f_program, prog, sizeof(f.f_program)); 3160 3161 /* scan through the list of selectors */ --- 687 unchanged lines hidden --- |