summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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