RFC: Set environment variables after switching user (Patch included)

Message ID 5140A6F1.9070604@gmx.de
State New

Commit Message

Manuel Reimer March 13, 2013, 4:18 p.m. UTC

depending on the init system and the way, how it is configured, scripts, 
executed by VDR, either have variables like "HOME" unset or still set to 
"/root". This is useless for scripts or other external software, called by VDR.

My small patch sets the common environment variables to the correct values for 
the VDR "runtime user". This fixes many problems with all kinds of external 
software, called by VDR (ProjectX or even Firefox via "externalplayer" to browse 
the web on your TV).

Would be great if this small change could still make it into 2.0.


Manuel Reimer


VDRU VDRU March 13, 2013, 11:46 p.m. UTC | #1
Why not just move vdr to the end of your init instead of having it
fool around with setting things like $HOME, $SHELL, etc?
Klaus Schmidinger March 14, 2013, 8:13 a.m. UTC | #2
On 14.03.2013 00:46, VDR User wrote:
> Why not just move vdr to the end of your init instead of having it
> fool around with setting things like $HOME, $SHELL, etc?

Probably because he starts VDR as root to allow it to, for instance,
set the system time, but wants to limit its rights to those of a particular
user when actually running. So the patch looks reasonable to me and I'll
adopt it for version 2.0.



Common subdirectories: vdr-1.7.40.org/libsi and vdr-1.7.40/libsi
Common subdirectories: vdr-1.7.40.org/PLUGINS and vdr-1.7.40/PLUGINS
Common subdirectories: vdr-1.7.40.org/po and vdr-1.7.40/po
Common subdirectories: vdr-1.7.40.org/symbols and vdr-1.7.40/symbols
diff -U 8 -p vdr-1.7.40.org/vdr.c vdr-1.7.40/vdr.c
--- vdr-1.7.40.org/vdr.c	2013-03-13 16:59:48.315370970 +0100
+++ vdr-1.7.40/vdr.c	2013-03-13 17:02:49.027999521 +0100
@@ -104,16 +104,20 @@  static bool SetUser(const char *UserName
         return false;
      if (setuid(user->pw_uid) < 0) {
         fprintf(stderr, "vdr: cannot set user id %u: %s\n", (unsigned int)user->pw_uid, strerror(errno));
         return false;
      if (UserDump && prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) < 0)
         fprintf(stderr, "vdr: warning - cannot set dumpable: %s\n", strerror(errno));
+     setenv("HOME", user->pw_dir, 1);
+     setenv("USER", user->pw_name, 1);
+     setenv("LOGNAME", user->pw_name, 1);
+     setenv("SHELL", user->pw_shell, 1);
   return true;
 static bool DropCaps(void)
   // drop all capabilities except selected ones
   cap_t caps = cap_from_text("= cap_sys_nice,cap_sys_time,cap_net_raw=ep");