diff options
Diffstat (limited to 'tdesu/client.cpp')
-rw-r--r-- | tdesu/client.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tdesu/client.cpp b/tdesu/client.cpp index fe5733ee7..8c775bbed 100644 --- a/tdesu/client.cpp +++ b/tdesu/client.cpp @@ -19,6 +19,9 @@ #include <pwd.h> #include <errno.h> #include <string.h> +#ifdef HAVE_UCRED_H +#include <ucred.h> +#endif /* HAVE_UCRED_H */ #include <sys/types.h> #include <sys/socket.h> @@ -146,6 +149,21 @@ int TDEsuClient::connect() return -1; } # endif +#elif defined(HAVE_GETPEERUCRED) + ucred_t *cred = nullptr; + + if (getpeerucred(sockfd, &cred) == 0) { + uid_t peer_uid = ucred_geteuid(cred); + + ucred_free(cred); + if (peer_uid != getuid()) { + kdWarning(900) << "socket not owned by me! socket uid = " << peer_uid << endl; + close(sockfd); sockfd = -1; + return -1; + } + } + if (cred != nullptr) + ucred_free(cred); #else struct ucred cred; socklen_t siz = sizeof(cred); |