You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2015/09/11 02:25:57 UTC
[06/11] mesos git commit: Extended permissions.hpp to work on both
Windows and POSIX.
Extended permissions.hpp to work on both Windows and POSIX.
Review: https://reviews.apache.org/r/37032
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/3b034277
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/3b034277
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/3b034277
Branch: refs/heads/master
Commit: 3b03427790a9d443c677bbbebd6016b798302b1e
Parents: 342f2b3
Author: Alex Clemmer <cl...@gmail.com>
Authored: Thu Sep 10 12:07:06 2015 -0700
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Thu Sep 10 17:15:00 2015 -0700
----------------------------------------------------------------------
.../3rdparty/stout/include/Makefile.am | 2 -
.../stout/include/stout/os/permissions.hpp | 60 ++++++++++--
.../include/stout/os/posix/permissions.hpp | 69 --------------
.../include/stout/os/windows/permissions.hpp | 41 --------
.../3rdparty/stout/include/stout/windows.hpp | 98 ++++++++++++++++++++
5 files changed, 151 insertions(+), 119 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/3b034277/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
index 58844a2..9e9c311 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
@@ -65,7 +65,6 @@ nobase_include_HEADERS = \
stout/os/posix/killtree.hpp \
stout/os/posix/ls.hpp \
stout/os/posix/open.hpp \
- stout/os/posix/permissions.hpp \
stout/os/posix/process.hpp \
stout/os/posix/pstree.hpp \
stout/os/posix/read.hpp \
@@ -93,7 +92,6 @@ nobase_include_HEADERS = \
stout/os/windows/killtree.hpp \
stout/os/windows/ls.hpp \
stout/os/windows/open.hpp \
- stout/os/windows/permissions.hpp \
stout/os/windows/process.hpp \
stout/os/windows/pstree.hpp \
stout/os/windows/read.hpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/3b034277/3rdparty/libprocess/3rdparty/stout/include/stout/os/permissions.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/permissions.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/permissions.hpp
index 196c3f5..2d8820a 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/permissions.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/permissions.hpp
@@ -14,14 +14,60 @@
#ifndef __STOUT_OS_PERMISSIONS_HPP__
#define __STOUT_OS_PERMISSIONS_HPP__
+#include <sys/stat.h>
-// For readability, we minimize the number of #ifdef blocks in the code by
-// splitting platform specifc system calls into separate directories.
-#ifdef __WINDOWS__
-#include <stout/os/windows/permissions.hpp>
-#else
-#include <stout/os/posix/permissions.hpp>
-#endif // __WINDOWS__
+#include <string>
+
+
+namespace os {
+
+struct Permissions
+{
+ explicit Permissions(mode_t mode)
+ {
+ owner.r = mode & S_IRUSR;
+ owner.w = mode & S_IWUSR;
+ owner.x = mode & S_IXUSR;
+ owner.rwx = mode & S_IRWXU;
+ group.r = mode & S_IRGRP;
+ group.w = mode & S_IWGRP;
+ group.x = mode & S_IXGRP;
+ group.rwx = mode & S_IRWXG;
+ others.r = mode & S_IROTH;
+ others.w = mode & S_IWOTH;
+ others.x = mode & S_IXOTH;
+ others.rwx = mode & S_IRWXO;
+ setuid = mode & S_ISUID;
+ setgid = mode & S_ISGID;
+ sticky = mode & S_ISVTX;
+ }
+
+ struct
+ {
+ bool r;
+ bool w;
+ bool x;
+ bool rwx;
+ } owner, group, others;
+
+ bool setuid;
+ bool setgid;
+ bool sticky;
+};
+
+
+inline Try<Permissions> permissions(const std::string& path)
+{
+ struct stat status;
+ if (::stat(path.c_str(), &status) < 0) {
+ return ErrnoError();
+ }
+
+ return Permissions(status.st_mode);
+}
+
+
+} // namespace os {
#endif // __STOUT_OS_PERMISSIONS_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/3b034277/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/permissions.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/permissions.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/permissions.hpp
deleted file mode 100644
index 98f0b3c..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/permissions.hpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __STOUT_OS_POSIX_PERMISSIONS_HPP__
-#define __STOUT_OS_POSIX_PERMISSIONS_HPP__
-
-#include <sys/stat.h>
-
-#include <string>
-
-
-namespace os {
-
-struct Permissions
-{
- explicit Permissions(mode_t mode)
- {
- owner.r = mode & S_IRUSR;
- owner.w = mode & S_IWUSR;
- owner.x = mode & S_IXUSR;
- owner.rwx = mode & S_IRWXU;
- group.r = mode & S_IRGRP;
- group.w = mode & S_IWGRP;
- group.x = mode & S_IXGRP;
- group.rwx = mode & S_IRWXG;
- others.r = mode & S_IROTH;
- others.w = mode & S_IWOTH;
- others.x = mode & S_IXOTH;
- others.rwx = mode & S_IRWXO;
- setuid = mode & S_ISUID;
- setgid = mode & S_ISGID;
- sticky = mode & S_ISVTX;
- }
-
- struct {
- bool r;
- bool w;
- bool x;
- bool rwx;
- } owner, group, others;
-
- bool setuid;
- bool setgid;
- bool sticky;
-};
-
-
-inline Try<Permissions> permissions(const std::string& path)
-{
- struct stat s;
- if (::stat(path.c_str(), &s) < 0) {
- return ErrnoError();
- }
- return Permissions(s.st_mode);
-}
-
-} // namespace os {
-
-#endif // __STOUT_OS_POSIX_PERMISSIONS_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/3b034277/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/permissions.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/permissions.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/permissions.hpp
deleted file mode 100644
index daed4b4..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/permissions.hpp
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __STOUT_OS_WINDOWS_PERMISSIONS_HPP__
-#define __STOUT_OS_WINDOWS_PERMISSIONS_HPP__
-
-#include <sys/stat.h>
-
-#include <string>
-
-
-namespace os {
-
-// Forward declaration.
-struct Permissions
-{
- explicit Permissions(mode_t mode)
- {
- UNIMPLEMENTED;
- }
-};
-
-
-inline Try<Permissions> permissions(const std::string& path)
-{
- UNIMPLEMENTED;
-}
-
-} // namespace os {
-
-#endif // __STOUT_OS_WINDOWS_PERMISSIONS_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/3b034277/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
index 10bfa40..5f564d2 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
@@ -117,4 +117,102 @@ decltype(_mkdir(path))
}
+// Permissions API. (cf. MESOS-3176 to track ongoing permissions work.)
+//
+// We are currently able to emulate a subset of the POSIX permissions model
+// with the Windows model:
+// [x] User write permissions.
+// [x] User read permissions.
+// [ ] User execute permissions.
+// [ ] Group permissions of any sort.
+// [ ] Other permissions of any sort.
+// [x] Flags to control "fallback" behavior (e.g., we might choose
+// to fall back to user readability when the user passes the
+// group readability flag in, since we currently do not support
+// group readability).
+//
+//
+// Rationale:
+// Windows currently implements two permissions models: (1) an extremely
+// primitive permission model it largely inherited from DOS, and (2) the Access
+// Control List (ACL) API. Because there is no trivial way to map the classic
+// POSIX model into the ACL model, we have implemented POSIX-style permissions
+// in terms of the DOS model. The result is the permissions limitations above.
+//
+//
+// Flag implementation:
+// Flags fall into the following two categories.
+// (1) Flags which exist in both permission models, but which have
+// different names (e.g., `S_IRUSR` in POSIX is called `_S_IREAD` on
+// Windows). In this case, we define the POSIX name to be the Windows
+// value (e.g., we define `S_IRUSR` to have the same value as `_S_IREAD`),
+// so that we can pass the POSIX name into Windows functions like
+// `_open`.
+// (2) Flags which exist only on POSIX (e.g., `S_IXUSR`). Here we
+// define the POSIX name to be the value given in the glibc
+// documentation[1], shifted left by 16 bits (since `mode_t`
+// is unsigned short on POSIX and `int` on Windows). We give these
+// flags glibc values to stay consistent, and so that existing
+// calls to functions like `open` do not break when they try to
+// use a flag that doesn't exist on Windows. But, of course,
+// these flags do not affect the execution of these functions.
+//
+//
+// Flag strictness:
+// Because the current implementation does not directly support setting or
+// getting group or other permission bits on the Windows platform, there is a
+// question of what we should fall back to when these flags are passed in to
+// Stout methods.
+//
+// TODO(hausdorff): Investigate permissions mappings.
+// We force "strictness" of the permission flag semantics:
+// * The group permissions flags will not fall back to anything, and will be
+// completely ignored.
+// * Other permissions: Same as above, but with other permissions.
+//
+//
+// Execute permissions:
+// Because DOS has no notion of "execute permissions", we define execute
+// permissions to be read permissions. This is not ideal, but it is closest to
+// being accurate.
+//
+//
+// [1] http://www.delorie.com/gnu/docs/glibc/libc_288.html
+
+
+// Corresponds to `mode_t` defined in sys/types.h of the POSIX spec.
+// See note above for an explanation of why this is an int instead of
+// unsigned short (as is common on *nix).
+typedef int mode_t;
+
+
+// User permission flags.
+const mode_t S_IRUSR = mode_t(_S_IREAD); // Readable by user.
+const mode_t S_IWUSR = mode_t(_S_IWRITE); // Writeable by user.
+const mode_t S_IXUSR = S_IRUSR; // Fallback to user read.
+const mode_t S_IRWXU = S_IRUSR | S_IWUSR | S_IXUSR;
+
+
+// Group permission flags. Lossy mapping to Windows permissions. See
+// note above about flag strictness for explanation.
+const mode_t S_IRGRP = 0x00200000; // No-op.
+const mode_t S_IWGRP = 0x00100000; // No-op.
+const mode_t S_IXGRP = 0x00080000; // No-op.
+const mode_t S_IRWXG = S_IRGRP | S_IWGRP | S_IXGRP;
+
+
+// Other permission flags. Lossy mapping to Windows permissions. See
+// note above about flag stictness for explanation.
+const mode_t S_IROTH = 0x00040000; // No-op.
+const mode_t S_IWOTH = 0x00020000; // No-op.
+const mode_t S_IXOTH = 0x00010000; // No-op.
+const mode_t S_IRWXO = S_IROTH | S_IWOTH | S_IXOTH;
+
+
+// Flags for set-ID-on-exec.
+const mode_t S_ISUID = 0x08000000; // No-op.
+const mode_t S_ISGID = 0x04000000; // No-op.
+const mode_t S_ISVTX = 0x02000000; // No-op.
+
+
#endif // __STOUT_WINDOWS_HPP__