// Spectre 2 // // Douglas Thrift // // $Id$ #include "Mounter.hpp" #include #include void Mounter::operator()() { // XXX: make sure the directory exists! #ifdef __FreeBSD__ { bool password(false); // XXX: _unsynchronized _synchronized (Daemon::secretLock) { api::FileReader in(Daemon::secret); ext::String line; while (ios::ReadLine(in, line)) if (line == "[" + share.getHost() + ":" + share.getOwner() + "]") { password = true; break; } } if (!password) _synchronized (Daemon::secretLock) { AppendFileWriter out(Daemon::secret); ios::FormatWriter fout(out); fout << "[" << share.getHost() << ":" << share.getOwner() << "]" << ios::NewLine << "password=" << share.getPassword() << ios::NewLine; } } #else _S credentials; // XXX: _unsynchronized _synchronized (Daemon::secretsLock) if (Daemon::secrets.Contains(share.getOwner() + "@" + share.getHost())) credentials = Daemon::secrets[share.getOwner() + "@" + share.getHost()]; if (credentials.IsEmpty()) { credentials << "/tmp/.spectre" << api::Uuid::Create(); { SecretFileWriter out(credentials); ios::FormatWriter fout(out); fout << "username = " << share.getOwner() << ios::NewLine << "password = " << share.getPassword() << ios::NewLine; } _synchronized (Daemon::secretsLock) Daemon::secrets[share.getOwner() + "@" + share.getHost()]; } #endif _S uid; { ::passwd pwd, * result; ext::Buffer buffer(1024); api::Posix::CheckError(::getpwnam_r(share.getUser().NullTerminate(), &pwd, buffer.Begin(), buffer.GetSize(), &result)); uid << pwd.pw_uid; } _S gid; { ::group grp, * result; ext::Buffer buffer(1024); api::Posix::CheckError(::getgrnam_r(share.getGroup().NullTerminate(), &grp, buffer.Begin(), buffer.GetSize(), &result)); gid << grp.gr_gid; } _L options; #ifdef __FreeBSD__ options.InsertLast("-N"); // XXX: hmm? // options.InsertLast("-O=" + share.getOwner() + ":"); options.InsertLast("-u=" + uid); options.InsertLast("-g=" + gid); #else options.InsertLast("credentials=" + credentials); options.InsertLast("uid=" + uid); options.InsertLast("gid=" + gid); options.InsertLast("rw"); #endif _L args(1, "-o"); args.InsertLast(ext::JoinAll(options, ",")); args.InsertLast("-t"); args.InsertLast("smbfs"); args.InsertLast(share.getService()); args.InsertLast(share.getMount()); _S mount(Spectre2::mount, args); if (Spectre2::debug) ios::ReadToWrite(*mount.GetReader(), api::Cout); else ios::Discard(*mount.GetReader()); }