mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-05-28 15:34:31 +00:00
feat(kernel): implement handling symbolic links in paths
Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
parent
13d52897b8
commit
7491f19f9a
@ -100,6 +100,12 @@ namespace Execute
|
|||||||
BinaryType GetBinaryType(std::string Path)
|
BinaryType GetBinaryType(std::string Path)
|
||||||
{
|
{
|
||||||
FileNode *node = fs->GetByPath(Path.c_str(), nullptr);
|
FileNode *node = fs->GetByPath(Path.c_str(), nullptr);
|
||||||
|
if (node->IsSymbolicLink())
|
||||||
|
{
|
||||||
|
char buffer[512];
|
||||||
|
node->ReadLink(buffer, sizeof(buffer));
|
||||||
|
node = fs->GetByPath(buffer, node->Parent);
|
||||||
|
}
|
||||||
debug("Checking binary type of %s (returning %p)", Path.c_str(), node);
|
debug("Checking binary type of %s (returning %p)", Path.c_str(), node);
|
||||||
assert(node != nullptr);
|
assert(node != nullptr);
|
||||||
return GetBinaryType(node);
|
return GetBinaryType(node);
|
||||||
|
@ -335,6 +335,13 @@ namespace Execute
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (ifd->IsSymbolicLink())
|
||||||
|
{
|
||||||
|
char buffer[512];
|
||||||
|
ifd->ReadLink(buffer, sizeof(buffer));
|
||||||
|
ifd = fs->GetByPath(buffer, ifd->Parent);
|
||||||
|
}
|
||||||
|
|
||||||
debug("ifd: %p, interpreter: %s", ifd, interpreterPath.c_str());
|
debug("ifd: %p, interpreter: %s", ifd, interpreterPath.c_str());
|
||||||
if (GetBinaryType(interpreterPath) != BinTypeELF)
|
if (GetBinaryType(interpreterPath) != BinTypeELF)
|
||||||
{
|
{
|
||||||
@ -798,6 +805,14 @@ namespace Execute
|
|||||||
error("Failed to open %s, errno: %d", AbsolutePath.c_str(), fd);
|
error("Failed to open %s, errno: %d", AbsolutePath.c_str(), fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fd->IsSymbolicLink())
|
||||||
|
{
|
||||||
|
char buffer[512];
|
||||||
|
fd->ReadLink(buffer, sizeof(buffer));
|
||||||
|
fd = fs->GetByPath(buffer, fd->Parent);
|
||||||
|
}
|
||||||
|
|
||||||
debug("Opened %s", AbsolutePath.c_str());
|
debug("Opened %s", AbsolutePath.c_str());
|
||||||
|
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
|
@ -40,9 +40,20 @@ namespace Execute
|
|||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
if (!fd->IsRegularFile())
|
if (!fd->IsRegularFile())
|
||||||
return -ENOEXEC;
|
{
|
||||||
|
if (fd->IsSymbolicLink())
|
||||||
|
{
|
||||||
|
char buffer[512];
|
||||||
|
fd->ReadLink(buffer, sizeof(buffer));
|
||||||
|
fd = fs->GetByPath(buffer, fd->Parent);
|
||||||
|
if (fd == nullptr)
|
||||||
|
return -ENOENT;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return -ENOEXEC;
|
||||||
|
}
|
||||||
|
|
||||||
switch (GetBinaryType(Path))
|
switch (GetBinaryType(fd))
|
||||||
{
|
{
|
||||||
case BinaryType::BinTypeELF:
|
case BinaryType::BinTypeELF:
|
||||||
{
|
{
|
||||||
|
@ -161,6 +161,7 @@ namespace vfs
|
|||||||
}
|
}
|
||||||
|
|
||||||
Inode *Node = NULL;
|
Inode *Node = NULL;
|
||||||
|
bool readSymlinks = true; /* FIXME: implement */
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
auto it = DeviceMap.find(__Parent->Node->Device);
|
auto it = DeviceMap.find(__Parent->Node->Device);
|
||||||
@ -170,6 +171,22 @@ namespace vfs
|
|||||||
if (it->second.fsi->Ops.Lookup == NULL)
|
if (it->second.fsi->Ops.Lookup == NULL)
|
||||||
ReturnLogError(nullptr, "Lookup not supported for %d", it->first);
|
ReturnLogError(nullptr, "Lookup not supported for %d", it->first);
|
||||||
|
|
||||||
|
if (readSymlinks && __Parent->IsSymbolicLink())
|
||||||
|
{
|
||||||
|
if (it->second.fsi->Ops.ReadLink == NULL)
|
||||||
|
ReturnLogError(nullptr, "Readlink not supported for %d", it->first);
|
||||||
|
|
||||||
|
char buffer[256];
|
||||||
|
int ret = it->second.fsi->Ops.ReadLink(__Parent->Node, buffer, sizeof(buffer));
|
||||||
|
if (ret < 0)
|
||||||
|
ReturnLogError(nullptr, "Readlink for \"%s\"(%d) failed with %d", __Parent->Path.c_str(), it->first, ret);
|
||||||
|
|
||||||
|
FileNode *target = this->GetByPath(buffer, __Parent->Parent ? __Parent->Parent : __Parent);
|
||||||
|
if (target == nullptr)
|
||||||
|
ReturnLogError(nullptr, "Failed to find target for \"%s\"", __Parent->Path.c_str());
|
||||||
|
__Parent = target;
|
||||||
|
}
|
||||||
|
|
||||||
std::string segmentName(segment.begin, segment.size);
|
std::string segmentName(segment.begin, segment.size);
|
||||||
int ret = it->second.fsi->Ops.Lookup(__Parent->Node, segmentName.c_str(), &Node);
|
int ret = it->second.fsi->Ops.Lookup(__Parent->Node, segmentName.c_str(), &Node);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
@ -389,7 +389,7 @@ namespace vfs
|
|||||||
Size = strlen(node->Header->link);
|
Size = strlen(node->Header->link);
|
||||||
|
|
||||||
strncpy(Buffer, node->Header->link, Size);
|
strncpy(Buffer, node->Header->link, Size);
|
||||||
debug("Read %d bytes from %d", Size, Node->Index);
|
debug("Read %d bytes from %d: \"%s\"", Size, Node->Index, Buffer);
|
||||||
return Size;
|
return Size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,6 +113,12 @@ namespace Tasking
|
|||||||
trace("Setting exe %s to %s",
|
trace("Setting exe %s to %s",
|
||||||
this->Name, path);
|
this->Name, path);
|
||||||
Executable = fs->GetByPath(path, ProcDirectory);
|
Executable = fs->GetByPath(path, ProcDirectory);
|
||||||
|
if (Executable->IsSymbolicLink())
|
||||||
|
{
|
||||||
|
char buffer[512];
|
||||||
|
Executable->ReadLink(buffer, sizeof(buffer));
|
||||||
|
Executable = fs->GetByPath(buffer, Executable->Parent);
|
||||||
|
}
|
||||||
FileNode *exe = fs->GetByPath("exe", ProcDirectory);
|
FileNode *exe = fs->GetByPath("exe", ProcDirectory);
|
||||||
if (exe)
|
if (exe)
|
||||||
fs->Remove(exe);
|
fs->Remove(exe);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user