1 |
|
|
/* $OpenBSD: errwarn.c,v 1.23 2016/02/06 19:30:52 krw Exp $ */ |
2 |
|
|
|
3 |
|
|
/* Errors and warnings. */ |
4 |
|
|
|
5 |
|
|
/* |
6 |
|
|
* Copyright (c) 1996 The Internet Software Consortium. |
7 |
|
|
* All Rights Reserved. |
8 |
|
|
* Copyright (c) 1995 RadioMail Corporation. All rights reserved. |
9 |
|
|
* |
10 |
|
|
* Redistribution and use in source and binary forms, with or without |
11 |
|
|
* modification, are permitted provided that the following conditions |
12 |
|
|
* are met: |
13 |
|
|
* |
14 |
|
|
* 1. Redistributions of source code must retain the above copyright |
15 |
|
|
* notice, this list of conditions and the following disclaimer. |
16 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
17 |
|
|
* notice, this list of conditions and the following disclaimer in the |
18 |
|
|
* documentation and/or other materials provided with the distribution. |
19 |
|
|
* 3. Neither the name of RadioMail Corporation, the Internet Software |
20 |
|
|
* Consortium nor the names of its contributors may be used to endorse |
21 |
|
|
* or promote products derived from this software without specific |
22 |
|
|
* prior written permission. |
23 |
|
|
* |
24 |
|
|
* THIS SOFTWARE IS PROVIDED BY RADIOMAIL CORPORATION, THE INTERNET |
25 |
|
|
* SOFTWARE CONSORTIUM AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR |
26 |
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
27 |
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
28 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL RADIOMAIL CORPORATION OR CONTRIBUTORS |
29 |
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
30 |
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
31 |
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
32 |
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
33 |
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
34 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
35 |
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE. |
36 |
|
|
* |
37 |
|
|
* This software was written for RadioMail Corporation by Ted Lemon |
38 |
|
|
* under a contract with Vixie Enterprises. Further modifications have |
39 |
|
|
* been made for the Internet Software Consortium under a contract |
40 |
|
|
* with Vixie Laboratories. |
41 |
|
|
*/ |
42 |
|
|
|
43 |
|
|
#include <sys/queue.h> |
44 |
|
|
#include <sys/socket.h> |
45 |
|
|
|
46 |
|
|
#include <arpa/inet.h> |
47 |
|
|
|
48 |
|
|
#include <net/if.h> |
49 |
|
|
|
50 |
|
|
#include <netinet/in.h> |
51 |
|
|
#include <netinet/if_ether.h> |
52 |
|
|
|
53 |
|
|
#include <signal.h> |
54 |
|
|
#include <stdarg.h> |
55 |
|
|
#include <stdio.h> |
56 |
|
|
#include <stdlib.h> |
57 |
|
|
#include <string.h> |
58 |
|
|
#include <syslog.h> |
59 |
|
|
#include <unistd.h> |
60 |
|
|
|
61 |
|
|
#include "dhcp.h" |
62 |
|
|
#include "dhcpd.h" |
63 |
|
|
|
64 |
|
|
static char mbuf[1024]; |
65 |
|
|
|
66 |
|
|
int warnings_occurred; |
67 |
|
|
|
68 |
|
|
/* |
69 |
|
|
* Log an error message, then exit. |
70 |
|
|
*/ |
71 |
|
|
void |
72 |
|
|
error(char *fmt, ...) |
73 |
|
|
{ |
74 |
|
|
va_list list; |
75 |
|
|
|
76 |
|
|
va_start(list, fmt); |
77 |
|
|
vsnprintf(mbuf, sizeof(mbuf), fmt, list); |
78 |
|
|
va_end(list); |
79 |
|
|
|
80 |
|
|
#ifndef DEBUG |
81 |
|
|
syslog(LOG_ERR, "%s", mbuf); |
82 |
|
|
#endif |
83 |
|
|
|
84 |
|
|
/* Also log it to stderr? */ |
85 |
|
|
if (log_perror) { |
86 |
|
|
write(STDERR_FILENO, mbuf, strlen(mbuf)); |
87 |
|
|
write(STDERR_FILENO, "\n", 1); |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
if (log_perror) { |
91 |
|
|
fflush(stderr); |
92 |
|
|
} |
93 |
|
|
exit(1); |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
/* |
97 |
|
|
* Log a warning message. |
98 |
|
|
*/ |
99 |
|
|
void |
100 |
|
|
warning(char *fmt, ...) |
101 |
|
|
{ |
102 |
|
|
va_list list; |
103 |
|
|
|
104 |
|
|
va_start(list, fmt); |
105 |
|
|
vsnprintf(mbuf, sizeof(mbuf), fmt, list); |
106 |
|
|
va_end(list); |
107 |
|
|
|
108 |
|
|
#ifndef DEBUG |
109 |
|
|
syslog(LOG_ERR, "%s", mbuf); |
110 |
|
|
#endif |
111 |
|
|
|
112 |
|
|
if (log_perror) { |
113 |
|
|
write(STDERR_FILENO, mbuf, strlen(mbuf)); |
114 |
|
|
write(STDERR_FILENO, "\n", 1); |
115 |
|
|
} |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
/* |
119 |
|
|
* Log a note. |
120 |
|
|
*/ |
121 |
|
|
void |
122 |
|
|
note(char *fmt, ...) |
123 |
|
|
{ |
124 |
|
|
va_list list; |
125 |
|
|
|
126 |
|
|
va_start(list, fmt); |
127 |
|
|
vsnprintf(mbuf, sizeof(mbuf), fmt, list); |
128 |
|
|
va_end(list); |
129 |
|
|
|
130 |
|
|
#ifndef DEBUG |
131 |
|
|
syslog(LOG_INFO, "%s", mbuf); |
132 |
|
|
#endif |
133 |
|
|
|
134 |
|
|
if (log_perror) { |
135 |
|
|
write(STDERR_FILENO, mbuf, strlen(mbuf)); |
136 |
|
|
write(STDERR_FILENO, "\n", 1); |
137 |
|
|
} |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
#ifdef DEBUG |
141 |
|
|
/* |
142 |
|
|
* Log a debug message. |
143 |
|
|
*/ |
144 |
|
|
void |
145 |
|
|
debug(char *fmt, ...) |
146 |
|
|
{ |
147 |
|
|
va_list list; |
148 |
|
|
|
149 |
|
|
va_start(list, fmt); |
150 |
|
|
vsnprintf(mbuf, sizeof(mbuf), fmt, list); |
151 |
|
|
va_end(list); |
152 |
|
|
|
153 |
|
|
syslog(LOG_DEBUG, "%s", mbuf); |
154 |
|
|
|
155 |
|
|
if (log_perror) { |
156 |
|
|
write(STDERR_FILENO, mbuf, strlen(mbuf)); |
157 |
|
|
write(STDERR_FILENO, "\n", 1); |
158 |
|
|
} |
159 |
|
|
} |
160 |
|
|
#endif |
161 |
|
|
|
162 |
|
|
void |
163 |
|
|
parse_warn(char *msg) |
164 |
|
|
{ |
165 |
|
|
static char spaces[81]; |
166 |
|
|
struct iovec iov[6]; |
167 |
|
|
size_t iovcnt; |
168 |
|
|
int i; |
169 |
|
|
|
170 |
|
|
snprintf(mbuf, sizeof(mbuf), "%s line %d: %s", tlname, lexline, msg); |
171 |
|
|
|
172 |
|
|
#ifndef DEBUG |
173 |
|
|
syslog(LOG_ERR, "%s", mbuf); |
174 |
|
|
syslog(LOG_ERR, "%s", token_line); |
175 |
|
|
if (lexchar < 81) |
176 |
|
|
syslog(LOG_ERR, "%*c", lexchar, '^'); |
177 |
|
|
#endif |
178 |
|
|
|
179 |
|
|
if (log_perror) { |
180 |
|
|
iov[0].iov_base = mbuf; |
181 |
|
|
iov[0].iov_len = strlen(mbuf); |
182 |
|
|
iov[1].iov_base = "\n"; |
183 |
|
|
iov[1].iov_len = 1; |
184 |
|
|
iov[2].iov_base = token_line; |
185 |
|
|
iov[2].iov_len = strlen(token_line); |
186 |
|
|
iov[3].iov_base = "\n"; |
187 |
|
|
iov[3].iov_len = 1; |
188 |
|
|
iovcnt = 4; |
189 |
|
|
if (lexchar < 81) { |
190 |
|
|
for (i = 0; i < lexchar; i++) { |
191 |
|
|
if (token_line[i] == '\t') |
192 |
|
|
spaces[i] = '\t'; |
193 |
|
|
else |
194 |
|
|
spaces[i] = ' '; |
195 |
|
|
} |
196 |
|
|
iov[4].iov_base = spaces; |
197 |
|
|
iov[4].iov_len = lexchar - 1; |
198 |
|
|
iov[5].iov_base = "^\n"; |
199 |
|
|
iov[5].iov_len = 2; |
200 |
|
|
iovcnt += 2; |
201 |
|
|
} |
202 |
|
|
writev(STDERR_FILENO, iov, iovcnt); |
203 |
|
|
} |
204 |
|
|
warnings_occurred = 1; |
205 |
|
|
} |