~roger-booth/mysql-proxy/laminator

« back to all changes in this revision

Viewing changes to src/chassis-perm.c

  • Committer: jan at mysql
  • Author(s): michael.schuster at sun
  • Date: 2009-12-02 13:05:23 UTC
  • Revision ID: michael.schuster@sun.com-20091202130523-mlqz10w2anpgp6iv
PR-250 Chassis should refuse configfile readable to everyone

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
23
#include <gmodule.h>
 
24
 
 
25
/*
 
26
 * check whether the given filename points to a file the permissions
 
27
 * of which are 0 for group and other (ie read/writable only by owner).
 
28
 * return 0 for "OK", -1 of the file cannot be accessed or is the wrong
 
29
 * type of file, and 1 if permissions are wrong
 
30
 *
 
31
 * since Windows has no concept of owner/group/other, this function
 
32
 * just return 0 for windows
 
33
 *
 
34
 * FIXME? this function currently ignores ACLs
 
35
 */
 
36
int
 
37
chassis_filemode_check(gchar *filename)
 
38
{
 
39
#ifndef _WIN32
 
40
        struct stat stbuf;
 
41
        mode_t          fmode;
 
42
        
 
43
        if (stat(filename, &stbuf) == -1) {
 
44
                g_critical("%s: cannot stat %s: %s", G_STRLOC, filename, 
 
45
                                strerror(errno));
 
46
                return -1;
 
47
        }
 
48
 
 
49
        fmode = stbuf.st_mode;
 
50
        if ((fmode & S_IFMT) != S_IFREG) {
 
51
                g_critical("%s: %s is not a regular file", G_STRLOC, filename);
 
52
                return -1;
 
53
        }
 
54
 
 
55
#define MASK (S_IROTH|S_IWOTH|S_IXOTH)
 
56
 
 
57
        if ((fmode & MASK) != 0) {
 
58
                g_critical("%s: %s permissions not secure", G_STRLOC, filename);
 
59
                return 1;
 
60
        }
 
61
        
 
62
#undef MASK
 
63
 
 
64
#endif /* _WIN32 */
 
65
        return 0;
 
66
}