From: niklas Date: Fri, 8 Mar 1996 22:02:54 +0000 (+0000) Subject: From NetBSD: X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=93e5a94505f50f142de1b07a83ebec91cdc7bbd9;p=openbsd From NetBSD: Add remote tape capabilities. Since we're setuid, let's be paranoid. Picked up a little lint in the dryer. --- diff --git a/bin/mt/Makefile b/bin/mt/Makefile index 303b40e9f60..bcab624163c 100644 --- a/bin/mt/Makefile +++ b/bin/mt/Makefile @@ -1,6 +1,9 @@ -# $NetBSD: Makefile,v 1.3 1995/03/21 06:57:43 cgd Exp $ +# $NetBSD: Makefile,v 1.5 1996/03/06 06:22:04 scottr Exp $ # @(#)Makefile 8.1 (Berkeley) 6/6/93 PROG= mt +SRCS= mt.c mtrmt.c +BINOWN= root +BINMODE=4555 .include diff --git a/bin/mt/mt.1 b/bin/mt/mt.1 index e134616b776..0f23ed44d04 100644 --- a/bin/mt/mt.1 +++ b/bin/mt/mt.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: mt.1,v 1.6 1995/08/22 19:36:00 jtc Exp $ +.\" $NetBSD: mt.1,v 1.7 1996/03/05 20:39:42 scottr Exp $ .\" .\" Copyright (c) 1981, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -56,6 +56,15 @@ Note that .Ar tapename must reference a raw (not block) tape device. +If +.Ar tapename +is of the form +.Dq host:tapename , +or +.Dq user@host:tapename , +.Nm mt +writes to the named tape device on the remote host using +.Xr rmt 8 . .Pp The available commands are listed below. Only as many characters as are required to uniquely identify a command diff --git a/bin/mt/mt.c b/bin/mt/mt.c index aa82d1a3546..7db658ac81e 100644 --- a/bin/mt/mt.c +++ b/bin/mt/mt.c @@ -1,4 +1,4 @@ -/* $NetBSD: mt.c,v 1.8 1995/09/28 07:18:20 tls Exp $ */ +/* $NetBSD: mt.c,v 1.11 1996/03/06 06:34:20 scottr Exp $ */ /* * Copyright (c) 1980, 1993 @@ -43,7 +43,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)mt.c 8.2 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$NetBSD: mt.c,v 1.8 1995/09/28 07:18:20 tls Exp $"; +static char rcsid[] = "$NetBSD: mt.c,v 1.11 1996/03/06 06:34:20 scottr Exp $"; #endif #endif /* not lint */ @@ -60,6 +60,9 @@ static char rcsid[] = "$NetBSD: mt.c,v 1.8 1995/09/28 07:18:20 tls Exp $"; #include #include #include +#include + +#include "mt.h" struct commands { char *c_name; @@ -86,6 +89,10 @@ void printreg __P((char *, u_int, char *)); void status __P((struct mtget *)); void usage __P((void)); +char *host = NULL; /* remote host (if any) */ +uid_t uid; /* read uid */ +uid_t euid; /* effective uid */ + int main(argc, argv) int argc; @@ -97,6 +104,10 @@ main(argc, argv) int ch, len, mtfd; char *p, *tape; + uid = getuid(); + euid = geteuid(); + (void) seteuid(uid); + if ((tape = getenv("TAPE")) == NULL) tape = DEFTAPE; @@ -116,6 +127,15 @@ main(argc, argv) if (argc < 1 || argc > 2) usage(); + if (strchr(tape, ':')) { + host = tape; + tape = strchr(host, ':'); + *tape++ = '\0'; + if (rmthost(host) == 0) + exit(X_ABORT); + } + (void) setuid(uid); /* rmthost() is the only reason to be setuid */ + len = strlen(p = *argv++); for (comp = com;; comp++) { if (comp->c_name == NULL) @@ -123,7 +143,8 @@ main(argc, argv) if (strncmp(p, comp->c_name, len) == 0) break; } - if ((mtfd = open(tape, comp->c_ronly ? O_RDONLY : O_RDWR)) < 0) + if ((mtfd = host ? rmtopen(tape, 2) : + open(tape, O_WRONLY|O_CREAT, 0666)) < 0) err(2, "%s", tape); if (comp->c_code != MTNOP) { mt_com.mt_op = comp->c_code; @@ -134,14 +155,23 @@ main(argc, argv) } else mt_com.mt_count = 1; - if (ioctl(mtfd, MTIOCTOP, &mt_com) < 0) + if ((host ? rmtioctl(mt_com.mt_op, mt_com.mt_count) : + ioctl(mtfd, MTIOCTOP, &mt_com)) < 0) err(2, "%s: %s", tape, comp->c_name); } else { - if (ioctl(mtfd, MTIOCGET, &mt_status) < 0) - err(2, "ioctl MTIOCGET"); - status(&mt_status); + if (host) { + status(rmtstatus()); + } else { + if (ioctl(mtfd, MTIOCGET, &mt_status) < 0) + err(2, "ioctl MTIOCGET"); + status(&mt_status); + } } - exit (0); + + if (host) + rmtclose(); + + exit(X_FINOK); /* NOTREACHED */ } @@ -213,7 +243,7 @@ printreg(s, v, bits) bits++; if (v && bits) { putchar('<'); - while (i = *bits++) { + while ((i = *bits++)) { if (v & (1 << (i-1))) { if (any) putchar(','); @@ -232,5 +262,5 @@ void usage() { (void)fprintf(stderr, "usage: mt [-f device] command [ count ]\n"); - exit(1); + exit(X_USAGE); }