summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-07-19 20:21:38 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2015-07-19 20:45:22 +0100
commitd9a61f78579240cc81da32804379b58a1688b75d (patch)
tree7811f634b038196058a7e68cd2dce0774f634ed8
parentMove TempPrivs into ModeCheck (diff)
downloadnetfs-d9a61f78579240cc81da32804379b58a1688b75d.tar.bz2
netfs-d9a61f78579240cc81da32804379b58a1688b75d.tar.xz
netfs-d9a61f78579240cc81da32804379b58a1688b75d.zip
Tidy up a little
-rw-r--r--netfs/daemon/modeCheck.cpp22
-rw-r--r--netfs/daemon/modeCheck.h3
2 files changed, 15 insertions, 10 deletions
diff --git a/netfs/daemon/modeCheck.cpp b/netfs/daemon/modeCheck.cpp
index 2a928a1..7a201e0 100644
--- a/netfs/daemon/modeCheck.cpp
+++ b/netfs/daemon/modeCheck.cpp
@@ -6,8 +6,8 @@
#define gs GroupEntCache::instance
ModeCheck::ModeCheck(const NetFS::ReqEnv & re, const boost::filesystem::path & r) :
- myu(UserEntCache::instance.getEntry(re.user)->id),
- myg(GroupEntCache::instance.getEntry(re.grp)->id),
+ myu(us.getEntry(re.user)->id),
+ myg(gs.getEntry(re.grp)->id),
root(r)
{
}
@@ -18,11 +18,7 @@ ModeCheck::AssertRead(const boost::filesystem::path & p) const
if (p != root) {
AssertRead(p.parent_path());
}
- struct stat s;
- if (::lstat(p.string().c_str(), &s) != 0) {
- throw NetFS::SystemError(errno);
- }
- if (!ModeCheck::ReadableBy(s, myu, myg)) {
+ if (!ModeCheck::ReadableBy(lstat(p), myu, myg)) {
throw NetFS::SystemError(EACCES);
}
}
@@ -33,13 +29,19 @@ ModeCheck::AssertWrite(const boost::filesystem::path & p) const
if (p != root) {
AssertRead(p.parent_path());
}
+ if (!ModeCheck::WritableBy(lstat(p), myu, myg)) {
+ throw NetFS::SystemError(EACCES);
+ }
+}
+
+struct stat
+ModeCheck::lstat(const boost::filesystem::path & p)
+{
struct stat s;
if (::lstat(p.string().c_str(), &s) != 0) {
throw NetFS::SystemError(errno);
}
- if (!ModeCheck::WritableBy(s, myu, myg)) {
- throw NetFS::SystemError(EACCES);
- }
+ return s;
}
bool
diff --git a/netfs/daemon/modeCheck.h b/netfs/daemon/modeCheck.h
index fae30d8..17d40fc 100644
--- a/netfs/daemon/modeCheck.h
+++ b/netfs/daemon/modeCheck.h
@@ -19,6 +19,9 @@ class ModeCheck {
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);
+
+ private:
+ static struct stat lstat(const boost::filesystem::path &);
};
#endif