AuroraRuntime/Source/IO/FS/FileTrust.NT.cpp

79 lines
1.8 KiB
C++

/***
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: FileTrust.NT.cpp
Date: 2023-1-25
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "FS.hpp"
#include "FileTrust.NT.hpp"
namespace Aurora::IO::FS
{
AUKN_SYM bool BlockFile(const AuString &path)
{
return AuFS::WriteFile(path + ":Zone.Identifier", "[ZoneTransfer]\r\nZoneId=3\r\n");
}
AUKN_SYM bool UnblockFile(const AuString &path)
{
return AuFS::WriteFile(path + ":Zone.Identifier", "[ZoneTransfer]\r\nZoneId=0\r\n");
}
AUKN_SYM bool TrustFile(const AuString &path)
{
AuString idc;
auto uri = path + ":Zone.Identifier";
if (AuFS::FileExists(uri))
{
if (AuFS::ReadString(uri, idc))
{
return AuFS::Remove(uri);
}
}
return true;
}
AUKN_SYM bool IsFileBlocked(const AuString &path)
{
AuString content;
auto uri = path + ":Zone.Identifier";
if (!AuFS::FileExists(uri))
{
return !AuFS::FileExists(path);
}
if (!AuFS::ReadString(uri, content))
{
return !AuFS::FileExists(path);
}
return (!gRuntimeConfig.fio.bIsIntranetTrusted && AuStringContains(content, "ZoneId=1\r\n")) || // intranet
AuStringContains(content, "ZoneId=3\r\n") || // internet
AuStringContains(content, "ZoneId=4\r\n"); // untrusted
}
AUKN_SYM bool IsFileTrusted(const AuString &path)
{
AuString content;
auto uri = path + ":Zone.Identifier";
if (!AuFS::FileExists(uri))
{
return AuFS::FileExists(path);
}
if (!AuFS::ReadString(uri, content))
{
return AuFS::FileExists(path);
}
return false;
}
}