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 439 by douglas, 2005-04-07T15:56:53-07:00 vs.
Revision 441 by douglas, 2005-04-12T15:42:24-07:00

# Line 6 | Line 6
6  
7   #include "Mounter.hpp"
8  
9 + #include <menes-ext/stack.hpp>
10 +
11   #include <grp.h>
12   #include <pwd.h>
13  
14   void Mounter::operator()()
15   {
16 <        // XXX: make sure the directory exists!
16 >        ext::String service(share.getService());
17 >
18 >        {
19 >                ext::Stack<ext::String> stack;
20 >
21 >                for (api::Path path(service); !path.Exists(); path = path.GetParent())
22 >                        stack.Push(path.GetPath());
23 >
24 >                while (!stack.IsEmpty())
25 >                {
26 >                        try
27 >                        {
28 >                                api::Posix::CheckError(::mkdir(stack.Top().NullTerminate(), 0755));
29 >                        }
30 >                        catch (const api::Posix::Error&) {}
31 >
32 >                        stack.Pop();
33 >                }
34 >        }
35 >
36 >        uid_t uid;
37 >
38 >        {
39 >                ::passwd pwd, * result;
40 >                ext::Buffer buffer(1024);
41 >
42 >                api::Posix::CheckError(::getpwnam_r(share.getUser().NullTerminate(), &pwd, buffer.Begin(), buffer.GetSize(), &result));
43 >
44 >                uid = pwd.pw_uid;
45 >        }
46 >
47 >        gid_t gid;
48 >
49 >        {
50 >                ::group grp, * result;
51 >                ext::Buffer buffer(1024);
52 >
53 >                api::Posix::CheckError(::getgrnam_r(share.getGroup().NullTerminate(), &grp, buffer.Begin(), buffer.GetSize(), &result));
54 >
55 >                gid = grp.gr_gid;
56 >        }
57 >
58 >        try
59 >        {
60 >                api::Posix::CheckError(::chown(service.NullTerminate(), uid, gid));
61 >        }
62 >        catch (const api::Posix::Error&) {}
63  
64   #ifdef __FreeBSD__
65          {
# Line 62 | Line 110 | void Mounter::operator()()
110          }
111   #endif
112  
65        _S<ios::String> uid;
66
67        {
68                ::passwd pwd, * result;
69                ext::Buffer buffer(1024);
70
71                api::Posix::CheckError(::getpwnam_r(share.getUser().NullTerminate(), &pwd, buffer.Begin(), buffer.GetSize(), &result));
72
73                uid << pwd.pw_uid;
74        }
75
76        _S<ios::String> gid;
77
78        {
79                ::group grp, * result;
80                ext::Buffer buffer(1024);
81
82                api::Posix::CheckError(::getgrnam_r(share.getGroup().NullTerminate(), &grp, buffer.Begin(), buffer.GetSize(), &result));
83
84                gid << grp.gr_gid;
85        }
86
113          _L<ext::String> options;
114  
115   #ifdef __FreeBSD__
116          options.InsertLast("-N");
117          // XXX: hmm?
118   //      options.InsertLast("-O=" + share.getOwner() + ":");
119 <        options.InsertLast("-u=" + uid);
120 <        options.InsertLast("-g=" + gid);
119 >        options.InsertLast("-u=" + lexical_cast<ext::String>(uid));
120 >        options.InsertLast("-g=" + lexical_cast<ext::String>(gid));
121   #else
122          options.InsertLast("credentials=" + credentials);
123 <        options.InsertLast("uid=" + uid);
124 <        options.InsertLast("gid=" + gid);
123 >        options.InsertLast("uid=" + lexical_cast<ext::String>(uid));
124 >        options.InsertLast("gid=" + lexical_cast<ext::String>(gid));
125          options.InsertLast("rw");
126   #endif
127  
# Line 104 | Line 130 | void Mounter::operator()()
130          args.InsertLast(ext::JoinAll<ext::String>(options, ","));
131          args.InsertLast("-t");
132          args.InsertLast("smbfs");
133 <        args.InsertLast(share.getService());
133 >        args.InsertLast(service);
134          args.InsertLast(share.getMount());
135  
136          _S<api::Process> mount(Spectre2::mount, args);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines