ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Spectre2/Share.cpp
Revision: 431
Committed: 2005-03-26T22:35:26-08:00 (20 years, 2 months ago) by douglas
File size: 2140 byte(s)
Log Message:
Grr! Why must this thing decided to ask for all the memory in existance at a certain point?

File Contents

# Content
1 // Spectre 2
2 //
3 // Douglas Thrift
4 //
5 // $Id$
6
7 #include "Share.hpp"
8
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 }

Properties

Name Value
svn:eol-style native
svn:keywords Id