vdr/vdr/debian/patches 07_not_as_root.dpatch 00list 05_set_system_time_as_user.dpatch

Thomas Schmidt pkg-vdr-dvb-changes@lists.alioth.debian.org
Sun, 16 Jan 2005 19:39:49 +0000


Update of /cvsroot/pkg-vdr-dvb/vdr/vdr/debian/patches
In directory haydn:/tmp/cvs-serv15395/vdr/vdr/debian/patches

Modified Files:
	00list 05_set_system_time_as_user.dpatch 
Added Files:
	07_not_as_root.dpatch 
Log Message:
* changed 05_set_system_time_as_user so that not defines are necesscary anymore
* added 07_not_as_root.dpatch - do not allow root to run vdr anymore (adapted from Darren Salt's patch)

Index: 00list
===================================================================
RCS file: /cvsroot/pkg-vdr-dvb/vdr/vdr/debian/patches/00list,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- 00list	15 Jan 2005 18:14:18 -0000	1.12
+++ 00list	16 Jan 2005 19:39:47 -0000	1.13
@@ -5,6 +5,7 @@
 04_newplugin
 05_set_system_time_as_user
 06_default_svdrp_port_0
+07_not_as_root
 
 # The Elchi AIO 4d patch for a nicer OSD, inlcuding the frames and black
 # square fix.

Index: 05_set_system_time_as_user.dpatch
===================================================================
RCS file: /cvsroot/pkg-vdr-dvb/vdr/vdr/debian/patches/05_set_system_time_as_user.dpatch,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- 05_set_system_time_as_user.dpatch	30 Dec 2004 23:03:20 -0000	1.1
+++ 05_set_system_time_as_user.dpatch	16 Jan 2005 19:39:47 -0000	1.2
@@ -7,56 +7,33 @@
 ## DP: <ludwig.nussel@gmx.de>
 
 @DPATCH@
-diff -urNad vdr-1.2.6/Makefile /tmp/dpep.NAw891/vdr-1.2.6/Makefile
---- vdr-1.2.6/Makefile	2004-04-22 12:48:23.000000000 +0200
-+++ /tmp/dpep.NAw891/vdr-1.2.6/Makefile	2004-12-30 22:32:22.000000000 +0100
-@@ -55,7 +55,7 @@
- 
- ifdef DEBUG_OSD
- DEFINES += -DDEBUG_OSD
--NCURSESLIB = -lncurses
-+LIBS += -lncurses
- endif
- 
- ifdef VFAT
-@@ -63,6 +63,11 @@
- DEFINES += -DVFAT
- endif
- 
-+ifdef WITH_CAPABILITIES
-+DEFINES += -DWITH_CAPABILITIES
-+LIBS += -lcap
-+endif
-+
- all: vdr
- font: genfontfile fontfix.c fontosd.c
- 	@echo "font files created."
-@@ -84,7 +89,7 @@
+diff -urNad vdr-1.2.6/Makefile /tmp/dpep.Olbr86/vdr-1.2.6/Makefile
+--- vdr-1.2.6/Makefile	2005-01-16 17:45:11.000000000 +0100
++++ /tmp/dpep.Olbr86/vdr-1.2.6/Makefile	2005-01-16 17:45:11.000000000 +0100
+@@ -87,7 +87,7 @@
  # The main program:
  
  vdr: $(OBJS) $(DTVLIB)
 -	$(CXX) $(CXXFLAGS) -rdynamic $(OBJS) $(NCURSESLIB) -ljpeg -lpthread -ldl $(LIBDIRS) $(DTVLIB) -o vdr
-+	$(CXX) $(CXXFLAGS) -rdynamic $(OBJS) $(LIBS) -ljpeg -lpthread -ldl $(LIBDIRS) $(DTVLIB) -o vdr
++	$(CXX) $(CXXFLAGS) -rdynamic $(OBJS) $(NCURSESLIB) -lcap -ljpeg -lpthread -ldl $(LIBDIRS) $(DTVLIB) -o vdr
  
  # The font files:
  
-diff -urNad vdr-1.2.6/vdr.c /tmp/dpep.NAw891/vdr-1.2.6/vdr.c
---- vdr-1.2.6/vdr.c	2004-04-22 12:48:59.000000000 +0200
-+++ /tmp/dpep.NAw891/vdr-1.2.6/vdr.c	2004-12-30 22:32:22.000000000 +0100
-@@ -31,6 +31,12 @@
+diff -urNad vdr-1.2.6/vdr.c /tmp/dpep.Olbr86/vdr-1.2.6/vdr.c
+--- vdr-1.2.6/vdr.c	2005-01-16 17:45:11.000000000 +0100
++++ /tmp/dpep.Olbr86/vdr-1.2.6/vdr.c	2005-01-16 17:45:11.000000000 +0100
+@@ -31,6 +31,10 @@
  #include <stdlib.h>
  #include <termios.h>
  #include <unistd.h>
 +#include <pwd.h>
 +#include <grp.h>
-+#ifdef WITH_CAPABILITIES
 +#include <sys/capability.h>
 +#include <sys/prctl.h>
-+#endif
  #include "audio.h"
  #include "channels.h"
  #include "config.h"
-@@ -77,6 +83,104 @@
+@@ -77,6 +81,96 @@
    exit(1);
  }
  
@@ -115,7 +92,6 @@
 +  return 0;
 +}
 +
-+#ifdef WITH_CAPABILITIES
 +// drop all capabilities except cap_sys_time
 +static int set_cap_sys_time(void)
 +{
@@ -150,18 +126,11 @@
 +{
 +  return prctl(PR_SET_KEEPCAPS, 0, 0, 0, 0);
 +}
-+#else
-+static inline int return0() { return 0; }
-+#define printcap() return0()
-+#define set_cap_sys_time() return0()
-+#define set_keepcaps() return0()
-+#define set_nokeepcaps() return0()
-+#endif
 +
  int main(int argc, char *argv[])
  {
    // Save terminal settings:
-@@ -106,6 +210,8 @@
+@@ -106,6 +200,8 @@
    const char *Terminal = NULL;
    const char *Shutdown = NULL;
    cPluginManager PluginManager(DEFAULTPLUGINDIR);
@@ -170,7 +139,7 @@
  
    static struct option long_options[] = {
        { "audio",    required_argument, NULL, 'a' },
-@@ -125,11 +231,13 @@
+@@ -125,11 +221,13 @@
        { "version",  no_argument,       NULL, 'V' },
        { "video",    required_argument, NULL, 'v' },
        { "watchdog", required_argument, NULL, 'w' },
@@ -185,7 +154,7 @@
          switch (c) {
            case 'a': AudioCommand = optarg;
                      break;
-@@ -219,6 +327,10 @@
+@@ -219,6 +317,10 @@
                      fprintf(stderr, "vdr: invalid watchdog timeout: %s\n", optarg);
                      return 2;
                      break;
@@ -196,7 +165,7 @@
            default:  return 2;
            }
          }
-@@ -260,6 +372,8 @@
+@@ -260,6 +362,8 @@
                 "  -V,       --version      print version information and exit\n"
                 "  -w SEC,   --watchdog=SEC activate the watchdog timer with a timeout of SEC\n"
                 "                           seconds (default: %d); '0' disables the watchdog\n"
@@ -205,7 +174,7 @@
                 "\n",
                 cSIProcessor::GetEpgDataFileName() ? cSIProcessor::GetEpgDataFileName() : "'-'",
                 DEFAULTPLUGINDIR,
-@@ -290,6 +404,17 @@
+@@ -290,6 +394,17 @@
       return 0;
       }
  

--- NEW FILE: 07_not_as_root.dpatch ---
#! /bin/sh /usr/share/dpatch/dpatch-run
## 07_not_as_root.dpatch by Thomas Schmidt <thomas.schmidt@in.stud.tu-ilmenau.de>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Refuse to run vdr as user root (Note: This patch requires the
## DP: 05_set_system_time_as_user.dpatch)

@DPATCH@
diff -urNad vdr-1.2.6/vdr.c /tmp/dpep.zQi8Wv/vdr-1.2.6/vdr.c
--- vdr-1.2.6/vdr.c	2005-01-16 20:24:35.000000000 +0100
+++ /tmp/dpep.zQi8Wv/vdr-1.2.6/vdr.c	2005-01-16 20:32:07.000000000 +0100
@@ -35,6 +35,7 @@
 #include <grp.h>
 #include <sys/capability.h>
 #include <sys/prctl.h>
+#include <sys/types.h>
 #include "audio.h"
 #include "channels.h"
 #include "config.h"
@@ -325,12 +326,22 @@
           }
         }
 
+  // Check if the program should run as root
+  bool IsRoot=0; 
+  
+  if (username == NULL) 
+     IsRoot = !getuid () || !getgid () || !geteuid () || !getegid ();
+  else if (strcmp(username,"root") == 0)
+     IsRoot = 1;
+  
   // Help and version info:
 
   if (DisplayHelp || DisplayVersion) {
-     if (!PluginManager.HasPlugins())
-        PluginManager.AddPlugin("*"); // adds all available plugins
-     PluginManager.LoadPlugins();
+     if (!IsRoot) {
+     	if (!PluginManager.HasPlugins())
+        	PluginManager.AddPlugin("*"); // adds all available plugins
+     	PluginManager.LoadPlugins();
+     }
      if (DisplayHelp) {
         printf("Usage: vdr [OPTIONS]\n\n"          // for easier orientation, this is column 80|
                "  -a CMD,   --audio=CMD    send Dolby Digital audio to stdin of command CMD\n"
@@ -374,7 +385,7 @@
         }
      if (DisplayVersion)
         printf("vdr (%s) - The Video Disk Recorder\n", VDRVERSION);
-     if (PluginManager.HasPlugins()) {
+     if (!IsRoot && PluginManager.HasPlugins()) {
         if (DisplayHelp)
            printf("Plugins: vdr -P\"name [OPTIONS]\"\n\n");
         for (int i = 0; ; i++) {
@@ -394,6 +405,11 @@
      return 0;
      }
 
+  if (IsRoot) {
+	fprintf (stderr, "%s: sorry, I refuse to run with root privileges\n", argv[0]);
+     	return 0;
+  }
+
   if(username && set_keepcaps() != 0)
     return 2;