3 * This file is part of the KDE project, module kdesu.
4 * Copyright (C) 1999,2000 Geert Jansen <g.t.jansen@stud.tue.nl>
6 * secure.cpp: Peer credentials for a UNIX socket.
11 #include <config-runtime.h>
19 #include <sys/types.h>
21 #include <sys/socket.h>
25 // FIXME: This is just here to make it compile (since ksock* was removed from kdelibs).
26 // It would be better to fix it more globally. (Caleb Tennis)
27 typedef unsigned ksocklen_t
;
30 * Under Linux, Socket_security is supported.
33 #if defined(SO_PEERCRED)
35 SocketSecurity::SocketSecurity(int sockfd
) : pid(-1), gid(-1), uid(-1)
38 ksocklen_t len
= sizeof(struct ucred
);
39 if (getsockopt(sockfd
, SOL_SOCKET
, SO_PEERCRED
, &cred
, &len
) < 0) {
40 kError() << "getsockopt(SO_PEERCRED) " << perror
<< endl
;
49 # if defined(HAVE_GETPEEREID)
50 SocketSecurity::SocketSecurity(int sockfd
) : pid(-1), gid(-1), uid(-1)
54 if (getpeereid(sockfd
, &euid
, &egid
) == 0) {
63 #warning SocketSecurity support for your platform not implemented/available!
66 * The default version does nothing.
69 SocketSecurity::SocketSecurity(int sockfd
) : pid(-1), gid(-1), uid(-1)
71 static bool warned_him
= false;
74 kWarning() << "Using void socket security. Please add support for your" ;
75 kWarning() << "platform to kdesu/kdesud/secure.cpp" ;
79 // This passes the test made in handler.cpp