Merge lp:~s-launchpad-paulsd-com/rsyslog/trusty-proposed into lp:ubuntu/trusty-proposed/rsyslog
- trusty-proposed
- Merge into trusty-proposed
Proposed by
Paul Donohue
Status: | Needs review |
---|---|
Proposed branch: | lp:~s-launchpad-paulsd-com/rsyslog/trusty-proposed |
Merge into: | lp:ubuntu/trusty-proposed/rsyslog |
Diff against target: |
1631 lines (+1432/-29) 13 files modified
.pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/bsd.c (+298/-0) .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/imklog.c (+488/-0) .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/imklog.h (+70/-0) .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imkmsg/imkmsg.c (+295/-0) .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imkmsg/imkmsg.h (+64/-0) debian/changelog (+7/-0) debian/patches/11-fix-infinite-loop-openvz-vms.patch (+157/-15) plugins/imklog/bsd.c (+25/-2) plugins/imklog/imklog.c (+2/-1) plugins/imklog/imklog.h (+2/-1) plugins/imkmsg/imkmsg.c (+2/-1) plugins/imkmsg/imkmsg.h (+2/-1) plugins/imkmsg/kmsg.c (+20/-8) |
To merge this branch: | bzr merge lp:~s-launchpad-paulsd-com/rsyslog/trusty-proposed |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Brian Murray | Pending | ||
Review via email: mp+245974@code.launchpad.net |
Commit message
Description of the change
Updated fix for infinite loop on OpenVZ VMs (LP: #1366829)
To post a comment you must log in.
Unmerged revisions
- 60. By Paul Donohue
-
Applied updated upstream patch fixing infinite loop on OpenVZ VMs.
(LP: #1366829)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory '.pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog' | |||
2 | === added file '.pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/bsd.c' | |||
3 | --- .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/bsd.c 1970-01-01 00:00:00 +0000 | |||
4 | +++ .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/bsd.c 2015-01-09 16:11:08 +0000 | |||
5 | @@ -0,0 +1,298 @@ | |||
6 | 1 | /* combined imklog driver for BSD and Linux | ||
7 | 2 | * | ||
8 | 3 | * This contains OS-specific functionality to read the BSD | ||
9 | 4 | * or Linux kernel log. For a general overview, see head comment in | ||
10 | 5 | * imklog.c. This started out as the BSD-specific drivers, but it | ||
11 | 6 | * turned out that on modern Linux the implementation details | ||
12 | 7 | * are very small, and so we use a single driver for both OS's with | ||
13 | 8 | * a little help of conditional compilation. | ||
14 | 9 | * | ||
15 | 10 | * Copyright 2008-2012 Adiscon GmbH | ||
16 | 11 | * | ||
17 | 12 | * This file is part of rsyslog. | ||
18 | 13 | * | ||
19 | 14 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
20 | 15 | * you may not use this file except in compliance with the License. | ||
21 | 16 | * You may obtain a copy of the License at | ||
22 | 17 | * | ||
23 | 18 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
24 | 19 | * -or- | ||
25 | 20 | * see COPYING.ASL20 in the source distribution | ||
26 | 21 | * | ||
27 | 22 | * Unless required by applicable law or agreed to in writing, software | ||
28 | 23 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
29 | 24 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
30 | 25 | * See the License for the specific language governing permissions and | ||
31 | 26 | * limitations under the License. | ||
32 | 27 | */ | ||
33 | 28 | #ifdef HAVE_CONFIG_H | ||
34 | 29 | # include "config.h" | ||
35 | 30 | #endif | ||
36 | 31 | #include <stdlib.h> | ||
37 | 32 | #include <unistd.h> | ||
38 | 33 | #include <fcntl.h> | ||
39 | 34 | #include <errno.h> | ||
40 | 35 | #include <string.h> | ||
41 | 36 | #include <ctype.h> | ||
42 | 37 | #ifdef OS_LINUX | ||
43 | 38 | # include <sys/klog.h> | ||
44 | 39 | #endif | ||
45 | 40 | |||
46 | 41 | #include "rsyslog.h" | ||
47 | 42 | #include "srUtils.h" | ||
48 | 43 | #include "debug.h" | ||
49 | 44 | #include "imklog.h" | ||
50 | 45 | |||
51 | 46 | /* globals */ | ||
52 | 47 | static int fklog = -1; /* kernel log fd */ | ||
53 | 48 | |||
54 | 49 | #ifndef _PATH_KLOG | ||
55 | 50 | # ifdef OS_LINUX | ||
56 | 51 | # define _PATH_KLOG "/proc/kmsg" | ||
57 | 52 | # else | ||
58 | 53 | # define _PATH_KLOG "/dev/klog" | ||
59 | 54 | # endif | ||
60 | 55 | #endif | ||
61 | 56 | |||
62 | 57 | |||
63 | 58 | #ifdef OS_LINUX | ||
64 | 59 | /* submit a message to imklog Syslog() API. In this function, we check if | ||
65 | 60 | * a kernel timestamp is present and, if so, extract and strip it. | ||
66 | 61 | * Note that this is heavily Linux specific and thus is not compiled or | ||
67 | 62 | * used for BSD. | ||
68 | 63 | * Special thanks to Lennart Poettering for suggesting on how to convert | ||
69 | 64 | * the kernel timestamp to a realtime timestamp. This method depends on | ||
70 | 65 | * the fact the the kernel timestamp is written using the monotonic clock. | ||
71 | 66 | * Shall that change (very unlikely), this code must be changed as well. Note | ||
72 | 67 | * that due to the way we generate the delta, we are unable to write the | ||
73 | 68 | * absolutely correct timestamp (system call overhead of the clock calls | ||
74 | 69 | * prevents us from doing so). However, the difference is very minor. | ||
75 | 70 | * rgerhards, 2011-06-24 | ||
76 | 71 | */ | ||
77 | 72 | static void | ||
78 | 73 | submitSyslog(modConfData_t *pModConf, int pri, uchar *buf) | ||
79 | 74 | { | ||
80 | 75 | long secs; | ||
81 | 76 | long usecs; | ||
82 | 77 | long secOffs; | ||
83 | 78 | long usecOffs; | ||
84 | 79 | unsigned i; | ||
85 | 80 | unsigned bufsize; | ||
86 | 81 | struct timespec monotonic, realtime; | ||
87 | 82 | struct timeval tv; | ||
88 | 83 | struct timeval *tp = NULL; | ||
89 | 84 | |||
90 | 85 | if(!pModConf->bParseKernelStamp) | ||
91 | 86 | goto done; | ||
92 | 87 | |||
93 | 88 | if(buf[3] != '[') | ||
94 | 89 | goto done; | ||
95 | 90 | DBGPRINTF("imklog: kernel timestamp detected, extracting it\n"); | ||
96 | 91 | |||
97 | 92 | /* we now try to parse the timestamp. iff it parses, we assume | ||
98 | 93 | * it is a timestamp. Otherwise we know for sure it is no ts ;) | ||
99 | 94 | */ | ||
100 | 95 | i = 4; /* space or first digit after '[' */ | ||
101 | 96 | while(buf[i] && isspace(buf[i])) | ||
102 | 97 | ++i; /* skip space */ | ||
103 | 98 | secs = 0; | ||
104 | 99 | while(buf[i] && isdigit(buf[i])) { | ||
105 | 100 | secs = secs * 10 + buf[i] - '0'; | ||
106 | 101 | ++i; | ||
107 | 102 | } | ||
108 | 103 | if(buf[i] != '.') { | ||
109 | 104 | DBGPRINTF("no dot --> no kernel timestamp\n"); | ||
110 | 105 | goto done; /* no TS! */ | ||
111 | 106 | } | ||
112 | 107 | |||
113 | 108 | ++i; /* skip dot */ | ||
114 | 109 | usecs = 0; | ||
115 | 110 | while(buf[i] && isdigit(buf[i])) { | ||
116 | 111 | usecs = usecs * 10 + buf[i] - '0'; | ||
117 | 112 | ++i; | ||
118 | 113 | } | ||
119 | 114 | if(buf[i] != ']') { | ||
120 | 115 | DBGPRINTF("no trailing ']' --> no kernel timestamp\n"); | ||
121 | 116 | goto done; /* no TS! */ | ||
122 | 117 | } | ||
123 | 118 | ++i; /* skip ']' */ | ||
124 | 119 | |||
125 | 120 | /* we have a timestamp */ | ||
126 | 121 | DBGPRINTF("kernel timestamp is %ld %ld\n", secs, usecs); | ||
127 | 122 | if(!pModConf->bKeepKernelStamp) { | ||
128 | 123 | bufsize= strlen((char*)buf); | ||
129 | 124 | memmove(buf+3, buf+i, bufsize - i + 1); | ||
130 | 125 | } | ||
131 | 126 | |||
132 | 127 | clock_gettime(CLOCK_MONOTONIC, &monotonic); | ||
133 | 128 | clock_gettime(CLOCK_REALTIME, &realtime); | ||
134 | 129 | secOffs = realtime.tv_sec - monotonic.tv_sec; | ||
135 | 130 | usecOffs = (realtime.tv_nsec - monotonic.tv_nsec) / 1000; | ||
136 | 131 | if(usecOffs < 0) { | ||
137 | 132 | secOffs--; | ||
138 | 133 | usecOffs += 1000000l; | ||
139 | 134 | } | ||
140 | 135 | |||
141 | 136 | usecs += usecOffs; | ||
142 | 137 | if(usecs > 999999l) { | ||
143 | 138 | secs++; | ||
144 | 139 | usecs -= 1000000l; | ||
145 | 140 | } | ||
146 | 141 | secs += secOffs; | ||
147 | 142 | tv.tv_sec = secs; | ||
148 | 143 | tv.tv_usec = usecs; | ||
149 | 144 | tp = &tv; | ||
150 | 145 | |||
151 | 146 | done: | ||
152 | 147 | Syslog(pri, buf, tp); | ||
153 | 148 | } | ||
154 | 149 | #else /* now comes the BSD "code" (just a shim) */ | ||
155 | 150 | static void | ||
156 | 151 | submitSyslog(modConfData_t *pModConf, int pri, uchar *buf) | ||
157 | 152 | { | ||
158 | 153 | Syslog(pri, buf, NULL); | ||
159 | 154 | } | ||
160 | 155 | #endif /* #ifdef LINUX */ | ||
161 | 156 | |||
162 | 157 | |||
163 | 158 | static uchar *GetPath(modConfData_t *pModConf) | ||
164 | 159 | { | ||
165 | 160 | return pModConf->pszPath ? pModConf->pszPath : (uchar*) _PATH_KLOG; | ||
166 | 161 | } | ||
167 | 162 | |||
168 | 163 | /* open the kernel log - will be called inside the willRun() imklog | ||
169 | 164 | * entry point. -- rgerhards, 2008-04-09 | ||
170 | 165 | */ | ||
171 | 166 | rsRetVal | ||
172 | 167 | klogWillRun(modConfData_t *pModConf) | ||
173 | 168 | { | ||
174 | 169 | char errmsg[2048]; | ||
175 | 170 | int r; | ||
176 | 171 | DEFiRet; | ||
177 | 172 | |||
178 | 173 | fklog = open((char*)GetPath(pModConf), O_RDONLY, 0); | ||
179 | 174 | if (fklog < 0) { | ||
180 | 175 | imklogLogIntMsg(LOG_ERR, "imklog: cannot open kernel log(%s): %s.", | ||
181 | 176 | GetPath(pModConf), rs_strerror_r(errno, errmsg, sizeof(errmsg))); | ||
182 | 177 | ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG); | ||
183 | 178 | } | ||
184 | 179 | |||
185 | 180 | # ifdef OS_LINUX | ||
186 | 181 | /* Set level of kernel console messaging.. */ | ||
187 | 182 | if(pModConf->console_log_level != -1) { | ||
188 | 183 | r = klogctl(8, NULL, pModConf->console_log_level); | ||
189 | 184 | if(r != 0) { | ||
190 | 185 | imklogLogIntMsg(LOG_WARNING, "imklog: cannot set console log level: %s", | ||
191 | 186 | rs_strerror_r(errno, errmsg, sizeof(errmsg))); | ||
192 | 187 | /* make sure we do not try to re-set! */ | ||
193 | 188 | pModConf->console_log_level = -1; | ||
194 | 189 | } | ||
195 | 190 | } | ||
196 | 191 | # endif /* #ifdef OS_LINUX */ | ||
197 | 192 | |||
198 | 193 | finalize_it: | ||
199 | 194 | RETiRet; | ||
200 | 195 | } | ||
201 | 196 | |||
202 | 197 | |||
203 | 198 | /* Read kernel log while data are available, split into lines. | ||
204 | 199 | */ | ||
205 | 200 | static void | ||
206 | 201 | readklog(modConfData_t *pModConf) | ||
207 | 202 | { | ||
208 | 203 | char *p, *q; | ||
209 | 204 | int len, i; | ||
210 | 205 | int iMaxLine; | ||
211 | 206 | uchar bufRcv[128*1024+1]; | ||
212 | 207 | char errmsg[2048]; | ||
213 | 208 | uchar *pRcv = NULL; /* receive buffer */ | ||
214 | 209 | |||
215 | 210 | iMaxLine = klog_getMaxLine(); | ||
216 | 211 | |||
217 | 212 | /* we optimize performance: if iMaxLine is below our fixed size buffer (which | ||
218 | 213 | * usually is sufficiently large), we use this buffer. if it is higher, heap memory | ||
219 | 214 | * is used. We could use alloca() to achive a similar aspect, but there are so | ||
220 | 215 | * many issues with alloca() that I do not want to take that route. | ||
221 | 216 | * rgerhards, 2008-09-02 | ||
222 | 217 | */ | ||
223 | 218 | if((size_t) iMaxLine < sizeof(bufRcv) - 1) { | ||
224 | 219 | pRcv = bufRcv; | ||
225 | 220 | } else { | ||
226 | 221 | if((pRcv = (uchar*) MALLOC(sizeof(uchar) * (iMaxLine + 1))) == NULL) | ||
227 | 222 | iMaxLine = sizeof(bufRcv) - 1; /* better this than noting */ | ||
228 | 223 | } | ||
229 | 224 | |||
230 | 225 | len = 0; | ||
231 | 226 | for (;;) { | ||
232 | 227 | dbgprintf("imklog(BSD/Linux) waiting for kernel log line\n"); | ||
233 | 228 | i = read(fklog, pRcv + len, iMaxLine - len); | ||
234 | 229 | if (i > 0) { | ||
235 | 230 | pRcv[i + len] = '\0'; | ||
236 | 231 | } else { | ||
237 | 232 | if (i < 0 && errno != EINTR && errno != EAGAIN) { | ||
238 | 233 | imklogLogIntMsg(LOG_ERR, | ||
239 | 234 | "imklog: error reading kernel log - shutting down: %s", | ||
240 | 235 | rs_strerror_r(errno, errmsg, sizeof(errmsg))); | ||
241 | 236 | fklog = -1; | ||
242 | 237 | } | ||
243 | 238 | break; | ||
244 | 239 | } | ||
245 | 240 | |||
246 | 241 | for (p = (char*)pRcv; (q = strchr(p, '\n')) != NULL; p = q + 1) { | ||
247 | 242 | *q = '\0'; | ||
248 | 243 | submitSyslog(pModConf, LOG_INFO, (uchar*) p); | ||
249 | 244 | } | ||
250 | 245 | len = strlen(p); | ||
251 | 246 | if (len >= iMaxLine - 1) { | ||
252 | 247 | submitSyslog(pModConf, LOG_INFO, (uchar*)p); | ||
253 | 248 | len = 0; | ||
254 | 249 | } | ||
255 | 250 | if(len > 0) | ||
256 | 251 | memmove(pRcv, p, len + 1); | ||
257 | 252 | } | ||
258 | 253 | if (len > 0) | ||
259 | 254 | submitSyslog(pModConf, LOG_INFO, pRcv); | ||
260 | 255 | |||
261 | 256 | if(pRcv != NULL && (size_t) iMaxLine >= sizeof(bufRcv) - 1) | ||
262 | 257 | free(pRcv); | ||
263 | 258 | } | ||
264 | 259 | |||
265 | 260 | |||
266 | 261 | /* to be called in the module's AfterRun entry point | ||
267 | 262 | * rgerhards, 2008-04-09 | ||
268 | 263 | */ | ||
269 | 264 | rsRetVal klogAfterRun(modConfData_t *pModConf) | ||
270 | 265 | { | ||
271 | 266 | DEFiRet; | ||
272 | 267 | if(fklog != -1) | ||
273 | 268 | close(fklog); | ||
274 | 269 | # ifdef OS_LINUX | ||
275 | 270 | /* Turn on logging of messages to console, but only if a log level was speficied */ | ||
276 | 271 | if(pModConf->console_log_level != -1) | ||
277 | 272 | klogctl(7, NULL, 0); | ||
278 | 273 | # endif | ||
279 | 274 | RETiRet; | ||
280 | 275 | } | ||
281 | 276 | |||
282 | 277 | |||
283 | 278 | |||
284 | 279 | /* to be called in the module's WillRun entry point, this is the main | ||
285 | 280 | * "message pull" mechanism. | ||
286 | 281 | * rgerhards, 2008-04-09 | ||
287 | 282 | */ | ||
288 | 283 | rsRetVal klogLogKMsg(modConfData_t *pModConf) | ||
289 | 284 | { | ||
290 | 285 | DEFiRet; | ||
291 | 286 | readklog(pModConf); | ||
292 | 287 | RETiRet; | ||
293 | 288 | } | ||
294 | 289 | |||
295 | 290 | |||
296 | 291 | /* provide the (system-specific) default facility for internal messages | ||
297 | 292 | * rgerhards, 2008-04-14 | ||
298 | 293 | */ | ||
299 | 294 | int | ||
300 | 295 | klogFacilIntMsg(void) | ||
301 | 296 | { | ||
302 | 297 | return LOG_SYSLOG; | ||
303 | 298 | } | ||
304 | 0 | 299 | ||
305 | === added file '.pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/imklog.c' | |||
306 | --- .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/imklog.c 1970-01-01 00:00:00 +0000 | |||
307 | +++ .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/imklog.c 2015-01-09 16:11:08 +0000 | |||
308 | @@ -0,0 +1,488 @@ | |||
309 | 1 | /* The kernel log module. | ||
310 | 2 | * | ||
311 | 3 | * This is an abstracted module. As Linux and BSD kernel log is conceptually the | ||
312 | 4 | * same, we do not do different input plugins for them but use | ||
313 | 5 | * imklog in both cases, just with different "backend drivers" for | ||
314 | 6 | * the different platforms. This also enables a rsyslog.conf to | ||
315 | 7 | * be used on multiple platforms without the need to take care of | ||
316 | 8 | * what the kernel log is coming from. | ||
317 | 9 | * | ||
318 | 10 | * See platform-specific files (e.g. linux.c, bsd.c) in the plugin's | ||
319 | 11 | * working directory. For other systems with similar kernel logging | ||
320 | 12 | * functionality, no new input plugin shall be written but rather a | ||
321 | 13 | * driver be developed for imklog. Please note that imklog itself is | ||
322 | 14 | * mostly concerned with handling the interface. Any real action happens | ||
323 | 15 | * in the drivers, as things may be pretty different on different | ||
324 | 16 | * platforms. | ||
325 | 17 | * | ||
326 | 18 | * Please note that this file replaces the klogd daemon that was | ||
327 | 19 | * also present in pre-v3 versions of rsyslog. | ||
328 | 20 | * | ||
329 | 21 | * To test under Linux: | ||
330 | 22 | * echo test1 > /dev/kmsg | ||
331 | 23 | * | ||
332 | 24 | * Copyright (C) 2008-2014 Adiscon GmbH | ||
333 | 25 | * | ||
334 | 26 | * This file is part of rsyslog. | ||
335 | 27 | * | ||
336 | 28 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
337 | 29 | * you may not use this file except in compliance with the License. | ||
338 | 30 | * You may obtain a copy of the License at | ||
339 | 31 | * | ||
340 | 32 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
341 | 33 | * -or- | ||
342 | 34 | * see COPYING.ASL20 in the source distribution | ||
343 | 35 | * | ||
344 | 36 | * Unless required by applicable law or agreed to in writing, software | ||
345 | 37 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
346 | 38 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
347 | 39 | * See the License for the specific language governing permissions and | ||
348 | 40 | * limitations under the License. | ||
349 | 41 | */ | ||
350 | 42 | #include "config.h" | ||
351 | 43 | #include "rsyslog.h" | ||
352 | 44 | #include <stdio.h> | ||
353 | 45 | #include <assert.h> | ||
354 | 46 | #include <string.h> | ||
355 | 47 | #include <stdarg.h> | ||
356 | 48 | #include <ctype.h> | ||
357 | 49 | #include <stdlib.h> | ||
358 | 50 | #include <sys/socket.h> | ||
359 | 51 | |||
360 | 52 | #include "dirty.h" | ||
361 | 53 | #include "cfsysline.h" | ||
362 | 54 | #include "obj.h" | ||
363 | 55 | #include "msg.h" | ||
364 | 56 | #include "module-template.h" | ||
365 | 57 | #include "datetime.h" | ||
366 | 58 | #include "imklog.h" | ||
367 | 59 | #include "net.h" | ||
368 | 60 | #include "glbl.h" | ||
369 | 61 | #include "prop.h" | ||
370 | 62 | #include "errmsg.h" | ||
371 | 63 | #include "unicode-helper.h" | ||
372 | 64 | |||
373 | 65 | MODULE_TYPE_INPUT | ||
374 | 66 | MODULE_TYPE_NOKEEP | ||
375 | 67 | MODULE_CNFNAME("imklog") | ||
376 | 68 | |||
377 | 69 | /* Module static data */ | ||
378 | 70 | DEF_IMOD_STATIC_DATA | ||
379 | 71 | DEFobjCurrIf(datetime) | ||
380 | 72 | DEFobjCurrIf(glbl) | ||
381 | 73 | DEFobjCurrIf(prop) | ||
382 | 74 | DEFobjCurrIf(net) | ||
383 | 75 | DEFobjCurrIf(errmsg) | ||
384 | 76 | |||
385 | 77 | /* config settings */ | ||
386 | 78 | typedef struct configSettings_s { | ||
387 | 79 | int bPermitNonKernel; /* permit logging of messages not having LOG_KERN facility */ | ||
388 | 80 | int bParseKernelStamp; /* if try to parse kernel timestamps for message time */ | ||
389 | 81 | int bKeepKernelStamp; /* keep the kernel timestamp in the message */ | ||
390 | 82 | int iFacilIntMsg; /* the facility to use for internal messages (set by driver) */ | ||
391 | 83 | uchar *pszPath; | ||
392 | 84 | int console_log_level; /* still used for BSD */ | ||
393 | 85 | } configSettings_t; | ||
394 | 86 | static configSettings_t cs; | ||
395 | 87 | |||
396 | 88 | static modConfData_t *loadModConf = NULL;/* modConf ptr to use for the current load process */ | ||
397 | 89 | static modConfData_t *runModConf = NULL;/* modConf ptr to use for the current load process */ | ||
398 | 90 | static int bLegacyCnfModGlobalsPermitted;/* are legacy module-global config parameters permitted? */ | ||
399 | 91 | |||
400 | 92 | /* module-global parameters */ | ||
401 | 93 | static struct cnfparamdescr modpdescr[] = { | ||
402 | 94 | { "logpath", eCmdHdlrGetWord, 0 }, | ||
403 | 95 | { "permitnonkernelfacility", eCmdHdlrBinary, 0 }, | ||
404 | 96 | { "consoleloglevel", eCmdHdlrInt, 0 }, | ||
405 | 97 | { "parsekerneltimestamp", eCmdHdlrBinary, 0 }, | ||
406 | 98 | { "keepkerneltimestamp", eCmdHdlrBinary, 0 }, | ||
407 | 99 | { "internalmsgfacility", eCmdHdlrFacility, 0 } | ||
408 | 100 | }; | ||
409 | 101 | static struct cnfparamblk modpblk = | ||
410 | 102 | { CNFPARAMBLK_VERSION, | ||
411 | 103 | sizeof(modpdescr)/sizeof(struct cnfparamdescr), | ||
412 | 104 | modpdescr | ||
413 | 105 | }; | ||
414 | 106 | |||
415 | 107 | static prop_t *pInputName = NULL; /* there is only one global inputName for all messages generated by this module */ | ||
416 | 108 | static prop_t *pLocalHostIP = NULL; | ||
417 | 109 | |||
418 | 110 | static inline void | ||
419 | 111 | initConfigSettings(void) | ||
420 | 112 | { | ||
421 | 113 | cs.bPermitNonKernel = 0; | ||
422 | 114 | cs.bParseKernelStamp = 0; | ||
423 | 115 | cs.bKeepKernelStamp = 0; | ||
424 | 116 | cs.console_log_level = -1; | ||
425 | 117 | cs.pszPath = NULL; | ||
426 | 118 | cs.iFacilIntMsg = klogFacilIntMsg(); | ||
427 | 119 | } | ||
428 | 120 | |||
429 | 121 | |||
430 | 122 | /* enqueue the the kernel message into the message queue. | ||
431 | 123 | * The provided msg string is not freed - thus must be done | ||
432 | 124 | * by the caller. | ||
433 | 125 | * rgerhards, 2008-04-12 | ||
434 | 126 | */ | ||
435 | 127 | static rsRetVal | ||
436 | 128 | enqMsg(uchar *msg, uchar* pszTag, int iFacility, int iSeverity, struct timeval *tp) | ||
437 | 129 | { | ||
438 | 130 | struct syslogTime st; | ||
439 | 131 | msg_t *pMsg; | ||
440 | 132 | DEFiRet; | ||
441 | 133 | |||
442 | 134 | assert(msg != NULL); | ||
443 | 135 | assert(pszTag != NULL); | ||
444 | 136 | |||
445 | 137 | if(tp == NULL) { | ||
446 | 138 | CHKiRet(msgConstruct(&pMsg)); | ||
447 | 139 | } else { | ||
448 | 140 | datetime.timeval2syslogTime(tp, &st); | ||
449 | 141 | CHKiRet(msgConstructWithTime(&pMsg, &st, tp->tv_sec)); | ||
450 | 142 | } | ||
451 | 143 | MsgSetFlowControlType(pMsg, eFLOWCTL_LIGHT_DELAY); | ||
452 | 144 | MsgSetInputName(pMsg, pInputName); | ||
453 | 145 | MsgSetRawMsgWOSize(pMsg, (char*)msg); | ||
454 | 146 | MsgSetMSGoffs(pMsg, 0); /* we do not have a header... */ | ||
455 | 147 | MsgSetRcvFrom(pMsg, glbl.GetLocalHostNameProp()); | ||
456 | 148 | MsgSetRcvFromIP(pMsg, pLocalHostIP); | ||
457 | 149 | MsgSetHOSTNAME(pMsg, glbl.GetLocalHostName(), ustrlen(glbl.GetLocalHostName())); | ||
458 | 150 | MsgSetTAG(pMsg, pszTag, ustrlen(pszTag)); | ||
459 | 151 | pMsg->iFacility = iFacility; | ||
460 | 152 | pMsg->iSeverity = iSeverity; | ||
461 | 153 | /* note: we do NOT use rate-limiting, as the kernel itself does rate-limiting */ | ||
462 | 154 | CHKiRet(submitMsg2(pMsg)); | ||
463 | 155 | |||
464 | 156 | finalize_it: | ||
465 | 157 | RETiRet; | ||
466 | 158 | } | ||
467 | 159 | |||
468 | 160 | /* parse the PRI from a kernel message. At least BSD seems to have | ||
469 | 161 | * non-kernel messages inside the kernel log... | ||
470 | 162 | * Expected format: "<pri>". piPri is only valid if the function | ||
471 | 163 | * successfully returns. If there was a proper pri ppSz is advanced to the | ||
472 | 164 | * position right after ">". | ||
473 | 165 | * rgerhards, 2008-04-14 | ||
474 | 166 | */ | ||
475 | 167 | static rsRetVal | ||
476 | 168 | parsePRI(uchar **ppSz, int *piPri) | ||
477 | 169 | { | ||
478 | 170 | DEFiRet; | ||
479 | 171 | int i; | ||
480 | 172 | uchar *pSz; | ||
481 | 173 | |||
482 | 174 | assert(ppSz != NULL); | ||
483 | 175 | pSz = *ppSz; | ||
484 | 176 | assert(pSz != NULL); | ||
485 | 177 | assert(piPri != NULL); | ||
486 | 178 | |||
487 | 179 | if(*pSz != '<' || !isdigit(*(pSz+1))) | ||
488 | 180 | ABORT_FINALIZE(RS_RET_INVALID_PRI); | ||
489 | 181 | |||
490 | 182 | ++pSz; | ||
491 | 183 | i = 0; | ||
492 | 184 | while(isdigit(*pSz)) { | ||
493 | 185 | i = i * 10 + *pSz++ - '0'; | ||
494 | 186 | } | ||
495 | 187 | |||
496 | 188 | if(*pSz != '>') | ||
497 | 189 | ABORT_FINALIZE(RS_RET_INVALID_PRI); | ||
498 | 190 | |||
499 | 191 | /* OK, we have a valid PRI */ | ||
500 | 192 | *piPri = i; | ||
501 | 193 | *ppSz = pSz + 1; /* update msg ptr to position after PRI */ | ||
502 | 194 | |||
503 | 195 | finalize_it: | ||
504 | 196 | RETiRet; | ||
505 | 197 | } | ||
506 | 198 | |||
507 | 199 | |||
508 | 200 | /* log an imklog-internal message | ||
509 | 201 | * rgerhards, 2008-04-14 | ||
510 | 202 | */ | ||
511 | 203 | rsRetVal imklogLogIntMsg(int priority, char *fmt, ...) | ||
512 | 204 | { | ||
513 | 205 | DEFiRet; | ||
514 | 206 | va_list ap; | ||
515 | 207 | uchar msgBuf[2048]; /* we use the same size as sysklogd to remain compatible */ | ||
516 | 208 | |||
517 | 209 | va_start(ap, fmt); | ||
518 | 210 | vsnprintf((char*)msgBuf, sizeof(msgBuf) / sizeof(char), fmt, ap); | ||
519 | 211 | va_end(ap); | ||
520 | 212 | |||
521 | 213 | logmsgInternal(NO_ERRCODE ,priority, msgBuf, 0); | ||
522 | 214 | |||
523 | 215 | RETiRet; | ||
524 | 216 | } | ||
525 | 217 | |||
526 | 218 | |||
527 | 219 | /* log a kernel message. If tp is non-NULL, it contains the message creation | ||
528 | 220 | * time to use. | ||
529 | 221 | * rgerhards, 2008-04-14 | ||
530 | 222 | */ | ||
531 | 223 | rsRetVal Syslog(int priority, uchar *pMsg, struct timeval *tp) | ||
532 | 224 | { | ||
533 | 225 | int pri = -1; | ||
534 | 226 | rsRetVal localRet; | ||
535 | 227 | DEFiRet; | ||
536 | 228 | |||
537 | 229 | /* then check if we have two PRIs. This can happen in case of systemd, | ||
538 | 230 | * in which case the second PRI is the right one. | ||
539 | 231 | */ | ||
540 | 232 | if(pMsg[3] == '<' || (pMsg[3] == ' ' && pMsg[4] == '<')) { /* could be a pri... */ | ||
541 | 233 | uchar *pMsgTmp = pMsg + ((pMsg[3] == '<') ? 3 : 4); | ||
542 | 234 | localRet = parsePRI(&pMsgTmp, &pri); | ||
543 | 235 | if(localRet == RS_RET_OK && pri >= 8 && pri <= 192) { | ||
544 | 236 | /* *this* is our PRI */ | ||
545 | 237 | DBGPRINTF("imklog detected secondary PRI(%d) in klog msg\n", pri); | ||
546 | 238 | pMsg = pMsgTmp; | ||
547 | 239 | priority = pri; | ||
548 | 240 | } | ||
549 | 241 | } | ||
550 | 242 | if(pri == -1) { | ||
551 | 243 | localRet = parsePRI(&pMsg, &priority); | ||
552 | 244 | if(localRet != RS_RET_INVALID_PRI && localRet != RS_RET_OK) | ||
553 | 245 | FINALIZE; | ||
554 | 246 | } | ||
555 | 247 | /* if we don't get the pri, we use whatever we were supplied */ | ||
556 | 248 | |||
557 | 249 | /* ignore non-kernel messages if not permitted */ | ||
558 | 250 | if(cs.bPermitNonKernel == 0 && pri2fac(priority) != LOG_KERN) | ||
559 | 251 | FINALIZE; /* silently ignore */ | ||
560 | 252 | |||
561 | 253 | iRet = enqMsg((uchar*)pMsg, (uchar*) "kernel:", pri2fac(priority), pri2sev(priority), tp); | ||
562 | 254 | |||
563 | 255 | finalize_it: | ||
564 | 256 | RETiRet; | ||
565 | 257 | } | ||
566 | 258 | |||
567 | 259 | |||
568 | 260 | /* helper for some klog drivers which need to know the MaxLine global setting. They can | ||
569 | 261 | * not obtain it themselfs, because they are no modules and can not query the object hander. | ||
570 | 262 | * It would probably be a good idea to extend the interface to support it, but so far | ||
571 | 263 | * we create a (sufficiently valid) work-around. -- rgerhards, 2008-11-24 | ||
572 | 264 | */ | ||
573 | 265 | int klog_getMaxLine(void) | ||
574 | 266 | { | ||
575 | 267 | return glbl.GetMaxLine(); | ||
576 | 268 | } | ||
577 | 269 | |||
578 | 270 | |||
579 | 271 | BEGINrunInput | ||
580 | 272 | CODESTARTrunInput | ||
581 | 273 | /* this is an endless loop - it is terminated when the thread is | ||
582 | 274 | * signalled to do so. This, however, is handled by the framework, | ||
583 | 275 | * right into the sleep below. | ||
584 | 276 | */ | ||
585 | 277 | while(!pThrd->bShallStop) { | ||
586 | 278 | /* klogLogKMsg() waits for the next kernel message, obtains it | ||
587 | 279 | * and then submits it to the rsyslog main queue. | ||
588 | 280 | * rgerhards, 2008-04-09 | ||
589 | 281 | */ | ||
590 | 282 | CHKiRet(klogLogKMsg(runModConf)); | ||
591 | 283 | } | ||
592 | 284 | finalize_it: | ||
593 | 285 | ENDrunInput | ||
594 | 286 | |||
595 | 287 | |||
596 | 288 | BEGINbeginCnfLoad | ||
597 | 289 | CODESTARTbeginCnfLoad | ||
598 | 290 | loadModConf = pModConf; | ||
599 | 291 | pModConf->pConf = pConf; | ||
600 | 292 | /* init our settings */ | ||
601 | 293 | pModConf->pszPath = NULL; | ||
602 | 294 | pModConf->bPermitNonKernel = 0; | ||
603 | 295 | pModConf->bParseKernelStamp = 0; | ||
604 | 296 | pModConf->bKeepKernelStamp = 0; | ||
605 | 297 | pModConf->console_log_level = -1; | ||
606 | 298 | pModConf->bKeepKernelStamp = 0; | ||
607 | 299 | pModConf->iFacilIntMsg = klogFacilIntMsg(); | ||
608 | 300 | loadModConf->configSetViaV2Method = 0; | ||
609 | 301 | bLegacyCnfModGlobalsPermitted = 1; | ||
610 | 302 | /* init legacy config vars */ | ||
611 | 303 | initConfigSettings(); | ||
612 | 304 | ENDbeginCnfLoad | ||
613 | 305 | |||
614 | 306 | |||
615 | 307 | BEGINsetModCnf | ||
616 | 308 | struct cnfparamvals *pvals = NULL; | ||
617 | 309 | int i; | ||
618 | 310 | CODESTARTsetModCnf | ||
619 | 311 | pvals = nvlstGetParams(lst, &modpblk, NULL); | ||
620 | 312 | if(pvals == NULL) { | ||
621 | 313 | errmsg.LogError(0, RS_RET_MISSING_CNFPARAMS, "error processing module " | ||
622 | 314 | "config parameters [module(...)]"); | ||
623 | 315 | ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS); | ||
624 | 316 | } | ||
625 | 317 | |||
626 | 318 | if(Debug) { | ||
627 | 319 | dbgprintf("module (global) param blk for imklog:\n"); | ||
628 | 320 | cnfparamsPrint(&modpblk, pvals); | ||
629 | 321 | } | ||
630 | 322 | |||
631 | 323 | for(i = 0 ; i < modpblk.nParams ; ++i) { | ||
632 | 324 | if(!pvals[i].bUsed) | ||
633 | 325 | continue; | ||
634 | 326 | if(!strcmp(modpblk.descr[i].name, "logpath")) { | ||
635 | 327 | loadModConf->pszPath = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL); | ||
636 | 328 | } else if(!strcmp(modpblk.descr[i].name, "permitnonkernelfacility")) { | ||
637 | 329 | loadModConf->bPermitNonKernel = (int) pvals[i].val.d.n; | ||
638 | 330 | } else if(!strcmp(modpblk.descr[i].name, "parsekerneltimestamp")) { | ||
639 | 331 | loadModConf->bParseKernelStamp = (int) pvals[i].val.d.n; | ||
640 | 332 | } else if(!strcmp(modpblk.descr[i].name, "keepkerneltimestamp")) { | ||
641 | 333 | loadModConf->bKeepKernelStamp = (int) pvals[i].val.d.n; | ||
642 | 334 | } else if(!strcmp(modpblk.descr[i].name, "consoleloglevel")) { | ||
643 | 335 | loadModConf->console_log_level= (int) pvals[i].val.d.n; | ||
644 | 336 | } else if(!strcmp(modpblk.descr[i].name, "internalmsgfacility")) { | ||
645 | 337 | loadModConf->iFacilIntMsg = (int) pvals[i].val.d.n; | ||
646 | 338 | } else { | ||
647 | 339 | dbgprintf("imklog: program error, non-handled " | ||
648 | 340 | "param '%s' in beginCnfLoad\n", modpblk.descr[i].name); | ||
649 | 341 | } | ||
650 | 342 | } | ||
651 | 343 | |||
652 | 344 | /* disable legacy module-global config directives */ | ||
653 | 345 | bLegacyCnfModGlobalsPermitted = 0; | ||
654 | 346 | loadModConf->configSetViaV2Method = 1; | ||
655 | 347 | |||
656 | 348 | finalize_it: | ||
657 | 349 | if(pvals != NULL) | ||
658 | 350 | cnfparamvalsDestruct(pvals, &modpblk); | ||
659 | 351 | ENDsetModCnf | ||
660 | 352 | |||
661 | 353 | |||
662 | 354 | BEGINendCnfLoad | ||
663 | 355 | CODESTARTendCnfLoad | ||
664 | 356 | if(!loadModConf->configSetViaV2Method) { | ||
665 | 357 | /* persist module-specific settings from legacy config system */ | ||
666 | 358 | loadModConf->bPermitNonKernel = cs.bPermitNonKernel; | ||
667 | 359 | loadModConf->bParseKernelStamp = cs.bParseKernelStamp; | ||
668 | 360 | loadModConf->bKeepKernelStamp = cs.bKeepKernelStamp; | ||
669 | 361 | loadModConf->iFacilIntMsg = cs.iFacilIntMsg; | ||
670 | 362 | loadModConf->console_log_level = cs.console_log_level; | ||
671 | 363 | if((cs.pszPath == NULL) || (cs.pszPath[0] == '\0')) { | ||
672 | 364 | loadModConf->pszPath = NULL; | ||
673 | 365 | if(cs.pszPath != NULL) | ||
674 | 366 | free(cs.pszPath); | ||
675 | 367 | } else { | ||
676 | 368 | loadModConf->pszPath = cs.pszPath; | ||
677 | 369 | } | ||
678 | 370 | cs.pszPath = NULL; | ||
679 | 371 | } | ||
680 | 372 | |||
681 | 373 | loadModConf = NULL; /* done loading */ | ||
682 | 374 | ENDendCnfLoad | ||
683 | 375 | |||
684 | 376 | |||
685 | 377 | BEGINcheckCnf | ||
686 | 378 | CODESTARTcheckCnf | ||
687 | 379 | ENDcheckCnf | ||
688 | 380 | |||
689 | 381 | |||
690 | 382 | BEGINactivateCnfPrePrivDrop | ||
691 | 383 | CODESTARTactivateCnfPrePrivDrop | ||
692 | 384 | runModConf = pModConf; | ||
693 | 385 | iRet = klogWillRun(runModConf); | ||
694 | 386 | ENDactivateCnfPrePrivDrop | ||
695 | 387 | |||
696 | 388 | |||
697 | 389 | BEGINactivateCnf | ||
698 | 390 | CODESTARTactivateCnf | ||
699 | 391 | ENDactivateCnf | ||
700 | 392 | |||
701 | 393 | |||
702 | 394 | BEGINfreeCnf | ||
703 | 395 | CODESTARTfreeCnf | ||
704 | 396 | ENDfreeCnf | ||
705 | 397 | |||
706 | 398 | |||
707 | 399 | BEGINwillRun | ||
708 | 400 | CODESTARTwillRun | ||
709 | 401 | ENDwillRun | ||
710 | 402 | |||
711 | 403 | |||
712 | 404 | BEGINafterRun | ||
713 | 405 | CODESTARTafterRun | ||
714 | 406 | iRet = klogAfterRun(runModConf); | ||
715 | 407 | ENDafterRun | ||
716 | 408 | |||
717 | 409 | |||
718 | 410 | BEGINmodExit | ||
719 | 411 | CODESTARTmodExit | ||
720 | 412 | if(pInputName != NULL) | ||
721 | 413 | prop.Destruct(&pInputName); | ||
722 | 414 | if(pLocalHostIP != NULL) | ||
723 | 415 | prop.Destruct(&pLocalHostIP); | ||
724 | 416 | |||
725 | 417 | /* release objects we used */ | ||
726 | 418 | objRelease(glbl, CORE_COMPONENT); | ||
727 | 419 | objRelease(net, CORE_COMPONENT); | ||
728 | 420 | objRelease(datetime, CORE_COMPONENT); | ||
729 | 421 | objRelease(prop, CORE_COMPONENT); | ||
730 | 422 | objRelease(errmsg, CORE_COMPONENT); | ||
731 | 423 | ENDmodExit | ||
732 | 424 | |||
733 | 425 | |||
734 | 426 | BEGINqueryEtryPt | ||
735 | 427 | CODESTARTqueryEtryPt | ||
736 | 428 | CODEqueryEtryPt_STD_IMOD_QUERIES | ||
737 | 429 | CODEqueryEtryPt_STD_CONF2_QUERIES | ||
738 | 430 | CODEqueryEtryPt_STD_CONF2_setModCnf_QUERIES | ||
739 | 431 | CODEqueryEtryPt_STD_CONF2_PREPRIVDROP_QUERIES | ||
740 | 432 | ENDqueryEtryPt | ||
741 | 433 | |||
742 | 434 | static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal) | ||
743 | 435 | { | ||
744 | 436 | cs.bPermitNonKernel = 0; | ||
745 | 437 | cs.bParseKernelStamp = 0; | ||
746 | 438 | cs.bKeepKernelStamp = 0; | ||
747 | 439 | if(cs.pszPath != NULL) { | ||
748 | 440 | free(cs.pszPath); | ||
749 | 441 | cs.pszPath = NULL; | ||
750 | 442 | } | ||
751 | 443 | cs.iFacilIntMsg = klogFacilIntMsg(); | ||
752 | 444 | return RS_RET_OK; | ||
753 | 445 | } | ||
754 | 446 | |||
755 | 447 | BEGINmodInit() | ||
756 | 448 | CODESTARTmodInit | ||
757 | 449 | *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ | ||
758 | 450 | CODEmodInit_QueryRegCFSLineHdlr | ||
759 | 451 | CHKiRet(objUse(datetime, CORE_COMPONENT)); | ||
760 | 452 | CHKiRet(objUse(glbl, CORE_COMPONENT)); | ||
761 | 453 | CHKiRet(objUse(prop, CORE_COMPONENT)); | ||
762 | 454 | CHKiRet(objUse(net, CORE_COMPONENT)); | ||
763 | 455 | CHKiRet(objUse(errmsg, CORE_COMPONENT)); | ||
764 | 456 | |||
765 | 457 | /* we need to create the inputName property (only once during our lifetime) */ | ||
766 | 458 | CHKiRet(prop.CreateStringProp(&pInputName, UCHAR_CONSTANT("imklog"), sizeof("imklog") - 1)); | ||
767 | 459 | CHKiRet(prop.CreateStringProp(&pLocalHostIP, UCHAR_CONSTANT("127.0.0.1"), sizeof("127.0.0.1") - 1)); | ||
768 | 460 | |||
769 | 461 | /* init legacy config settings */ | ||
770 | 462 | initConfigSettings(); | ||
771 | 463 | |||
772 | 464 | CHKiRet(omsdRegCFSLineHdlr((uchar *)"debugprintkernelsymbols", 0, eCmdHdlrGoneAway, | ||
773 | 465 | NULL, NULL, STD_LOADABLE_MODULE_ID)); | ||
774 | 466 | CHKiRet(regCfSysLineHdlr2((uchar *)"klogpath", 0, eCmdHdlrGetWord, | ||
775 | 467 | NULL, &cs.pszPath, STD_LOADABLE_MODULE_ID, &bLegacyCnfModGlobalsPermitted)); | ||
776 | 468 | CHKiRet(omsdRegCFSLineHdlr((uchar *)"klogsymbollookup", 0, eCmdHdlrGoneAway, | ||
777 | 469 | NULL, NULL, STD_LOADABLE_MODULE_ID)); | ||
778 | 470 | CHKiRet(omsdRegCFSLineHdlr((uchar *)"klogsymbolstwice", 0, eCmdHdlrGoneAway, | ||
779 | 471 | NULL, NULL, STD_LOADABLE_MODULE_ID)); | ||
780 | 472 | CHKiRet(omsdRegCFSLineHdlr((uchar *)"klogusesyscallinterface", 0, eCmdHdlrGoneAway, | ||
781 | 473 | NULL, NULL, STD_LOADABLE_MODULE_ID)); | ||
782 | 474 | CHKiRet(regCfSysLineHdlr2((uchar *)"klogpermitnonkernelfacility", 0, eCmdHdlrBinary, | ||
783 | 475 | NULL, &cs.bPermitNonKernel, STD_LOADABLE_MODULE_ID, &bLegacyCnfModGlobalsPermitted)); | ||
784 | 476 | CHKiRet(regCfSysLineHdlr2((uchar *)"klogconsoleloglevel", 0, eCmdHdlrInt, | ||
785 | 477 | NULL, &cs.console_log_level, STD_LOADABLE_MODULE_ID, &bLegacyCnfModGlobalsPermitted)); | ||
786 | 478 | CHKiRet(regCfSysLineHdlr2((uchar *)"kloginternalmsgfacility", 0, eCmdHdlrFacility, | ||
787 | 479 | NULL, &cs.iFacilIntMsg, STD_LOADABLE_MODULE_ID, &bLegacyCnfModGlobalsPermitted)); | ||
788 | 480 | CHKiRet(regCfSysLineHdlr2((uchar *)"klogparsekerneltimestamp", 0, eCmdHdlrBinary, | ||
789 | 481 | NULL, &cs.bParseKernelStamp, STD_LOADABLE_MODULE_ID, &bLegacyCnfModGlobalsPermitted)); | ||
790 | 482 | CHKiRet(regCfSysLineHdlr2((uchar *)"klogkeepkerneltimestamp", 0, eCmdHdlrBinary, | ||
791 | 483 | NULL, &cs.bKeepKernelStamp, STD_LOADABLE_MODULE_ID, &bLegacyCnfModGlobalsPermitted)); | ||
792 | 484 | CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, | ||
793 | 485 | resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID)); | ||
794 | 486 | ENDmodInit | ||
795 | 487 | /* vim:set ai: | ||
796 | 488 | */ | ||
797 | 0 | 489 | ||
798 | === added file '.pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/imklog.h' | |||
799 | --- .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/imklog.h 1970-01-01 00:00:00 +0000 | |||
800 | +++ .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imklog/imklog.h 2015-01-09 16:11:08 +0000 | |||
801 | @@ -0,0 +1,70 @@ | |||
802 | 1 | /* imklog.h | ||
803 | 2 | * These are the definitions for the klog message generation module. | ||
804 | 3 | * | ||
805 | 4 | * File begun on 2007-12-17 by RGerhards | ||
806 | 5 | * Major change: 2008-04-09: switched to a driver interface for | ||
807 | 6 | * several platforms | ||
808 | 7 | * | ||
809 | 8 | * Copyright 2007-2012 Rainer Gerhards and Adiscon GmbH. | ||
810 | 9 | * | ||
811 | 10 | * This file is part of rsyslog. | ||
812 | 11 | * | ||
813 | 12 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
814 | 13 | * you may not use this file except in compliance with the License. | ||
815 | 14 | * You may obtain a copy of the License at | ||
816 | 15 | * | ||
817 | 16 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
818 | 17 | * -or- | ||
819 | 18 | * see COPYING.ASL20 in the source distribution | ||
820 | 19 | * | ||
821 | 20 | * Unless required by applicable law or agreed to in writing, software | ||
822 | 21 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
823 | 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
824 | 23 | * See the License for the specific language governing permissions and | ||
825 | 24 | * limitations under the License. | ||
826 | 25 | */ | ||
827 | 26 | #ifndef IMKLOG_H_INCLUDED | ||
828 | 27 | #define IMKLOG_H_INCLUDED 1 | ||
829 | 28 | |||
830 | 29 | #include "rsyslog.h" | ||
831 | 30 | #include "dirty.h" | ||
832 | 31 | |||
833 | 32 | /* we need to have the modConf type present in all submodules */ | ||
834 | 33 | struct modConfData_s { | ||
835 | 34 | rsconf_t *pConf; | ||
836 | 35 | int iFacilIntMsg; | ||
837 | 36 | uchar *pszPath; | ||
838 | 37 | int console_log_level; | ||
839 | 38 | sbool bParseKernelStamp; | ||
840 | 39 | sbool bKeepKernelStamp; | ||
841 | 40 | sbool bPermitNonKernel; | ||
842 | 41 | sbool configSetViaV2Method; | ||
843 | 42 | }; | ||
844 | 43 | |||
845 | 44 | /* interface to "drivers" | ||
846 | 45 | * the platform specific drivers must implement these entry points. Only one | ||
847 | 46 | * driver may be active at any given time, thus we simply rely on the linker | ||
848 | 47 | * to resolve the addresses. | ||
849 | 48 | * rgerhards, 2008-04-09 | ||
850 | 49 | */ | ||
851 | 50 | rsRetVal klogLogKMsg(modConfData_t *pModConf); | ||
852 | 51 | rsRetVal klogWillRun(modConfData_t *pModConf); | ||
853 | 52 | rsRetVal klogAfterRun(modConfData_t *pModConf); | ||
854 | 53 | int klogFacilIntMsg(); | ||
855 | 54 | |||
856 | 55 | /* the functions below may be called by the drivers */ | ||
857 | 56 | rsRetVal imklogLogIntMsg(int priority, char *fmt, ...) __attribute__((format(printf,2, 3))); | ||
858 | 57 | rsRetVal Syslog(int priority, uchar *msg, struct timeval *tp); | ||
859 | 58 | |||
860 | 59 | /* prototypes */ | ||
861 | 60 | extern int klog_getMaxLine(void); /* work-around for klog drivers to get configured max line size */ | ||
862 | 61 | extern int InitKsyms(modConfData_t*); | ||
863 | 62 | extern void DeinitKsyms(void); | ||
864 | 63 | extern int InitMsyms(void); | ||
865 | 64 | extern void DeinitMsyms(void); | ||
866 | 65 | extern char * ExpandKadds(char *, char *); | ||
867 | 66 | extern void SetParanoiaLevel(int); | ||
868 | 67 | |||
869 | 68 | #endif /* #ifndef IMKLOG_H_INCLUDED */ | ||
870 | 69 | /* vi:set ai: | ||
871 | 70 | */ | ||
872 | 0 | 71 | ||
873 | === added file '.pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imkmsg/imkmsg.c' | |||
874 | --- .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imkmsg/imkmsg.c 1970-01-01 00:00:00 +0000 | |||
875 | +++ .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imkmsg/imkmsg.c 2015-01-09 16:11:08 +0000 | |||
876 | @@ -0,0 +1,295 @@ | |||
877 | 1 | /* The kernel log module. | ||
878 | 2 | * | ||
879 | 3 | * This is rsyslog Linux only module for reading structured kernel logs. | ||
880 | 4 | * Module is based on imklog module so it retains its structure | ||
881 | 5 | * and other part is currently in kmsg.c file instead of this (imkmsg.c) | ||
882 | 6 | * For more information see that file. | ||
883 | 7 | * | ||
884 | 8 | * To test under Linux: | ||
885 | 9 | * echo test1 > /dev/kmsg | ||
886 | 10 | * | ||
887 | 11 | * Copyright (C) 2008-2012 Adiscon GmbH | ||
888 | 12 | * | ||
889 | 13 | * This file is part of rsyslog. | ||
890 | 14 | * | ||
891 | 15 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
892 | 16 | * you may not use this file except in compliance with the License. | ||
893 | 17 | * You may obtain a copy of the License at | ||
894 | 18 | * | ||
895 | 19 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
896 | 20 | * -or- | ||
897 | 21 | * see COPYING.ASL20 in the source distribution | ||
898 | 22 | * | ||
899 | 23 | * Unless required by applicable law or agreed to in writing, software | ||
900 | 24 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
901 | 25 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
902 | 26 | * See the License for the specific language governing permissions and | ||
903 | 27 | * limitations under the License. | ||
904 | 28 | */ | ||
905 | 29 | #include "config.h" | ||
906 | 30 | #include "rsyslog.h" | ||
907 | 31 | #include <stdio.h> | ||
908 | 32 | #include <assert.h> | ||
909 | 33 | #include <string.h> | ||
910 | 34 | #include <stdarg.h> | ||
911 | 35 | #include <ctype.h> | ||
912 | 36 | #include <stdlib.h> | ||
913 | 37 | #include <sys/socket.h> | ||
914 | 38 | |||
915 | 39 | #include "dirty.h" | ||
916 | 40 | #include "cfsysline.h" | ||
917 | 41 | #include "obj.h" | ||
918 | 42 | #include "msg.h" | ||
919 | 43 | #include "module-template.h" | ||
920 | 44 | #include "datetime.h" | ||
921 | 45 | #include "imkmsg.h" | ||
922 | 46 | #include "net.h" | ||
923 | 47 | #include "glbl.h" | ||
924 | 48 | #include "prop.h" | ||
925 | 49 | #include "errmsg.h" | ||
926 | 50 | #include "unicode-helper.h" | ||
927 | 51 | |||
928 | 52 | MODULE_TYPE_INPUT | ||
929 | 53 | MODULE_TYPE_NOKEEP | ||
930 | 54 | MODULE_CNFNAME("imkmsg") | ||
931 | 55 | |||
932 | 56 | /* Module static data */ | ||
933 | 57 | DEF_IMOD_STATIC_DATA | ||
934 | 58 | DEFobjCurrIf(datetime) | ||
935 | 59 | DEFobjCurrIf(glbl) | ||
936 | 60 | DEFobjCurrIf(prop) | ||
937 | 61 | DEFobjCurrIf(net) | ||
938 | 62 | DEFobjCurrIf(errmsg) | ||
939 | 63 | |||
940 | 64 | /* config settings */ | ||
941 | 65 | typedef struct configSettings_s { | ||
942 | 66 | int iFacilIntMsg; /* the facility to use for internal messages (set by driver) */ | ||
943 | 67 | } configSettings_t; | ||
944 | 68 | static configSettings_t cs; | ||
945 | 69 | |||
946 | 70 | static modConfData_t *loadModConf = NULL;/* modConf ptr to use for the current load process */ | ||
947 | 71 | static modConfData_t *runModConf = NULL;/* modConf ptr to use for the current load process */ | ||
948 | 72 | static int bLegacyCnfModGlobalsPermitted;/* are legacy module-global config parameters permitted? */ | ||
949 | 73 | |||
950 | 74 | static prop_t *pInputName = NULL; /* there is only one global inputName for all messages generated by this module */ | ||
951 | 75 | static prop_t *pLocalHostIP = NULL; /* a pseudo-constant propterty for 127.0.0.1 */ | ||
952 | 76 | |||
953 | 77 | static inline void | ||
954 | 78 | initConfigSettings(void) | ||
955 | 79 | { | ||
956 | 80 | cs.iFacilIntMsg = klogFacilIntMsg(); | ||
957 | 81 | } | ||
958 | 82 | |||
959 | 83 | |||
960 | 84 | /* enqueue the the kernel message into the message queue. | ||
961 | 85 | * The provided msg string is not freed - thus must be done | ||
962 | 86 | * by the caller. | ||
963 | 87 | * rgerhards, 2008-04-12 | ||
964 | 88 | */ | ||
965 | 89 | static rsRetVal | ||
966 | 90 | enqMsg(uchar *msg, uchar* pszTag, int iFacility, int iSeverity, struct timeval *tp, struct json_object *json) | ||
967 | 91 | { | ||
968 | 92 | struct syslogTime st; | ||
969 | 93 | msg_t *pMsg; | ||
970 | 94 | DEFiRet; | ||
971 | 95 | |||
972 | 96 | assert(msg != NULL); | ||
973 | 97 | assert(pszTag != NULL); | ||
974 | 98 | |||
975 | 99 | if(tp == NULL) { | ||
976 | 100 | CHKiRet(msgConstruct(&pMsg)); | ||
977 | 101 | } else { | ||
978 | 102 | datetime.timeval2syslogTime(tp, &st); | ||
979 | 103 | CHKiRet(msgConstructWithTime(&pMsg, &st, tp->tv_sec)); | ||
980 | 104 | } | ||
981 | 105 | MsgSetFlowControlType(pMsg, eFLOWCTL_LIGHT_DELAY); | ||
982 | 106 | MsgSetInputName(pMsg, pInputName); | ||
983 | 107 | MsgSetRawMsgWOSize(pMsg, (char*)msg); | ||
984 | 108 | MsgSetMSGoffs(pMsg, 0); /* we do not have a header... */ | ||
985 | 109 | MsgSetRcvFrom(pMsg, glbl.GetLocalHostNameProp()); | ||
986 | 110 | MsgSetRcvFromIP(pMsg, pLocalHostIP); | ||
987 | 111 | MsgSetHOSTNAME(pMsg, glbl.GetLocalHostName(), ustrlen(glbl.GetLocalHostName())); | ||
988 | 112 | MsgSetTAG(pMsg, pszTag, ustrlen(pszTag)); | ||
989 | 113 | pMsg->iFacility = iFacility; | ||
990 | 114 | pMsg->iSeverity = iSeverity; | ||
991 | 115 | pMsg->json = json; | ||
992 | 116 | CHKiRet(submitMsg(pMsg)); | ||
993 | 117 | |||
994 | 118 | finalize_it: | ||
995 | 119 | RETiRet; | ||
996 | 120 | } | ||
997 | 121 | |||
998 | 122 | |||
999 | 123 | /* log an imkmsg-internal message | ||
1000 | 124 | * rgerhards, 2008-04-14 | ||
1001 | 125 | */ | ||
1002 | 126 | rsRetVal imkmsgLogIntMsg(int priority, char *fmt, ...) | ||
1003 | 127 | { | ||
1004 | 128 | DEFiRet; | ||
1005 | 129 | va_list ap; | ||
1006 | 130 | uchar msgBuf[2048]; /* we use the same size as sysklogd to remain compatible */ | ||
1007 | 131 | |||
1008 | 132 | va_start(ap, fmt); | ||
1009 | 133 | vsnprintf((char*)msgBuf, sizeof(msgBuf) / sizeof(char), fmt, ap); | ||
1010 | 134 | va_end(ap); | ||
1011 | 135 | |||
1012 | 136 | logmsgInternal(NO_ERRCODE ,priority, msgBuf, 0); | ||
1013 | 137 | |||
1014 | 138 | RETiRet; | ||
1015 | 139 | } | ||
1016 | 140 | |||
1017 | 141 | |||
1018 | 142 | /* log a message from /dev/kmsg | ||
1019 | 143 | */ | ||
1020 | 144 | rsRetVal Syslog(int priority, uchar *pMsg, struct timeval *tp, struct json_object *json) | ||
1021 | 145 | { | ||
1022 | 146 | DEFiRet; | ||
1023 | 147 | iRet = enqMsg((uchar*)pMsg, (uchar*) "kernel:", pri2fac(priority), pri2sev(priority), tp, json); | ||
1024 | 148 | RETiRet; | ||
1025 | 149 | } | ||
1026 | 150 | |||
1027 | 151 | |||
1028 | 152 | /* helper for some klog drivers which need to know the MaxLine global setting. They can | ||
1029 | 153 | * not obtain it themselfs, because they are no modules and can not query the object hander. | ||
1030 | 154 | * It would probably be a good idea to extend the interface to support it, but so far | ||
1031 | 155 | * we create a (sufficiently valid) work-around. -- rgerhards, 2008-11-24 | ||
1032 | 156 | */ | ||
1033 | 157 | int klog_getMaxLine(void) | ||
1034 | 158 | { | ||
1035 | 159 | return glbl.GetMaxLine(); | ||
1036 | 160 | } | ||
1037 | 161 | |||
1038 | 162 | |||
1039 | 163 | BEGINrunInput | ||
1040 | 164 | CODESTARTrunInput | ||
1041 | 165 | /* this is an endless loop - it is terminated when the thread is | ||
1042 | 166 | * signalled to do so. This, however, is handled by the framework, | ||
1043 | 167 | * right into the sleep below. | ||
1044 | 168 | */ | ||
1045 | 169 | while(!pThrd->bShallStop) { | ||
1046 | 170 | /* klogLogKMsg() waits for the next kernel message, obtains it | ||
1047 | 171 | * and then submits it to the rsyslog main queue. | ||
1048 | 172 | * rgerhards, 2008-04-09 | ||
1049 | 173 | */ | ||
1050 | 174 | CHKiRet(klogLogKMsg(runModConf)); | ||
1051 | 175 | } | ||
1052 | 176 | finalize_it: | ||
1053 | 177 | ENDrunInput | ||
1054 | 178 | |||
1055 | 179 | |||
1056 | 180 | BEGINbeginCnfLoad | ||
1057 | 181 | CODESTARTbeginCnfLoad | ||
1058 | 182 | loadModConf = pModConf; | ||
1059 | 183 | pModConf->pConf = pConf; | ||
1060 | 184 | /* init our settings */ | ||
1061 | 185 | pModConf->iFacilIntMsg = klogFacilIntMsg(); | ||
1062 | 186 | loadModConf->configSetViaV2Method = 0; | ||
1063 | 187 | bLegacyCnfModGlobalsPermitted = 1; | ||
1064 | 188 | /* init legacy config vars */ | ||
1065 | 189 | initConfigSettings(); | ||
1066 | 190 | ENDbeginCnfLoad | ||
1067 | 191 | |||
1068 | 192 | |||
1069 | 193 | BEGINendCnfLoad | ||
1070 | 194 | CODESTARTendCnfLoad | ||
1071 | 195 | if(!loadModConf->configSetViaV2Method) { | ||
1072 | 196 | /* persist module-specific settings from legacy config system */ | ||
1073 | 197 | loadModConf->iFacilIntMsg = cs.iFacilIntMsg; | ||
1074 | 198 | } | ||
1075 | 199 | |||
1076 | 200 | loadModConf = NULL; /* done loading */ | ||
1077 | 201 | ENDendCnfLoad | ||
1078 | 202 | |||
1079 | 203 | |||
1080 | 204 | BEGINcheckCnf | ||
1081 | 205 | CODESTARTcheckCnf | ||
1082 | 206 | ENDcheckCnf | ||
1083 | 207 | |||
1084 | 208 | |||
1085 | 209 | BEGINactivateCnfPrePrivDrop | ||
1086 | 210 | CODESTARTactivateCnfPrePrivDrop | ||
1087 | 211 | runModConf = pModConf; | ||
1088 | 212 | iRet = klogWillRun(runModConf); | ||
1089 | 213 | ENDactivateCnfPrePrivDrop | ||
1090 | 214 | |||
1091 | 215 | |||
1092 | 216 | BEGINactivateCnf | ||
1093 | 217 | CODESTARTactivateCnf | ||
1094 | 218 | ENDactivateCnf | ||
1095 | 219 | |||
1096 | 220 | |||
1097 | 221 | BEGINfreeCnf | ||
1098 | 222 | CODESTARTfreeCnf | ||
1099 | 223 | ENDfreeCnf | ||
1100 | 224 | |||
1101 | 225 | |||
1102 | 226 | BEGINwillRun | ||
1103 | 227 | CODESTARTwillRun | ||
1104 | 228 | ENDwillRun | ||
1105 | 229 | |||
1106 | 230 | |||
1107 | 231 | BEGINafterRun | ||
1108 | 232 | CODESTARTafterRun | ||
1109 | 233 | iRet = klogAfterRun(runModConf); | ||
1110 | 234 | ENDafterRun | ||
1111 | 235 | |||
1112 | 236 | |||
1113 | 237 | BEGINmodExit | ||
1114 | 238 | CODESTARTmodExit | ||
1115 | 239 | if(pInputName != NULL) | ||
1116 | 240 | prop.Destruct(&pInputName); | ||
1117 | 241 | if(pLocalHostIP != NULL) | ||
1118 | 242 | prop.Destruct(&pLocalHostIP); | ||
1119 | 243 | |||
1120 | 244 | /* release objects we used */ | ||
1121 | 245 | objRelease(glbl, CORE_COMPONENT); | ||
1122 | 246 | objRelease(net, CORE_COMPONENT); | ||
1123 | 247 | objRelease(datetime, CORE_COMPONENT); | ||
1124 | 248 | objRelease(prop, CORE_COMPONENT); | ||
1125 | 249 | objRelease(errmsg, CORE_COMPONENT); | ||
1126 | 250 | ENDmodExit | ||
1127 | 251 | |||
1128 | 252 | |||
1129 | 253 | BEGINqueryEtryPt | ||
1130 | 254 | CODESTARTqueryEtryPt | ||
1131 | 255 | CODEqueryEtryPt_STD_IMOD_QUERIES | ||
1132 | 256 | CODEqueryEtryPt_STD_CONF2_QUERIES | ||
1133 | 257 | CODEqueryEtryPt_STD_CONF2_PREPRIVDROP_QUERIES | ||
1134 | 258 | ENDqueryEtryPt | ||
1135 | 259 | |||
1136 | 260 | static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal) | ||
1137 | 261 | { | ||
1138 | 262 | cs.iFacilIntMsg = klogFacilIntMsg(); | ||
1139 | 263 | return RS_RET_OK; | ||
1140 | 264 | } | ||
1141 | 265 | |||
1142 | 266 | BEGINmodInit() | ||
1143 | 267 | CODESTARTmodInit | ||
1144 | 268 | *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ | ||
1145 | 269 | CODEmodInit_QueryRegCFSLineHdlr | ||
1146 | 270 | CHKiRet(objUse(datetime, CORE_COMPONENT)); | ||
1147 | 271 | CHKiRet(objUse(glbl, CORE_COMPONENT)); | ||
1148 | 272 | CHKiRet(objUse(prop, CORE_COMPONENT)); | ||
1149 | 273 | CHKiRet(objUse(net, CORE_COMPONENT)); | ||
1150 | 274 | CHKiRet(objUse(errmsg, CORE_COMPONENT)); | ||
1151 | 275 | |||
1152 | 276 | /* we need to create the inputName property (only once during our lifetime) */ | ||
1153 | 277 | CHKiRet(prop.CreateStringProp(&pInputName, UCHAR_CONSTANT("imkmsg"), sizeof("imkmsg") - 1)); | ||
1154 | 278 | CHKiRet(prop.CreateStringProp(&pLocalHostIP, UCHAR_CONSTANT("127.0.0.1"), sizeof("127.0.0.1") - 1)); | ||
1155 | 279 | |||
1156 | 280 | /* init legacy config settings */ | ||
1157 | 281 | initConfigSettings(); | ||
1158 | 282 | |||
1159 | 283 | CHKiRet(omsdRegCFSLineHdlr((uchar *)"debugprintkernelsymbols", 0, eCmdHdlrGoneAway, | ||
1160 | 284 | NULL, NULL, STD_LOADABLE_MODULE_ID)); | ||
1161 | 285 | CHKiRet(omsdRegCFSLineHdlr((uchar *)"klogsymbollookup", 0, eCmdHdlrGoneAway, | ||
1162 | 286 | NULL, NULL, STD_LOADABLE_MODULE_ID)); | ||
1163 | 287 | CHKiRet(omsdRegCFSLineHdlr((uchar *)"klogsymbolstwice", 0, eCmdHdlrGoneAway, | ||
1164 | 288 | NULL, NULL, STD_LOADABLE_MODULE_ID)); | ||
1165 | 289 | CHKiRet(omsdRegCFSLineHdlr((uchar *)"klogusesyscallinterface", 0, eCmdHdlrGoneAway, | ||
1166 | 290 | NULL, NULL, STD_LOADABLE_MODULE_ID)); | ||
1167 | 291 | CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, | ||
1168 | 292 | resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID)); | ||
1169 | 293 | ENDmodInit | ||
1170 | 294 | /* vim:set ai: | ||
1171 | 295 | */ | ||
1172 | 0 | 296 | ||
1173 | === added file '.pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imkmsg/imkmsg.h' | |||
1174 | --- .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imkmsg/imkmsg.h 1970-01-01 00:00:00 +0000 | |||
1175 | +++ .pc/11-fix-infinite-loop-openvz-vms.patch/plugins/imkmsg/imkmsg.h 2015-01-09 16:11:08 +0000 | |||
1176 | @@ -0,0 +1,64 @@ | |||
1177 | 1 | /* imkmsg.h | ||
1178 | 2 | * These are the definitions for the kmsg message generation module. | ||
1179 | 3 | * | ||
1180 | 4 | * Copyright 2007-2012 Rainer Gerhards and Adiscon GmbH. | ||
1181 | 5 | * | ||
1182 | 6 | * This file is part of rsyslog. | ||
1183 | 7 | * | ||
1184 | 8 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
1185 | 9 | * you may not use this file except in compliance with the License. | ||
1186 | 10 | * You may obtain a copy of the License at | ||
1187 | 11 | * | ||
1188 | 12 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
1189 | 13 | * -or- | ||
1190 | 14 | * see COPYING.ASL20 in the source distribution | ||
1191 | 15 | * | ||
1192 | 16 | * Unless required by applicable law or agreed to in writing, software | ||
1193 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
1194 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
1195 | 19 | * See the License for the specific language governing permissions and | ||
1196 | 20 | * limitations under the License. | ||
1197 | 21 | */ | ||
1198 | 22 | #ifndef IMKLOG_H_INCLUDED | ||
1199 | 23 | #define IMKLOG_H_INCLUDED 1 | ||
1200 | 24 | |||
1201 | 25 | #include "rsyslog.h" | ||
1202 | 26 | #include "dirty.h" | ||
1203 | 27 | |||
1204 | 28 | /* we need to have the modConf type present in all submodules */ | ||
1205 | 29 | struct modConfData_s { | ||
1206 | 30 | rsconf_t *pConf; | ||
1207 | 31 | int iFacilIntMsg; | ||
1208 | 32 | uchar *pszPath; | ||
1209 | 33 | int console_log_level; | ||
1210 | 34 | sbool bPermitNonKernel; | ||
1211 | 35 | sbool configSetViaV2Method; | ||
1212 | 36 | }; | ||
1213 | 37 | |||
1214 | 38 | /* interface to "drivers" | ||
1215 | 39 | * the platform specific drivers must implement these entry points. Only one | ||
1216 | 40 | * driver may be active at any given time, thus we simply rely on the linker | ||
1217 | 41 | * to resolve the addresses. | ||
1218 | 42 | * rgerhards, 2008-04-09 | ||
1219 | 43 | */ | ||
1220 | 44 | rsRetVal klogLogKMsg(modConfData_t *pModConf); | ||
1221 | 45 | rsRetVal klogWillRun(modConfData_t *pModConf); | ||
1222 | 46 | rsRetVal klogAfterRun(modConfData_t *pModConf); | ||
1223 | 47 | int klogFacilIntMsg(); | ||
1224 | 48 | |||
1225 | 49 | /* the functions below may be called by the drivers */ | ||
1226 | 50 | rsRetVal imkmsgLogIntMsg(int priority, char *fmt, ...) __attribute__((format(printf,2, 3))); | ||
1227 | 51 | rsRetVal Syslog(int priority, uchar *msg, struct timeval *tp, struct json_object *json); | ||
1228 | 52 | |||
1229 | 53 | /* prototypes */ | ||
1230 | 54 | extern int klog_getMaxLine(void); /* work-around for klog drivers to get configured max line size */ | ||
1231 | 55 | extern int InitKsyms(modConfData_t*); | ||
1232 | 56 | extern void DeinitKsyms(void); | ||
1233 | 57 | extern int InitMsyms(void); | ||
1234 | 58 | extern void DeinitMsyms(void); | ||
1235 | 59 | extern char * ExpandKadds(char *, char *); | ||
1236 | 60 | extern void SetParanoiaLevel(int); | ||
1237 | 61 | |||
1238 | 62 | #endif /* #ifndef IMKLOG_H_INCLUDED */ | ||
1239 | 63 | /* vi:set ai: | ||
1240 | 64 | */ | ||
1241 | 0 | 65 | ||
1242 | === modified file 'debian/changelog' | |||
1243 | --- debian/changelog 2015-01-05 10:52:48 +0000 | |||
1244 | +++ debian/changelog 2015-01-09 16:11:08 +0000 | |||
1245 | @@ -1,3 +1,10 @@ | |||
1246 | 1 | rsyslog (7.4.4-1ubuntu2.5) trusty-proposed; urgency=medium | ||
1247 | 2 | |||
1248 | 3 | * Applied updated upstream patch fixing infinite loop on OpenVZ VMs. | ||
1249 | 4 | (LP: #1366829) | ||
1250 | 5 | |||
1251 | 6 | -- Paul Donohue <ubuntu-rsyslog@PaulSD.com> Fri, 09 Jan 2015 10:50:36 -0500 | ||
1252 | 7 | |||
1253 | 1 | rsyslog (7.4.4-1ubuntu2.4) trusty-proposed; urgency=medium | 8 | rsyslog (7.4.4-1ubuntu2.4) trusty-proposed; urgency=medium |
1254 | 2 | 9 | ||
1255 | 3 | * Applied upstream patch fixing infinite loop on OpenVZ VMs. Thanks to Paul | 10 | * Applied upstream patch fixing infinite loop on OpenVZ VMs. Thanks to Paul |
1256 | 4 | 11 | ||
1257 | === modified file 'debian/patches/11-fix-infinite-loop-openvz-vms.patch' | |||
1258 | --- debian/patches/11-fix-infinite-loop-openvz-vms.patch 2015-01-05 10:52:48 +0000 | |||
1259 | +++ debian/patches/11-fix-infinite-loop-openvz-vms.patch 2015-01-09 16:11:08 +0000 | |||
1260 | @@ -3,27 +3,46 @@ | |||
1261 | 3 | Author: Paul Donohue <git@PaulSD.com> | 3 | Author: Paul Donohue <git@PaulSD.com> |
1262 | 4 | Applied-Upstream: commit 86904f96805d70fad6b4b1b90e06dcb8f789605c | 4 | Applied-Upstream: commit 86904f96805d70fad6b4b1b90e06dcb8f789605c |
1263 | 5 | 5 | ||
1265 | 6 | Index: rsyslog-7.4.4/plugins/imkmsg/kmsg.c | 6 | Index: rsyslog.trusty/plugins/imkmsg/kmsg.c |
1266 | 7 | =================================================================== | 7 | =================================================================== |
1270 | 8 | --- rsyslog-7.4.4.orig/plugins/imkmsg/kmsg.c | 8 | --- rsyslog.trusty.orig/plugins/imkmsg/kmsg.c |
1271 | 9 | +++ rsyslog-7.4.4/plugins/imkmsg/kmsg.c | 9 | +++ rsyslog.trusty/plugins/imkmsg/kmsg.c |
1272 | 10 | @@ -157,6 +157,7 @@ submitSyslog(uchar *buf) | 10 | @@ -155,18 +155,41 @@ submitSyslog(uchar *buf) |
1273 | 11 | /* open the kernel log - will be called inside the willRun() imkmsg entry point | ||
1274 | 12 | */ | ||
1275 | 11 | rsRetVal | 13 | rsRetVal |
1277 | 12 | klogWillRun(modConfData_t *pModConf) | 14 | -klogWillRun(modConfData_t *pModConf) |
1278 | 15 | +klogWillRunPrePrivDrop(modConfData_t *pModConf) | ||
1279 | 13 | { | 16 | { |
1280 | 14 | + int i; | ||
1281 | 15 | char errmsg[2048]; | 17 | char errmsg[2048]; |
1282 | 16 | DEFiRet; | 18 | DEFiRet; |
1283 | 17 | 19 | ||
1285 | 18 | @@ -167,6 +168,16 @@ klogWillRun(modConfData_t *pModConf) | 20 | fklog = open(_PATH_KLOG, O_RDONLY, 0); |
1286 | 21 | if (fklog < 0) { | ||
1287 | 22 | - imkmsgLogIntMsg(RS_RET_ERR_OPEN_KLOG, "imkmsg: cannot open kernel log(%s): %s.", | ||
1288 | 23 | + imkmsgLogIntMsg(LOG_ERR, "imkmsg: cannot open kernel log (%s): %s.", | ||
1289 | 24 | _PATH_KLOG, rs_strerror_r(errno, errmsg, sizeof(errmsg))); | ||
1290 | 19 | ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG); | 25 | ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG); |
1291 | 20 | } | 26 | } |
1292 | 21 | 27 | ||
1298 | 22 | + /* make sure the kernel log is readable */ | 28 | +finalize_it: |
1299 | 23 | + /* this normally returns EINVAL - on an OpenVZ VM, we get EBADF */ | 29 | + RETiRet; |
1300 | 24 | + i = read(fklog, NULL, 0); | 30 | +} |
1301 | 25 | + if (i < 0 && errno == EBADF) { | 31 | + |
1302 | 26 | + imkmsgLogIntMsg(RS_RET_ERR_OPEN_KLOG, "imkmsg: cannot read kernel log(%s): %s.", | 32 | +/* make sure the kernel log is readable after dropping privileges |
1303 | 33 | + */ | ||
1304 | 34 | +rsRetVal | ||
1305 | 35 | +klogWillRunPostPrivDrop(modConfData_t *pModConf) | ||
1306 | 36 | +{ | ||
1307 | 37 | + char errmsg[2048]; | ||
1308 | 38 | + int r; | ||
1309 | 39 | + DEFiRet; | ||
1310 | 40 | + | ||
1311 | 41 | + /* this normally returns EINVAL */ | ||
1312 | 42 | + /* on an OpenVZ VM, we get EPERM */ | ||
1313 | 43 | + r = read(fklog, NULL, 0); | ||
1314 | 44 | + if (r < 0 && errno != EINVAL) { | ||
1315 | 45 | + imkmsgLogIntMsg(LOG_ERR, "imkmsg: cannot open kernel log (%s): %s.", | ||
1316 | 27 | + _PATH_KLOG, rs_strerror_r(errno, errmsg, sizeof(errmsg))); | 46 | + _PATH_KLOG, rs_strerror_r(errno, errmsg, sizeof(errmsg))); |
1317 | 28 | + fklog = -1; | 47 | + fklog = -1; |
1318 | 29 | + ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG); | 48 | + ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG); |
1319 | @@ -32,10 +51,10 @@ | |||
1320 | 32 | finalize_it: | 51 | finalize_it: |
1321 | 33 | RETiRet; | 52 | RETiRet; |
1322 | 34 | } | 53 | } |
1324 | 35 | Index: rsyslog-7.4.4/runtime/rsyslog.h | 54 | Index: rsyslog.trusty/runtime/rsyslog.h |
1325 | 36 | =================================================================== | 55 | =================================================================== |
1328 | 37 | --- rsyslog-7.4.4.orig/runtime/rsyslog.h | 56 | --- rsyslog.trusty.orig/runtime/rsyslog.h |
1329 | 38 | +++ rsyslog-7.4.4/runtime/rsyslog.h | 57 | +++ rsyslog.trusty/runtime/rsyslog.h |
1330 | 39 | @@ -358,7 +358,7 @@ enum rsRetVal_ /** return value. All | 58 | @@ -358,7 +358,7 @@ enum rsRetVal_ /** return value. All |
1331 | 40 | RS_RET_VAR_NOT_FOUND = -2142, /**< variable not found */ | 59 | RS_RET_VAR_NOT_FOUND = -2142, /**< variable not found */ |
1332 | 41 | RS_RET_EMPTY_MSG = -2143, /**< provided (raw) MSG is empty */ | 60 | RS_RET_EMPTY_MSG = -2143, /**< provided (raw) MSG is empty */ |
1333 | @@ -45,3 +64,126 @@ | |||
1334 | 45 | RS_RET_ERR_AQ_CONLOG = -2146, /**< error aquiring console log (on solaris) */ | 64 | RS_RET_ERR_AQ_CONLOG = -2146, /**< error aquiring console log (on solaris) */ |
1335 | 46 | RS_RET_ERR_DOOR = -2147, /**< some problems with handling the Solaris door functionality */ | 65 | RS_RET_ERR_DOOR = -2147, /**< some problems with handling the Solaris door functionality */ |
1336 | 47 | RS_RET_NO_SRCNAME_TPL = -2150, /**< sourcename template was not specified where one was needed (omudpspoof spoof addr) */ | 66 | RS_RET_NO_SRCNAME_TPL = -2150, /**< sourcename template was not specified where one was needed (omudpspoof spoof addr) */ |
1337 | 67 | Index: rsyslog.trusty/plugins/imklog/bsd.c | ||
1338 | 68 | =================================================================== | ||
1339 | 69 | --- rsyslog.trusty.orig/plugins/imklog/bsd.c | ||
1340 | 70 | +++ rsyslog.trusty/plugins/imklog/bsd.c | ||
1341 | 71 | @@ -164,7 +164,7 @@ static uchar *GetPath(modConfData_t *pMo | ||
1342 | 72 | * entry point. -- rgerhards, 2008-04-09 | ||
1343 | 73 | */ | ||
1344 | 74 | rsRetVal | ||
1345 | 75 | -klogWillRun(modConfData_t *pModConf) | ||
1346 | 76 | +klogWillRunPrePrivDrop(modConfData_t *pModConf) | ||
1347 | 77 | { | ||
1348 | 78 | char errmsg[2048]; | ||
1349 | 79 | int r; | ||
1350 | 80 | @@ -172,7 +172,7 @@ klogWillRun(modConfData_t *pModConf) | ||
1351 | 81 | |||
1352 | 82 | fklog = open((char*)GetPath(pModConf), O_RDONLY, 0); | ||
1353 | 83 | if (fklog < 0) { | ||
1354 | 84 | - imklogLogIntMsg(LOG_ERR, "imklog: cannot open kernel log(%s): %s.", | ||
1355 | 85 | + imklogLogIntMsg(LOG_ERR, "imklog: cannot open kernel log (%s): %s.", | ||
1356 | 86 | GetPath(pModConf), rs_strerror_r(errno, errmsg, sizeof(errmsg))); | ||
1357 | 87 | ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG); | ||
1358 | 88 | } | ||
1359 | 89 | @@ -192,6 +192,29 @@ klogWillRun(modConfData_t *pModConf) | ||
1360 | 90 | |||
1361 | 91 | finalize_it: | ||
1362 | 92 | RETiRet; | ||
1363 | 93 | +} | ||
1364 | 94 | + | ||
1365 | 95 | +/* make sure the kernel log is readable after dropping privileges | ||
1366 | 96 | + */ | ||
1367 | 97 | +rsRetVal | ||
1368 | 98 | +klogWillRunPostPrivDrop(modConfData_t *pModConf) | ||
1369 | 99 | +{ | ||
1370 | 100 | + char errmsg[2048]; | ||
1371 | 101 | + int r; | ||
1372 | 102 | + DEFiRet; | ||
1373 | 103 | + | ||
1374 | 104 | + /* this normally returns EINVAL */ | ||
1375 | 105 | + /* on an OpenVZ VM, we get EPERM */ | ||
1376 | 106 | + r = read(fklog, NULL, 0); | ||
1377 | 107 | + if (r < 0 && errno != EINVAL) { | ||
1378 | 108 | + imklogLogIntMsg(LOG_ERR, "imklog: cannot open kernel log (%s): %s.", | ||
1379 | 109 | + GetPath(pModConf), rs_strerror_r(errno, errmsg, sizeof(errmsg))); | ||
1380 | 110 | + fklog = -1; | ||
1381 | 111 | + ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG); | ||
1382 | 112 | + } | ||
1383 | 113 | + | ||
1384 | 114 | +finalize_it: | ||
1385 | 115 | + RETiRet; | ||
1386 | 116 | } | ||
1387 | 117 | |||
1388 | 118 | |||
1389 | 119 | Index: rsyslog.trusty/plugins/imklog/imklog.c | ||
1390 | 120 | =================================================================== | ||
1391 | 121 | --- rsyslog.trusty.orig/plugins/imklog/imklog.c | ||
1392 | 122 | +++ rsyslog.trusty/plugins/imklog/imklog.c | ||
1393 | 123 | @@ -382,7 +382,7 @@ ENDcheckCnf | ||
1394 | 124 | BEGINactivateCnfPrePrivDrop | ||
1395 | 125 | CODESTARTactivateCnfPrePrivDrop | ||
1396 | 126 | runModConf = pModConf; | ||
1397 | 127 | - iRet = klogWillRun(runModConf); | ||
1398 | 128 | + iRet = klogWillRunPrePrivDrop(runModConf); | ||
1399 | 129 | ENDactivateCnfPrePrivDrop | ||
1400 | 130 | |||
1401 | 131 | |||
1402 | 132 | @@ -398,6 +398,7 @@ ENDfreeCnf | ||
1403 | 133 | |||
1404 | 134 | BEGINwillRun | ||
1405 | 135 | CODESTARTwillRun | ||
1406 | 136 | + iRet = klogWillRunPostPrivDrop(runModConf); | ||
1407 | 137 | ENDwillRun | ||
1408 | 138 | |||
1409 | 139 | |||
1410 | 140 | Index: rsyslog.trusty/plugins/imklog/imklog.h | ||
1411 | 141 | =================================================================== | ||
1412 | 142 | --- rsyslog.trusty.orig/plugins/imklog/imklog.h | ||
1413 | 143 | +++ rsyslog.trusty/plugins/imklog/imklog.h | ||
1414 | 144 | @@ -48,8 +48,9 @@ struct modConfData_s { | ||
1415 | 145 | * rgerhards, 2008-04-09 | ||
1416 | 146 | */ | ||
1417 | 147 | rsRetVal klogLogKMsg(modConfData_t *pModConf); | ||
1418 | 148 | -rsRetVal klogWillRun(modConfData_t *pModConf); | ||
1419 | 149 | rsRetVal klogAfterRun(modConfData_t *pModConf); | ||
1420 | 150 | +rsRetVal klogWillRunPrePrivDrop(modConfData_t *pModConf); | ||
1421 | 151 | +rsRetVal klogWillRunPostPrivDrop(modConfData_t *pModConf); | ||
1422 | 152 | int klogFacilIntMsg(); | ||
1423 | 153 | |||
1424 | 154 | /* the functions below may be called by the drivers */ | ||
1425 | 155 | Index: rsyslog.trusty/plugins/imkmsg/imkmsg.c | ||
1426 | 156 | =================================================================== | ||
1427 | 157 | --- rsyslog.trusty.orig/plugins/imkmsg/imkmsg.c | ||
1428 | 158 | +++ rsyslog.trusty/plugins/imkmsg/imkmsg.c | ||
1429 | 159 | @@ -209,7 +209,7 @@ ENDcheckCnf | ||
1430 | 160 | BEGINactivateCnfPrePrivDrop | ||
1431 | 161 | CODESTARTactivateCnfPrePrivDrop | ||
1432 | 162 | runModConf = pModConf; | ||
1433 | 163 | - iRet = klogWillRun(runModConf); | ||
1434 | 164 | + iRet = klogWillRunPrePrivDrop(runModConf); | ||
1435 | 165 | ENDactivateCnfPrePrivDrop | ||
1436 | 166 | |||
1437 | 167 | |||
1438 | 168 | @@ -225,6 +225,7 @@ ENDfreeCnf | ||
1439 | 169 | |||
1440 | 170 | BEGINwillRun | ||
1441 | 171 | CODESTARTwillRun | ||
1442 | 172 | + iRet = klogWillRunPostPrivDrop(runModConf); | ||
1443 | 173 | ENDwillRun | ||
1444 | 174 | |||
1445 | 175 | |||
1446 | 176 | Index: rsyslog.trusty/plugins/imkmsg/imkmsg.h | ||
1447 | 177 | =================================================================== | ||
1448 | 178 | --- rsyslog.trusty.orig/plugins/imkmsg/imkmsg.h | ||
1449 | 179 | +++ rsyslog.trusty/plugins/imkmsg/imkmsg.h | ||
1450 | 180 | @@ -42,7 +42,8 @@ struct modConfData_s { | ||
1451 | 181 | * rgerhards, 2008-04-09 | ||
1452 | 182 | */ | ||
1453 | 183 | rsRetVal klogLogKMsg(modConfData_t *pModConf); | ||
1454 | 184 | -rsRetVal klogWillRun(modConfData_t *pModConf); | ||
1455 | 185 | +rsRetVal klogWillRunPrePrivDrop(modConfData_t *pModConf); | ||
1456 | 186 | +rsRetVal klogWillRunPostPrivDrop(modConfData_t *pModConf); | ||
1457 | 187 | rsRetVal klogAfterRun(modConfData_t *pModConf); | ||
1458 | 188 | int klogFacilIntMsg(); | ||
1459 | 189 | |||
1460 | 48 | 190 | ||
1461 | === modified file 'plugins/imklog/bsd.c' | |||
1462 | --- plugins/imklog/bsd.c 2013-03-18 16:21:35 +0000 | |||
1463 | +++ plugins/imklog/bsd.c 2015-01-09 16:11:08 +0000 | |||
1464 | @@ -164,7 +164,7 @@ | |||
1465 | 164 | * entry point. -- rgerhards, 2008-04-09 | 164 | * entry point. -- rgerhards, 2008-04-09 |
1466 | 165 | */ | 165 | */ |
1467 | 166 | rsRetVal | 166 | rsRetVal |
1469 | 167 | klogWillRun(modConfData_t *pModConf) | 167 | klogWillRunPrePrivDrop(modConfData_t *pModConf) |
1470 | 168 | { | 168 | { |
1471 | 169 | char errmsg[2048]; | 169 | char errmsg[2048]; |
1472 | 170 | int r; | 170 | int r; |
1473 | @@ -172,7 +172,7 @@ | |||
1474 | 172 | 172 | ||
1475 | 173 | fklog = open((char*)GetPath(pModConf), O_RDONLY, 0); | 173 | fklog = open((char*)GetPath(pModConf), O_RDONLY, 0); |
1476 | 174 | if (fklog < 0) { | 174 | if (fklog < 0) { |
1478 | 175 | imklogLogIntMsg(LOG_ERR, "imklog: cannot open kernel log(%s): %s.", | 175 | imklogLogIntMsg(LOG_ERR, "imklog: cannot open kernel log (%s): %s.", |
1479 | 176 | GetPath(pModConf), rs_strerror_r(errno, errmsg, sizeof(errmsg))); | 176 | GetPath(pModConf), rs_strerror_r(errno, errmsg, sizeof(errmsg))); |
1480 | 177 | ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG); | 177 | ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG); |
1481 | 178 | } | 178 | } |
1482 | @@ -194,6 +194,29 @@ | |||
1483 | 194 | RETiRet; | 194 | RETiRet; |
1484 | 195 | } | 195 | } |
1485 | 196 | 196 | ||
1486 | 197 | /* make sure the kernel log is readable after dropping privileges | ||
1487 | 198 | */ | ||
1488 | 199 | rsRetVal | ||
1489 | 200 | klogWillRunPostPrivDrop(modConfData_t *pModConf) | ||
1490 | 201 | { | ||
1491 | 202 | char errmsg[2048]; | ||
1492 | 203 | int r; | ||
1493 | 204 | DEFiRet; | ||
1494 | 205 | |||
1495 | 206 | /* this normally returns EINVAL */ | ||
1496 | 207 | /* on an OpenVZ VM, we get EPERM */ | ||
1497 | 208 | r = read(fklog, NULL, 0); | ||
1498 | 209 | if (r < 0 && errno != EINVAL) { | ||
1499 | 210 | imklogLogIntMsg(LOG_ERR, "imklog: cannot open kernel log (%s): %s.", | ||
1500 | 211 | GetPath(pModConf), rs_strerror_r(errno, errmsg, sizeof(errmsg))); | ||
1501 | 212 | fklog = -1; | ||
1502 | 213 | ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG); | ||
1503 | 214 | } | ||
1504 | 215 | |||
1505 | 216 | finalize_it: | ||
1506 | 217 | RETiRet; | ||
1507 | 218 | } | ||
1508 | 219 | |||
1509 | 197 | 220 | ||
1510 | 198 | /* Read kernel log while data are available, split into lines. | 221 | /* Read kernel log while data are available, split into lines. |
1511 | 199 | */ | 222 | */ |
1512 | 200 | 223 | ||
1513 | === modified file 'plugins/imklog/imklog.c' | |||
1514 | --- plugins/imklog/imklog.c 2014-10-02 11:32:50 +0000 | |||
1515 | +++ plugins/imklog/imklog.c 2015-01-09 16:11:08 +0000 | |||
1516 | @@ -382,7 +382,7 @@ | |||
1517 | 382 | BEGINactivateCnfPrePrivDrop | 382 | BEGINactivateCnfPrePrivDrop |
1518 | 383 | CODESTARTactivateCnfPrePrivDrop | 383 | CODESTARTactivateCnfPrePrivDrop |
1519 | 384 | runModConf = pModConf; | 384 | runModConf = pModConf; |
1521 | 385 | iRet = klogWillRun(runModConf); | 385 | iRet = klogWillRunPrePrivDrop(runModConf); |
1522 | 386 | ENDactivateCnfPrePrivDrop | 386 | ENDactivateCnfPrePrivDrop |
1523 | 387 | 387 | ||
1524 | 388 | 388 | ||
1525 | @@ -398,6 +398,7 @@ | |||
1526 | 398 | 398 | ||
1527 | 399 | BEGINwillRun | 399 | BEGINwillRun |
1528 | 400 | CODESTARTwillRun | 400 | CODESTARTwillRun |
1529 | 401 | iRet = klogWillRunPostPrivDrop(runModConf); | ||
1530 | 401 | ENDwillRun | 402 | ENDwillRun |
1531 | 402 | 403 | ||
1532 | 403 | 404 | ||
1533 | 404 | 405 | ||
1534 | === modified file 'plugins/imklog/imklog.h' | |||
1535 | --- plugins/imklog/imklog.h 2013-03-18 16:21:35 +0000 | |||
1536 | +++ plugins/imklog/imklog.h 2015-01-09 16:11:08 +0000 | |||
1537 | @@ -48,8 +48,9 @@ | |||
1538 | 48 | * rgerhards, 2008-04-09 | 48 | * rgerhards, 2008-04-09 |
1539 | 49 | */ | 49 | */ |
1540 | 50 | rsRetVal klogLogKMsg(modConfData_t *pModConf); | 50 | rsRetVal klogLogKMsg(modConfData_t *pModConf); |
1541 | 51 | rsRetVal klogWillRun(modConfData_t *pModConf); | ||
1542 | 52 | rsRetVal klogAfterRun(modConfData_t *pModConf); | 51 | rsRetVal klogAfterRun(modConfData_t *pModConf); |
1543 | 52 | rsRetVal klogWillRunPrePrivDrop(modConfData_t *pModConf); | ||
1544 | 53 | rsRetVal klogWillRunPostPrivDrop(modConfData_t *pModConf); | ||
1545 | 53 | int klogFacilIntMsg(); | 54 | int klogFacilIntMsg(); |
1546 | 54 | 55 | ||
1547 | 55 | /* the functions below may be called by the drivers */ | 56 | /* the functions below may be called by the drivers */ |
1548 | 56 | 57 | ||
1549 | === modified file 'plugins/imkmsg/imkmsg.c' | |||
1550 | --- plugins/imkmsg/imkmsg.c 2014-10-02 11:32:50 +0000 | |||
1551 | +++ plugins/imkmsg/imkmsg.c 2015-01-09 16:11:08 +0000 | |||
1552 | @@ -209,7 +209,7 @@ | |||
1553 | 209 | BEGINactivateCnfPrePrivDrop | 209 | BEGINactivateCnfPrePrivDrop |
1554 | 210 | CODESTARTactivateCnfPrePrivDrop | 210 | CODESTARTactivateCnfPrePrivDrop |
1555 | 211 | runModConf = pModConf; | 211 | runModConf = pModConf; |
1557 | 212 | iRet = klogWillRun(runModConf); | 212 | iRet = klogWillRunPrePrivDrop(runModConf); |
1558 | 213 | ENDactivateCnfPrePrivDrop | 213 | ENDactivateCnfPrePrivDrop |
1559 | 214 | 214 | ||
1560 | 215 | 215 | ||
1561 | @@ -225,6 +225,7 @@ | |||
1562 | 225 | 225 | ||
1563 | 226 | BEGINwillRun | 226 | BEGINwillRun |
1564 | 227 | CODESTARTwillRun | 227 | CODESTARTwillRun |
1565 | 228 | iRet = klogWillRunPostPrivDrop(runModConf); | ||
1566 | 228 | ENDwillRun | 229 | ENDwillRun |
1567 | 229 | 230 | ||
1568 | 230 | 231 | ||
1569 | 231 | 232 | ||
1570 | === modified file 'plugins/imkmsg/imkmsg.h' | |||
1571 | --- plugins/imkmsg/imkmsg.h 2012-10-29 16:30:14 +0000 | |||
1572 | +++ plugins/imkmsg/imkmsg.h 2015-01-09 16:11:08 +0000 | |||
1573 | @@ -42,7 +42,8 @@ | |||
1574 | 42 | * rgerhards, 2008-04-09 | 42 | * rgerhards, 2008-04-09 |
1575 | 43 | */ | 43 | */ |
1576 | 44 | rsRetVal klogLogKMsg(modConfData_t *pModConf); | 44 | rsRetVal klogLogKMsg(modConfData_t *pModConf); |
1578 | 45 | rsRetVal klogWillRun(modConfData_t *pModConf); | 45 | rsRetVal klogWillRunPrePrivDrop(modConfData_t *pModConf); |
1579 | 46 | rsRetVal klogWillRunPostPrivDrop(modConfData_t *pModConf); | ||
1580 | 46 | rsRetVal klogAfterRun(modConfData_t *pModConf); | 47 | rsRetVal klogAfterRun(modConfData_t *pModConf); |
1581 | 47 | int klogFacilIntMsg(); | 48 | int klogFacilIntMsg(); |
1582 | 48 | 49 | ||
1583 | 49 | 50 | ||
1584 | === modified file 'plugins/imkmsg/kmsg.c' | |||
1585 | --- plugins/imkmsg/kmsg.c 2015-01-05 10:52:48 +0000 | |||
1586 | +++ plugins/imkmsg/kmsg.c 2015-01-09 16:11:08 +0000 | |||
1587 | @@ -155,24 +155,36 @@ | |||
1588 | 155 | /* open the kernel log - will be called inside the willRun() imkmsg entry point | 155 | /* open the kernel log - will be called inside the willRun() imkmsg entry point |
1589 | 156 | */ | 156 | */ |
1590 | 157 | rsRetVal | 157 | rsRetVal |
1592 | 158 | klogWillRun(modConfData_t *pModConf) | 158 | klogWillRunPrePrivDrop(modConfData_t *pModConf) |
1593 | 159 | { | 159 | { |
1594 | 160 | int i; | ||
1595 | 161 | char errmsg[2048]; | 160 | char errmsg[2048]; |
1596 | 162 | DEFiRet; | 161 | DEFiRet; |
1597 | 163 | 162 | ||
1598 | 164 | fklog = open(_PATH_KLOG, O_RDONLY, 0); | 163 | fklog = open(_PATH_KLOG, O_RDONLY, 0); |
1599 | 165 | if (fklog < 0) { | 164 | if (fklog < 0) { |
1601 | 166 | imkmsgLogIntMsg(RS_RET_ERR_OPEN_KLOG, "imkmsg: cannot open kernel log(%s): %s.", | 165 | imkmsgLogIntMsg(LOG_ERR, "imkmsg: cannot open kernel log (%s): %s.", |
1602 | 167 | _PATH_KLOG, rs_strerror_r(errno, errmsg, sizeof(errmsg))); | 166 | _PATH_KLOG, rs_strerror_r(errno, errmsg, sizeof(errmsg))); |
1603 | 168 | ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG); | 167 | ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG); |
1604 | 169 | } | 168 | } |
1605 | 170 | 169 | ||
1611 | 171 | /* make sure the kernel log is readable */ | 170 | finalize_it: |
1612 | 172 | /* this normally returns EINVAL - on an OpenVZ VM, we get EBADF */ | 171 | RETiRet; |
1613 | 173 | i = read(fklog, NULL, 0); | 172 | } |
1614 | 174 | if (i < 0 && errno == EBADF) { | 173 | |
1615 | 175 | imkmsgLogIntMsg(RS_RET_ERR_OPEN_KLOG, "imkmsg: cannot read kernel log(%s): %s.", | 174 | /* make sure the kernel log is readable after dropping privileges |
1616 | 175 | */ | ||
1617 | 176 | rsRetVal | ||
1618 | 177 | klogWillRunPostPrivDrop(modConfData_t *pModConf) | ||
1619 | 178 | { | ||
1620 | 179 | char errmsg[2048]; | ||
1621 | 180 | int r; | ||
1622 | 181 | DEFiRet; | ||
1623 | 182 | |||
1624 | 183 | /* this normally returns EINVAL */ | ||
1625 | 184 | /* on an OpenVZ VM, we get EPERM */ | ||
1626 | 185 | r = read(fklog, NULL, 0); | ||
1627 | 186 | if (r < 0 && errno != EINVAL) { | ||
1628 | 187 | imkmsgLogIntMsg(LOG_ERR, "imkmsg: cannot open kernel log (%s): %s.", | ||
1629 | 176 | _PATH_KLOG, rs_strerror_r(errno, errmsg, sizeof(errmsg))); | 188 | _PATH_KLOG, rs_strerror_r(errno, errmsg, sizeof(errmsg))); |
1630 | 177 | fklog = -1; | 189 | fklog = -1; |
1631 | 178 | ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG); | 190 | ABORT_FINALIZE(RS_RET_ERR_OPEN_KLOG); |