summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/rmt.h4
-rw-r--r--lib/rtapelib.c23
-rw-r--r--lib/system.h7
3 files changed, 19 insertions, 15 deletions
diff --git a/lib/rmt.h b/lib/rmt.h
index 2ce9dc5..ff10e7c 100644
--- a/lib/rmt.h
+++ b/lib/rmt.h
@@ -17,8 +17,8 @@
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-extern char *rmt_command;
-extern char *rmt_dev_name__;
+extern char const *rmt_command;
+extern char const *rmt_dev_name__;
int rmt_open__ (const char *, int, int, const char *);
int rmt_close__ (int);
diff --git a/lib/rtapelib.c b/lib/rtapelib.c
index 3aee428..7213031 100644
--- a/lib/rtapelib.c
+++ b/lib/rtapelib.c
@@ -90,10 +90,10 @@ static int from_remote[MAXUNIT][2] = {{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}};
/* The pipes for sending data to remote tape drives. */
static int to_remote[MAXUNIT][2] = {{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}};
-char *rmt_command = DEFAULT_RMT_COMMAND;
+char const *rmt_command = DEFAULT_RMT_COMMAND;
/* Temporary variable used by macros in rmt.h. */
-char *rmt_dev_name__;
+char const *rmt_dev_name__;
/* If true, always consider file names to be local, even if they contain
colons */
@@ -490,15 +490,16 @@ rmt_open__ (const char *file_name, int open_mode, int bias,
{
/* Child. */
- close (STDIN_FILENO);
- dup (to_remote[remote_pipe_number][PREAD]);
- close (to_remote[remote_pipe_number][PREAD]);
- close (to_remote[remote_pipe_number][PWRITE]);
-
- close (STDOUT_FILENO);
- dup (from_remote[remote_pipe_number][PWRITE]);
- close (from_remote[remote_pipe_number][PREAD]);
- close (from_remote[remote_pipe_number][PWRITE]);
+ if (dup2 (to_remote[remote_pipe_number][PREAD], STDIN_FILENO) < 0
+ || (to_remote[remote_pipe_number][PREAD] != STDIN_FILENO
+ && close (to_remote[remote_pipe_number][PREAD]) != 0)
+ || (to_remote[remote_pipe_number][PWRITE] != STDIN_FILENO
+ && close (to_remote[remote_pipe_number][PWRITE]) != 0)
+ || dup2 (from_remote[remote_pipe_number][PWRITE], STDOUT_FILENO) < 0
+ || close (from_remote[remote_pipe_number][PREAD]) != 0
+ || close (from_remote[remote_pipe_number][PWRITE]) != 0)
+ error (EXIT_ON_EXEC_ERROR, errno,
+ _("Cannot redirect files for remote shell"));
sys_reset_uid_gid ();
diff --git a/lib/system.h b/lib/system.h
index 2deb585..ef46267 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -471,8 +471,11 @@ char *getenv ();
# define SET_BINARY_MODE(arc)
# define ERRNO_IS_EACCES 0
# define TTY_NAME "/dev/tty"
-# define sys_reset_uid_gid() \
- do { setuid (getuid ()); setgid (getgid ()); } while (0)
+# define sys_reset_uid_gid() \
+ do { \
+ if (! (setuid (getuid ()) == 0 && setgid (getgid ()) == 0)) \
+ abort (); \
+ } while (0)
#endif
#if XENIX