delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / runtime / kdesu / kdesud / secure.cpp
bloba6a1b6900bc75f79c5f9f9450a5374f773919f86
1 /* vi: ts=8 sts=4 sw=4
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.
7 */
9 #include "secure.h"
11 #include <config-runtime.h>
13 #include <stdio.h>
14 #include <unistd.h>
15 #include <fcntl.h>
16 #include <string.h>
17 #include <errno.h>
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <sys/socket.h>
23 #include <kdebug.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;
29 /**
30 * Under Linux, Socket_security is supported.
33 #if defined(SO_PEERCRED)
35 SocketSecurity::SocketSecurity(int sockfd) : pid(-1), gid(-1), uid(-1)
37 ucred cred;
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;
41 return;
43 pid = cred.pid;
44 gid = cred.gid;
45 uid = cred.uid;
48 #else
49 # if defined(HAVE_GETPEEREID)
50 SocketSecurity::SocketSecurity(int sockfd) : pid(-1), gid(-1), uid(-1)
52 uid_t euid;
53 gid_t egid;
54 if (getpeereid(sockfd, &euid, &egid) == 0) {
55 uid = euid;
56 gid = egid;
57 pid = -1;
61 # else
62 #ifdef __GNUC__
63 #warning SocketSecurity support for your platform not implemented/available!
64 #endif
65 /**
66 * The default version does nothing.
69 SocketSecurity::SocketSecurity(int sockfd) : pid(-1), gid(-1), uid(-1)
71 static bool warned_him = false;
73 if (!warned_him) {
74 kWarning() << "Using void socket security. Please add support for your" ;
75 kWarning() << "platform to kdesu/kdesud/secure.cpp" ;
76 warned_him = true;
79 // This passes the test made in handler.cpp
80 uid = getuid();
83 # endif
84 #endif