* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
#ifndef lint
static const char rcsid[] =
- "$Id: rmt.c,v 1.21 2002/07/29 12:00:34 stelian Exp $";
+ "$Id: rmt.c,v 1.26 2003/04/08 19:52:37 stelian Exp $";
#endif /* not linux */
/*
char *checkbuf __P((char *, int));
void error __P((int));
void getstring __P((char *));
+#ifdef ERMT
+char *cipher __P((char *, int, int));
+void decrypt __P((void));
+#endif
int
main(int argc, char *argv[])
{
- int rval = 0;
+ OFF_T rval = 0;
char c;
int n, i, cc, oflags;
unsigned long block = 0;
+ char *cp;
+#ifdef ERMT
+ if (argc > 1 && strcmp(argv[1], "-d") == 0)
+ decrypt(); /* decrypt stdin to stdout, and exit() */
+#endif
+ /* Skip "-c /etc/rmt", which appears when rmt is used as a shell */
+ if (argc > 2 && strcmp(argv[1], "-c") == 0)
+ argc -= 2, argv += 2;
argc--, argv++;
if (argc > 0) {
debug = fopen(*argv, "w");
getstring(count);
getstring(pos);
DEBUG2("rmtd: L %s %s\n", count, pos);
- rval = LSEEK(tape, (off_t)atol(count), atoi(pos));
+ rval = LSEEK(tape, (OFF_T)atoll(count), atoi(pos));
if (rval < 0)
goto ioerror;
goto respond;
case 'W':
getstring(count);
n = atoi(count);
+ if (n < 1)
+ exit(2);
DEBUG2("rmtd: W %s (block = %lu)\n", count, block);
record = checkbuf(record, n);
for (i = 0; i < n; i += cc) {
exit(2);
}
}
- rval = write(tape, record, n);
+#ifdef ERMT
+ if ((cp = cipher(record, n, 1)) == NULL)
+ goto ioerror;
+#else
+ cp = record;
+#endif
+ rval = write(tape, cp, n);
if (rval < 0)
goto ioerror;
block += n >> 10;
rval = read(tape, record, n);
if (rval < 0)
goto ioerror;
- (void)sprintf(resp, "A%d\n", rval);
+#ifdef ERMT
+ if ((cp = cipher(record, rval, 0)) == NULL)
+ goto ioerror;
+#else
+ cp = record;
+#endif
+ (void)sprintf(resp, "A%lld\n", (long long)rval);
(void)write(1, resp, strlen(resp));
- (void)write(1, record, rval);
+ (void)write(1, cp, rval);
block += n >> 10;
goto top;
if (ioctl(tape, MTIOCGET, (char *)&mtget) < 0)
goto ioerror;
rval = sizeof (mtget);
- (void)sprintf(resp, "A%d\n", rval);
+ (void)sprintf(resp, "A%lld\n", (long long)rval);
(void)write(1, resp, strlen(resp));
(void)write(1, (char *)&mtget, sizeof (mtget));
goto top;
exit(3);
}
respond:
- DEBUG1("rmtd: A %d\n", rval);
- (void)sprintf(resp, "A%d\n", rval);
+ DEBUG1("rmtd: A %lld\n", (long long)rval);
+ (void)sprintf(resp, "A%lld\n", (long long)rval);
(void)write(1, resp, strlen(resp));
goto top;
ioerror:
int i;
char *cp = bp;
- for (i = 0; i < SSIZE; i++) {
+ for (i = 0; i < SSIZE - 1; i++) {
if (read(0, cp+i, 1) != 1)
exit(0);
if (cp[i] == '\n')