mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:57:43 +00:00
Kernel: Add getsockopt(SO_PEERCRED) for local sockets
This sockopt gives you a struct with the PID, UID and GID of a socket's peer process.
This commit is contained in:
parent
6e6e0b9de8
commit
23e802518d
10 changed files with 72 additions and 12 deletions
|
@ -33,6 +33,7 @@ LocalSocket::LocalSocket(int type)
|
|||
{
|
||||
LOCKER(all_sockets().lock());
|
||||
all_sockets().resource().append(this);
|
||||
|
||||
#ifdef DEBUG_LOCAL_SOCKET
|
||||
kprintf("%s(%u) LocalSocket{%p} created with type=%u\n", current->process().name().characters(), current->pid(), this, type);
|
||||
#endif
|
||||
|
@ -302,3 +303,34 @@ String LocalSocket::absolute_path(const FileDescription& description) const
|
|||
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
KResult LocalSocket::getsockopt(FileDescription& description, int level, int option, void* value, socklen_t* value_size)
|
||||
{
|
||||
if (level != SOL_SOCKET)
|
||||
return Socket::getsockopt(description, level, option, value, value_size);
|
||||
|
||||
switch (option) {
|
||||
case SO_PEERCRED: {
|
||||
if (*value_size < sizeof(ucred))
|
||||
return KResult(-EINVAL);
|
||||
auto& creds = *(ucred*)value;
|
||||
switch (role(description)) {
|
||||
case Role::Accepted:
|
||||
creds = m_origin;
|
||||
*value_size = sizeof(ucred);
|
||||
return KSuccess;
|
||||
case Role::Connected:
|
||||
creds = m_acceptor;
|
||||
*value_size = sizeof(ucred);
|
||||
return KSuccess;
|
||||
case Role::Connecting:
|
||||
return KResult(-ENOTCONN);
|
||||
default:
|
||||
return KResult(-EINVAL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return Socket::getsockopt(description, level, option, value, value_size);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue