94 lines
2.4 KiB
C++
94 lines
2.4 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: AuOpen.Unix.cpp
|
|
Date: 2021-6-12
|
|
Author: Reece
|
|
***/
|
|
#include <RuntimeInternal.hpp>
|
|
#include "AuProcesses.hpp"
|
|
#include "AuOpen.Unix.hpp"
|
|
|
|
#include <unistd.h>
|
|
#include <Source/IO/FS/FS.hpp>
|
|
|
|
namespace Aurora::Processes
|
|
{
|
|
static void UnixOpenAsyncThread(const AuString &uri, bool bType)
|
|
{
|
|
bool bDirExists {};
|
|
bool bFileExists {};
|
|
|
|
bFileExists = AuIOFS::FileExists(uri);
|
|
|
|
if (!bType)
|
|
{
|
|
bDirExists = AuIOFS::DirExists(uri);
|
|
|
|
if (!bFileExists &&
|
|
!bDirExists)
|
|
{
|
|
SysPushErrorGeneric("Exploit attempt? Attempted to open non-existent file/directory. (request: {})", uri);
|
|
return;
|
|
}
|
|
|
|
if (bFileExists)
|
|
{
|
|
if (!AuFS::IsFileBlocked(uri))
|
|
{
|
|
SysPushErrorGeneric("Exploit attempt? Attempted to open untrusted file/directory. (request: {})", uri);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (bFileExists)
|
|
{
|
|
SysPushErrorGeneric("Exploit attempt? Attempted to open existing file/directory via URI ({})", uri);
|
|
return;
|
|
}
|
|
}
|
|
|
|
// TODO: MacOS is special. This will break IPC and the process binary is 'open'
|
|
if (fork() == 0)
|
|
{
|
|
setsid();
|
|
execl("xdg-open", uri.c_str());
|
|
exit(0);
|
|
}
|
|
}
|
|
|
|
static void UnixOpenAsync(const AuString &uri, bool bType)
|
|
{
|
|
if (uri.empty())
|
|
{
|
|
return;
|
|
}
|
|
|
|
// TODO: No, just no.
|
|
auto thread = AuThreads::ThreadUnique(AuThreads::ThreadInfo(
|
|
AuMakeShared<AuThreads::IThreadVectorsFunctional>(AuThreads::IThreadVectorsFunctional::OnEntry_t(std::bind(std::bind(&UnixOpenAsyncThread, uri, bType))),
|
|
AuThreads::IThreadVectorsFunctional::OnExit_t{})
|
|
));
|
|
|
|
if (!thread)
|
|
{
|
|
SysPushErrorGeneric("no resource");
|
|
return;
|
|
}
|
|
|
|
thread->Run();
|
|
thread->Detach();
|
|
}
|
|
|
|
AUKN_SYM void OpenUri(const AuString &uri)
|
|
{
|
|
UnixOpenAsync(uri, true);
|
|
}
|
|
|
|
AUKN_SYM void OpenFile(const AuString &file)
|
|
{
|
|
UnixOpenAsync(file, false);
|
|
}
|
|
} |