4 |
|
// |
5 |
|
// Mounter.cpp |
6 |
|
|
7 |
+ |
#include "Mounter.h" |
8 |
+ |
|
9 |
|
#ifdef _FreeBSD_ |
10 |
+ |
#include <cctype> |
11 |
|
#include <fcntl.h> |
9 |
– |
#endif |
12 |
|
|
13 |
< |
#include "Mounter.h" |
13 |
> |
inline string toupper(const string& lower) |
14 |
> |
{ |
15 |
> |
string upper; |
16 |
> |
|
17 |
> |
for (unsigned index = 0; index < lower.length(); index++) |
18 |
> |
{ |
19 |
> |
upper += toupper(lower[index]); |
20 |
> |
} |
21 |
> |
|
22 |
> |
return upper; |
23 |
> |
} |
24 |
> |
#endif |
25 |
|
|
26 |
|
void Mounter::mount() |
27 |
|
{ |
171 |
|
|
172 |
|
string smb = "//" + host + "/" + folder; |
173 |
|
#elif defined _FreeBSD_ |
174 |
< |
char* credentials = "~/.nsmbrc"; |
175 |
< |
|
174 |
> |
char* credentials = new char[strlen(getenv("HOME")) + 9]; |
175 |
> |
|
176 |
> |
sprintf(credentials, "%s/.nsmbrc", getenv("HOME")); |
177 |
|
int dot = open(credentials, O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); |
178 |
|
close(dot); |
179 |
|
|
180 |
|
ofstream fout(credentials); |
181 |
|
|
182 |
< |
fout << "[default]\n" |
182 |
> |
fout << "[" << toupper(host) << ":" << toupper(owner) << "]\n" |
183 |
|
<< "password=" << password(owner) << "\n"; |
184 |
|
|
185 |
|
fout.close(); |
221 |
|
mount.close(); |
222 |
|
|
223 |
|
unlink(credentials); |
224 |
+ |
#ifdef _FreeBSD_ |
225 |
+ |
delete [] credentials; |
226 |
+ |
#endif |
227 |
|
} |