summaryrefslogtreecommitdiffstats
path: root/proxy/src/gp_socket.c
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2013-02-25 20:50:34 +0100
committerSimo Sorce <simo@redhat.com>2013-03-14 13:42:50 -0400
commit439cdc5dd9e67badb9c5ed9c3df8a5efed6f314a (patch)
tree53eb1925352fea4702ca821fb76e0a6bfc004f93 /proxy/src/gp_socket.c
parent149c8346588e98949ca15ef98634a5b8e37a0be6 (diff)
downloadgss-proxy-439cdc5dd9e67badb9c5ed9c3df8a5efed6f314a.tar.gz
gss-proxy-439cdc5dd9e67badb9c5ed9c3df8a5efed6f314a.tar.xz
gss-proxy-439cdc5dd9e67badb9c5ed9c3df8a5efed6f314a.zip
Add support to get peer's SeLinux context
Diffstat (limited to 'proxy/src/gp_socket.c')
-rw-r--r--proxy/src/gp_socket.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/proxy/src/gp_socket.c b/proxy/src/gp_socket.c
index a782564..8bb71d1 100644
--- a/proxy/src/gp_socket.c
+++ b/proxy/src/gp_socket.c
@@ -36,6 +36,13 @@
#include "gp_proxy.h"
#include "gp_creds.h"
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#define SEC_CTX security_context_t
+#else
+#define SEC_CTX void *
+#endif /* HAVE_SELINUX */
+
#define FRAGMENT_BIT (1 << 31)
struct unix_sock_conn {
@@ -51,6 +58,7 @@ struct gp_conn {
struct gssproxy_ctx *gpctx;
struct unix_sock_conn us;
struct gp_creds creds;
+ SEC_CTX secctx;
};
struct gp_buffer {
@@ -172,8 +180,6 @@ done:
return fd;
}
-/* TODO: use getpeercon for SeLinux context */
-
static int get_peercred(int fd, struct gp_conn *conn)
{
socklen_t len;
@@ -192,6 +198,19 @@ static int get_peercred(int fd, struct gp_conn *conn)
}
conn->creds.type |= CRED_TYPE_UNIX;
+
+#ifdef HAVE_SELINUX
+ ret = getpeercon(fd, &conn->secctx);
+ if (ret == 0) {
+ conn->creds.type |= CRED_TYPE_SELINUX;
+ } else {
+ ret = errno;
+ GPDEBUG("Failed to get peer's SELinux context (%d:%s)\n",
+ ret, strerror(ret));
+ /* consider thisnot fatal, selinux may be disabled */
+ }
+#endif /* HAVE_SELINUX */
+
return 0;
}