~arges/ubuntu/quantal/rsyslog/fix-lp1059592

« back to all changes in this revision

Viewing changes to conf.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2009-02-15 21:56:23 UTC
  • mto: (3.2.4 squeeze) (1.1.9 upstream)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20090215215623-xsycf628eo3kguc0
Tags: upstream-3.20.4
ImportĀ upstreamĀ versionĀ 3.20.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The config file handler (not yet a real object)
2
 
 *
3
 
 * This file is based on an excerpt from syslogd.c, which dates back
4
 
 * much later. I began the file on 2008-02-19 as part of the modularization
5
 
 * effort. Over time, a clean abstration will become even more important
6
 
 * because the config file handler will by dynamically be loaded and be
7
 
 * kept in memory only as long as the config file is actually being 
8
 
 * processed. Thereafter, it shall be unloaded. -- rgerhards
9
 
 *
10
 
 * Copyright 2008 Rainer Gerhards and Adiscon GmbH.
11
 
 *
12
 
 * This file is part of rsyslog.
13
 
 *
14
 
 * Rsyslog is free software: you can redistribute it and/or modify
15
 
 * it under the terms of the GNU General Public License as published by
16
 
 * the Free Software Foundation, either version 3 of the License, or
17
 
 * (at your option) any later version.
18
 
 *
19
 
 * Rsyslog is distributed in the hope that it will be useful,
20
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 
 * GNU General Public License for more details.
23
 
 *
24
 
 * You should have received a copy of the GNU General Public License
25
 
 * along with Rsyslog.  If not, see <http://www.gnu.org/licenses/>.
26
 
 *
27
 
 * A copy of the GPL can be found in the file "COPYING" in this distribution.
28
 
 */
29
 
 
30
 
#include "config.h"
31
 
#include <stdlib.h>
32
 
#include <stdio.h>
33
 
#include <stddef.h>
34
 
#include <string.h>
35
 
#include <dlfcn.h>
36
 
#include <sys/stat.h>
37
 
#include <errno.h>
38
 
#include <ctype.h>
39
 
#include <assert.h>
40
 
#include <dirent.h>
41
 
#include <glob.h>
42
 
#include <sys/types.h>
43
 
#ifdef HAVE_LIBGEN_H
44
 
#       include <libgen.h>
45
 
#endif
46
 
 
47
 
#include "rsyslog.h"
48
 
#include "syslogd.h"
49
 
#include "parse.h"
50
 
#include "action.h"
51
 
#include "template.h"
52
 
#include "cfsysline.h"
53
 
#include "modules.h"
54
 
#include "outchannel.h"
55
 
#include "stringbuf.h"
56
 
#include "conf.h"
57
 
#include "stringbuf.h"
58
 
#include "srUtils.h"
59
 
#include "errmsg.h"
60
 
 
61
 
 
62
 
/* forward definitions */
63
 
static rsRetVal cfline(uchar *line, selector_t **pfCurr);
64
 
static rsRetVal processConfFile(uchar *pConfFile);
65
 
 
66
 
 
67
 
/* static data */
68
 
DEFobjStaticHelpers
69
 
DEFobjCurrIf(expr)
70
 
DEFobjCurrIf(ctok)
71
 
DEFobjCurrIf(ctok_token)
72
 
DEFobjCurrIf(module)
73
 
DEFobjCurrIf(errmsg)
74
 
DEFobjCurrIf(net)
75
 
 
76
 
/* The following global variables are used for building
77
 
 * tag and host selector lines during startup and config reload.
78
 
 * This is stored as a global variable pool because of its ease. It is
79
 
 * also fairly compatible with multi-threading as the stratup code must
80
 
 * be run in a single thread anyways. So there can be no race conditions. These
81
 
 * variables are no longer used once the configuration has been loaded (except,
82
 
 * of course, during a reload). rgerhards 2005-10-18
83
 
 */
84
 
EHostnameCmpMode eDfltHostnameCmpMode;
85
 
cstr_t *pDfltHostnameCmp;
86
 
cstr_t *pDfltProgNameCmp;
87
 
 
88
 
 
89
 
/* process a directory and include all of its files into
90
 
 * the current config file. There is no specific order of inclusion,
91
 
 * files are included in the order they are read from the directory.
92
 
 * The caller must have make sure that the provided parameter is
93
 
 * indeed a directory.
94
 
 * rgerhards, 2007-08-01
95
 
 */
96
 
static rsRetVal doIncludeDirectory(uchar *pDirName)
97
 
{
98
 
        DEFiRet;
99
 
        int iEntriesDone = 0;
100
 
        DIR *pDir;
101
 
        union {
102
 
              struct dirent d;
103
 
              char b[offsetof(struct dirent, d_name) + NAME_MAX + 1];
104
 
        } u;
105
 
        struct dirent *res;
106
 
        size_t iDirNameLen;
107
 
        size_t iFileNameLen;
108
 
        uchar szFullFileName[MAXFNAME];
109
 
 
110
 
        ASSERT(pDirName != NULL);
111
 
 
112
 
        if((pDir = opendir((char*) pDirName)) == NULL) {
113
 
                errmsg.LogError(NO_ERRCODE, "error opening include directory");
114
 
                ABORT_FINALIZE(RS_RET_FOPEN_FAILURE);
115
 
        }
116
 
 
117
 
        /* prepare file name buffer */
118
 
        iDirNameLen = strlen((char*) pDirName);
119
 
        memcpy(szFullFileName, pDirName, iDirNameLen);
120
 
 
121
 
        /* now read the directory */
122
 
        iEntriesDone = 0;
123
 
        while(readdir_r(pDir, &u.d, &res) == 0) {
124
 
                if(res == NULL)
125
 
                        break; /* this also indicates end of directory */
126
 
#               ifdef DT_REG
127
 
                /* TODO: find an alternate way to checking for special files if this is
128
 
                 * not defined. This is currently a known problem on HP UX, but the work-
129
 
                 * around is simple: do not create special files in that directory. So 
130
 
                 * fixing this is actually not the most important thing on earth...
131
 
                 * rgerhards, 2008-03-04
132
 
                 */
133
 
                if(res->d_type != DT_REG)
134
 
                        continue; /* we are not interested in special files */
135
 
#               endif
136
 
                if(res->d_name[0] == '.')
137
 
                        continue; /* these files we are also not interested in */
138
 
                ++iEntriesDone;
139
 
                /* construct filename */
140
 
                iFileNameLen = strlen(res->d_name);
141
 
                if (iFileNameLen > NAME_MAX)
142
 
                        iFileNameLen = NAME_MAX;
143
 
                memcpy(szFullFileName + iDirNameLen, res->d_name, iFileNameLen);
144
 
                *(szFullFileName + iDirNameLen + iFileNameLen) = '\0';
145
 
                dbgprintf("including file '%s'\n", szFullFileName);
146
 
                processConfFile(szFullFileName);
147
 
                /* we deliberately ignore the iRet of processConfFile() - this is because
148
 
                 * failure to process one file does not mean all files will fail. By ignoring,
149
 
                 * we retry with the next file, which is the best thing we can do. -- rgerhards, 2007-08-01
150
 
                 */
151
 
        }
152
 
 
153
 
        if(iEntriesDone == 0) {
154
 
                /* I just make it a debug output, because I can think of a lot of cases where it
155
 
                 * makes sense not to have any files. E.g. a system maintainer may place a $Include
156
 
                 * into the config file just in case, when additional modules be installed. When none
157
 
                 * are installed, the directory will be empty, which is fine. -- rgerhards 2007-08-01
158
 
                 */
159
 
                dbgprintf("warning: the include directory contained no files - this may be ok.\n");
160
 
        }
161
 
 
162
 
finalize_it:
163
 
        if(pDir != NULL)
164
 
                closedir(pDir);
165
 
 
166
 
        RETiRet;
167
 
}
168
 
 
169
 
 
170
 
/* process a $include config line. That type of line requires
171
 
 * inclusion of another file.
172
 
 * rgerhards, 2007-08-01
173
 
 */
174
 
rsRetVal
175
 
doIncludeLine(uchar **pp, __attribute__((unused)) void* pVal)
176
 
{
177
 
        DEFiRet;
178
 
        char pattern[MAXFNAME];
179
 
        uchar *cfgFile;
180
 
        glob_t cfgFiles;
181
 
        size_t i = 0;
182
 
        struct stat fileInfo;
183
 
 
184
 
        ASSERT(pp != NULL);
185
 
        ASSERT(*pp != NULL);
186
 
 
187
 
        if(getSubString(pp, (char*) pattern, sizeof(pattern) / sizeof(char), ' ')  != 0) {
188
 
                errmsg.LogError(NO_ERRCODE, "could not extract group name");
189
 
                ABORT_FINALIZE(RS_RET_NOT_FOUND);
190
 
        }
191
 
 
192
 
        /* Use GLOB_MARK to append a trailing slash for directories.
193
 
         * Required by doIncludeDirectory().
194
 
         */
195
 
        glob(pattern, GLOB_MARK, NULL, &cfgFiles);
196
 
 
197
 
        for(i = 0; i < cfgFiles.gl_pathc; i++) {
198
 
                cfgFile = (uchar*) cfgFiles.gl_pathv[i];
199
 
 
200
 
                if(stat((char*) cfgFile, &fileInfo) != 0) 
201
 
                        continue; /* continue with the next file if we can't stat() the file */
202
 
 
203
 
                if(S_ISREG(fileInfo.st_mode)) { /* config file */
204
 
                        dbgprintf("requested to include config file '%s'\n", cfgFile);
205
 
                        iRet = processConfFile(cfgFile);
206
 
                } else if(S_ISDIR(fileInfo.st_mode)) { /* config directory */
207
 
                        dbgprintf("requested to include directory '%s'\n", cfgFile);
208
 
                        iRet = doIncludeDirectory(cfgFile);
209
 
                } else { /* TODO: shall we handle symlinks or not? */
210
 
                        dbgprintf("warning: unable to process IncludeConfig directive '%s'\n", cfgFile);
211
 
                }
212
 
        }
213
 
 
214
 
        globfree(&cfgFiles);
215
 
 
216
 
finalize_it:
217
 
        RETiRet;
218
 
}
219
 
 
220
 
 
221
 
/* process a $ModLoad config line.
222
 
 */
223
 
rsRetVal
224
 
doModLoad(uchar **pp, __attribute__((unused)) void* pVal)
225
 
{
226
 
        DEFiRet;
227
 
        uchar szName[512];
228
 
        uchar *pModName;
229
 
 
230
 
        ASSERT(pp != NULL);
231
 
        ASSERT(*pp != NULL);
232
 
 
233
 
        skipWhiteSpace(pp); /* skip over any whitespace */
234
 
        if(getSubString(pp, (char*) szName, sizeof(szName) / sizeof(uchar), ' ')  != 0) {
235
 
                errmsg.LogError(NO_ERRCODE, "could not extract module name");
236
 
                ABORT_FINALIZE(RS_RET_NOT_FOUND);
237
 
        }
238
 
        skipWhiteSpace(pp); /* skip over any whitespace */
239
 
 
240
 
        /* this below is a quick and dirty hack to provide compatibility with the
241
 
         * $ModLoad MySQL forward compatibility statement. TODO: clean this up
242
 
         * For the time being, it is clean enough, it just needs to be done
243
 
         * differently when we have a full design for loadable plug-ins. For the
244
 
         * time being, we just mangle the names a bit.
245
 
         * rgerhards, 2007-08-14
246
 
         */
247
 
        if(!strcmp((char*) szName, "MySQL"))
248
 
                pModName = (uchar*) "ommysql.so";
249
 
        else
250
 
                pModName = szName;
251
 
 
252
 
        CHKiRet(module.Load(pModName));
253
 
 
254
 
finalize_it:
255
 
        RETiRet;
256
 
}
257
 
 
258
 
 
259
 
/* parse and interpret a $-config line that starts with
260
 
 * a name (this is common code). It is parsed to the name
261
 
 * and then the proper sub-function is called to handle
262
 
 * the actual directive.
263
 
 * rgerhards 2004-11-17
264
 
 * rgerhards 2005-06-21: previously only for templates, now 
265
 
 *    generalized.
266
 
 */
267
 
rsRetVal
268
 
doNameLine(uchar **pp, void* pVal)
269
 
{
270
 
        DEFiRet;
271
 
        uchar *p;
272
 
        enum eDirective eDir;
273
 
        char szName[128];
274
 
 
275
 
        ASSERT(pp != NULL);
276
 
        p = *pp;
277
 
        ASSERT(p != NULL);
278
 
 
279
 
        eDir = (enum eDirective) pVal;  /* this time, it actually is NOT a pointer! */
280
 
 
281
 
        if(getSubString(&p, szName, sizeof(szName) / sizeof(char), ',')  != 0) {
282
 
                errmsg.LogError(NO_ERRCODE, "Invalid config line: could not extract name - line ignored");
283
 
                ABORT_FINALIZE(RS_RET_NOT_FOUND);
284
 
        }
285
 
        if(*p == ',')
286
 
                ++p; /* comma was eaten */
287
 
        
288
 
        /* we got the name - now we pass name & the rest of the string
289
 
         * to the subfunction. It makes no sense to do further
290
 
         * parsing here, as this is in close interaction with the
291
 
         * respective subsystem. rgerhards 2004-11-17
292
 
         */
293
 
        
294
 
        switch(eDir) {
295
 
                case DIR_TEMPLATE: 
296
 
                        tplAddLine(szName, &p);
297
 
                        break;
298
 
                case DIR_OUTCHANNEL: 
299
 
                        ochAddLine(szName, &p);
300
 
                        break;
301
 
                case DIR_ALLOWEDSENDER: 
302
 
                        net.addAllowedSenderLine(szName, &p);
303
 
                        break;
304
 
                default:/* we do this to avoid compiler warning - not all
305
 
                         * enum values call this function, so an incomplete list
306
 
                         * is quite ok (but then we should not run into this code,
307
 
                         * so at least we log a debug warning).
308
 
                         */
309
 
                        dbgprintf("INTERNAL ERROR: doNameLine() called with invalid eDir %d.\n",
310
 
                                eDir);
311
 
                        break;
312
 
        }
313
 
 
314
 
        *pp = p;
315
 
 
316
 
finalize_it:
317
 
        RETiRet;
318
 
}
319
 
 
320
 
 
321
 
/* Parse and interpret a system-directive in the config line
322
 
 * A system directive is one that starts with a "$" sign. It offers
323
 
 * extended configuration parameters.
324
 
 * 2004-11-17 rgerhards
325
 
 */
326
 
rsRetVal
327
 
cfsysline(uchar *p)
328
 
{
329
 
        DEFiRet;
330
 
        uchar szCmd[64];
331
 
        uchar errMsg[128];      /* for dynamic error messages */
332
 
 
333
 
        ASSERT(p != NULL);
334
 
        errno = 0;
335
 
        if(getSubString(&p, (char*) szCmd, sizeof(szCmd) / sizeof(uchar), ' ')  != 0) {
336
 
                errmsg.LogError(NO_ERRCODE, "Invalid $-configline - could not extract command - line ignored\n");
337
 
                ABORT_FINALIZE(RS_RET_NOT_FOUND);
338
 
        }
339
 
 
340
 
        /* we now try and see if we can find the command in the registered
341
 
         * list of cfsysline handlers. -- rgerhards, 2007-07-31
342
 
         */
343
 
        CHKiRet(processCfSysLineCommand(szCmd, &p));
344
 
 
345
 
        /* now check if we have some extra characters left on the line - that
346
 
         * should not be the case. Whitespace is OK, but everything else should
347
 
         * trigger a warning (that may be an indication of undesired behaviour).
348
 
         * An exception, of course, are comments (starting with '#').
349
 
         * rgerhards, 2007-07-04
350
 
         */
351
 
        skipWhiteSpace(&p);
352
 
 
353
 
        if(*p && *p != '#') { /* we have a non-whitespace, so let's complain */
354
 
                snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar),
355
 
                         "error: extra characters in config line ignored: '%s'", p);
356
 
                errno = 0;
357
 
                errmsg.LogError(NO_ERRCODE, "%s", errMsg);
358
 
        }
359
 
 
360
 
finalize_it:
361
 
        RETiRet;
362
 
}
363
 
 
364
 
 
365
 
 
366
 
 
367
 
/* process a configuration file
368
 
 * started with code from init() by rgerhards on 2007-07-31
369
 
 */
370
 
static rsRetVal
371
 
processConfFile(uchar *pConfFile)
372
 
{
373
 
        DEFiRet;
374
 
        int iLnNbr = 0;
375
 
        FILE *cf;
376
 
        selector_t *fCurr = NULL;
377
 
        uchar *p;
378
 
        uchar cbuf[BUFSIZ];
379
 
        uchar *cline;
380
 
        int i;
381
 
        ASSERT(pConfFile != NULL);
382
 
 
383
 
        if((cf = fopen((char*)pConfFile, "r")) == NULL) {
384
 
                ABORT_FINALIZE(RS_RET_FOPEN_FAILURE);
385
 
        }
386
 
 
387
 
        /* Now process the file.
388
 
         */
389
 
        cline = cbuf;
390
 
        while (fgets((char*)cline, sizeof(cbuf) - (cline - cbuf), cf) != NULL) {
391
 
                ++iLnNbr;
392
 
                /* drop LF - TODO: make it better, replace fgets(), but its clean as it is */
393
 
                if(cline[strlen((char*)cline)-1] == '\n') {
394
 
                        cline[strlen((char*)cline) -1] = '\0';
395
 
                }
396
 
                /* check for end-of-section, comments, strip off trailing
397
 
                 * spaces and newline character.
398
 
                 */
399
 
                p = cline;
400
 
                skipWhiteSpace(&p);
401
 
                if (*p == '\0' || *p == '#')
402
 
                        continue;
403
 
 
404
 
                /* we now need to copy the characters to the begin of line. As this overlaps,
405
 
                 * we can not use strcpy(). -- rgerhards, 2008-03-20
406
 
                 * TODO: review the code at whole - this is highly suspect (but will go away
407
 
                 * once we do the rest of RainerScript).
408
 
                 */
409
 
                /* was: strcpy((char*)cline, (char*)p); */
410
 
                for( i = 0 ; p[i] != '\0' ; ++i) {
411
 
                        cline[i] = p[i];
412
 
                }
413
 
                cline[i] = '\0';
414
 
 
415
 
                for (p = (uchar*) strchr((char*)cline, '\0'); isspace((int) *--p);)
416
 
                        /*EMPTY*/;
417
 
                if (*p == '\\') {
418
 
                        if ((p - cbuf) > BUFSIZ - 30) {
419
 
                                /* Oops the buffer is full - what now? */
420
 
                                cline = cbuf;
421
 
                        } else {
422
 
                                *p = 0;
423
 
                                cline = p;
424
 
                                continue;
425
 
                        }
426
 
                }  else
427
 
                        cline = cbuf;
428
 
                *++p = '\0'; /* TODO: check this */
429
 
 
430
 
                /* we now have the complete line, and are positioned at the first non-whitespace
431
 
                 * character. So let's process it
432
 
                 */
433
 
                if(cfline(cbuf, &fCurr) != RS_RET_OK) {
434
 
                        /* we log a message, but otherwise ignore the error. After all, the next
435
 
                         * line can be correct.  -- rgerhards, 2007-08-02
436
 
                         */
437
 
                        uchar szErrLoc[MAXFNAME + 64];
438
 
                        dbgprintf("config line NOT successfully processed\n");
439
 
                        snprintf((char*)szErrLoc, sizeof(szErrLoc) / sizeof(uchar),
440
 
                                 "%s, line %d", pConfFile, iLnNbr);
441
 
                        errmsg.LogError(NO_ERRCODE, "the last error occured in %s", (char*)szErrLoc);
442
 
                }
443
 
        }
444
 
 
445
 
        /* we probably have one selector left to be added - so let's do that now */
446
 
        CHKiRet(selectorAddList(fCurr));
447
 
 
448
 
        /* close the configuration file */
449
 
        (void) fclose(cf);
450
 
 
451
 
finalize_it:
452
 
        if(iRet != RS_RET_OK) {
453
 
                char errStr[1024];
454
 
                if(fCurr != NULL)
455
 
                        selectorDestruct(fCurr);
456
 
 
457
 
                rs_strerror_r(errno, errStr, sizeof(errStr));
458
 
                dbgprintf("error %d processing config file '%s'; os error (if any): %s\n",
459
 
                        iRet, pConfFile, errStr);
460
 
        }
461
 
        RETiRet;
462
 
}
463
 
 
464
 
 
465
 
/* Helper to cfline() and its helpers. Parses a template name
466
 
 * from an "action" line. Must be called with the Line pointer
467
 
 * pointing to the first character after the semicolon.
468
 
 * rgerhards 2004-11-19
469
 
 * changed function to work with OMSR. -- rgerhards, 2007-07-27
470
 
 * the default template is to be used when no template is specified.
471
 
 */
472
 
rsRetVal cflineParseTemplateName(uchar** pp, omodStringRequest_t *pOMSR, int iEntry, int iTplOpts, uchar *dfltTplName)
473
 
{
474
 
        uchar *p;
475
 
        uchar *tplName;
476
 
        cstr_t *pStrB;
477
 
        DEFiRet;
478
 
 
479
 
        ASSERT(pp != NULL);
480
 
        ASSERT(*pp != NULL);
481
 
        ASSERT(pOMSR != NULL);
482
 
 
483
 
        p =*pp;
484
 
        /* a template must follow - search it and complain, if not found */
485
 
        skipWhiteSpace(&p);
486
 
        if(*p == ';')
487
 
                ++p; /* eat it */
488
 
        else if(*p != '\0' && *p != '#') {
489
 
                errmsg.LogError(NO_ERRCODE, "invalid character in selector line - ';template' expected");
490
 
                ABORT_FINALIZE(RS_RET_ERR);
491
 
        }
492
 
 
493
 
        skipWhiteSpace(&p); /* go to begin of template name */
494
 
 
495
 
        if(*p == '\0' || *p == '#') {
496
 
                /* no template specified, use the default */
497
 
                /* TODO: check NULL ptr */
498
 
                tplName = (uchar*) strdup((char*)dfltTplName);
499
 
        } else {
500
 
                /* template specified, pick it up */
501
 
                if(rsCStrConstruct(&pStrB) != RS_RET_OK) {
502
 
                        glblHadMemShortage = 1;
503
 
                        iRet = RS_RET_OUT_OF_MEMORY;
504
 
                        goto finalize_it;
505
 
                }
506
 
 
507
 
                /* now copy the string */
508
 
                while(*p && *p != '#' && !isspace((int) *p)) {
509
 
                        CHKiRet(rsCStrAppendChar(pStrB, *p));
510
 
                        ++p;
511
 
                }
512
 
                CHKiRet(rsCStrFinish(pStrB));
513
 
                CHKiRet(rsCStrConvSzStrAndDestruct(pStrB, &tplName, 0));
514
 
        }
515
 
 
516
 
        iRet = OMSRsetEntry(pOMSR, iEntry, tplName, iTplOpts);
517
 
        if(iRet != RS_RET_OK) goto finalize_it;
518
 
 
519
 
finalize_it:
520
 
        *pp = p;
521
 
 
522
 
        RETiRet;
523
 
}
524
 
 
525
 
/* Helper to cfline(). Parses a file name up until the first
526
 
 * comma and then looks for the template specifier. Tries
527
 
 * to find that template.
528
 
 * rgerhards 2004-11-18
529
 
 * parameter pFileName must point to a buffer large enough
530
 
 * to hold the largest possible filename.
531
 
 * rgerhards, 2007-07-25
532
 
 * updated to include OMSR pointer -- rgerhards, 2007-07-27
533
 
 * updated to include template name -- rgerhards, 2008-03-28
534
 
 */
535
 
rsRetVal
536
 
cflineParseFileName(uchar* p, uchar *pFileName, omodStringRequest_t *pOMSR, int iEntry, int iTplOpts, uchar *pszTpl)
537
 
{
538
 
        register uchar *pName;
539
 
        int i;
540
 
        DEFiRet;
541
 
 
542
 
        ASSERT(pOMSR != NULL);
543
 
 
544
 
        pName = pFileName;
545
 
        i = 1; /* we start at 1 so that we reseve space for the '\0'! */
546
 
        while(*p && *p != ';' && i < MAXFNAME) {
547
 
                *pName++ = *p++;
548
 
                ++i;
549
 
        }
550
 
        *pName = '\0';
551
 
 
552
 
        iRet = cflineParseTemplateName(&p, pOMSR, iEntry, iTplOpts, pszTpl);
553
 
 
554
 
        RETiRet;
555
 
}
556
 
 
557
 
 
558
 
/*
559
 
 * Helper to cfline(). This function takes the filter part of a traditional, PRI
560
 
 * based line and decodes the PRIs given in the selector line. It processed the
561
 
 * line up to the beginning of the action part. A pointer to that beginnig is
562
 
 * passed back to the caller.
563
 
 * rgerhards 2005-09-15
564
 
 */
565
 
static rsRetVal cflineProcessTradPRIFilter(uchar **pline, register selector_t *f)
566
 
{
567
 
        uchar *p;
568
 
        register uchar *q;
569
 
        register int i, i2;
570
 
        uchar *bp;
571
 
        int pri;
572
 
        int singlpri = 0;
573
 
        int ignorepri = 0;
574
 
        uchar buf[MAXLINE];
575
 
        uchar xbuf[200];
576
 
 
577
 
        ASSERT(pline != NULL);
578
 
        ASSERT(*pline != NULL);
579
 
        ASSERT(f != NULL);
580
 
 
581
 
        dbgprintf(" - traditional PRI filter\n");
582
 
        errno = 0;      /* keep strerror_r() stuff out of logerror messages */
583
 
 
584
 
        f->f_filter_type = FILTER_PRI;
585
 
        /* Note: file structure is pre-initialized to zero because it was
586
 
         * created with calloc()!
587
 
         */
588
 
        for (i = 0; i <= LOG_NFACILITIES; i++) {
589
 
                f->f_filterData.f_pmask[i] = TABLE_NOPRI;
590
 
        }
591
 
 
592
 
        /* scan through the list of selectors */
593
 
        for (p = *pline; *p && *p != '\t' && *p != ' ';) {
594
 
 
595
 
                /* find the end of this facility name list */
596
 
                for (q = p; *q && *q != '\t' && *q++ != '.'; )
597
 
                        continue;
598
 
 
599
 
                /* collect priority name */
600
 
                for (bp = buf; *q && !strchr("\t ,;", *q); )
601
 
                        *bp++ = *q++;
602
 
                *bp = '\0';
603
 
 
604
 
                /* skip cruft */
605
 
                while (strchr(",;", *q))
606
 
                        q++;
607
 
 
608
 
                /* decode priority name */
609
 
                if ( *buf == '!' ) {
610
 
                        ignorepri = 1;
611
 
                        for (bp=buf; *(bp+1); bp++)
612
 
                                *bp=*(bp+1);
613
 
                        *bp='\0';
614
 
                }
615
 
                else {
616
 
                        ignorepri = 0;
617
 
                }
618
 
                if ( *buf == '=' )
619
 
                {
620
 
                        singlpri = 1;
621
 
                        pri = decodeSyslogName(&buf[1], syslogPriNames);
622
 
                }
623
 
                else {
624
 
                        singlpri = 0;
625
 
                        pri = decodeSyslogName(buf, syslogPriNames);
626
 
                }
627
 
 
628
 
                if (pri < 0) {
629
 
                        snprintf((char*) xbuf, sizeof(xbuf), "unknown priority name \"%s\"", buf);
630
 
                        errmsg.LogError(NO_ERRCODE, "%s", xbuf);
631
 
                        return RS_RET_ERR;
632
 
                }
633
 
 
634
 
                /* scan facilities */
635
 
                while (*p && !strchr("\t .;", *p)) {
636
 
                        for (bp = buf; *p && !strchr("\t ,;.", *p); )
637
 
                                *bp++ = *p++;
638
 
                        *bp = '\0';
639
 
                        if (*buf == '*') {
640
 
                                for (i = 0; i <= LOG_NFACILITIES; i++) {
641
 
                                        if ( pri == INTERNAL_NOPRI ) {
642
 
                                                if ( ignorepri )
643
 
                                                        f->f_filterData.f_pmask[i] = TABLE_ALLPRI;
644
 
                                                else
645
 
                                                        f->f_filterData.f_pmask[i] = TABLE_NOPRI;
646
 
                                        }
647
 
                                        else if ( singlpri ) {
648
 
                                                if ( ignorepri )
649
 
                                                        f->f_filterData.f_pmask[i] &= ~(1<<pri);
650
 
                                                else
651
 
                                                        f->f_filterData.f_pmask[i] |= (1<<pri);
652
 
                                        }
653
 
                                        else
654
 
                                        {
655
 
                                                if ( pri == TABLE_ALLPRI ) {
656
 
                                                        if ( ignorepri )
657
 
                                                                f->f_filterData.f_pmask[i] = TABLE_NOPRI;
658
 
                                                        else
659
 
                                                                f->f_filterData.f_pmask[i] = TABLE_ALLPRI;
660
 
                                                }
661
 
                                                else
662
 
                                                {
663
 
                                                        if ( ignorepri )
664
 
                                                                for (i2= 0; i2 <= pri; ++i2)
665
 
                                                                        f->f_filterData.f_pmask[i] &= ~(1<<i2);
666
 
                                                        else
667
 
                                                                for (i2= 0; i2 <= pri; ++i2)
668
 
                                                                        f->f_filterData.f_pmask[i] |= (1<<i2);
669
 
                                                }
670
 
                                        }
671
 
                                }
672
 
                        } else {
673
 
                                i = decodeSyslogName(buf, syslogFacNames);
674
 
                                if (i < 0) {
675
 
 
676
 
                                        snprintf((char*) xbuf, sizeof(xbuf), "unknown facility name \"%s\"", buf);
677
 
                                        errmsg.LogError(NO_ERRCODE, "%s", xbuf);
678
 
                                        return RS_RET_ERR;
679
 
                                }
680
 
 
681
 
                                if ( pri == INTERNAL_NOPRI ) {
682
 
                                        if ( ignorepri )
683
 
                                                f->f_filterData.f_pmask[i >> 3] = TABLE_ALLPRI;
684
 
                                        else
685
 
                                                f->f_filterData.f_pmask[i >> 3] = TABLE_NOPRI;
686
 
                                } else if ( singlpri ) {
687
 
                                        if ( ignorepri )
688
 
                                                f->f_filterData.f_pmask[i >> 3] &= ~(1<<pri);
689
 
                                        else
690
 
                                                f->f_filterData.f_pmask[i >> 3] |= (1<<pri);
691
 
                                } else {
692
 
                                        if ( pri == TABLE_ALLPRI ) {
693
 
                                                if ( ignorepri )
694
 
                                                        f->f_filterData.f_pmask[i >> 3] = TABLE_NOPRI;
695
 
                                                else
696
 
                                                        f->f_filterData.f_pmask[i >> 3] = TABLE_ALLPRI;
697
 
                                        } else {
698
 
                                                if ( ignorepri )
699
 
                                                        for (i2= 0; i2 <= pri; ++i2)
700
 
                                                                f->f_filterData.f_pmask[i >> 3] &= ~(1<<i2);
701
 
                                                else
702
 
                                                        for (i2= 0; i2 <= pri; ++i2)
703
 
                                                                f->f_filterData.f_pmask[i >> 3] |= (1<<i2);
704
 
                                        }
705
 
                                }
706
 
                        }
707
 
                        while (*p == ',' || *p == ' ')
708
 
                                p++;
709
 
                }
710
 
 
711
 
                p = q;
712
 
        }
713
 
 
714
 
        /* skip to action part */
715
 
        while (*p == '\t' || *p == ' ')
716
 
                p++;
717
 
 
718
 
        *pline = p;
719
 
        return RS_RET_OK;
720
 
}
721
 
 
722
 
 
723
 
/* Helper to cfline(). This function processes an "if" type of filter,
724
 
 * what essentially means it parses an expression. As usual, 
725
 
 * It processes the line up to the beginning of the action part.
726
 
 * A pointer to that beginnig is passed back to the caller.
727
 
 * rgerhards 2008-01-19
728
 
 */
729
 
static rsRetVal cflineProcessIfFilter(uchar **pline, register selector_t *f)
730
 
{
731
 
        DEFiRet;
732
 
        ctok_t *tok;
733
 
        ctok_token_t *pToken;
734
 
 
735
 
        ASSERT(pline != NULL);
736
 
        ASSERT(*pline != NULL);
737
 
        ASSERT(f != NULL);
738
 
 
739
 
        dbgprintf(" - general expression-based filter\n");
740
 
        errno = 0;      /* keep strerror_r() stuff out of logerror messages */
741
 
 
742
 
dbgprintf("calling expression parser, pp %p ('%s')\n", *pline, *pline);
743
 
        f->f_filter_type = FILTER_EXPR;
744
 
 
745
 
        /* if we come to over here, pline starts with "if ". We just skip that part. */
746
 
        (*pline) += 3;
747
 
 
748
 
        /* we first need a tokenizer... */
749
 
        CHKiRet(ctok.Construct(&tok));
750
 
        CHKiRet(ctok.Setpp(tok, *pline));
751
 
        CHKiRet(ctok.ConstructFinalize(tok));
752
 
 
753
 
        /* now construct our expression */
754
 
        CHKiRet(expr.Construct(&f->f_filterData.f_expr));
755
 
        CHKiRet(expr.ConstructFinalize(f->f_filterData.f_expr));
756
 
 
757
 
        /* ready to go... */
758
 
        CHKiRet(expr.Parse(f->f_filterData.f_expr, tok));
759
 
 
760
 
        /* we now need to parse off the "then" - and note an error if it is
761
 
         * missing...
762
 
         */
763
 
        CHKiRet(ctok.GetToken(tok, &pToken));
764
 
        if(pToken->tok != ctok_THEN) {
765
 
                ctok_token.Destruct(&pToken);
766
 
                ABORT_FINALIZE(RS_RET_SYNTAX_ERROR);
767
 
        }
768
 
 
769
 
        ctok_token.Destruct(&pToken); /* no longer needed */
770
 
 
771
 
        /* we are done, so we now need to restore things */
772
 
        CHKiRet(ctok.Getpp(tok, pline));
773
 
        CHKiRet(ctok.Destruct(&tok));
774
 
 
775
 
        /* we now need to skip whitespace to the action part, else we confuse
776
 
         * the legacy rsyslog conf parser. -- rgerhards, 2008-02-25
777
 
         */
778
 
        while(isspace(**pline))
779
 
                ++(*pline);
780
 
 
781
 
finalize_it:
782
 
        if(iRet == RS_RET_SYNTAX_ERROR) {
783
 
                errmsg.LogError(NO_ERRCODE, "syntax error in expression");
784
 
        }
785
 
 
786
 
        RETiRet;
787
 
}
788
 
 
789
 
 
790
 
/* Helper to cfline(). This function takes the filter part of a property
791
 
 * based filter and decodes it. It processes the line up to the beginning
792
 
 * of the action part. A pointer to that beginnig is passed back to the caller.
793
 
 * rgerhards 2005-09-15
794
 
 */
795
 
static rsRetVal cflineProcessPropFilter(uchar **pline, register selector_t *f)
796
 
{
797
 
        rsParsObj *pPars;
798
 
        cstr_t *pCSCompOp;
799
 
        rsRetVal iRet;
800
 
        int iOffset; /* for compare operations */
801
 
 
802
 
        ASSERT(pline != NULL);
803
 
        ASSERT(*pline != NULL);
804
 
        ASSERT(f != NULL);
805
 
 
806
 
        dbgprintf(" - property-based filter\n");
807
 
        errno = 0;      /* keep strerror_r() stuff out of logerror messages */
808
 
 
809
 
        f->f_filter_type = FILTER_PROP;
810
 
 
811
 
        /* create parser object starting with line string without leading colon */
812
 
        if((iRet = rsParsConstructFromSz(&pPars, (*pline)+1)) != RS_RET_OK) {
813
 
                errmsg.LogError(NO_ERRCODE, "Error %d constructing parser object - ignoring selector", iRet);
814
 
                return(iRet);
815
 
        }
816
 
 
817
 
        /* read property */
818
 
        iRet = parsDelimCStr(pPars, &f->f_filterData.prop.pCSPropName, ',', 1, 1, 1);
819
 
        if(iRet != RS_RET_OK) {
820
 
                errmsg.LogError(NO_ERRCODE, "error %d parsing filter property - ignoring selector", iRet);
821
 
                rsParsDestruct(pPars);
822
 
                return(iRet);
823
 
        }
824
 
 
825
 
        /* read operation */
826
 
        iRet = parsDelimCStr(pPars, &pCSCompOp, ',', 1, 1, 1);
827
 
        if(iRet != RS_RET_OK) {
828
 
                errmsg.LogError(NO_ERRCODE, "error %d compare operation property - ignoring selector", iRet);
829
 
                rsParsDestruct(pPars);
830
 
                return(iRet);
831
 
        }
832
 
 
833
 
        /* we now first check if the condition is to be negated. To do so, we first
834
 
         * must make sure we have at least one char in the param and then check the
835
 
         * first one.
836
 
         * rgerhards, 2005-09-26
837
 
         */
838
 
        if(rsCStrLen(pCSCompOp) > 0) {
839
 
                if(*rsCStrGetBufBeg(pCSCompOp) == '!') {
840
 
                        f->f_filterData.prop.isNegated = 1;
841
 
                        iOffset = 1; /* ignore '!' */
842
 
                } else {
843
 
                        f->f_filterData.prop.isNegated = 0;
844
 
                        iOffset = 0;
845
 
                }
846
 
        } else {
847
 
                f->f_filterData.prop.isNegated = 0;
848
 
                iOffset = 0;
849
 
        }
850
 
 
851
 
        if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (uchar*) "contains", 8)) {
852
 
                f->f_filterData.prop.operation = FIOP_CONTAINS;
853
 
        } else if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (uchar*) "isequal", 7)) {
854
 
                f->f_filterData.prop.operation = FIOP_ISEQUAL;
855
 
        } else if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (uchar*) "startswith", 10)) {
856
 
                f->f_filterData.prop.operation = FIOP_STARTSWITH;
857
 
        } else if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (unsigned char*) "regex", 5)) {
858
 
                f->f_filterData.prop.operation = FIOP_REGEX;
859
 
        } else {
860
 
                errmsg.LogError(NO_ERRCODE, "error: invalid compare operation '%s' - ignoring selector",
861
 
                           (char*) rsCStrGetSzStrNoNULL(pCSCompOp));
862
 
        }
863
 
        rsCStrDestruct(&pCSCompOp); /* no longer needed */
864
 
 
865
 
        /* read compare value */
866
 
        iRet = parsQuotedCStr(pPars, &f->f_filterData.prop.pCSCompValue);
867
 
        if(iRet != RS_RET_OK) {
868
 
                errmsg.LogError(NO_ERRCODE, "error %d compare value property - ignoring selector", iRet);
869
 
                rsParsDestruct(pPars);
870
 
                return(iRet);
871
 
        }
872
 
 
873
 
        /* skip to action part */
874
 
        if((iRet = parsSkipWhitespace(pPars)) != RS_RET_OK) {
875
 
                errmsg.LogError(NO_ERRCODE, "error %d skipping to action part - ignoring selector", iRet);
876
 
                rsParsDestruct(pPars);
877
 
                return(iRet);
878
 
        }
879
 
 
880
 
        /* cleanup */
881
 
        *pline = *pline + rsParsGetParsePointer(pPars) + 1;
882
 
                /* we are adding one for the skipped initial ":" */
883
 
 
884
 
        return rsParsDestruct(pPars);
885
 
}
886
 
 
887
 
 
888
 
/*
889
 
 * Helper to cfline(). This function interprets a BSD host selector line
890
 
 * from the config file ("+/-hostname"). It stores it for further reference.
891
 
 * rgerhards 2005-10-19
892
 
 */
893
 
static rsRetVal cflineProcessHostSelector(uchar **pline)
894
 
{
895
 
        rsRetVal iRet;
896
 
 
897
 
        ASSERT(pline != NULL);
898
 
        ASSERT(*pline != NULL);
899
 
        ASSERT(**pline == '-' || **pline == '+');
900
 
 
901
 
        dbgprintf(" - host selector line\n");
902
 
 
903
 
        /* check include/exclude setting */
904
 
        if(**pline == '+') {
905
 
                eDfltHostnameCmpMode = HN_COMP_MATCH;
906
 
        } else { /* we do not check for '-', it must be, else we wouldn't be here */
907
 
                eDfltHostnameCmpMode = HN_COMP_NOMATCH;
908
 
        }
909
 
        (*pline)++;     /* eat + or - */
910
 
 
911
 
        /* the below is somewhat of a quick hack, but it is efficient (this is
912
 
         * why it is in here. "+*" resets the tag selector with BSD syslog. We mimic
913
 
         * this, too. As it is easy to check that condition, we do not fire up a
914
 
         * parser process, just make sure we do not address beyond our space.
915
 
         * Order of conditions in the if-statement is vital! rgerhards 2005-10-18
916
 
         */
917
 
        if(**pline != '\0' && **pline == '*' && *(*pline+1) == '\0') {
918
 
                dbgprintf("resetting BSD-like hostname filter\n");
919
 
                eDfltHostnameCmpMode = HN_NO_COMP;
920
 
                if(pDfltHostnameCmp != NULL) {
921
 
                        if((iRet = rsCStrSetSzStr(pDfltHostnameCmp, NULL)) != RS_RET_OK)
922
 
                                return(iRet);
923
 
                }
924
 
        } else {
925
 
                dbgprintf("setting BSD-like hostname filter to '%s'\n", *pline);
926
 
                if(pDfltHostnameCmp == NULL) {
927
 
                        /* create string for parser */
928
 
                        if((iRet = rsCStrConstructFromszStr(&pDfltHostnameCmp, *pline)) != RS_RET_OK)
929
 
                                return(iRet);
930
 
                } else { /* string objects exists, just update... */
931
 
                        if((iRet = rsCStrSetSzStr(pDfltHostnameCmp, *pline)) != RS_RET_OK)
932
 
                                return(iRet);
933
 
                }
934
 
        }
935
 
        return RS_RET_OK;
936
 
}
937
 
 
938
 
 
939
 
/*
940
 
 * Helper to cfline(). This function interprets a BSD tag selector line
941
 
 * from the config file ("!tagname"). It stores it for further reference.
942
 
 * rgerhards 2005-10-18
943
 
 */
944
 
static rsRetVal cflineProcessTagSelector(uchar **pline)
945
 
{
946
 
        rsRetVal iRet;
947
 
 
948
 
        ASSERT(pline != NULL);
949
 
        ASSERT(*pline != NULL);
950
 
        ASSERT(**pline == '!');
951
 
 
952
 
        dbgprintf(" - programname selector line\n");
953
 
 
954
 
        (*pline)++;     /* eat '!' */
955
 
 
956
 
        /* the below is somewhat of a quick hack, but it is efficient (this is
957
 
         * why it is in here. "!*" resets the tag selector with BSD syslog. We mimic
958
 
         * this, too. As it is easy to check that condition, we do not fire up a
959
 
         * parser process, just make sure we do not address beyond our space.
960
 
         * Order of conditions in the if-statement is vital! rgerhards 2005-10-18
961
 
         */
962
 
        if(**pline != '\0' && **pline == '*' && *(*pline+1) == '\0') {
963
 
                dbgprintf("resetting programname filter\n");
964
 
                if(pDfltProgNameCmp != NULL) {
965
 
                        if((iRet = rsCStrSetSzStr(pDfltProgNameCmp, NULL)) != RS_RET_OK)
966
 
                                return(iRet);
967
 
                }
968
 
        } else {
969
 
                dbgprintf("setting programname filter to '%s'\n", *pline);
970
 
                if(pDfltProgNameCmp == NULL) {
971
 
                        /* create string for parser */
972
 
                        if((iRet = rsCStrConstructFromszStr(&pDfltProgNameCmp, *pline)) != RS_RET_OK)
973
 
                                return(iRet);
974
 
                } else { /* string objects exists, just update... */
975
 
                        if((iRet = rsCStrSetSzStr(pDfltProgNameCmp, *pline)) != RS_RET_OK)
976
 
                                return(iRet);
977
 
                }
978
 
        }
979
 
        return RS_RET_OK;
980
 
}
981
 
 
982
 
 
983
 
/* read the filter part of a configuration line and store the filter
984
 
 * in the supplied selector_t
985
 
 * rgerhards, 2007-08-01
986
 
 */
987
 
static rsRetVal cflineDoFilter(uchar **pp, selector_t *f)
988
 
{
989
 
        DEFiRet;
990
 
 
991
 
        ASSERT(pp != NULL);
992
 
        ASSERT(f != NULL);
993
 
 
994
 
        /* check which filter we need to pull... */
995
 
        switch(**pp) {
996
 
                case ':':
997
 
                        CHKiRet(cflineProcessPropFilter(pp, f));
998
 
                        break;
999
 
                case 'i': /* "if" filter? */
1000
 
                        if(*(*pp+1) && (*(*pp+1) == 'f') && isspace(*(*pp+2))) {
1001
 
                                CHKiRet(cflineProcessIfFilter(pp, f));
1002
 
                                break;
1003
 
                                }
1004
 
                        /*FALLTHROUGH*/
1005
 
                default:
1006
 
                        CHKiRet(cflineProcessTradPRIFilter(pp, f));
1007
 
                        break;
1008
 
        }
1009
 
 
1010
 
        /* we now check if there are some global (BSD-style) filter conditions
1011
 
         * and, if so, we copy them over. rgerhards, 2005-10-18
1012
 
         */
1013
 
        if(pDfltProgNameCmp != NULL) {
1014
 
                CHKiRet(rsCStrConstructFromCStr(&(f->pCSProgNameComp), pDfltProgNameCmp));
1015
 
        }
1016
 
 
1017
 
        if(eDfltHostnameCmpMode != HN_NO_COMP) {
1018
 
                f->eHostnameCmpMode = eDfltHostnameCmpMode;
1019
 
                CHKiRet(rsCStrConstructFromCStr(&(f->pCSHostnameComp), pDfltHostnameCmp));
1020
 
        }
1021
 
 
1022
 
finalize_it:
1023
 
        RETiRet;
1024
 
}
1025
 
 
1026
 
 
1027
 
/* process the action part of a selector line
1028
 
 * rgerhards, 2007-08-01
1029
 
 */
1030
 
static rsRetVal cflineDoAction(uchar **p, action_t **ppAction)
1031
 
{
1032
 
        DEFiRet;
1033
 
        modInfo_t *pMod;
1034
 
        omodStringRequest_t *pOMSR;
1035
 
        action_t *pAction;
1036
 
        void *pModData;
1037
 
 
1038
 
        ASSERT(p != NULL);
1039
 
        ASSERT(ppAction != NULL);
1040
 
 
1041
 
        /* loop through all modules and see if one picks up the line */
1042
 
        pMod = module.GetNxtType(NULL, eMOD_OUT);
1043
 
        while(pMod != NULL) {
1044
 
                pOMSR = NULL;
1045
 
                iRet = pMod->mod.om.parseSelectorAct(p, &pModData, &pOMSR);
1046
 
                dbgprintf("tried selector action for %s: %d\n", module.GetName(pMod), iRet);
1047
 
                if(iRet == RS_RET_OK || iRet == RS_RET_SUSPENDED) {
1048
 
                        if((iRet = addAction(&pAction, pMod, pModData, pOMSR, (iRet == RS_RET_SUSPENDED)? 1 : 0)) == RS_RET_OK) {
1049
 
                                /* now check if the module is compatible with select features */
1050
 
                                if(pMod->isCompatibleWithFeature(sFEATURERepeatedMsgReduction) == RS_RET_OK)
1051
 
                                        pAction->f_ReduceRepeated = bReduceRepeatMsgs;
1052
 
                                else {
1053
 
                                        dbgprintf("module is incompatible with RepeatedMsgReduction - turned off\n");
1054
 
                                        pAction->f_ReduceRepeated = 0;
1055
 
                                }
1056
 
                                pAction->bEnabled = 1; /* action is enabled */
1057
 
                        }
1058
 
                        break;
1059
 
                }
1060
 
                else if(iRet != RS_RET_CONFLINE_UNPROCESSED) {
1061
 
                        /* In this case, the module would have handled the config
1062
 
                         * line, but some error occured while doing so. This error should
1063
 
                         * already by reported by the module. We do not try any other
1064
 
                         * modules on this line, because we found the right one.
1065
 
                         * rgerhards, 2007-07-24
1066
 
                         */
1067
 
                        dbgprintf("error %d parsing config line\n", (int) iRet);
1068
 
                        break;
1069
 
                }
1070
 
                pMod = module.GetNxtType(pMod, eMOD_OUT);
1071
 
        }
1072
 
 
1073
 
        *ppAction = pAction;
1074
 
        RETiRet;
1075
 
}
1076
 
 
1077
 
 
1078
 
/* Process a configuration file line in traditional "filter selector" format
1079
 
 * or one that builds upon this format.
1080
 
 */
1081
 
static rsRetVal cflineClassic(uchar *p, selector_t **pfCurr)
1082
 
{
1083
 
        DEFiRet;
1084
 
        action_t *pAction;
1085
 
        selector_t *fCurr;
1086
 
 
1087
 
        ASSERT(pfCurr != NULL);
1088
 
 
1089
 
        fCurr = *pfCurr;
1090
 
 
1091
 
        /* lines starting with '&' have no new filters and just add
1092
 
         * new actions to the currently processed selector.
1093
 
         */
1094
 
        if(*p == '&') {
1095
 
                ++p; /* eat '&' */
1096
 
                skipWhiteSpace(&p); /* on to command */
1097
 
        } else {
1098
 
                /* we are finished with the current selector (on previous line).
1099
 
                 * So we now need to check
1100
 
                 * if it has any actions associated and, if so, link it to the linked
1101
 
                 * list. If it has nothing associated with it, we can simply discard
1102
 
                 * it. In any case, we create a fresh selector for our new filter.
1103
 
                 * We have one special case during initialization: then, the current
1104
 
                 * selector is NULL, which means we do not need to care about it at
1105
 
                 * all.  -- rgerhards, 2007-08-01
1106
 
                 */
1107
 
                CHKiRet(selectorAddList(fCurr));
1108
 
                CHKiRet(selectorConstruct(&fCurr)); /* create "fresh" selector */
1109
 
                CHKiRet(cflineDoFilter(&p, fCurr)); /* pull filters */
1110
 
        }
1111
 
 
1112
 
        CHKiRet(cflineDoAction(&p, &pAction));
1113
 
        CHKiRet(llAppend(&fCurr->llActList,  NULL, (void*) pAction));
1114
 
 
1115
 
finalize_it:
1116
 
        *pfCurr = fCurr;
1117
 
        RETiRet;
1118
 
}
1119
 
 
1120
 
 
1121
 
/* process a configuration line
1122
 
 * I re-did this functon because it was desperately time to do so
1123
 
 * rgerhards, 2007-08-01
1124
 
 */
1125
 
static rsRetVal
1126
 
cfline(uchar *line, selector_t **pfCurr)
1127
 
{
1128
 
        DEFiRet;
1129
 
 
1130
 
        ASSERT(line != NULL);
1131
 
 
1132
 
        dbgprintf("cfline: '%s'\n", line);
1133
 
 
1134
 
        /* check type of line and call respective processing */
1135
 
        switch(*line) {
1136
 
                case '!':
1137
 
                        iRet = cflineProcessTagSelector(&line);
1138
 
                        break;
1139
 
                case '+':
1140
 
                case '-':
1141
 
                        iRet = cflineProcessHostSelector(&line);
1142
 
                        break;
1143
 
                case '$':
1144
 
                        ++line; /* eat '$' */
1145
 
                        iRet = cfsysline(line);
1146
 
                        break;
1147
 
                default:
1148
 
                        iRet = cflineClassic(line, pfCurr);
1149
 
                        break;
1150
 
        }
1151
 
 
1152
 
        RETiRet;
1153
 
}
1154
 
 
1155
 
 
1156
 
/* queryInterface function
1157
 
 * rgerhards, 2008-02-29
1158
 
 */
1159
 
BEGINobjQueryInterface(conf)
1160
 
CODESTARTobjQueryInterface(conf)
1161
 
        if(pIf->ifVersion != confCURR_IF_VERSION) { /* check for current version, increment on each change */
1162
 
                ABORT_FINALIZE(RS_RET_INTERFACE_NOT_SUPPORTED);
1163
 
        }
1164
 
 
1165
 
        /* ok, we have the right interface, so let's fill it
1166
 
         * Please note that we may also do some backwards-compatibility
1167
 
         * work here (if we can support an older interface version - that,
1168
 
         * of course, also affects the "if" above).
1169
 
         */
1170
 
        pIf->doNameLine = doNameLine;
1171
 
        pIf->cfsysline = cfsysline;
1172
 
        pIf->doModLoad = doModLoad;
1173
 
        pIf->doIncludeLine = doIncludeLine;
1174
 
        pIf->cfline = cfline;
1175
 
        pIf->processConfFile = processConfFile;
1176
 
 
1177
 
finalize_it:
1178
 
ENDobjQueryInterface(conf)
1179
 
 
1180
 
 
1181
 
/* exit our class
1182
 
 * rgerhards, 2008-03-11
1183
 
 */
1184
 
BEGINObjClassExit(conf, OBJ_IS_CORE_MODULE) /* CHANGE class also in END MACRO! */
1185
 
CODESTARTObjClassExit(conf)
1186
 
        /* release objects we no longer need */
1187
 
        objRelease(expr, CORE_COMPONENT);
1188
 
        objRelease(ctok, CORE_COMPONENT);
1189
 
        objRelease(ctok_token, CORE_COMPONENT);
1190
 
        objRelease(module, CORE_COMPONENT);
1191
 
        objRelease(errmsg, CORE_COMPONENT);
1192
 
        objRelease(net, LM_NET_FILENAME);
1193
 
ENDObjClassExit(conf)
1194
 
 
1195
 
 
1196
 
/* Initialize our class. Must be called as the very first method
1197
 
 * before anything else is called inside this class.
1198
 
 * rgerhards, 2008-02-29
1199
 
 */
1200
 
BEGINAbstractObjClassInit(conf, 1, OBJ_IS_CORE_MODULE) /* class, version - CHANGE class also in END MACRO! */
1201
 
        /* request objects we use */
1202
 
        CHKiRet(objUse(expr, CORE_COMPONENT));
1203
 
        CHKiRet(objUse(ctok, CORE_COMPONENT));
1204
 
        CHKiRet(objUse(ctok_token, CORE_COMPONENT));
1205
 
        CHKiRet(objUse(module, CORE_COMPONENT));
1206
 
        CHKiRet(objUse(errmsg, CORE_COMPONENT));
1207
 
        CHKiRet(objUse(net, LM_NET_FILENAME)); /* TODO: make this dependcy go away! */
1208
 
ENDObjClassInit(conf)
1209
 
 
1210
 
/* vi:set ai:
1211
 
 */