26 |
|
|
27 |
|
#ifdef __FreeBSD__ |
28 |
|
api::Posix::CheckError(::unlink(secret.NullTerminate())); |
29 |
+ |
#else |
30 |
+ |
_foreach (const ext::RedBlackMap<ext::String>, secret, secrets) |
31 |
+ |
api::Posix::CheckError(::unlink(secret.NullTerminate())); |
32 |
|
#endif |
33 |
|
} |
34 |
|
|
35 |
|
ext::RedBlackSet<Share> Daemon::shares; |
33 |
– |
//api::ThreadMutex Daemon::smbcLock; |
36 |
|
#ifdef __FreeBSD__ |
37 |
|
ext::String Daemon::secret(api::TheEnvironment.Get("HOME") + "/.nsmbrc"); |
38 |
+ |
api::ThreadMutex Daemon::secretLock; |
39 |
+ |
#else |
40 |
+ |
ext::RedBlackMap<ext::String> Daemon::secrets; |
41 |
+ |
api::ThreadMutex Daemon::secretsLock; |
42 |
|
#endif |
43 |
|
|
44 |
|
int Daemon::loop() |
58 |
|
|
59 |
|
void Daemon::load() |
60 |
|
{ |
61 |
+ |
#ifndef __FreeBSD__ |
62 |
+ |
_foreach (const ext::RedBlackMap<ext::String>, secret, secrets) |
63 |
+ |
api::Posix::CheckError(::unlink(secret.NullTerminate())); |
64 |
+ |
|
65 |
+ |
secrets.Clear(); |
66 |
+ |
#endif |
67 |
|
shares.Clear(); |
68 |
|
Share::passwords.Clear(); |
69 |
|
|
79 |
|
if (!(*spectre/"mount").IsEmpty()) |
80 |
|
Spectre2::mount = *spectre/"mount"; |
81 |
|
|
82 |
+ |
if (!(*spectre/"umount").IsEmpty()) |
83 |
+ |
Spectre2::umount = *spectre/"umount"; |
84 |
+ |
|
85 |
|
if (!(*spectre/"interval").IsEmpty()) |
86 |
|
interval = lexical_cast<unsigned>(ext::String(*spectre/"interval")); |
87 |
|
|
88 |
|
CheckError(::smbc_init(authenticate, Spectre2::debug ? 2 : 0)); |
89 |
|
|
90 |
|
#ifdef __FreeBSD__ |
91 |
< |
SecretFileWriter out(secret); |
91 |
> |
api::FileWriter out(secret, O_WRONLY | O_CREAT | O_TRUNC, 0600); |
92 |
|
ios::FormatWriter fout(out); |
93 |
|
#endif |
94 |
|
|
133 |
|
_foreach (const ext::RedBlackSet<Share>, share, shares) |
134 |
|
workers.Add(etl::BindAll(&Daemon::work_<Worker>, this, *share)); |
135 |
|
|
136 |
< |
// XXX: not useful for solving the problem it was supposed to solve |
122 |
< |
/*_synchronized (smbcLock) if (++count % 8 == 0) try |
123 |
< |
{ |
124 |
< |
::SMBCCTX* context(::smbc_new_context()); |
125 |
< |
|
126 |
< |
context->debug = Spectre2::debug ? 2 : 0; |
127 |
< |
context->callbacks.auth_fn = authenticate; |
128 |
< |
|
129 |
< |
CheckError(::smbc_init_context(context)); |
130 |
< |
|
131 |
< |
::SMBCCTX* old(::smbc_set_context(context)); |
132 |
< |
|
133 |
< |
CheckError(::smbc_free_context(old, 0)); |
134 |
< |
} |
135 |
< |
catch (const Error&) { --count; }*/ |
136 |
< |
|
137 |
< |
if (running && loaded) try |
138 |
< |
{ |
136 |
> |
if (running && loaded) |
137 |
|
sleep(); |
140 |
– |
} |
141 |
– |
catch (const api::Error&) |
142 |
– |
{ |
143 |
– |
api::Cout << "Can't sleep!" << ios::NewLine; |
144 |
– |
} |
138 |
|
|
139 |
|
workers.Join(); |
140 |
|
} |
157 |
|
{ |
158 |
|
::timespec wait = { interval, 0 }; |
159 |
|
|
160 |
< |
api::Posix::CheckError(::nanosleep(&wait, NULL)); |
160 |
> |
::nanosleep(&wait, NULL); |
161 |
|
} |