ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Spectre2/Share.cpp
(Generate patch)

Comparing Spectre2/Share.cpp (file contents):
Revision 430 by douglas, 2005-03-25T19:01:08-08:00 vs.
Revision 431 by douglas, 2005-03-26T22:35:26-08:00

# Line 7 | Line 7
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
# Line 89 | Line 77 | bool Share::mountable() const
77          {
78                  struct stat share;
79  
80 <                CheckError(::smbc_stat(getUri().NullTerminate(), &share));
80 >                // XXX: _unsynchronized
81 > //              _synchronized (Daemon::smbcLock)
82 >                        CheckError(::smbc_stat(getUri().NullTerminate(), &share));
83  
84                  return true;
85          }
# Line 99 | Line 89 | bool Share::mountable() const
89          }
90   }
91  
102 bool Share::initialized(false);
103 ext::RedBlackMap<ext::String, ext::String> Share::passwords;
104 api::ThreadMutex Share::passwordsLock;
105
92   extern "C"
93   {
94          void authenticate(const char* host, const char* name, char* work, int workSize, char* owner, int ownerSize, char* password, int passwordSize)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines