1 |
+ |
/* ============================================================================ |
2 |
+ |
* Spectre Samba Mounter |
3 |
+ |
* |
4 |
+ |
* Copyright © 2003-2004, Douglas Thrift. All Rights Reserved. |
5 |
+ |
* |
6 |
+ |
* Redistribution and use in source and binary forms, with or without |
7 |
+ |
* modification, are permitted provided that the following conditions are met: |
8 |
+ |
* |
9 |
+ |
* 1. Redistributions of source code must retain the above copyright notice, |
10 |
+ |
* this list of conditions and the following disclaimer. |
11 |
+ |
* |
12 |
+ |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
13 |
+ |
* this list of conditions and the following disclaimer in the documentation |
14 |
+ |
* and/or other materials provided with the distribution. |
15 |
+ |
* |
16 |
+ |
* 3. The end-user documentation included with the redistribution, if any, must |
17 |
+ |
* include the following acknowledgment: |
18 |
+ |
* |
19 |
+ |
* "This product includes software developed by Douglas Thrift |
20 |
+ |
* (http://computers.douglasthrift.net/spectre.xml)." |
21 |
+ |
* |
22 |
+ |
* Alternately, this acknowledgment may appear in the software itself, if |
23 |
+ |
* and wherever such third-party acknowledgments normally appear. |
24 |
+ |
* |
25 |
+ |
* 4. The names "Douglas Thrift" and "Spectre Samba Mounter" must not be used |
26 |
+ |
* to endorse or promote products derived from this software without |
27 |
+ |
* specific prior written permission. For written permission, please visit |
28 |
+ |
* http://www.douglasthrift.net/contact.cgi for contact information. |
29 |
+ |
* |
30 |
+ |
* 5. Products derived from this software may not be called "Spectre Samba |
31 |
+ |
* Mounter", nor may "Spectre Samba Mounter" appear in their name, without |
32 |
+ |
* prior written permission. |
33 |
+ |
* |
34 |
+ |
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
35 |
+ |
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
36 |
+ |
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
37 |
+ |
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
38 |
+ |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
39 |
+ |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
40 |
+ |
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
41 |
+ |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
42 |
+ |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
43 |
+ |
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
44 |
+ |
* ============================================================================ |
45 |
+ |
*/ |
46 |
|
// Spectre Samba Mounter |
47 |
|
// |
48 |
|
// Douglas Thrift |
49 |
|
// |
50 |
< |
// $Id: Mounter.cpp,v 1.11 2003/07/31 04:14:12 douglas Exp $ |
50 |
> |
// $Id: Mounter.cpp,v 1.12 2004/03/23 04:22:17 douglas Exp $ |
51 |
|
|
52 |
|
#include "Mounter.h" |
53 |
|
|
103 |
|
|
104 |
|
return; |
105 |
|
} |
106 |
< |
|
106 |
> |
|
107 |
|
while ((file = readdir(dir)) != NULL) |
108 |
|
{ |
109 |
|
struct stat dir; |
116 |
|
string folder = file->d_name; |
117 |
|
|
118 |
|
if (folder == "." || folder == "..") continue; |
119 |
< |
|
119 |
> |
|
120 |
|
string share = folder.find('.') == 0 ? folder.erase(0, 1) + "$" : |
121 |
|
folder; |
122 |
|
|
179 |
|
{ |
180 |
|
string path = config.root + "/" + host + "/" + (folder[folder.length() - 1] |
181 |
|
== '$' ? "." + folder.substr(0, folder.length() - 1) : folder); |
182 |
< |
|
182 |
> |
|
183 |
|
if (mounted.find(path) != mounted.end()) return; |
184 |
|
|
185 |
|
struct passwd* item = getpwnam(user.c_str()); |
191 |
|
} |
192 |
|
|
193 |
|
ostringstream options; |
194 |
< |
|
194 |
> |
|
195 |
|
#if defined _Linux_ |
196 |
|
char credentials[17]; |
197 |
|
|
198 |
|
sprintf(credentials, "%s", "/tmp/spectre.XXXX"); |
199 |
|
mkstemp(credentials); |
200 |
< |
|
200 |
> |
|
201 |
|
ofstream fout(credentials); |
202 |
|
|
203 |
|
fout << "username = " << owner << "\n" |
208 |
|
options << "credentials=" << credentials << "," |
209 |
|
<< "uid=" << item->pw_uid << "," |
210 |
|
<< "gid=" << item->pw_gid; |
211 |
< |
|
211 |
> |
|
212 |
|
string smb = "//" + host + "/" + folder; |
213 |
|
#elif defined _FreeBSD_ |
214 |
|
char* credentials = new char[strlen(getenv("HOME")) + 9]; |
215 |
< |
|
215 |
> |
|
216 |
|
sprintf(credentials, "%s/.nsmbrc", getenv("HOME")); |
217 |
|
int dot = open(credentials, O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); |
218 |
|
close(dot); |