[Initng-svn] r3624 - initng/trunk/plugins/suid
svn at initng.thinktux.net
svn at initng.thinktux.net
Sun Apr 2 00:21:14 CEST 2006
Author: bonbons
Date: Sun Apr 2 00:21:13 2006
New Revision: 3624
Modified:
initng/trunk/plugins/suid/initng_suid.c
Log:
Extended suid plugin to update $USER, $HOME and $PATH environment variables
when switching uid (to != 0):
- USER=<username (as detected by getpwnam)>
- HOME=<homedir (as detected by getpwnam)>
- PATH=/bin:/usr/bin
Modified: initng/trunk/plugins/suid/initng_suid.c
==============================================================================
--- initng/trunk/plugins/suid/initng_suid.c (original)
+++ initng/trunk/plugins/suid/initng_suid.c Sun Apr 2 00:21:13 2006
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <initng_toolbox.h>
#include <initng_handler.h>
#include <initng_global.h>
#include <initng_plugin_hook.h>
@@ -37,6 +38,19 @@
s_entry SUID = { "suid", STRING, NULL, "Set this user id on launch." };
s_entry SGID = { "sgid", STRING, NULL, "Set this group id on launch." };
+void adjust_env(active_db_h * service, const char* vn, const char* vv);
+void adjust_env(active_db_h * service, const char* vn, const char* vv)
+{
+ /* add to service cache */
+ if (initng_service_cache_is_var(&ENV, vn, service->from_service))
+ {
+ return; /* Assume they were set by .i file, don't override */
+ }
+ else
+ {
+ initng_service_cache_set_string_var(&ENV, i_strdup(vn), service->from_service, i_strdup(vv));
+ }
+}
static int do_suid(active_db_h * service, process_h * process
__attribute__ ((unused)))
@@ -112,6 +126,11 @@
{
D_("Change to uid %i", uid);
setuid(uid);
+
+ /* Set UID-related env variables */
+ adjust_env(service, "USER", passwd->pw_name);
+ adjust_env(service, "HOME", passwd->pw_dir);
+ adjust_env(service, "PATH", "/bin:/usr/bin");
}
if (groupname)
More information about the Initng-svn
mailing list