diff options
author | Andreas Kling <kling@serenityos.org> | 2021-08-29 01:30:05 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-29 01:33:15 +0200 |
commit | 7f962885357046a9c7c085d2ec240acd890f28f1 (patch) | |
tree | bbcdcaf43b9ad600d50ed6fce81630c4f58389f8 /Kernel/Net | |
parent | 242063866f855bf01259f8cae5d1a877fe1fc031 (diff) | |
download | serenity-7f962885357046a9c7c085d2ec240acd890f28f1.zip |
Kernel: Encapsulate assignment of socket origin/acceptor credentials
Diffstat (limited to 'Kernel/Net')
-rw-r--r-- | Kernel/Net/LocalSocket.cpp | 4 | ||||
-rw-r--r-- | Kernel/Net/Socket.cpp | 15 | ||||
-rw-r--r-- | Kernel/Net/Socket.h | 3 |
3 files changed, 16 insertions, 6 deletions
diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp index b783102a37..a8e1aef7fc 100644 --- a/Kernel/Net/LocalSocket.cpp +++ b/Kernel/Net/LocalSocket.cpp @@ -62,9 +62,7 @@ KResultOr<SocketPair> LocalSocket::create_connected_pair(int type) socket->m_address.sun_family = AF_LOCAL; memcpy(socket->m_address.sun_path, "[socketpair]", 13); - auto& process = Process::current(); - socket->m_acceptor = { process.pid().value(), process.uid().value(), process.gid().value() }; - + socket->set_acceptor(Process::current()); socket->set_connected(true); socket->set_connect_side_role(Role::Connected); socket->m_role = Role::Accepted; diff --git a/Kernel/Net/Socket.cpp b/Kernel/Net/Socket.cpp index 7ef57da95d..7dfa24ad34 100644 --- a/Kernel/Net/Socket.cpp +++ b/Kernel/Net/Socket.cpp @@ -38,8 +38,7 @@ Socket::Socket(int domain, int type, int protocol) , m_type(type) , m_protocol(protocol) { - auto& process = Process::current(); - m_origin = { process.pid().value(), process.uid().value(), process.gid().value() }; + set_origin(Process::current()); } Socket::~Socket() @@ -62,7 +61,7 @@ RefPtr<Socket> Socket::accept() auto client = m_pending.take_first(); VERIFY(!client->is_connected()); auto& process = Process::current(); - client->m_acceptor = { process.pid().value(), process.uid().value(), process.gid().value() }; + client->set_acceptor(process); client->m_connected = true; client->m_role = Role::Accepted; if (!m_pending.is_empty()) @@ -274,4 +273,14 @@ void Socket::set_connected(bool connected) evaluate_block_conditions(); } +void Socket::set_origin(Process const& process) +{ + m_origin = { process.pid().value(), process.uid().value(), process.gid().value() }; +} + +void Socket::set_acceptor(Process const& process) +{ + m_acceptor = { process.pid().value(), process.uid().value(), process.gid().value() }; +} + } diff --git a/Kernel/Net/Socket.h b/Kernel/Net/Socket.h index e6f1472213..88c89500b7 100644 --- a/Kernel/Net/Socket.h +++ b/Kernel/Net/Socket.h @@ -137,6 +137,9 @@ protected: return error; } + void set_origin(Process const&); + void set_acceptor(Process const&); + protected: ucred m_origin { 0, 0, 0 }; ucred m_acceptor { 0, 0, 0 }; |