MainFrame::MainFrame (wxWindow* parent) : MainFrameBase (parent), ListItemRightClickEventPending (false), SelectedItemIndex (-1), SelectedSlotNumber (0), ShowRequestFifo (-1) { wxBusyCursor busy; SetName (Application::GetName()); SetTitle (Application::GetName()); SetIcon (Resources::GetTrueCrypt64Icon()); #if defined(TC_UNIX) && !defined(TC_MACOSX) try { string fifoPath = GetShowRequestFifoPath(); remove (fifoPath.c_str()); throw_sys_if (mkfifo (fifoPath.c_str(), S_IRUSR | S_IWUSR) == -1); ShowRequestFifo = open (fifoPath.c_str(), O_RDONLY | O_NONBLOCK); throw_sys_if (ShowRequestFifo == -1); } catch (...) { #ifdef DEBUG throw; #endif } #endif InitControls(); InitPreferences(); InitTaskBarIcon(); InitEvents(); InitMessageFilter(); if (!GetPreferences().SecurityTokenModule.IsEmpty() && !SecurityToken::IsInitialized()) { try { Gui->InitSecurityTokenLibrary(); } catch (exception &e) { Gui->ShowError (e); } } }
Pipe::Pipe () { int fd[2]; throw_sys_if (pipe (fd) == -1); ReadFileDescriptor = fd[0]; WriteFileDescriptor = fd[1]; }
UserId FilesystemPath::GetOwner () const { struct stat statData; throw_sys_if (stat (StringConverter::ToSingle (Path).c_str(), &statData) == -1); UserId owner; owner.SystemId = statData.st_uid; return owner; }
void CoreService::ProcessElevatedRequests () { int pid = fork(); throw_sys_if (pid == -1); if (pid == 0) { try { int f = open ("/dev/null", 0); throw_sys_sub_if (f == -1, "/dev/null"); throw_sys_if (dup2 (f, STDERR_FILENO) == -1); // Wait for sync code while (true) { byte b; throw_sys_if (read (STDIN_FILENO, &b, 1) != 1); if (b != 0x00) continue; throw_sys_if (read (STDIN_FILENO, &b, 1) != 1); if (b != 0x11) continue; throw_sys_if (read (STDIN_FILENO, &b, 1) != 1); if (b == 0x22) break; } ElevatedPrivileges = true; ProcessRequests (STDIN_FILENO, STDOUT_FILENO); _exit (0); } catch (exception &e) { #ifdef DEBUG SystemLog::WriteException (e); #endif } catch (...) { } _exit (1); } }
vector <int> SystemInfo::GetVersion () { struct utsname unameData; throw_sys_if (uname (&unameData) == -1); vector <string> versionStrings = StringConverter::Split (unameData.release, "."); vector <int> version; for (size_t i = 0; i < versionStrings.size(); ++i) { string s = versionStrings[i]; size_t p = s.find_first_not_of ("0123456789"); if (p != string::npos) s = s.substr (0, p); if (s.empty()) break; version.push_back (StringConverter::ToUInt32 (s)); } return version; }
void CoreUnix::SetFileOwner (const FilesystemPath &path, const UserId &owner) const { throw_sys_if (chown (string (path).c_str(), owner.SystemId, (gid_t) -1) == -1); }
void FuseService::ExecFunctor::operator() (int argc, char *argv[]) { struct timeval tv; gettimeofday (&tv, NULL); FuseService::OpenVolumeInfo.SerialInstanceNumber = (uint64)tv.tv_sec * 1000000ULL + tv.tv_usec; FuseService::MountedVolume = MountedVolume; FuseService::SlotNumber = SlotNumber; FuseService::UserId = getuid(); FuseService::GroupId = getgid(); if (getenv ("SUDO_UID")) { try { string s (getenv ("SUDO_UID")); FuseService::UserId = static_cast <uid_t> (StringConverter::ToUInt64 (s)); if (getenv ("SUDO_GID")) { s = getenv ("SUDO_GID"); FuseService::GroupId = static_cast <gid_t> (StringConverter::ToUInt64 (s)); } } catch (...) { } } static fuse_operations fuse_service_oper; fuse_service_oper.access = fuse_service_access; fuse_service_oper.destroy = fuse_service_destroy; fuse_service_oper.getattr = fuse_service_getattr; fuse_service_oper.init = fuse_service_init; fuse_service_oper.open = fuse_service_open; fuse_service_oper.opendir = fuse_service_opendir; fuse_service_oper.read = fuse_service_read; fuse_service_oper.readdir = fuse_service_readdir; fuse_service_oper.write = fuse_service_write; // Create a new session setsid (); // Fork handler of termination signals SignalHandlerPipe.reset (new Pipe); int forkedPid = fork(); throw_sys_if (forkedPid == -1); if (forkedPid == 0) { CloseMountedVolume(); struct sigaction action; Memory::Zero (&action, sizeof (action)); action.sa_handler = OnSignal; sigaction (SIGINT, &action, nullptr); sigaction (SIGQUIT, &action, nullptr); sigaction (SIGTERM, &action, nullptr); // Wait for the exit of the main service byte buf[1]; if (read (SignalHandlerPipe->GetReadFD(), buf, sizeof (buf))) { } // Errors ignored _exit (0); } SignalHandlerPipe->GetWriteFD(); _exit (fuse_main (argc, argv, &fuse_service_oper)); }