1 |
douglas |
402 |
// Spectre 2 |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
|
|
#include "Mounter.hpp" |
8 |
|
|
|
9 |
douglas |
408 |
#include <menes-api/environment.hpp> |
10 |
douglas |
428 |
#include <menes-api/socket.hpp> |
11 |
douglas |
408 |
|
12 |
douglas |
428 |
#include <arpa/inet.h> |
13 |
|
|
|
14 |
douglas |
418 |
Mounter::Mounter(const api::Path& config) : Daemon(), config(config) {} |
15 |
douglas |
402 |
|
16 |
douglas |
408 |
Mounter::~Mounter() |
17 |
|
|
{ |
18 |
|
|
#ifdef __FreeBSD__ |
19 |
|
|
api::Posix::CheckError(::unlink(secret.NullTerminate())); |
20 |
|
|
#endif |
21 |
|
|
} |
22 |
|
|
|
23 |
|
|
#ifdef __FreeBSD__ |
24 |
|
|
ext::String Mounter::secret(api::TheEnvironment.Get("HOME") + "/.nsmbrc"); |
25 |
|
|
#endif |
26 |
|
|
|
27 |
douglas |
402 |
void Mounter::load() |
28 |
|
|
{ |
29 |
douglas |
428 |
_synchronized (Spectre2::sharesLock) |
30 |
|
|
Spectre2::shares.Clear(); |
31 |
douglas |
408 |
|
32 |
douglas |
428 |
_synchronized (Share::passwordsLock) |
33 |
|
|
Share::passwords.Clear(); |
34 |
|
|
|
35 |
|
|
_H<xml::Document> document(xml::Parse(config.GetPath())); |
36 |
|
|
_H<xml::Node> spectre(*document/"spectre"); |
37 |
douglas |
408 |
#ifdef __FreeBSD__ |
38 |
douglas |
428 |
SecretFileWriter out(secret); |
39 |
|
|
ios::FormatWriter fout(out); |
40 |
|
|
#endif |
41 |
|
|
|
42 |
|
|
_foreach (const xml::NodeSet, host_, *spectre/"host") |
43 |
douglas |
408 |
{ |
44 |
douglas |
428 |
ext::String host(**host_/"name"); |
45 |
douglas |
408 |
|
46 |
douglas |
428 |
_foreach (const xml::NodeSet, share, **host_/"share") |
47 |
|
|
{ |
48 |
|
|
ext::String name(**share/"name"), owner(**share/"owner"), user(**share/"user"), group(**share/"group"); |
49 |
|
|
|
50 |
|
|
_synchronized (Spectre2::sharesLock) |
51 |
|
|
Spectre2::shares.Insert(Share(host, name, owner, user, group)); |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
#ifdef __FreeBSD__ |
55 |
|
|
::addrinfo* info; |
56 |
|
|
|
57 |
|
|
api::Posix::CheckGaiError(::getaddrinfo(host.NullTerminate(), NULL, NULL, &info)); |
58 |
|
|
|
59 |
|
|
::sockaddr_in& sock(*reinterpret_cast< ::sockaddr_in*>(info->ai_addr)); |
60 |
|
|
ext::Buffer buffer(128); |
61 |
|
|
|
62 |
|
|
fout << "[" << host << "]" << ios::NewLine << "addr=" << ::inet_ntop(sock.sin_family, &sock.sin_addr, buffer.Begin(), buffer.GetSize()) << ios::NewLine; |
63 |
|
|
|
64 |
|
|
::freeaddrinfo(info); |
65 |
|
|
#endif |
66 |
douglas |
408 |
} |
67 |
douglas |
428 |
|
68 |
|
|
_synchronized (Spectre2::sharesLock) |
69 |
|
|
Spectre2::shares.Output(api::Cout); |
70 |
douglas |
402 |
|
71 |
|
|
loaded = true; |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
void Mounter::run() |
75 |
|
|
{ |
76 |
douglas |
428 |
ext::ThreadSet<> workers; |
77 |
douglas |
402 |
|
78 |
douglas |
428 |
_synchronized (Spectre2::sharesLock) _foreach (const ext::RedBlackSet<Share>, share, Spectre2::shares) if (!share->mounted() && share->mountable()) |
79 |
|
|
{ |
80 |
|
|
api::Cerr << "STUB: mount " << *share << ios::NewLine; |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
workers.Join(); |
84 |
|
|
|
85 |
douglas |
407 |
::sleep(5); |
86 |
douglas |
402 |
} |