summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgregor <dgregor@openbsd.org>1998-08-31 02:13:41 +0000
committerdgregor <dgregor@openbsd.org>1998-08-31 02:13:41 +0000
commitcdf268f8140dfc8f02f586f9daef0b46d43a2391 (patch)
treea245821c25ee3c3fff358a590761b4a88bbd3eb8
parentmostly fix build problems (diff)
downloadwireguard-openbsd-cdf268f8140dfc8f02f586f9daef0b46d43a2391.tar.xz
wireguard-openbsd-cdf268f8140dfc8f02f586f9daef0b46d43a2391.zip
Add pass-through ('-p') option to uudecode.
-rw-r--r--usr.bin/uudecode/uudecode.c46
-rw-r--r--usr.bin/uuencode/uuencode.17
2 files changed, 35 insertions, 18 deletions
diff --git a/usr.bin/uudecode/uudecode.c b/usr.bin/uudecode/uudecode.c
index 588534e0756..2a68977be77 100644
--- a/usr.bin/uudecode/uudecode.c
+++ b/usr.bin/uudecode/uudecode.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uudecode.c,v 1.5 1998/05/29 21:07:22 deraadt Exp $ */
+/* $OpenBSD: uudecode.c,v 1.6 1998/08/31 02:13:41 dgregor Exp $ */
/* $NetBSD: uudecode.c,v 1.6 1994/11/17 07:40:43 jtc Exp $ */
/*-
@@ -42,14 +42,17 @@ char copyright[] =
#if 0
static char sccsid[] = "@(#)uudecode.c 8.2 (Berkeley) 4/2/94";
#endif
-static char rcsid[] = "$OpenBSD: uudecode.c,v 1.5 1998/05/29 21:07:22 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: uudecode.c,v 1.6 1998/08/31 02:13:41 dgregor Exp $";
#endif /* not lint */
/*
- * uudecode [file ...]
+ * uudecode [-p] [file ...]
*
* create the specified file, decoding as you go.
* used with uuencode.
+ *
+ * Write to stdout if '-p' is specified. Use this option if you care about
+ * security at all.
*/
#include <stdio.h>
#include <string.h>
@@ -61,7 +64,7 @@ static char rcsid[] = "$OpenBSD: uudecode.c,v 1.5 1998/05/29 21:07:22 deraadt Ex
#include <pwd.h>
#include <unistd.h>
-static int decode();
+static int decode(int);
static void usage();
char *filename;
@@ -71,11 +74,20 @@ main(argc, argv)
char *argv[];
{
int rval;
+ char ch;
+ int tostdout = 0;
setlocale(LC_ALL, "");
- while (getopt(argc, argv, "") != -1)
- usage();
+ while ((ch = getopt(argc, argv, "p")) != -1)
+ switch((char)ch) {
+ case 'p':
+ tostdout++;
+ break;
+ case '?':
+ default:
+ usage();
+ }
argc -= optind;
argv += optind;
@@ -88,17 +100,17 @@ main(argc, argv)
rval = 1;
continue;
}
- rval |= decode();
+ rval |= decode(tostdout);
} while (*++argv);
} else {
filename = "stdin";
- rval = decode();
+ rval = decode(tostdout);
}
exit(rval);
}
static int
-decode()
+decode(int tostdout)
{
extern int errno;
struct passwd *pw;
@@ -142,12 +154,14 @@ decode()
buf[n] = '/';
}
- /* create output file, set mode */
- if (!freopen(buf, "w", stdout) ||
- fchmod(fileno(stdout), mode&0666)) {
- (void)fprintf(stderr, "uudecode: %s: %s: %s\n", buf,
- filename, strerror(errno));
- return(1);
+ if (!tostdout) {
+ /* create output file, set mode */
+ if (!freopen(buf, "w", stdout) ||
+ fchmod(fileno(stdout), mode&0666)) {
+ (void)fprintf(stderr, "uudecode: %s: %s: %s\n", buf,
+ filename, strerror(errno));
+ return(1);
+ }
}
/* for each input line */
@@ -199,6 +213,6 @@ decode()
static void
usage()
{
- (void)fprintf(stderr, "usage: uudecode [file ...]\n");
+ (void)fprintf(stderr, "usage: uudecode [-p] [file ...]\n");
exit(1);
}
diff --git a/usr.bin/uuencode/uuencode.1 b/usr.bin/uuencode/uuencode.1
index 30f564b8297..58095b0a9eb 100644
--- a/usr.bin/uuencode/uuencode.1
+++ b/usr.bin/uuencode/uuencode.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: uuencode.1,v 1.3 1996/06/26 05:42:23 deraadt Exp $
+.\" $OpenBSD: uuencode.1,v 1.4 1998/08/31 02:13:43 dgregor Exp $
.\" $NetBSD: uuencode.1,v 1.4 1994/11/17 07:39:42 jtc Exp $
.\"
.\" Copyright (c) 1980, 1990, 1993
@@ -46,6 +46,7 @@
.Op Ar file
.Ar name
.Nm uudecode
+.Op Fl p
.Op Ar file ...
.Sh DESCRIPTION
.Nm Uuencode
@@ -76,7 +77,9 @@ files (or by default, the standard input) into the original form.
The resulting file is named
.Ar name
and will have the mode of the original file except that setuid
-and execute bits are not retained.
+and execute bits are not retained. If the
+.Fl p
+option is specified, the output will instead be written to stdout.
.Nm Uudecode
ignores any leading and trailing lines.
.Sh EXAMPLES