summaryrefslogtreecommitdiffstats
path: root/common/os_calls.c
diff options
context:
space:
mode:
authorKoichiro IWAO <meta@vmeta.jp>2015-03-18 08:41:43 +0000
committerKoichiro IWAO <meta@vmeta.jp>2015-03-18 08:46:23 +0000
commit1f844b2d0e3090cd6894eca990b761ca3a98f634 (patch)
treed4f7c75ce329b997a3333e840ee85e1b61f13fce /common/os_calls.c
parent5788133c4d119b9a57f8cc77dd22c3e73600bc62 (diff)
downloadxrdp-proprietary-1f844b2d0e3090cd6894eca990b761ca3a98f634.tar.gz
xrdp-proprietary-1f844b2d0e3090cd6894eca990b761ca3a98f634.zip
common: workaround for #146
Diffstat (limited to 'common/os_calls.c')
-rw-r--r--common/os_calls.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/common/os_calls.c b/common/os_calls.c
index 611cf420..50d7e549 100644
--- a/common/os_calls.c
+++ b/common/os_calls.c
@@ -86,6 +86,12 @@ extern char **environ;
#include <linux/unistd.h>
#endif
+/* sys/ucred.h needs to be included to use struct xucred
+ * in FreeBSD and OS X. No need for other BSDs */
+#if defined(__FreeBSD__) || defined(__APPLE__)
+#include <sys/ucred.h>
+#endif
+
/* for solaris */
#if !defined(PF_LOCAL)
#define PF_LOCAL AF_UNIX
@@ -656,6 +662,28 @@ g_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid)
*gid = credentials.gid;
}
return 0;
+#elif defined(LOCAL_PEERCRED)
+ /* FreeBSD, OS X reach here*/
+ struct xucred xucred;
+ unsigned int xucred_length;
+ xucred_length = sizeof(xucred);
+
+ if (getsockopt(sck, SOL_SOCKET, LOCAL_PEERCRED, &xucred, &xucred_length))
+ {
+ return 1;
+ }
+ if (pid !=0)
+ {
+ *pid = 0; /* can't get pid in FreeBSD, OS X */
+ }
+ if (uid != 0)
+ {
+ *uid = xucred.cr_uid;
+ }
+ if (gid != 0) {
+ *gid = xucred.cr_gid;
+ }
+ return 0;
#else
return 1;
#endif