blocxx
PathSecurity.hpp
Go to the documentation of this file.
1/*******************************************************************************
2* Copyright (C) 2005, Vintela, Inc. All rights reserved.
3* Copyright (C) 2006, Novell, Inc. All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7*
8* * Redistributions of source code must retain the above copyright notice,
9* this list of conditions and the following disclaimer.
10* * Redistributions in binary form must reproduce the above copyright
11* notice, this list of conditions and the following disclaimer in the
12* documentation and/or other materials provided with the distribution.
13* * Neither the name of
14* Vintela, Inc.,
15* nor Novell, Inc.,
16* nor the names of its contributors or employees may be used to
17* endorse or promote products derived from this software without
18* specific prior written permission.
19*
20* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30* POSSIBILITY OF SUCH DAMAGE.
31*******************************************************************************/
32
33
37
38#ifndef BLOCXX_PATHSECURITY_HPP_INCLUDE_GUARD_
39#define BLOCXX_PATHSECURITY_HPP_INCLUDE_GUARD_
40
41#include "blocxx/BLOCXX_config.h"
42#include "blocxx/String.hpp"
43#ifdef BLOCXX_HAVE_SYS_STAT_H
44#include <sys/stat.h>
45#endif
46
47namespace BLOCXX_NAMESPACE
48{
49
56
57#ifdef BLOCXX_WIN32
58
59#define S_IRUSR 400 /* Read by owner. */
60#define S_IWUSR 200 /* Write by owner. */
61#define S_IXUSR 100 /* Execute by owner. */
62/* Read, write, and execute by owner. */
63#define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR)
64
65#define S_IRGRP (S_IRUSR / 10) /* Read by group. */
66#define S_IWGRP (S_IWUSR / 10) /* Write by group. */
67#define S_IXGRP (S_IXUSR / 10) /* Execute by group. */
68/* Read, write, and execute by group. */
69#define S_IRWXG (S_IRGRP|S_IWGRP|S_IXGRP)
70
71#define S_IROTH (S_IRGRP / 10) /* Read by others. */
72#define S_IWOTH (S_IWGRP / 10) /* Write by others. */
73#define S_IXOTH (S_IXGRP / 10) /* Execute by others. */
74/* Read, write, and execute by others. */
75#define S_IRWXO (S_IROTH|S_IWOTH|S_IXOTH)
76
77#define S_ISVTX 0x0001000 /* sticky bit (see below) */
78#define S_ISDIR(__PARM__) (_S_IFDIR & __PARM__)
79#define S_ISREG(__PARM__) (_S_IFREG & __PARM__)
80#define S_ISLNK(__PARM__) (false) /*TODO: implement hardlinks */
81
82#ifndef ELOOP
83#define ELOOP 40 /* Too many symbolic links encountered */
84#endif
85
86static const unsigned long BLOCXX_WIN32_ACCESSMASK_FILE_READ_DATA = 1;
87static const unsigned long BLOCXX_WIN32_ACCESSMASK_FILE_WRITE_DATA = 1<<1;
88static const unsigned long BLOCXX_WIN32_ACCESSMASK_FILE_APPEND_DATA = 1<<2;
89static const unsigned long BLOCXX_WIN32_ACCESSMASK_FILE_READ_EA = 1<<3;
90static const unsigned long BLOCXX_WIN32_ACCESSMASK_FILE_WRITE_EA = 1<<4;
91static const unsigned long BLOCXX_WIN32_ACCESSMASK_FILE_EXEC = 1<<5;
92static const unsigned long BLOCXX_WIN32_ACCESSMASK_FILE_DELETE_CHILD = 1<<6;
93static const unsigned long BLOCXX_WIN32_ACCESSMASK_FILE_READ_ATTRS = 1<<7;
94static const unsigned long BLOCXX_WIN32_ACCESSMASK_FILE_WRITE_ATTRS = 1<<8;
95
96static const unsigned long BLOCXX_WIN32_ACCESSMASK_DELETE = 1<<16;
97static const unsigned long BLOCXX_WIN32_ACCESSMASK_READ_CONTROL = 1<<17;
98static const unsigned long BLOCXX_WIN32_ACCESSMASK_WRITE_DAC = 1<<18;
99static const unsigned long BLOCXX_WIN32_ACCESSMASK_WRITE_OWNER = 1<<19;
100static const unsigned long BLOCXX_WIN32_ACCESSMASK_SYNCHRONIZE = 1<<20;
101static const unsigned long BLOCXX_WIN32_ACCESSMASK_SYSSECURITY = 1<<24;
102
103static const unsigned long BLOCXX_WIN32_ACCESSMASK_GENERIC_ALL = 1<<28;
104static const unsigned long BLOCXX_WIN32_ACCESSMASK_GENERIC_EXEC = 1<<29;
105static const unsigned long BLOCXX_WIN32_ACCESSMASK_GENERIC_WRITE = 1<<30;
106static const unsigned long BLOCXX_WIN32_ACCESSMASK_GENERIC_READ = 1<<31;
107
108static const unsigned long BLOCXX_WIN32_ACCESSMASK_ALLOW_ANY_CHANGE = \
109 BLOCXX_WIN32_ACCESSMASK_GENERIC_ALL | \
110 BLOCXX_WIN32_ACCESSMASK_GENERIC_WRITE | \
111 BLOCXX_WIN32_ACCESSMASK_WRITE_DAC | \
112 BLOCXX_WIN32_ACCESSMASK_FILE_WRITE_ATTRS | \
113 BLOCXX_WIN32_ACCESSMASK_FILE_WRITE_DATA | \
114 BLOCXX_WIN32_ACCESSMASK_FILE_APPEND_DATA | \
115 BLOCXX_WIN32_ACCESSMASK_FILE_WRITE_EA ;
116
117
118#endif //ifdef BLOCXX_WIN32
119
120#if defined(BLOCXX_NETWARE) || defined(BLOCXX_WIN32)
121 #define LSTAT ::stat
122 #define S_ISLNK(x) false
123 #define READLINK(path, buf, size) 0
124 #define READLINK_ALLOWED false
125#else
126 #define LSTAT ::lstat
127 #define READLINK(path, buf, size) ::readlink((path), (buf), (size))
128 #define READLINK_ALLOWED true
129#endif
130
131
132BLOCXX_COMMON_API bool isPathAbsolute(String const & path);
134EFileStatusReturn getFileStatus(struct stat const & x, uid_t uid, bool is_full_path, const String& path);
135
136} // end namespace BLOCXX_NAMESPACE
137
138#endif
Taken from RFC 1321.
EFileStatusReturn getFileStatus(struct stat const &x, uid_t uid, bool is_full_path, const String &path)
GetFileStatus() - just to unify the call of file_ok() for Win and xNix.
BLOCXX_COMMON_API bool isPathAbsolute(String const &path)