summaryrefslogtreecommitdiffstats
path: root/tdesu/tdesud/secure.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-11-06 15:56:34 -0600
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-11-06 15:56:34 -0600
commitb529f046c9a64ac5fcfa60747af940cf972b3ebc (patch)
tree83c28cf7fa8fed1960ebd3924b579e7ed8c95cc6 /tdesu/tdesud/secure.cpp
parent6508fe4c40c60fd7a43bd3d9e19b762e10ea3f53 (diff)
downloadtdebase-b529f046c9a64ac5fcfa60747af940cf972b3ebc.tar.gz
tdebase-b529f046c9a64ac5fcfa60747af940cf972b3ebc.zip
Actually move the kde files that were renamed in the last commit
Diffstat (limited to 'tdesu/tdesud/secure.cpp')
-rw-r--r--tdesu/tdesud/secure.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/tdesu/tdesud/secure.cpp b/tdesu/tdesud/secure.cpp
new file mode 100644
index 000000000..9b30ab4ee
--- /dev/null
+++ b/tdesu/tdesud/secure.cpp
@@ -0,0 +1,80 @@
+/* vi: ts=8 sts=4 sw=4
+ *
+ * This file is part of the KDE project, module tdesu.
+ * Copyright (C) 1999,2000 Geert Jansen <g.t.jansen@stud.tue.nl>
+ *
+ * secure.cpp: Peer credentials for a UNIX socket.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+
+#include <kdebug.h>
+#include <ksockaddr.h>
+#include "secure.h"
+
+
+/**
+ * Under Linux, Socket_security is supported.
+ */
+
+#if defined(SO_PEERCRED)
+
+SocketSecurity::SocketSecurity(int sockfd)
+{
+ ksocklen_t len = sizeof(struct ucred);
+ if (getsockopt(sockfd, SOL_SOCKET, SO_PEERCRED, &cred, &len) < 0) {
+ kdError() << "getsockopt(SO_PEERCRED) " << perror << endl;
+ return;
+ }
+
+ ok = true;
+}
+
+#else
+# if defined(HAVE_GETPEEREID)
+SocketSecurity::SocketSecurity(int sockfd)
+{
+ uid_t euid;
+ gid_t egid;
+ if (getpeereid(sockfd, &euid, &egid) == 0) {
+ cred.uid = euid;
+ cred.gid = egid;
+ cred.pid = -1;
+ ok = true;
+ }
+}
+
+# else
+
+
+/**
+ * The default version does nothing.
+ */
+
+SocketSecurity::SocketSecurity(int sockfd)
+{
+ static bool warned_him = FALSE;
+
+ if (!warned_him) {
+ kdWarning() << "Using void socket security. Please add support for your" << endl;
+ kdWarning() << "platform to tdesu/tdesud/secure.cpp" << endl;
+ warned_him = TRUE;
+ }
+
+ // This passes the test made in handler.cpp
+ cred.uid = getuid();
+ ok = true;
+}
+
+# endif
+#endif