summaryrefslogtreecommitdiffstats
path: root/proxy/src/gp_init.c
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2013-12-22 16:13:56 -0500
committerSimo Sorce <simo@redhat.com>2013-12-26 16:08:58 -0500
commit0bc3f5213743030206d0f40b342599d87a68b474 (patch)
treebf0624720df297ceeea4ec203a59e793d0d02434 /proxy/src/gp_init.c
parent8b147c9196d9068d0fc5e5a8919b84e8cbb97ef4 (diff)
downloadgss-proxy-0bc3f5213743030206d0f40b342599d87a68b474.tar.gz
gss-proxy-0bc3f5213743030206d0f40b342599d87a68b474.tar.xz
gss-proxy-0bc3f5213743030206d0f40b342599d87a68b474.zip
Add support for dropping privileges
If the 'proxy user' configuation option is set in the [gssproxy] section then GSS Proxy will drop privileges to the specified after setting up all the sockets. Care must be taken to make sure all the resources the daemon need access to (keytabs, ccache directories, etc..) are accessible as the proxy user. Implements: https://fedorahosted.org/gss-proxy/ticket/102 Signed-off-by: Simo Sorce <simo@redhat.com>
Diffstat (limited to 'proxy/src/gp_init.c')
-rw-r--r--proxy/src/gp_init.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/proxy/src/gp_init.c b/proxy/src/gp_init.c
index 7e29c59..830ae16 100644
--- a/proxy/src/gp_init.c
+++ b/proxy/src/gp_init.c
@@ -33,6 +33,8 @@
#include <string.h>
#include <unistd.h>
#include <stdio.h>
+#include <pwd.h>
+#include <grp.h>
#include "gp_proxy.h"
void init_server(bool daemonize)
@@ -207,3 +209,47 @@ void write_pid(void)
GP_PID_FILE, ret, gp_strerror(ret));
}
}
+
+int drop_privs(struct gp_config *cfg)
+{
+ char buf[2048];
+ struct passwd *pw, pws;
+ int ret;
+
+ if (cfg->proxy_user == NULL) {
+ /* not dropping privs */
+ return 0;
+ }
+
+ ret = getpwnam_r(cfg->proxy_user, &pws, buf, 2048, &pw);
+ if (ret) {
+ GPDEBUG("Failed to look up proxy user: '%s'! [%d:%s]\n",
+ cfg->proxy_user, ret, gp_strerror(ret));
+ return ret;
+ }
+
+ ret = initgroups(pw->pw_name, pw->pw_gid);
+ if (ret) {
+ GPDEBUG("Failed to set access credentials: [%d:%s]\n",
+ ret, gp_strerror(ret));
+ return ret;
+ }
+
+ ret = setgid(pw->pw_gid);
+ if (ret == -1) {
+ ret = errno;
+ GPDEBUG("Failed to set group id to %d: [%d:%s]\n",
+ pw->pw_gid, ret, gp_strerror(ret));
+ return ret;
+ }
+
+ ret = setuid(pw->pw_uid);
+ if (ret == -1) {
+ ret = errno;
+ GPDEBUG("Failed to set user id to %d: [%d:%s]\n",
+ pw->pw_uid, ret, gp_strerror(ret));
+ return ret;
+ }
+
+ return 0;
+}