From cc5219493de34749b7c4eed12fc144f1520b8df6 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 19 Jul 2015 20:09:48 +0100 Subject: Make ModeCheck into a class --- netfs/daemon/daemon.cpp | 4 ++-- netfs/daemon/daemonVolume.cpp | 6 +++--- netfs/daemon/modeCheck.cpp | 6 +++--- netfs/daemon/modeCheck.h | 9 ++++++--- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/netfs/daemon/daemon.cpp b/netfs/daemon/daemon.cpp index 20a8562..59f3638 100644 --- a/netfs/daemon/daemon.cpp +++ b/netfs/daemon/daemon.cpp @@ -95,7 +95,7 @@ TempPrivs::AssertRead(const boost::filesystem::path & p) const if (::lstat(p.string().c_str(), &s) != 0) { throw NetFS::SystemError(errno); } - if (!ReadableBy(s, myu, myg)) { + if (!ModeCheck::ReadableBy(s, myu, myg)) { throw NetFS::SystemError(EACCES); } } @@ -110,7 +110,7 @@ TempPrivs::AssertWrite(const boost::filesystem::path & p) const if (::lstat(p.string().c_str(), &s) != 0) { throw NetFS::SystemError(errno); } - if (!WritableBy(s, myu, myg)) { + if (!ModeCheck::WritableBy(s, myu, myg)) { throw NetFS::SystemError(EACCES); } } diff --git a/netfs/daemon/daemonVolume.cpp b/netfs/daemon/daemonVolume.cpp index e457098..40082cc 100644 --- a/netfs/daemon/daemonVolume.cpp +++ b/netfs/daemon/daemonVolume.cpp @@ -47,13 +47,13 @@ VolumeServer::access(const NetFS::ReqEnv & re, const std::string & path, Ice::In return 0; } tp.AssertRead(p.parent_path()); - if (mode & R_OK && !ReadableBy(s, tp.myu, tp.myg)) { + if (mode & R_OK && !ModeCheck::ReadableBy(s, tp.myu, tp.myg)) { return EACCES; } - if (mode & W_OK && !WritableBy(s, tp.myu, tp.myg)) { + if (mode & W_OK && !ModeCheck::WritableBy(s, tp.myu, tp.myg)) { return EACCES; } - if (mode & X_OK && !ExecutableBy(s, tp.myu, tp.myg)) { + if (mode & X_OK && !ModeCheck::ExecutableBy(s, tp.myu, tp.myg)) { return EACCES; } return 0; diff --git a/netfs/daemon/modeCheck.cpp b/netfs/daemon/modeCheck.cpp index 63ae46a..637abe3 100644 --- a/netfs/daemon/modeCheck.cpp +++ b/netfs/daemon/modeCheck.cpp @@ -5,7 +5,7 @@ #define gs GroupEntCache::instance bool -ReadableBy(const struct stat & s, uid_t u, gid_t g) +ModeCheck::ReadableBy(const struct stat & s, uid_t u, gid_t g) { if (u == 0) return true; if (s.st_mode & S_IROTH) return true; @@ -15,7 +15,7 @@ ReadableBy(const struct stat & s, uid_t u, gid_t g) } bool -WritableBy(const struct stat & s, uid_t u, gid_t g) +ModeCheck::WritableBy(const struct stat & s, uid_t u, gid_t g) { if (u == 0) return true; if (s.st_mode & S_IWOTH) return true; @@ -25,7 +25,7 @@ WritableBy(const struct stat & s, uid_t u, gid_t g) } bool -ExecutableBy(const struct stat & s, uid_t u, gid_t g) +ModeCheck::ExecutableBy(const struct stat & s, uid_t u, gid_t g) { if (u == 0 && (s.st_mode & (S_IXOTH | S_IXGRP | S_IXUSR))) return true; if (s.st_mode & S_IXOTH) return true; diff --git a/netfs/daemon/modeCheck.h b/netfs/daemon/modeCheck.h index ed2d60b..b3377bd 100644 --- a/netfs/daemon/modeCheck.h +++ b/netfs/daemon/modeCheck.h @@ -3,9 +3,12 @@ #include -bool ReadableBy(const struct stat &, uid_t u, gid_t g); -bool WritableBy(const struct stat &, uid_t u, gid_t g); -bool ExecutableBy(const struct stat &, uid_t u, gid_t g); +class ModeCheck { + public: + static bool ReadableBy(const struct stat &, uid_t u, gid_t g); + static bool WritableBy(const struct stat &, uid_t u, gid_t g); + static bool ExecutableBy(const struct stat &, uid_t u, gid_t g); +}; #endif -- cgit v1.2.3