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 415 by douglas, 2005-01-15T18:26:13-08:00 vs.
Revision 431 by douglas, 2005-03-26T22:35:26-08:00

# Line 6 | Line 6
6  
7   #include "Share.hpp"
8  
9 < #include <libsmbclient.h>
9 > #include <stdio.h>
10 >
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 >        _synchronized(passwordsLock) try
21 >        {
22 >                api::FileReader in(Spectre2::prefix + "/etc/.spectre/" + owner + "@" + host);
23 >                ext::String& password(passwords[owner + "@" + host]);
24 >
25 >                ios::ReadLine(in, password);
26 >
27 >                return password;
28 >        }
29 >        catch (const api::Error&)
30 >        {
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
42 > {
43 > #ifdef __FreeBSD__
44 >        return "//" + owner + "@" + operator ext::String();
45 > #else
46 >        return "//" + operator ext::String();
47 > #endif
48 > }
49 >
50 > bool Share::mounted() const
51 > {
52 >        _L<ext::String> args(1, "-t");
53 >
54 >        args.InsertLast("smbfs");
55 >
56 >        _S<api::Process> mount(Spectre2::mount, args);
57 >        ext::String line;
58 > #ifdef __FreeBSD__
59 >        Matcher matcher("^//.* on " + getMount() + " \\(smbfs\\)$");
60 > #else
61 >        Matcher matcher("^.* on " + getMount() + " type smbfs$");
62 > #endif
63 >
64 >        while (ios::ReadLine(*mount.GetReader(), line)) if (line == matcher)
65 >        {
66 >                ios::Discard(*mount.GetReader());
67 >
68 >                return true;
69 >        }
70 >
71 >        return false;
72 > }
73 >
74 > bool Share::mountable() const
75 > {
76 >        try
77 >        {
78 >                struct stat share;
79 >
80 >                // XXX: _unsynchronized
81 > //              _synchronized (Daemon::smbcLock)
82 >                        CheckError(::smbc_stat(getUri().NullTerminate(), &share));
83 >
84 >                return true;
85 >        }
86 >        catch (const Error&)
87 >        {
88 >                return false;
89 >        }
90 > }
91 >
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)
95 >        {
96 >                const Share& share(*Daemon::shares.Find(Share(host, name)));
97 >
98 >                if (!share.getOwner().IsEmpty())
99 >                        ::snprintf(owner, ownerSize, "%s", share.getOwner().NullTerminate());
100 >                
101 >                ::snprintf(password, passwordSize, "%s", share.getPassword().NullTerminate());
102 >        }
103 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines