Merge lp:~schuster/mysql-proxy/filemode into lp:mysql-proxy

Proposed by Michael Schuster
Status: Merged
Approved by: Kay Roepke
Approved revision: not available
Merge reported by: Kay Roepke
Merged at revision: not available
Proposed branch: lp:~schuster/mysql-proxy/filemode
Merge into: lp:mysql-proxy
Diff against target: 336 lines (+219/-3)
8 files modified
src/CMakeLists.txt (+2/-0)
src/Makefile.am (+3/-1)
src/chassis-filemode.c (+67/-0)
src/chassis-filemode.h (+28/-0)
src/chassis.c (+6/-0)
tests/unit/CMakeLists.txt (+16/-2)
tests/unit/Makefile.am (+11/-0)
tests/unit/check_chassis_filemode.c (+86/-0)
To merge this branch: bzr merge lp:~schuster/mysql-proxy/filemode
Reviewer Review Type Date Requested Status
Jan Kneschke (community) Approve
Review via email: mp+15600@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jan Kneschke (jan-kneschke) wrote :

chassis.c: In function 'main_cmdline':
chassis.c:509: warning: implicit declaration of function 'chassis_filemode_check'

chassis-filemode.c: In function 'chassis_filemode_check':
chassis-filemode.c:44: warning: implicit declaration of function 'strerror'
chassis-filemode.c:44: warning: format '%s' expects type 'char *', but argument 6 has type 'int'

review: Needs Fixing
Revision history for this message
Jan Kneschke (jan-kneschke) wrote :

> chassis.c: In function 'main_cmdline':
> chassis.c:509: warning: implicit declaration of function
> 'chassis_filemode_check'
>
> chassis-filemode.c: In function 'chassis_filemode_check':
> chassis-filemode.c:44: warning: implicit declaration of function 'strerror'
> chassis-filemode.c:44: warning: format '%s' expects type 'char *', but
> argument 6 has type 'int'

... which leads to:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x00000000824d2df0
0x00007fff82390cc0 in strlen ()
...
#6 0x00000001000398d4 in g_log ()
#7 0x00000001000016e9 in chassis_filemode_check (filename=0x100001906 "/tmp/a_non_existent_file") at ../../src/chassis-filemode.c:44
#8 0x00000001000013e7 in test_file_permissions () at check_chassis_filemode.c:48
...

lp:~schuster/mysql-proxy/filemode updated
923. By Michael Schuster

fix for minor items

Revision history for this message
Jan Kneschke (jan-kneschke) wrote :

with the fixes from r923 this is approved.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2009-11-24 11:47:17 +0000
3+++ src/CMakeLists.txt 2009-12-09 14:44:10 +0000
4@@ -27,6 +27,7 @@
5 chassis-mainloop.c
6 chassis-keyfile.c
7 chassis-path.c
8+ chassis-filemode.c
9 chassis-limits.c
10 chassis-stats.c
11 chassis-timings.c
12@@ -162,6 +163,7 @@
13 chassis-keyfile.h
14 chassis-mainloop.h
15 chassis-path.h
16+ chassis-filemode.h
17 chassis-limits.h
18 chassis-event-thread.h
19 glib-ext.h
20
21=== modified file 'src/Makefile.am'
22--- src/Makefile.am 2009-11-25 21:29:36 +0000
23+++ src/Makefile.am 2009-12-09 14:44:10 +0000
24@@ -15,7 +15,7 @@
25 bin_PROGRAMS = mysql-binlog-dump mysql-myisam-dump mysql-proxy
26 endif
27
28-mysql_proxy_SOURCES = chassis.c
29+mysql_proxy_SOURCES = chassis.c
30 mysql_proxy_CPPFLAGS = $(BUILD_CPPFLAGS)
31 mysql_proxy_CFLAGS = $(BUILD_CFLAGS)
32 mysql_proxy_LDADD = $(BUILD_LDADD)
33@@ -58,6 +58,7 @@
34 chassis-event-thread.c \
35 chassis-keyfile.c \
36 chassis-path.c \
37+ chassis-filemode.c \
38 chassis-limits.c \
39 chassis-stats.c
40
41@@ -110,6 +111,7 @@
42 chassis-keyfile.h \
43 chassis-mainloop.h \
44 chassis-path.h \
45+ chassis-filemode.h \
46 chassis-limits.h \
47 chassis-event-thread.h \
48 glib-ext.h \
49
50=== added file 'src/chassis-filemode.c'
51--- src/chassis-filemode.c 1970-01-01 00:00:00 +0000
52+++ src/chassis-filemode.c 2009-12-09 14:44:10 +0000
53@@ -0,0 +1,67 @@
54+/* $%BEGINLICENSE%$
55+ Copyright (C) 2009 MySQL AB, 2009 Sun Microsystems, Inc
56+
57+ This program is free software; you can redistribute it and/or modify
58+ it under the terms of the GNU General Public License as published by
59+ the Free Software Foundation; version 2 of the License.
60+
61+ This program is distributed in the hope that it will be useful,
62+ but WITHOUT ANY WARRANTY; without even the implied warranty of
63+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64+ GNU General Public License for more details.
65+
66+ You should have received a copy of the GNU General Public License
67+ along with this program; if not, write to the Free Software
68+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
69+
70+ $%ENDLICENSE%$ */
71+
72+#include <sys/types.h>
73+#include <sys/stat.h>
74+#include <errno.h>
75+#include <string.h>
76+
77+#include <gmodule.h>
78+
79+/*
80+ * check whether the given filename points to a file the permissions
81+ * of which are 0 for group and other (ie read/writable only by owner).
82+ * return 0 for "OK", -1 of the file cannot be accessed or is the wrong
83+ * type of file, and 1 if permissions are wrong
84+ *
85+ * since Windows has no concept of owner/group/other, this function
86+ * just return 0 for windows
87+ *
88+ * FIXME? this function currently ignores ACLs
89+ */
90+int
91+chassis_filemode_check(gchar *filename)
92+{
93+#ifndef _WIN32
94+ struct stat stbuf;
95+ mode_t fmode;
96+
97+ if (stat(filename, &stbuf) == -1) {
98+ g_critical("%s: cannot stat %s: %s", G_STRLOC, filename,
99+ strerror(errno));
100+ return -1;
101+ }
102+
103+ fmode = stbuf.st_mode;
104+ if ((fmode & S_IFMT) != S_IFREG) {
105+ g_critical("%s: %s is not a regular file", G_STRLOC, filename);
106+ return -1;
107+ }
108+
109+#define MASK (S_IROTH|S_IWOTH|S_IXOTH)
110+
111+ if ((fmode & MASK) != 0) {
112+ g_critical("%s: %s permissions not secure", G_STRLOC, filename);
113+ return 1;
114+ }
115+
116+#undef MASK
117+
118+#endif /* _WIN32 */
119+ return 0;
120+}
121
122=== added file 'src/chassis-filemode.h'
123--- src/chassis-filemode.h 1970-01-01 00:00:00 +0000
124+++ src/chassis-filemode.h 2009-12-09 14:44:10 +0000
125@@ -0,0 +1,28 @@
126+/* $%BEGINLICENSE%$
127+ Copyright (C) 2009 MySQL AB, 2009 Sun Microsystems, Inc
128+
129+ This program is free software; you can redistribute it and/or modify
130+ it under the terms of the GNU General Public License as published by
131+ the Free Software Foundation; version 2 of the License.
132+
133+ This program is distributed in the hope that it will be useful,
134+ but WITHOUT ANY WARRANTY; without even the implied warranty of
135+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
136+ GNU General Public License for more details.
137+
138+ You should have received a copy of the GNU General Public License
139+ along with this program; if not, write to the Free Software
140+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
141+
142+ $%ENDLICENSE%$ */
143+
144+
145+#ifndef _CHASSIS_PERM_H_
146+#define _CHASSIS_PERM_H_
147+
148+#include <glib.h>
149+#include "chassis-exports.h"
150+
151+CHASSIS_API int chassis_filemode_check(gchar *filename);
152+
153+#endif
154
155=== modified file 'src/chassis.c'
156--- src/chassis.c 2009-11-27 10:15:08 +0000
157+++ src/chassis.c 2009-12-09 14:44:10 +0000
158@@ -79,6 +79,7 @@
159 #include "chassis-mainloop.h"
160 #include "chassis-path.h"
161 #include "chassis-limits.h"
162+#include "chassis-filemode.h"
163
164 #ifdef _WIN32
165 static char **shell_argv;
166@@ -506,6 +507,11 @@
167 }
168
169 if (default_file) {
170+ if (chassis_filemode_check(default_file) != 0) {
171+ exit_code = EXIT_FAILURE;
172+ exit_location = G_STRLOC;
173+ goto exit_nicely;
174+ }
175 keyfile = g_key_file_new();
176 g_key_file_set_list_separator(keyfile, ',');
177
178
179=== modified file 'tests/unit/CMakeLists.txt'
180--- tests/unit/CMakeLists.txt 2009-11-25 21:37:02 +0000
181+++ tests/unit/CMakeLists.txt 2009-12-09 14:44:10 +0000
182@@ -93,6 +93,16 @@
183 ${WINSOCK_LIBRARIES}
184 )
185
186+ADD_EXECUTABLE(check_chassis_filemode
187+ check_chassis_filemode.c
188+ ../../src/chassis-filemode.c
189+)
190+
191+TARGET_LINK_LIBRARIES(check_chassis_filemode
192+ ${GLIB_LIBRARIES}
193+ ${GTHREAD_LIBRARIES}
194+)
195+
196 ADD_EXECUTABLE(t_network_injection
197 t_network_injection.c
198 ../../src/network-injection.c
199@@ -129,8 +139,11 @@
200
201 IF(WIN32)
202 # turn off _declspec(dllimport) in tests, since we link statically
203-set_property(TARGET check_chassis_log check_plugin check_mysqld_proto check_loadscript check_chassis_path t_network_injection t_network_backend
204- APPEND PROPERTY COMPILE_DEFINITIONS "mysql_chassis_proxy_STATIC" COMPILE_DEFINITIONS "mysql_chassis_STATIC")
205+set_property(TARGET check_chassis_log check_plugin check_mysqld_proto
206+ check_loadscript check_chassis_path check_chassis_filemode
207+ t_network_injection t_network_backend
208+ APPEND PROPERTY COMPILE_DEFINITIONS "mysql_chassis_proxy_STATIC"
209+ COMPILE_DEFINITIONS "mysql_chassis_STATIC")
210 ENDIF(WIN32)
211
212 ## adding all tests
213@@ -141,6 +154,7 @@
214 #ADD_TEST(check_sql_tokenizer check_sql_tokenizer)
215 ADD_TEST(check_loadscript check_loadscript)
216 ADD_TEST(check_chassis_path check_chassis_path)
217+ADD_TEST(check_chassis_filemode check_chassis_filemode)
218 ADD_TEST(t_network_injection t_network_injection)
219 ADD_TEST(t_network_backend t_network_backend)
220
221
222=== modified file 'tests/unit/Makefile.am'
223--- tests/unit/Makefile.am 2009-11-26 12:35:27 +0000
224+++ tests/unit/Makefile.am 2009-12-09 14:44:10 +0000
225@@ -13,9 +13,20 @@
226 t_network_mysqld_packet \
227 t_network_mysqld_masterinfo \
228 t_chassis_timings \
229+ check_chassis_filemode \
230 check_chassis_path
231
232 check_PROGRAMS=$(TESTS)
233+
234+check_chassis_filemode_SOURCES = check_chassis_filemode.c \
235+ $(top_srcdir)/src/chassis-filemode.c
236+
237+check_chassis_filemode_CPPFLAGS = \
238+ -I$(top_srcdir)/src/ $(GLIB_CFLAGS) -I$(top_srcdir) \
239+ $(MYSQL_CFLAGS)
240+
241+check_chassis_filemode_LDADD = $(GLIB_LIBS) $(GTHREAD_LIBS)
242+
243 check_sql_tokenizer_SOURCES = check_sql_tokenizer.c \
244 $(top_srcdir)/lib/sql-tokenizer.l \
245 $(top_srcdir)/src/glib-ext.c
246
247=== added file 'tests/unit/check_chassis_filemode.c'
248--- tests/unit/check_chassis_filemode.c 1970-01-01 00:00:00 +0000
249+++ tests/unit/check_chassis_filemode.c 2009-12-09 14:44:10 +0000
250@@ -0,0 +1,86 @@
251+/* $%BEGINLICENSE%$
252+ Copyright (C) 2009 MySQL AB, 2009 Sun Microsystems, Inc
253+
254+ This program is free software; you can redistribute it and/or modify
255+ it under the terms of the GNU General Public License as published by
256+ the Free Software Foundation; version 2 of the License.
257+
258+ This program is distributed in the hope that it will be useful,
259+ but WITHOUT ANY WARRANTY; without even the implied warranty of
260+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
261+ GNU General Public License for more details.
262+
263+ You should have received a copy of the GNU General Public License
264+ along with this program; if not, write to the Free Software
265+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
266+
267+ $%ENDLICENSE%$ */
268+
269+/** @addtogroup unittests Unit tests */
270+
271+#include <stdio.h>
272+#include <stdlib.h>
273+#include <string.h>
274+#include <unistd.h>
275+#include <sys/stat.h>
276+#include <sys/param.h>
277+#include <fcntl.h>
278+
279+#include <glib.h>
280+
281+#include "chassis-filemode.h"
282+
283+#if GLIB_CHECK_VERSION(2, 16, 0)
284+
285+#define TOO_OPEN 0666
286+#define GOOD_PERMS 0660
287+/**
288+ * @test
289+ */
290+void test_file_permissions(void)
291+{
292+ char filename[MAXPATHLEN] = "/tmp/permsXXXXX";
293+ int fd;
294+
295+ g_log_set_always_fatal(G_LOG_FATAL_MASK);
296+
297+ /* 1st test: non-existent file */
298+ g_assert_cmpint(chassis_filemode_check("/tmp/a_non_existent_file"), ==, -1);
299+
300+ fd = mkstemp(filename);
301+
302+ /* 2nd test: too permissive */
303+ chmod(filename, TOO_OPEN);
304+ g_assert_cmpint(chassis_filemode_check(filename), ==, 1);
305+
306+ /* 3rd test: OK */
307+ chmod(filename, GOOD_PERMS);
308+ g_assert_cmpint(chassis_filemode_check(filename), ==, 0);
309+
310+ /* 4th test: non-regular file */
311+ close (fd);
312+ remove(filename);
313+ mkdir(filename, GOOD_PERMS);
314+ g_assert_cmpint(chassis_filemode_check(filename), ==, -1);
315+
316+ /* clean up */
317+ rmdir(filename);
318+}
319+/*@}*/
320+
321+int main(int argc, char **argv) {
322+ g_thread_init(NULL);
323+
324+
325+ g_test_init(&argc, &argv, NULL);
326+ g_test_bug_base("http://bugs.mysql.com/");
327+
328+ g_test_add_func("/core/basedir/fileperm", test_file_permissions);
329+
330+ return g_test_run();
331+}
332+#else
333+int main() {
334+ return 77;
335+}
336+#endif

Subscribers

People subscribed via source and target branches