[haiku-commits] haiku: hrev48093 - src/tools/fs_shell headers/private/fs_shell

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 25 Oct 2014 19:32:09 +0200 (CEST)

hrev48093 adds 1 changeset to branch 'master'
old head: 5a95af70a2c45a103b96046b5dae5c2b5a303dfa
new head: 50d274f7f9e714a0fd8a51192a37fd90cb6fbb2d
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=50d274f+%5E5a95af7

----------------------------------------------------------------------------

50d274f: fs_shell: Added missing new permission check function.
  
  * Fixes the build.

                                   [ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev48093
Commit:      50d274f7f9e714a0fd8a51192a37fd90cb6fbb2d
URL:         http://cgit.haiku-os.org/haiku/commit/?id=50d274f
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Sat Oct 25 17:31:15 2014 UTC

----------------------------------------------------------------------------

3 files changed, 40 insertions(+), 1 deletion(-)
headers/private/fs_shell/fssh_api_wrapper.h  |  1 +
headers/private/fs_shell/fssh_fs_interface.h |  4 ++-
src/tools/fs_shell/vfs.cpp                   | 36 ++++++++++++++++++++++++

----------------------------------------------------------------------------

diff --git a/headers/private/fs_shell/fssh_api_wrapper.h 
b/headers/private/fs_shell/fssh_api_wrapper.h
index f445fba..6a9e601 100644
--- a/headers/private/fs_shell/fssh_api_wrapper.h
+++ b/headers/private/fs_shell/fssh_api_wrapper.h
@@ -938,6 +938,7 @@
 #define unremove_vnode                         fssh_unremove_vnode
 #define get_vnode_removed                      fssh_get_vnode_removed
 #define volume_for_vnode                       fssh_volume_for_vnode
+#define check_access_permissions       fssh_check_access_permissions
 #define read_pages                                     fssh_read_pages
 #define write_pages                                    fssh_write_pages
 #define read_file_io_vec_pages         fssh_read_file_io_vec_pages
diff --git a/headers/private/fs_shell/fssh_fs_interface.h 
b/headers/private/fs_shell/fssh_fs_interface.h
index 6a0fdd0..48dfce0 100644
--- a/headers/private/fs_shell/fssh_fs_interface.h
+++ b/headers/private/fs_shell/fssh_fs_interface.h
@@ -361,7 +361,9 @@ extern fssh_status_t fssh_unremove_vnode(fssh_fs_volume 
*volume,
 extern fssh_status_t fssh_get_vnode_removed(fssh_fs_volume *volume,
                                fssh_vnode_id vnodeID, bool* removed);
 extern fssh_fs_volume* fssh_volume_for_vnode(fssh_fs_vnode *vnode);
-
+extern fssh_status_t fssh_check_access_permissions(int accessMode,
+                               fssh_mode_t mode, fssh_gid_t nodeGroupID,
+                               fssh_uid_t nodeUserID);
 
 extern fssh_status_t fssh_read_pages(int fd, fssh_off_t pos,
                                const struct fssh_iovec *vecs, fssh_size_t 
count,
diff --git a/src/tools/fs_shell/vfs.cpp b/src/tools/fs_shell/vfs.cpp
index 55a37b5..9308a35 100644
--- a/src/tools/fs_shell/vfs.cpp
+++ b/src/tools/fs_shell/vfs.cpp
@@ -2128,6 +2128,42 @@ fssh_volume_for_vnode(fssh_fs_vnode *_vnode)
 }
 
 
+extern "C" fssh_status_t
+fssh_check_access_permissions(int accessMode, fssh_mode_t mode,
+       fssh_gid_t nodeGroupID, fssh_uid_t nodeUserID)
+{
+       // get node permissions
+       int userPermissions = (mode & FSSH_S_IRWXU) >> 6;
+       int groupPermissions = (mode & FSSH_S_IRWXG) >> 3;
+       int otherPermissions = mode & FSSH_S_IRWXO;
+
+       // get the node permissions for this uid/gid
+       int permissions = 0;
+       fssh_uid_t uid = fssh_geteuid();
+
+       if (uid == 0) {
+               // user is root
+               // root has always read/write permission, but at least one of 
the
+               // X bits must be set for execute permission
+               permissions = userPermissions | groupPermissions | 
otherPermissions
+                       | FSSH_S_IROTH | FSSH_S_IWOTH;
+               if (FSSH_S_ISDIR(mode))
+                       permissions |= FSSH_S_IXOTH;
+       } else if (uid == nodeUserID) {
+               // user is node owner
+               permissions = userPermissions;
+       } else if (fssh_getegid() == nodeGroupID) {
+               // user is in owning group
+               permissions = groupPermissions;
+       } else {
+               // user is one of the others
+               permissions = otherPermissions;
+       }
+
+       return (accessMode & ~permissions) == 0 ? FSSH_B_OK : 
FSSH_B_NOT_ALLOWED;
+}
+
+
 //! Works directly on the host's file system
 extern "C" fssh_status_t
 fssh_read_pages(int fd, fssh_off_t pos, const fssh_iovec *vecs,


Other related posts:

  • » [haiku-commits] haiku: hrev48093 - src/tools/fs_shell headers/private/fs_shell - axeld