Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mRemoteNG/PuTTYNG.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'unix/peerinfo.c')
-rw-r--r--unix/peerinfo.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/unix/peerinfo.c b/unix/peerinfo.c
new file mode 100644
index 00000000..11f03291
--- /dev/null
+++ b/unix/peerinfo.c
@@ -0,0 +1,32 @@
+/*
+ * Unix: wrapper for getsockopt(SO_PEERCRED), conditionalised on
+ * appropriate autoconfery.
+ */
+
+#if HAVE_CMAKE_H
+#include "cmake.h"
+#endif
+
+#if HAVE_SO_PEERCRED
+#define _GNU_SOURCE
+#include <features.h>
+#endif
+
+#include <sys/socket.h>
+
+#include "putty.h"
+
+bool so_peercred(int fd, int *pid, int *uid, int *gid)
+{
+#if HAVE_SO_PEERCRED
+ struct ucred cr;
+ socklen_t crlen = sizeof(cr);
+ if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cr, &crlen) == 0) {
+ *pid = cr.pid;
+ *uid = cr.uid;
+ *gid = cr.gid;
+ return true;
+ }
+#endif
+ return false;
+}