Imported Upstream version 2.5.0p2
[debian/amanda] / client-src / runtar.c
index c8e9e6b4f504fb6278ff6e34a372f852964ac185..d24352bd907f7a31c1dc195f21f59e80e3ce8c39 100644 (file)
@@ -24,7 +24,7 @@
  * file named AUTHORS, in the root directory of this distribution.
  */
 /*
- * $Id: runtar.c,v 1.11.4.2.6.1 2002/10/27 14:31:18 martinea Exp $
+ * $Id: runtar.c,v 1.17 2006/01/14 04:37:18 paddy_s Exp $
  *
  * runs GNUTAR program as root
  */
@@ -39,24 +39,18 @@ char **argv;
 {
 #ifdef GNUTAR
     int i;
-#endif
-    int fd;
     char *e;
+    char *dbf;
+#endif
 
-    for(fd = 3; fd < FD_SETSIZE; fd++) {
-       /*
-        * Make sure nobody spoofs us with a lot of extra open files
-        * that would cause an open we do to get a very high file
-        * descriptor, which in turn might be used as an index into
-        * an array (e.g. an fd_set).
-        */
-       close(fd);
-    }
-
+    safe_fd(-1, 0);
     safe_cd();
 
     set_pname("runtar");
 
+    /* Don't die when child closes pipe */
+    signal(SIGPIPE, SIG_IGN);
+
     dbopen();
     dbprintf(("%s: version %s\n", argv[0], version()));
 
@@ -74,13 +68,11 @@ char **argv;
     }
 
 #ifdef FORCE_USERID
-    if (getuid() != client_uid) {
+    if (getuid() != client_uid)
        error("error [must be invoked by %s]\n", CLIENT_LOGIN);
-    }
 
-    if (geteuid() != 0) {
+    if (geteuid() != 0)
        error("error [must be setuid root]\n");
-    }
 #endif
 
 #if !defined (DONT_SUID_ROOT)
@@ -91,10 +83,17 @@ char **argv;
     for (i=0; argv[i]; i++)
        dbprintf(("%s ", argv[i]));
     dbprintf(("\n"));
+    dbf = dbfn();
+    if (dbf) {
+       dbf = stralloc(dbf);
+    }
+    dbclose();
 
     execve(GNUTAR, argv, safe_env());
 
     e = strerror(errno);
+    dbreopen(dbf, "more");
+    amfree(dbf);
     dbprintf(("execve of %s failed (%s)\n", GNUTAR, e));
     dbclose();