[+] AuFS::IsFileBlocked
[+] AuFS::IsFileTrusted
This commit is contained in:
parent
0fcd63d3a8
commit
b5a452a43d
@ -186,7 +186,11 @@ namespace Aurora::IO::FS
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
AUKN_SYM bool TrustFile(const AuString &path);
|
AUKN_SYM bool TrustFile(const AuString &path);
|
||||||
|
|
||||||
|
AUKN_SYM bool IsFileBlocked(const AuString &path);
|
||||||
|
|
||||||
|
AUKN_SYM bool IsFileTrusted(const AuString &path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Transfers the contents of the specified filepath through a
|
* @brief Transfers the contents of the specified filepath through a
|
||||||
* zstandard compression pipe to an ending path + ".zst" file.
|
* zstandard compression pipe to an ending path + ".zst" file.
|
||||||
|
@ -26,11 +26,54 @@ namespace Aurora::IO::FS
|
|||||||
AuString idc;
|
AuString idc;
|
||||||
|
|
||||||
auto uri = path + ":Zone.Identifier";
|
auto uri = path + ":Zone.Identifier";
|
||||||
if (AuFS::ReadString(uri, idc))
|
|
||||||
|
if (AuFS::FileExists(uri))
|
||||||
{
|
{
|
||||||
return AuFS::Remove(uri);
|
if (AuFS::ReadString(uri, idc))
|
||||||
|
{
|
||||||
|
return AuFS::Remove(uri);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
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 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;
|
||||||
|
}
|
||||||
}
|
}
|
@ -19,8 +19,12 @@ namespace Aurora::IO::FS
|
|||||||
{
|
{
|
||||||
AUKN_SYM bool BlockFile(const AuString &path)
|
AUKN_SYM bool BlockFile(const AuString &path)
|
||||||
{
|
{
|
||||||
AuString path2 = path;
|
auto srcPath = NormalizePathRet(path);
|
||||||
AuFS::NormalizePath(path2, path2);
|
if (srcPath.empty())
|
||||||
|
{
|
||||||
|
SysPushErrorMemory();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
AuString subdir;
|
AuString subdir;
|
||||||
|
|
||||||
@ -28,33 +32,33 @@ namespace Aurora::IO::FS
|
|||||||
((path[path.size() - 1] == '/') ||
|
((path[path.size() - 1] == '/') ||
|
||||||
(path[path.size() - 1] == '\\')))
|
(path[path.size() - 1] == '\\')))
|
||||||
{
|
{
|
||||||
subdir = path2.substr(0, path2.size() - 1);
|
subdir = srcPath.substr(0, srcPath.size() - 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
subdir = path2;
|
subdir = srcPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
GoUpToSeparator(subdir, subdir);
|
GoUpToSeparator(subdir, subdir);
|
||||||
|
|
||||||
subdir = "file:///" + subdir;
|
subdir = "file:///" + subdir;
|
||||||
|
|
||||||
if (::setxattr(path2.c_str(), "user.xdg.origin.url", subdir.c_str(), subdir.size(), XATTR_CREATE) == -1)
|
if (::setxattr(srcPath.c_str(), "user.xdg.origin.url", subdir.c_str(), subdir.size(), XATTR_CREATE) == -1)
|
||||||
{
|
{
|
||||||
if (errno == EEXIST)
|
if (errno == EEXIST)
|
||||||
{
|
{
|
||||||
if (::setxattr(path2.c_str(), "user.xdg.origin.url", subdir.c_str(), subdir.size(), XATTR_REPLACE) == -1)
|
if (::setxattr(srcPath.c_str(), "user.xdg.origin.url", subdir.c_str(), subdir.size(), XATTR_REPLACE) == -1)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (::setxattr(path2.c_str(), "user.xdg.referrer.url", subdir.c_str(), subdir.size(), XATTR_CREATE) == -1)
|
if (::setxattr(srcPath.c_str(), "user.xdg.referrer.url", subdir.c_str(), subdir.size(), XATTR_CREATE) == -1)
|
||||||
{
|
{
|
||||||
if (errno == EEXIST)
|
if (errno == EEXIST)
|
||||||
{
|
{
|
||||||
if (::setxattr(path2.c_str(), "user.xdg.referrer.url", subdir.c_str(), subdir.size(), XATTR_REPLACE) == -1)
|
if (::setxattr(srcPath.c_str(), "user.xdg.referrer.url", subdir.c_str(), subdir.size(), XATTR_REPLACE) == -1)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -63,13 +67,13 @@ namespace Aurora::IO::FS
|
|||||||
|
|
||||||
mode_t mode { 0644 };
|
mode_t mode { 0644 };
|
||||||
struct stat s;
|
struct stat s;
|
||||||
if (::stat(path2.c_str(), &s) != -1)
|
if (::stat(srcPath.c_str(), &s) < 0)
|
||||||
{
|
{
|
||||||
mode = s.st_mode;
|
mode = s.st_mode;
|
||||||
mode &= ~( 0111 );
|
mode &= ~( 0111 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (::chmod(path2.c_str(), mode) != 0)
|
if (::chmod(srcPath.c_str(), mode) != 0)
|
||||||
{
|
{
|
||||||
SysPushErrorIO("BlockFile chmod failed: {}", path);
|
SysPushErrorIO("BlockFile chmod failed: {}", path);
|
||||||
}
|
}
|
||||||
@ -79,43 +83,51 @@ namespace Aurora::IO::FS
|
|||||||
|
|
||||||
AUKN_SYM bool UnblockFile(const AuString &path)
|
AUKN_SYM bool UnblockFile(const AuString &path)
|
||||||
{
|
{
|
||||||
AuString path2 = path;
|
auto srcPath = NormalizePathRet(path);
|
||||||
AuFS::NormalizePath(path2, path2);
|
if (srcPath.empty())
|
||||||
|
{
|
||||||
|
SysPushErrorMemory();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
::removexattr(path2.c_str(), "user.xdg.origin.url");
|
::removexattr(srcPath.c_str(), "user.xdg.origin.url");
|
||||||
::removexattr(path2.c_str(), "user.xdg.referrer.url");
|
::removexattr(srcPath.c_str(), "user.xdg.referrer.url");
|
||||||
|
|
||||||
mode_t mode { 0644 };
|
mode_t mode { 0644 };
|
||||||
struct stat s;
|
struct stat s;
|
||||||
if (::stat(path2.c_str(), &s) != -1)
|
if (::stat(srcPath.c_str(), &s) < 0)
|
||||||
{
|
{
|
||||||
mode = s.st_mode;
|
mode = s.st_mode;
|
||||||
mode &= ~(0111);
|
mode &= ~(0111);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (::chmod(path2.c_str(), mode) != 0)
|
if (::chmod(srcPath.c_str(), mode) != 0)
|
||||||
{
|
{
|
||||||
SysPushErrorIO("UnblockFile chmod failed: {}", path);
|
SysPushErrorIO("UnblockFile chmod failed: {}", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return AuFS::FileExists(path2);
|
return AuFS::FileExists(srcPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
AUKN_SYM bool TrustFile(const AuString &path)
|
AUKN_SYM bool TrustFile(const AuString &path)
|
||||||
{
|
{
|
||||||
|
struct stat s;
|
||||||
mode_t mode { 0755 };
|
mode_t mode { 0755 };
|
||||||
|
|
||||||
AuString path2 = path;
|
auto srcPath = NormalizePathRet(path);
|
||||||
AuFS::NormalizePath(path2, path2);
|
if (srcPath.empty())
|
||||||
|
{
|
||||||
|
SysPushErrorMemory();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
struct stat s;
|
if (::stat(srcPath.c_str(), &s) < 0)
|
||||||
if (::stat(path2.c_str(), &s) != -1)
|
|
||||||
{
|
{
|
||||||
mode = s.st_mode;
|
mode = s.st_mode;
|
||||||
mode |= 0111;
|
mode |= 0111;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (::chmod(path2.c_str(), mode) != 0)
|
if (::chmod(srcPath.c_str(), mode) != 0)
|
||||||
{
|
{
|
||||||
SysPushErrorIO("chmod failed: {}", path);
|
SysPushErrorIO("chmod failed: {}", path);
|
||||||
return false;
|
return false;
|
||||||
@ -123,4 +135,44 @@ namespace Aurora::IO::FS
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AUKN_SYM bool IsFileBlocked(const AuString &path)
|
||||||
|
{
|
||||||
|
auto srcPath = NormalizePathRet(path);
|
||||||
|
if (srcPath.empty())
|
||||||
|
{
|
||||||
|
SysPushErrorMemory();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
auto length = ::getxattr(srcPath.c_str(), "user.xdg.referrer.url", nullptr, 0);
|
||||||
|
if (length <= 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AUKN_SYM bool IsFileTrusted(const AuString &path)
|
||||||
|
{
|
||||||
|
struct stat s;
|
||||||
|
auto srcPath = NormalizePathRet(path);
|
||||||
|
if (srcPath.empty())
|
||||||
|
{
|
||||||
|
SysPushErrorMemory();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (::stat(srcPath.c_str(), &s) < 0)
|
||||||
|
{
|
||||||
|
return (s.st_mode & 0111) != 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user