1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-03 12:35:02 +00:00

Add two new options:

-i     Do not overwrite files.

     -s     Do not strip output pathname to base filename. By default uuencode
	    deletes any prefix ending with the last slash '/' for security
	    purpose.
This commit is contained in:
Wolfram Schneider 1998-01-25 19:26:05 +00:00
parent b72ceac5ef
commit dfe64147d2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=32780
2 changed files with 39 additions and 11 deletions

View File

@ -42,7 +42,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)uudecode.c 8.2 (Berkeley) 4/2/94"; static char sccsid[] = "@(#)uudecode.c 8.2 (Berkeley) 4/2/94";
#endif #endif
static const char rcsid[] = static const char rcsid[] =
"$Id: uudecode.c,v 1.9 1997/08/22 06:51:43 charnier Exp $"; "$Id: uudecode.c,v 1.10 1997/09/18 14:07:26 phk Exp $";
#endif /* not lint */ #endif /* not lint */
/* /*
@ -63,7 +63,7 @@ static const char rcsid[] =
#include <unistd.h> #include <unistd.h>
char *filename; char *filename;
int cflag, pflag; int cflag, iflag, pflag, sflag;
static void usage __P((void)); static void usage __P((void));
int decode __P((void)); int decode __P((void));
@ -76,14 +76,20 @@ main(argc, argv)
{ {
int rval, ch; int rval, ch;
while ((ch = getopt(argc, argv, "cp")) != -1) { while ((ch = getopt(argc, argv, "cips")) != -1) {
switch(ch) { switch(ch) {
case 'c': case 'c':
cflag = 1; /* multiple uudecode'd files */ cflag = 1; /* multiple uudecode'd files */
break; break;
case 'i':
iflag = 1; /* ask before override files */
break;
case 'p': case 'p':
pflag = 1; /* print output to stdout */ pflag = 1; /* print output to stdout */
break; break;
case 's':
sflag = 1; /* do not strip pathnames for output */
break;
default: default:
usage(); usage();
} }
@ -134,7 +140,7 @@ decode2(flag)
{ {
struct passwd *pw; struct passwd *pw;
register int n; register int n;
register char ch, *p; register char ch, first, *p;
int mode, n1; int mode, n1;
char buf[MAXPATHLEN]; char buf[MAXPATHLEN];
char buffn[MAXPATHLEN]; /* file name buffer */ char buffn[MAXPATHLEN]; /* file name buffer */
@ -154,6 +160,16 @@ decode2(flag)
(void)sscanf(buf, "begin %o %s", &mode, buf); (void)sscanf(buf, "begin %o %s", &mode, buf);
if (!sflag && !pflag) {
strncpy(buffn, buf, sizeof(buffn));
if (strrchr(buffn, '/') != NULL)
strncpy(buf, strrchr(buffn, '/') + 1, sizeof(buf));
if (buf[0] == '\0') {
warnx("%s: illegal filename", buffn);
return(1);
}
}
/* handle ~user/file format */ /* handle ~user/file format */
if (buf[0] == '~') { if (buf[0] == '~') {
if (!(p = index(buf, '/'))) { if (!(p = index(buf, '/'))) {
@ -180,10 +196,14 @@ decode2(flag)
if (pflag) if (pflag)
; /* print to stdout */ ; /* print to stdout */
else if (!freopen(buf, "w", stdout) || else {
fchmod(fileno(stdout), mode&0666)) { if (iflag && !access(buf, F_OK))
warn("%s: %s", buf, filename); (void)fprintf(stderr, "not overwritten: %s\n", buf);
return(1); if (!freopen(buf, "w", stdout) ||
fchmod(fileno(stdout), mode&0666)) {
warn("%s: %s", buf, filename);
return(1);
}
} }
strcpy(buffn, buf); /* store file name from header line */ strcpy(buffn, buf); /* store file name from header line */
@ -262,6 +282,6 @@ decode2(flag)
static void static void
usage() usage()
{ {
(void)fprintf(stderr, "usage: uudecode [-cp] [file ...]\n"); (void)fprintf(stderr, "usage: uudecode [-cips] [file ...]\n");
exit(1); exit(1);
} }

View File

@ -30,7 +30,7 @@
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" @(#)uuencode.1 8.1 (Berkeley) 6/6/93 .\" @(#)uuencode.1 8.1 (Berkeley) 6/6/93
.\" $Id: uuencode.1,v 1.5 1997/02/22 19:57:36 peter Exp $ .\" $Id: uuencode.1,v 1.6 1997/08/22 06:52:59 charnier Exp $
.\" .\"
.Dd June 6, 1993 .Dd June 6, 1993
.Dt UUENCODE 1 .Dt UUENCODE 1
@ -44,7 +44,7 @@
.Op Ar file .Op Ar file
.Ar name .Ar name
.Nm uudecode .Nm uudecode
.Op Fl cp .Op Fl cips
.Op Ar .Op Ar
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm Uuencode .Nm Uuencode
@ -86,10 +86,17 @@ The following options are available for
Decode more than one uuencode'd file from Decode more than one uuencode'd file from
.Ar file .Ar file
if possible. if possible.
.It Fl i
Do not overwrite files.
.It Fl p .It Fl p
Decode Decode
.Ar file .Ar file
and write output to standard output. and write output to standard output.
.It Fl s
Do not strip output pathname to base filename. By default
.Nm uudecode
deletes any prefix ending with the last slash '/' for security
purpose.
.Sh EXAMPLES .Sh EXAMPLES
The following example packages up a source tree, compresses it, The following example packages up a source tree, compresses it,
uuencodes it and mails it to a user on another system. uuencodes it and mails it to a user on another system.
@ -118,6 +125,7 @@ archive from your mailbox
uudecode -p < $MAIL | zcat | tar xfv - uudecode -p < $MAIL | zcat | tar xfv -
.Ed .Ed
.Sh SEE ALSO .Sh SEE ALSO
.Xr basename 1 ,
.Xr compress 1 , .Xr compress 1 ,
.Xr mail 1 , .Xr mail 1 ,
.Xr uucp 1 , .Xr uucp 1 ,