Browse Source

LibCore: Implement socket credentials for Solaris

nipos 2 years ago
parent
commit
cdd1c8d0d9
2 changed files with 7 additions and 0 deletions
  1. 6 0
      Userland/Libraries/LibCore/Socket.cpp
  2. 1 0
      Userland/Libraries/LibCore/System.h

+ 6 - 0
Userland/Libraries/LibCore/Socket.cpp

@@ -370,6 +370,9 @@ ErrorOr<pid_t> LocalSocket::peer_pid() const
 #elif defined(AK_OS_NETBSD)
     struct sockcred creds = {};
     socklen_t creds_size = sizeof(creds);
+#elif defined(AK_OS_SOLARIS)
+    ucred_t* creds = NULL;
+    socklen_t creds_size = sizeof(creds);
 #else
     struct ucred creds = {};
     socklen_t creds_size = sizeof(creds);
@@ -384,6 +387,9 @@ ErrorOr<pid_t> LocalSocket::peer_pid() const
 #elif defined(AK_OS_NETBSD)
     TRY(System::getsockopt(m_helper.fd(), SOL_SOCKET, SCM_CREDS, &creds, &creds_size));
     return creds.sc_pid;
+#elif defined(AK_OS_SOLARIS)
+    TRY(System::getsockopt(m_helper.fd(), SOL_SOCKET, SO_RECVUCRED, &creds, &creds_size));
+    return ucred_getpid(creds);
 #else
     TRY(System::getsockopt(m_helper.fd(), SOL_SOCKET, SO_PEERCRED, &creds, &creds_size));
     return creds.pid;

+ 1 - 0
Userland/Libraries/LibCore/System.h

@@ -37,6 +37,7 @@
 
 #ifdef AK_OS_SOLARIS
 #    include <sys/filio.h>
+#    include <ucred.h>
 #endif
 
 namespace Core::System {