X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=rmt%2Frmt.c;h=6f01bcce70c78793a6b2dbf87dbbc1458152c4ed;hb=8c95cc301d14462e5b6c1b4e00dbccddad82ec88;hp=fc6eb827f4788c0c60b878f918c1eb0fc0e394b8;hpb=ba3af39e8b08027d3338b5533bddc86a9c803a74;p=dump.git diff --git a/rmt/rmt.c b/rmt/rmt.c index fc6eb82..6f01bcc 100644 --- a/rmt/rmt.c +++ b/rmt/rmt.c @@ -18,11 +18,7 @@ * 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. * @@ -41,7 +37,7 @@ #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 */ /* @@ -118,15 +114,27 @@ static int rmt_version = 0; 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"); @@ -183,7 +191,7 @@ top: 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; @@ -191,6 +199,8 @@ top: 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) { @@ -200,7 +210,13 @@ top: 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; @@ -214,9 +230,15 @@ top: 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; @@ -347,7 +369,7 @@ 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; @@ -407,8 +429,8 @@ 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: @@ -421,7 +443,7 @@ void getstring(char *bp) 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')