mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 17:55:08 +00:00
Add uid and gid to CharacterDevices.
The vast majority of them will be owned by 0:0 (the default.) However, PTY pairs will now be owned by the uid:gid of the opening process.
This commit is contained in:
parent
c4fce9b3f9
commit
34e745b0b4
7 changed files with 32 additions and 5 deletions
|
@ -32,10 +32,17 @@ public:
|
|||
|
||||
virtual const char* class_name() const = 0;
|
||||
|
||||
uid_t uid() const { return m_uid; }
|
||||
uid_t gid() const { return m_gid; }
|
||||
|
||||
protected:
|
||||
CharacterDevice(unsigned major, unsigned minor) : m_major(major), m_minor(minor) { }
|
||||
void set_uid(uid_t uid) { m_uid = uid; }
|
||||
void set_gid(gid_t gid) { m_gid = gid; }
|
||||
|
||||
private:
|
||||
unsigned m_major { 0 };
|
||||
unsigned m_minor { 0 };
|
||||
uid_t m_uid { 0 };
|
||||
gid_t m_gid { 0 };
|
||||
};
|
||||
|
|
|
@ -44,12 +44,15 @@ RetainPtr<SynthFSInode> DevPtsFS::create_slave_pty_device_file(unsigned index)
|
|||
builder.appendf("%u", index);
|
||||
file->m_name = builder.build();
|
||||
|
||||
auto* device = VFS::the().get_device(11, index);
|
||||
ASSERT(device);
|
||||
|
||||
file->m_metadata.size = 0;
|
||||
file->m_metadata.uid = 0;
|
||||
file->m_metadata.gid = 0;
|
||||
file->m_metadata.mode = 0020666;
|
||||
file->m_metadata.majorDevice = 11;
|
||||
file->m_metadata.minorDevice = index;
|
||||
file->m_metadata.uid = device->uid();
|
||||
file->m_metadata.gid = device->gid();
|
||||
file->m_metadata.mode = 0020644;
|
||||
file->m_metadata.majorDevice = device->major();
|
||||
file->m_metadata.minorDevice = device->minor();
|
||||
file->m_metadata.mtime = mepoch;
|
||||
return file;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "MasterPTY.h"
|
||||
#include "SlavePTY.h"
|
||||
#include "PTYMultiplexer.h"
|
||||
#include <Kernel/Process.h>
|
||||
#include <LibC/errno_numbers.h>
|
||||
|
||||
MasterPTY::MasterPTY(unsigned index)
|
||||
|
@ -8,6 +9,8 @@ MasterPTY::MasterPTY(unsigned index)
|
|||
, m_slave(adopt(*new SlavePTY(*this, index)))
|
||||
, m_index(index)
|
||||
{
|
||||
set_uid(current->uid());
|
||||
set_gid(current->gid());
|
||||
}
|
||||
|
||||
MasterPTY::~MasterPTY()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "PTYMultiplexer.h"
|
||||
#include "MasterPTY.h"
|
||||
#include <Kernel/Process.h>
|
||||
#include <LibC/errno_numbers.h>
|
||||
|
||||
static const unsigned s_max_pty_pairs = 8;
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
#include "SlavePTY.h"
|
||||
#include "MasterPTY.h"
|
||||
#include "DevPtsFS.h"
|
||||
#include <Kernel/Process.h>
|
||||
|
||||
SlavePTY::SlavePTY(MasterPTY& master, unsigned index)
|
||||
: TTY(11, index)
|
||||
, m_master(master)
|
||||
, m_index(index)
|
||||
{
|
||||
set_uid(current->uid());
|
||||
set_gid(current->gid());
|
||||
VFS::the().register_character_device(*this);
|
||||
DevPtsFS::the().register_slave_pty(*this);
|
||||
set_size(80, 25);
|
||||
|
|
|
@ -517,6 +517,14 @@ void VFS::unregister_character_device(CharacterDevice& device)
|
|||
m_character_devices.remove(encodedDevice(device.major(), device.minor()));
|
||||
}
|
||||
|
||||
CharacterDevice* VFS::get_device(unsigned major, unsigned minor)
|
||||
{
|
||||
auto it = m_character_devices.find(encodedDevice(major, minor));
|
||||
if (it == m_character_devices.end())
|
||||
return nullptr;
|
||||
return (*it).value;
|
||||
}
|
||||
|
||||
void VFS::for_each_mount(Function<void(const Mount&)> callback) const
|
||||
{
|
||||
for (auto& mount : m_mounts) {
|
||||
|
|
|
@ -86,6 +86,8 @@ public:
|
|||
|
||||
void sync();
|
||||
|
||||
CharacterDevice* get_device(unsigned major, unsigned minor);
|
||||
|
||||
private:
|
||||
friend class FileDescriptor;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue