]> git.pld-linux.org Git - packages/syslog-ng.git/blob - syslog-ng-fixes.patch
- don't allow to use pipe() on regular files and file() on fifos
[packages/syslog-ng.git] / syslog-ng-fixes.patch
1 --- syslog-ng-3.0.1/src/misc.c~ 2008-11-05 20:57:42.000000000 +0100
2 +++ syslog-ng-3.0.1/src/misc.c  2009-01-16 11:43:30.896633603 +0100
3 @@ -274,7 +274,7 @@
4    struct passwd *pw;
5  
6    *uid = 0;
7 -  if (*user)
8 +  if (!*user)
9      return FALSE;
10      
11    pw = getpwnam(user);
12 commit 11f8d45b016107a686dbfa29497960ae3f6145ac
13 Author: Balazs Scheidler <bazsi@balabit.hu>
14 Date:   Fri Jan 16 14:44:53 2009 +0100
15
16     [config parser] "syslog" became a reserved word, make it possible to use that as a facility name
17     
18         In syslog-ng 3.0, "syslog" became a reserved word, thus the facility()
19         filter couldn't use it as name for the facility named syslog.
20     
21         To avoid having to quote this word, I added a kludge to the
22         config grammar, to make it recognize syslog as a facility name
23         based on context.
24
25 diff --git a/src/cfg-grammar.y b/src/cfg-grammar.y
26 index c40b7fb..d54ba8f 100644
27 --- a/src/cfg-grammar.y
28 +++ b/src/cfg-grammar.y
29 @@ -277,6 +277,7 @@ cfg_check_template(LogTemplate *template)
30  
31  %type  <cptr> string
32  %type  <cptr> string_or_number
33 +%type  <cptr> facility_string
34  %type   <ptr> string_list
35  %type   <ptr> string_list_build
36  
37 @@ -464,7 +465,7 @@ source_affile_option
38                affile_sd_set_pri_level(last_driver, level); 
39              free($3);
40            }
41 -        | KW_FACILITY '(' string ')'    
42 +        | KW_FACILITY '(' facility_string ')'
43  
44            {
45              int facility = -1;
46 @@ -1305,7 +1306,7 @@ filter_fac_list
47         ;
48  
49  filter_fac
50 -       : string                                
51 +       : facility_string
52           { 
53             int n = syslog_name_lookup_facility_by_name($1);
54             if (n == -1)
55 @@ -1499,6 +1500,11 @@ string_list_build
56          |                                      { $$ = NULL; }
57          ;
58  
59 +facility_string
60 +        : string                                { $$ = $1; };
61 +        | KW_SYSLOG                             { $$ = strdup("syslog"); }
62 +        ;
63 +
64  %%
65  
66  extern int linenum;
67 commit ef5eb95d26fcfe3746b78bba8d39cfa2cdb9eeeb
68 Author: Balazs Scheidler <bazsi@balabit.hu>
69 Date:   Tue Dec 30 15:22:00 2008 +0100
70
71     [LogReader] only assume that a file was moved if the size of the file is non-zero
72     
73     If an external logrotate program is used to rotate a logfile, a
74     small race still exists when using syslog-ng to read that logfile,
75     as described by Evan Rempel:
76     
77     "
78     1. Application is writing to log file named "A".
79     2. External log rotation renames "A" to "A.1"
80     3. External log rotation touches/creates file named "A" and sets appropriate
81         permissions.
82     4. Internal timer of syslog-ng is triggered by follow_freq() setting. Syslog-ng will
83         switch to the new file "A" because it exists, even though it was created only
84         milliseconds earlier.
85     5. log rotation signals the application to switch log files (reload or restart).
86     6. Application flushes log buffers to current file which is now A.1, but syslog-ng
87         is no longer reading this file.
88     7. Application closes current log file "A.1" and opens new log file "A".
89     
90     This sequence will result in the last buffer flush (step 6) from the application to
91     be missed by syslog-ng.
92     "
93     
94     This patch makes syslog-ng to switch to the new log file if it already
95     received some data.
96
97 diff --git a/src/logreader.c b/src/logreader.c
98 index f9567ff..40e2ae7 100644
99 --- a/src/logreader.c
100 +++ b/src/logreader.c
101 @@ -167,7 +167,7 @@ log_reader_fd_check(GSource *source)
102          
103        if (self->reader->follow_filename && stat(self->reader->follow_filename, &followed_st) != -1)
104          {
105 -          if (fd < 0 || st.st_ino != followed_st.st_ino)
106 +          if (fd < 0 || (st.st_ino != followed_st.st_ino && st.st_size > 0))
107              {
108                msg_trace("log_reader_fd_check file moved eof",
109                          evt_tag_int("pos", pos),
110 commit 8ad0edb1e4198bbf657708d07360bbac8b30b55a
111 Author: Balazs Scheidler <bazsi@balabit.hu>
112 Date:   Thu Feb 5 11:26:18 2009 +0100
113
114     [affile] validate file type before opening
115     
116     report an error if a file is opened using the pipe() driver, OR a
117     fifo is opened using the file() driver. named pipes should really be
118     driven by the pipe() driver.
119
120 diff --git a/src/affile.c b/src/affile.c
121 index f9264a7..e582a5d 100644
122 --- a/src/affile.c
123 +++ b/src/affile.c
124 @@ -45,6 +45,7 @@ affile_open_file(gchar *name, gint flags,
125                   gboolean create_dirs, gboolean privileged, gboolean is_pipe, gint *fd)
126  {
127    cap_t saved_caps;
128 +  struct stat st;
129  
130    if (strstr(name, "../") || strstr(name, "/..")) 
131      {
132 @@ -63,6 +64,23 @@ affile_open_file(gchar *name, gint flags,
133        g_process_cap_modify(CAP_DAC_READ_SEARCH, TRUE);
134        g_process_cap_modify(CAP_SYS_ADMIN, TRUE);
135      }
136 +  if (stat(name, &st) >= 0)
137 +    {
138 +      if (is_pipe && !S_ISFIFO(st.st_mode))
139 +        {
140 +          msg_error("Error opening pipe, underlying file is not a FIFO, it should be used by file()",
141 +                    evt_tag_str("filename", name),
142 +                    NULL);
143 +          goto exit;
144 +        }
145 +      else if (!is_pipe && S_ISFIFO(st.st_mode))
146 +        {
147 +          msg_error("Error opening file, underlying file is a FIFO, it should be used by pipe()",
148 +                    evt_tag_str("filename", name),
149 +                    NULL);
150 +          goto exit;
151 +        }
152 +    }
153    *fd = open(name, flags, mode);
154    if (is_pipe && *fd < 0 && errno == ENOENT)
155      {
156 @@ -82,6 +100,7 @@ affile_open_file(gchar *name, gint flags,
157        if (mode != -1)
158          fchmod(*fd, mode);
159      }
160 + exit:
161    if (privileged)
162      {
163        g_process_cap_restore(saved_caps);
This page took 0.077259 seconds and 3 git commands to generate.