-.\" $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.
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
-/* $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
#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 */
#include <stdio.h>
#include <ctype.h>
#include <string.h>
+#include <unistd.h>
+
+#include "mt.h"
struct commands {
char *c_name;
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;
int ch, len, mtfd;
char *p, *tape;
+ uid = getuid();
+ euid = geteuid();
+ (void) seteuid(uid);
+
if ((tape = getenv("TAPE")) == NULL)
tape = DEFTAPE;
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)
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;
}
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 */
}
bits++;
if (v && bits) {
putchar('<');
- while (i = *bits++) {
+ while ((i = *bits++)) {
if (v & (1 << (i-1))) {
if (any)
putchar(',');
usage()
{
(void)fprintf(stderr, "usage: mt [-f device] command [ count ]\n");
- exit(1);
+ exit(X_USAGE);
}