1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#include "pch.hpp"
#include <Ice/Ice.h>
#include "daemon.h"
#include "daemonService.h"
#include "daemonVolume.h"
#include <slicer/slicer.h>
#include <xml/serializer.h>
#include "ioHelpers.h"
#include <sys/stat.h>
std::string
NetFSDaemon::hostname()
{
char buf[128];
gethostname(buf, sizeof(buf));
return buf;
}
// name = NetFSDaemonAdapter
void
NetFSDaemon::start(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq&)
{
this->ic = ic;
Ice::PropertiesPtr props = ic->getProperties();
LoadConfiguration(props->getProperty("NetFSD.ConfigPath"));
adapter = ic->createObjectAdapterWithEndpoints(name, dc->Self->Endpoint);
adapter->add(new ServiceServer(dc->CurrentConfiguration), ic->stringToIdentity("Service"));
adapter->activate();
}
void
NetFSDaemon::LoadConfiguration(const boost::filesystem::path & path)
{
dc = new NetFS::Daemon::RuntimeConfiguration();
dc->CurrentConfiguration = Slicer::Deserialize<Slicer::XmlFileDeserializer, NetFS::Daemon::Configuration>(path);
auto selfItr = dc->CurrentConfiguration->Hosts.find(hostname());
if (selfItr == dc->CurrentConfiguration->Hosts.end()) {
throw std::runtime_error("This host is not defined in the configuration.");
}
dc->Self = selfItr->second;
}
void
NetFSDaemon::stop()
{
adapter->deactivate();
}
extern "C" {
IceBox::Service *
createNetFSDaemon(Ice::CommunicatorPtr)
{
return new NetFSDaemon();
}
}
TempPrivs::TempPrivs(const NetFS::ReqEnv & re, const boost::filesystem::path & r) :
myu(UserEntCache::instance.getID(re.user)),
myg(GroupEntCache::instance.getID(re.grp)),
root(r)
{
}
void
TempPrivs::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 (!ReadableBy(s, myu, myg)) {
throw NetFS::SystemError(EACCES);
}
}
void
TempPrivs::AssertWrite(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 (!WritableBy(s, myu, myg)) {
throw NetFS::SystemError(EACCES);
}
}
|