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

Comparing Spectre2/Mounter.cpp (file contents):
Revision 415 by douglas, 2005-01-15T18:26:13-08:00 vs.
Revision 432 by douglas, 2005-03-27T01:56:29-08:00

# Line 6 | Line 6
6  
7   #include "Mounter.hpp"
8  
9 < #include <menes-api/environment.hpp>
9 > #include <grp.h>
10 > #include <pwd.h>
11  
12 < Mounter::Mounter(const ext::String& config) : Daemon(), config(config) {}
12 <
13 < Mounter::~Mounter()
12 > void Mounter::operator()()
13   {
14 < #ifdef __FreeBSD__
16 <        api::Posix::CheckError(::unlink(secret.NullTerminate()));
17 < #endif
18 < }
14 >        // XXX: make sure the directory exists!
15  
16   #ifdef __FreeBSD__
17 < ext::String Mounter::secret(api::TheEnvironment.Get("HOME") + "/.nsmbrc");
17 >        {
18 >                bool password(false);
19 >
20 >                {
21 >                        api::FileReader in(Daemon::secret);
22 >                        ext::String line;
23 >
24 >                        while (ios::ReadLine(in, line)) if (line == "[" + share.getHost() + ":" + share.getOwner() + "]")
25 >                        {
26 >                                password = true;
27 >
28 >                                break;
29 >                        }
30 >                }
31 >
32 >                if (!password)
33 >                {
34 >                        AppendFileWriter out(Daemon::secret);
35 >                        ios::FormatWriter fout(out);
36 >
37 >                        fout << "[" << share.getHost() << ":" << share.getOwner() << "]" << ios::NewLine << "password=" << share.getPassword() << ios::NewLine;
38 >                }
39 >        }
40 > #else
41 >        _S<ios::String> credentials;
42 >
43 >        // XXX: _unsynchronized
44 >        _synchronized (Daemon::secretsLock) if (Daemon::secrets.Contains(share.getOwner() + "@" + share.getHost()))
45 >                credentials = Daemon::secrets[share.getOwner() + "@" + share.getHost()];
46 >
47 >        if (credentials.IsEmpty())
48 >        {
49 >                credentials << "/tmp/.spectre" << api::Uuid::Create();
50 >
51 >                {
52 >                        SecretFileWriter out(credentials);
53 >                        ios::FormatWriter fout(out);
54 >
55 >                        fout << "username = " << share.getOwner() << ios::NewLine << "password = " << share.getPassword() << ios::NewLine;
56 >                }
57 >
58 >                _synchronized (Daemon::secretsLock)
59 >                        Daemon::secrets[share.getOwner() + "@" + share.getHost()];
60 >        }
61   #endif
62  
63 < void Mounter::load()
64 < {
65 <        if (Spectre2::debug) api::Cerr << "Mounter::load()" << ios::NewLine;
63 >        _S<ios::String> uid;
64 >
65 >        {
66 >                ::passwd pwd, * result;
67 >                ext::Buffer buffer(1024);
68 >
69 >                api::Posix::CheckError(::getpwnam_r(share.getUser().NullTerminate(), &pwd, buffer.Begin(), buffer.GetSize(), &result));
70 >
71 >                uid << pwd.pw_uid;
72 >        }
73 >
74 >        _S<ios::String> gid;
75  
28 #ifdef __FreeBSD__
76          {
77 <                SecretFileWriter file(secret);
77 >                ::group grp, * result;
78 >                ext::Buffer buffer(1024);
79 >
80 >                api::Posix::CheckError(::getgrnam_r(share.getGroup().NullTerminate(), &grp, buffer.Begin(), buffer.GetSize(), &result));
81  
82 <                //
82 >                gid << grp.gr_gid;
83          }
84 +
85 +        _L<ext::String> options;
86 +
87 + #ifdef __FreeBSD__
88 +        options.InsertLast("-N");
89 +        // XXX: hmm?
90 + //      options.InsertLast("-O=" + share.getOwner() + ":");
91 +        options.InsertLast("-u=" + uid);
92 +        options.InsertLast("-g=" + gid);
93 + #else
94 +        options.InsertLast("credentials=" + credentials);
95 +        options.InsertLast("uid=" + uid);
96 +        options.InsertLast("gid=" + gid);
97 +        options.InsertLast("rw");
98   #endif
35        
36        loaded = true;
37 }
99  
100 < void Mounter::run()
40 < {
41 <        if (Spectre2::debug) api::Cerr << "Mounter::run()" << ios::NewLine;
100 >        _L<ext::String> args(1, "-o");
101  
102 <        ::sleep(5);
102 >        args.InsertLast(ext::JoinAll<ext::String>(options, ","));
103 >        args.InsertLast("-t");
104 >        args.InsertLast("smbfs");
105 >        args.InsertLast(share.getService());
106 >        args.InsertLast(share.getMount());
107 >
108 >        _S<api::Process> mount(Spectre2::mount, args);
109 >
110 >        if (Spectre2::debug)
111 >                ios::ReadToWrite(*mount.GetReader(), api::Cout);
112 >        else
113 >                ios::Discard(*mount.GetReader());
114   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines