7 |
|
#include "Share.hpp" |
8 |
|
|
9 |
|
#include <stdio.h> |
10 |
– |
#include <libsmbclient.h> |
10 |
|
|
11 |
< |
extern "C" |
12 |
< |
{ |
14 |
< |
void authenticate(const char* server, const char* share, char* work, int workSize, char* user, int userSize, char* password, int passwordSize); |
15 |
< |
} |
16 |
< |
|
17 |
< |
Share::Share(const ext::String& host, const ext::String& name, const ext::String& owner, const ext::String& user, const ext::String& group) : host(host), name(name), owner(owner), user(user), group(group) |
18 |
< |
{ |
19 |
< |
if (!initialized) |
20 |
< |
{ |
21 |
< |
CheckError(::smbc_init(authenticate, Spectre2::debug ? 2 : 0)); |
22 |
< |
|
23 |
< |
initialized = true; |
24 |
< |
} |
25 |
< |
} |
11 |
> |
ext::RedBlackMap<ext::String, ext::String> Share::passwords; |
12 |
> |
api::ThreadMutex Share::passwordsLock; |
13 |
|
|
14 |
|
ext::String Share::getPassword() const |
15 |
|
{ |
16 |
+ |
// XXX: _unsynchronized |
17 |
|
_synchronized (passwordsLock) if (passwords.Contains(owner + "@" + host)) |
18 |
|
return passwords[owner + "@" + host]; |
19 |
|
|
20 |
< |
try |
20 |
> |
_synchronized(passwordsLock) try |
21 |
|
{ |
22 |
< |
api::FileReader in(Spectre2::prefix + "/etc/." + owner + "@" + host); |
23 |
< |
ext::String password(ios::ReadLine(in)); |
22 |
> |
api::FileReader in(Spectre2::prefix + "/etc/.spectre/" + owner + "@" + host); |
23 |
> |
ext::String& password(passwords[owner + "@" + host]); |
24 |
|
|
25 |
< |
_synchronized (passwordsLock) |
38 |
< |
passwords[owner + "@" + host] = password; |
25 |
> |
ios::ReadLine(in, password); |
26 |
|
|
27 |
|
return password; |
28 |
|
} |
29 |
|
catch (const api::Error&) |
30 |
|
{ |
31 |
< |
ext::String password(::getpass(("Password (" + owner + "@" + host + "):").NullTerminate())); |
32 |
< |
|
33 |
< |
_synchronized (passwordsLock) |
47 |
< |
passwords[owner + "@" + host] = password; |
31 |
> |
ext::String& password(passwords[owner + "@" + host]); |
32 |
> |
|
33 |
> |
password = ::getpass(("Password (" + owner + "@" + host + "):").NullTerminate()); |
34 |
|
|
35 |
|
return password; |
36 |
|
} |
37 |
+ |
|
38 |
+ |
throw api::UnexpectedErrorException(); |
39 |
|
} |
40 |
|
|
41 |
|
ext::String Share::getService() const |
87 |
|
} |
88 |
|
} |
89 |
|
|
102 |
– |
bool Share::initialized(false); |
103 |
– |
ext::RedBlackMap<ext::String, ext::String> Share::passwords; |
104 |
– |
api::ThreadMutex Share::passwordsLock; |
105 |
– |
|
90 |
|
extern "C" |
91 |
|
{ |
92 |
|
void authenticate(const char* host, const char* name, char* work, int workSize, char* owner, int ownerSize, char* password, int passwordSize) |
93 |
|
{ |
94 |
|
const Share& share(*Daemon::shares.Find(Share(host, name))); |
95 |
+ |
const ext::Buffer& owner_(share.getOwner().GetData()); |
96 |
+ |
|
97 |
+ |
if (!owner_.IsEmpty()) |
98 |
+ |
{ |
99 |
+ |
_foreach (const ext::Buffer, atom, owner_) |
100 |
+ |
owner[_index] = *atom; |
101 |
|
|
102 |
< |
if (!share.getOwner().IsEmpty()) |
103 |
< |
::snprintf(owner, ownerSize, "%s", share.getOwner().NullTerminate()); |
102 |
> |
owner[owner_.GetSize() < size_t(ownerSize) ? owner_.GetSize() : ownerSize - 1] = '\0'; |
103 |
> |
} |
104 |
|
|
105 |
< |
::snprintf(password, passwordSize, "%s", share.getPassword().NullTerminate()); |
105 |
> |
ext::Buffer password_(share.getPassword().GetData()); |
106 |
> |
|
107 |
> |
_foreach (ext::Buffer, atom, password_) |
108 |
> |
password[_index] = *atom; |
109 |
> |
|
110 |
> |
password[password_.GetSize() < size_t(passwordSize) ? password_.GetSize() : passwordSize - 1] = '\0'; |
111 |
|
} |
112 |
|
} |