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
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2009-11-24 11:47:17 +0000
+++ src/CMakeLists.txt 2009-12-09 14:44:10 +0000
@@ -27,6 +27,7 @@
27 chassis-mainloop.c27 chassis-mainloop.c
28 chassis-keyfile.c28 chassis-keyfile.c
29 chassis-path.c29 chassis-path.c
30 chassis-filemode.c
30 chassis-limits.c31 chassis-limits.c
31 chassis-stats.c32 chassis-stats.c
32 chassis-timings.c33 chassis-timings.c
@@ -162,6 +163,7 @@
162 chassis-keyfile.h163 chassis-keyfile.h
163 chassis-mainloop.h164 chassis-mainloop.h
164 chassis-path.h165 chassis-path.h
166 chassis-filemode.h
165 chassis-limits.h167 chassis-limits.h
166 chassis-event-thread.h168 chassis-event-thread.h
167 glib-ext.h169 glib-ext.h
168170
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2009-11-25 21:29:36 +0000
+++ src/Makefile.am 2009-12-09 14:44:10 +0000
@@ -15,7 +15,7 @@
15bin_PROGRAMS = mysql-binlog-dump mysql-myisam-dump mysql-proxy15bin_PROGRAMS = mysql-binlog-dump mysql-myisam-dump mysql-proxy
16endif16endif
1717
18mysql_proxy_SOURCES = chassis.c 18mysql_proxy_SOURCES = chassis.c
19mysql_proxy_CPPFLAGS = $(BUILD_CPPFLAGS)19mysql_proxy_CPPFLAGS = $(BUILD_CPPFLAGS)
20mysql_proxy_CFLAGS = $(BUILD_CFLAGS)20mysql_proxy_CFLAGS = $(BUILD_CFLAGS)
21mysql_proxy_LDADD = $(BUILD_LDADD)21mysql_proxy_LDADD = $(BUILD_LDADD)
@@ -58,6 +58,7 @@
58 chassis-event-thread.c \58 chassis-event-thread.c \
59 chassis-keyfile.c \59 chassis-keyfile.c \
60 chassis-path.c \60 chassis-path.c \
61 chassis-filemode.c \
61 chassis-limits.c \62 chassis-limits.c \
62 chassis-stats.c63 chassis-stats.c
6364
@@ -110,6 +111,7 @@
110 chassis-keyfile.h \111 chassis-keyfile.h \
111 chassis-mainloop.h \112 chassis-mainloop.h \
112 chassis-path.h \113 chassis-path.h \
114 chassis-filemode.h \
113 chassis-limits.h \115 chassis-limits.h \
114 chassis-event-thread.h \116 chassis-event-thread.h \
115 glib-ext.h \117 glib-ext.h \
116118
=== added file 'src/chassis-filemode.c'
--- src/chassis-filemode.c 1970-01-01 00:00:00 +0000
+++ src/chassis-filemode.c 2009-12-09 14:44:10 +0000
@@ -0,0 +1,67 @@
1/* $%BEGINLICENSE%$
2 Copyright (C) 2009 MySQL AB, 2009 Sun Microsystems, Inc
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
17 $%ENDLICENSE%$ */
18
19#include <sys/types.h>
20#include <sys/stat.h>
21#include <errno.h>
22#include <string.h>
23
24#include <gmodule.h>
25
26/*
27 * check whether the given filename points to a file the permissions
28 * of which are 0 for group and other (ie read/writable only by owner).
29 * return 0 for "OK", -1 of the file cannot be accessed or is the wrong
30 * type of file, and 1 if permissions are wrong
31 *
32 * since Windows has no concept of owner/group/other, this function
33 * just return 0 for windows
34 *
35 * FIXME? this function currently ignores ACLs
36 */
37int
38chassis_filemode_check(gchar *filename)
39{
40#ifndef _WIN32
41 struct stat stbuf;
42 mode_t fmode;
43
44 if (stat(filename, &stbuf) == -1) {
45 g_critical("%s: cannot stat %s: %s", G_STRLOC, filename,
46 strerror(errno));
47 return -1;
48 }
49
50 fmode = stbuf.st_mode;
51 if ((fmode & S_IFMT) != S_IFREG) {
52 g_critical("%s: %s is not a regular file", G_STRLOC, filename);
53 return -1;
54 }
55
56#define MASK (S_IROTH|S_IWOTH|S_IXOTH)
57
58 if ((fmode & MASK) != 0) {
59 g_critical("%s: %s permissions not secure", G_STRLOC, filename);
60 return 1;
61 }
62
63#undef MASK
64
65#endif /* _WIN32 */
66 return 0;
67}
068
=== added file 'src/chassis-filemode.h'
--- src/chassis-filemode.h 1970-01-01 00:00:00 +0000
+++ src/chassis-filemode.h 2009-12-09 14:44:10 +0000
@@ -0,0 +1,28 @@
1/* $%BEGINLICENSE%$
2 Copyright (C) 2009 MySQL AB, 2009 Sun Microsystems, Inc
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
17 $%ENDLICENSE%$ */
18
19
20#ifndef _CHASSIS_PERM_H_
21#define _CHASSIS_PERM_H_
22
23#include <glib.h>
24#include "chassis-exports.h"
25
26CHASSIS_API int chassis_filemode_check(gchar *filename);
27
28#endif
029
=== modified file 'src/chassis.c'
--- src/chassis.c 2009-11-27 10:15:08 +0000
+++ src/chassis.c 2009-12-09 14:44:10 +0000
@@ -79,6 +79,7 @@
79#include "chassis-mainloop.h"79#include "chassis-mainloop.h"
80#include "chassis-path.h"80#include "chassis-path.h"
81#include "chassis-limits.h"81#include "chassis-limits.h"
82#include "chassis-filemode.h"
8283
83#ifdef _WIN3284#ifdef _WIN32
84static char **shell_argv;85static char **shell_argv;
@@ -506,6 +507,11 @@
506 }507 }
507508
508 if (default_file) {509 if (default_file) {
510 if (chassis_filemode_check(default_file) != 0) {
511 exit_code = EXIT_FAILURE;
512 exit_location = G_STRLOC;
513 goto exit_nicely;
514 }
509 keyfile = g_key_file_new();515 keyfile = g_key_file_new();
510 g_key_file_set_list_separator(keyfile, ',');516 g_key_file_set_list_separator(keyfile, ',');
511517
512518
=== modified file 'tests/unit/CMakeLists.txt'
--- tests/unit/CMakeLists.txt 2009-11-25 21:37:02 +0000
+++ tests/unit/CMakeLists.txt 2009-12-09 14:44:10 +0000
@@ -93,6 +93,16 @@
93 ${WINSOCK_LIBRARIES}93 ${WINSOCK_LIBRARIES}
94)94)
9595
96ADD_EXECUTABLE(check_chassis_filemode
97 check_chassis_filemode.c
98 ../../src/chassis-filemode.c
99)
100
101TARGET_LINK_LIBRARIES(check_chassis_filemode
102 ${GLIB_LIBRARIES}
103 ${GTHREAD_LIBRARIES}
104)
105
96ADD_EXECUTABLE(t_network_injection106ADD_EXECUTABLE(t_network_injection
97 t_network_injection.c 107 t_network_injection.c
98 ../../src/network-injection.c 108 ../../src/network-injection.c
@@ -129,8 +139,11 @@
129139
130IF(WIN32)140IF(WIN32)
131# turn off _declspec(dllimport) in tests, since we link statically141# turn off _declspec(dllimport) in tests, since we link statically
132set_property(TARGET check_chassis_log check_plugin check_mysqld_proto check_loadscript check_chassis_path t_network_injection t_network_backend142set_property(TARGET check_chassis_log check_plugin check_mysqld_proto
133 APPEND PROPERTY COMPILE_DEFINITIONS "mysql_chassis_proxy_STATIC" COMPILE_DEFINITIONS "mysql_chassis_STATIC")143 check_loadscript check_chassis_path check_chassis_filemode
144 t_network_injection t_network_backend
145 APPEND PROPERTY COMPILE_DEFINITIONS "mysql_chassis_proxy_STATIC"
146 COMPILE_DEFINITIONS "mysql_chassis_STATIC")
134ENDIF(WIN32)147ENDIF(WIN32)
135148
136## adding all tests149## adding all tests
@@ -141,6 +154,7 @@
141#ADD_TEST(check_sql_tokenizer check_sql_tokenizer)154#ADD_TEST(check_sql_tokenizer check_sql_tokenizer)
142ADD_TEST(check_loadscript check_loadscript)155ADD_TEST(check_loadscript check_loadscript)
143ADD_TEST(check_chassis_path check_chassis_path)156ADD_TEST(check_chassis_path check_chassis_path)
157ADD_TEST(check_chassis_filemode check_chassis_filemode)
144ADD_TEST(t_network_injection t_network_injection)158ADD_TEST(t_network_injection t_network_injection)
145ADD_TEST(t_network_backend t_network_backend)159ADD_TEST(t_network_backend t_network_backend)
146160
147161
=== modified file 'tests/unit/Makefile.am'
--- tests/unit/Makefile.am 2009-11-26 12:35:27 +0000
+++ tests/unit/Makefile.am 2009-12-09 14:44:10 +0000
@@ -13,9 +13,20 @@
13 t_network_mysqld_packet \13 t_network_mysqld_packet \
14 t_network_mysqld_masterinfo \14 t_network_mysqld_masterinfo \
15 t_chassis_timings \15 t_chassis_timings \
16 check_chassis_filemode \
16 check_chassis_path17 check_chassis_path
1718
18check_PROGRAMS=$(TESTS)19check_PROGRAMS=$(TESTS)
20
21check_chassis_filemode_SOURCES = check_chassis_filemode.c \
22 $(top_srcdir)/src/chassis-filemode.c
23
24check_chassis_filemode_CPPFLAGS = \
25 -I$(top_srcdir)/src/ $(GLIB_CFLAGS) -I$(top_srcdir) \
26 $(MYSQL_CFLAGS)
27
28check_chassis_filemode_LDADD = $(GLIB_LIBS) $(GTHREAD_LIBS)
29
19check_sql_tokenizer_SOURCES = check_sql_tokenizer.c \30check_sql_tokenizer_SOURCES = check_sql_tokenizer.c \
20 $(top_srcdir)/lib/sql-tokenizer.l \31 $(top_srcdir)/lib/sql-tokenizer.l \
21 $(top_srcdir)/src/glib-ext.c32 $(top_srcdir)/src/glib-ext.c
2233
=== added file 'tests/unit/check_chassis_filemode.c'
--- tests/unit/check_chassis_filemode.c 1970-01-01 00:00:00 +0000
+++ tests/unit/check_chassis_filemode.c 2009-12-09 14:44:10 +0000
@@ -0,0 +1,86 @@
1/* $%BEGINLICENSE%$
2 Copyright (C) 2009 MySQL AB, 2009 Sun Microsystems, Inc
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
17 $%ENDLICENSE%$ */
18
19/** @addtogroup unittests Unit tests */
20
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <unistd.h>
25#include <sys/stat.h>
26#include <sys/param.h>
27#include <fcntl.h>
28
29#include <glib.h>
30
31#include "chassis-filemode.h"
32
33#if GLIB_CHECK_VERSION(2, 16, 0)
34
35#define TOO_OPEN 0666
36#define GOOD_PERMS 0660
37/**
38 * @test
39 */
40void test_file_permissions(void)
41{
42 char filename[MAXPATHLEN] = "/tmp/permsXXXXX";
43 int fd;
44
45 g_log_set_always_fatal(G_LOG_FATAL_MASK);
46
47 /* 1st test: non-existent file */
48 g_assert_cmpint(chassis_filemode_check("/tmp/a_non_existent_file"), ==, -1);
49
50 fd = mkstemp(filename);
51
52 /* 2nd test: too permissive */
53 chmod(filename, TOO_OPEN);
54 g_assert_cmpint(chassis_filemode_check(filename), ==, 1);
55
56 /* 3rd test: OK */
57 chmod(filename, GOOD_PERMS);
58 g_assert_cmpint(chassis_filemode_check(filename), ==, 0);
59
60 /* 4th test: non-regular file */
61 close (fd);
62 remove(filename);
63 mkdir(filename, GOOD_PERMS);
64 g_assert_cmpint(chassis_filemode_check(filename), ==, -1);
65
66 /* clean up */
67 rmdir(filename);
68}
69/*@}*/
70
71int main(int argc, char **argv) {
72 g_thread_init(NULL);
73
74
75 g_test_init(&argc, &argv, NULL);
76 g_test_bug_base("http://bugs.mysql.com/");
77
78 g_test_add_func("/core/basedir/fileperm", test_file_permissions);
79
80 return g_test_run();
81}
82#else
83int main() {
84 return 77;
85}
86#endif

Subscribers

People subscribed via source and target branches