mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-31 12:13:10 +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:
parent
b72ceac5ef
commit
dfe64147d2
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=32780
@ -42,7 +42,7 @@ static const char copyright[] =
|
||||
static char sccsid[] = "@(#)uudecode.c 8.2 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
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 */
|
||||
|
||||
/*
|
||||
@ -63,7 +63,7 @@ static const char rcsid[] =
|
||||
#include <unistd.h>
|
||||
|
||||
char *filename;
|
||||
int cflag, pflag;
|
||||
int cflag, iflag, pflag, sflag;
|
||||
|
||||
static void usage __P((void));
|
||||
int decode __P((void));
|
||||
@ -76,14 +76,20 @@ main(argc, argv)
|
||||
{
|
||||
int rval, ch;
|
||||
|
||||
while ((ch = getopt(argc, argv, "cp")) != -1) {
|
||||
while ((ch = getopt(argc, argv, "cips")) != -1) {
|
||||
switch(ch) {
|
||||
case 'c':
|
||||
cflag = 1; /* multiple uudecode'd files */
|
||||
break;
|
||||
case 'i':
|
||||
iflag = 1; /* ask before override files */
|
||||
break;
|
||||
case 'p':
|
||||
pflag = 1; /* print output to stdout */
|
||||
break;
|
||||
case 's':
|
||||
sflag = 1; /* do not strip pathnames for output */
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
@ -134,7 +140,7 @@ decode2(flag)
|
||||
{
|
||||
struct passwd *pw;
|
||||
register int n;
|
||||
register char ch, *p;
|
||||
register char ch, first, *p;
|
||||
int mode, n1;
|
||||
char buf[MAXPATHLEN];
|
||||
char buffn[MAXPATHLEN]; /* file name buffer */
|
||||
@ -154,6 +160,16 @@ decode2(flag)
|
||||
|
||||
(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 */
|
||||
if (buf[0] == '~') {
|
||||
if (!(p = index(buf, '/'))) {
|
||||
@ -180,10 +196,14 @@ decode2(flag)
|
||||
if (pflag)
|
||||
; /* print to stdout */
|
||||
|
||||
else if (!freopen(buf, "w", stdout) ||
|
||||
fchmod(fileno(stdout), mode&0666)) {
|
||||
warn("%s: %s", buf, filename);
|
||||
return(1);
|
||||
else {
|
||||
if (iflag && !access(buf, F_OK))
|
||||
(void)fprintf(stderr, "not overwritten: %s\n", buf);
|
||||
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 */
|
||||
|
||||
@ -262,6 +282,6 @@ decode2(flag)
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr, "usage: uudecode [-cp] [file ...]\n");
|
||||
(void)fprintf(stderr, "usage: uudecode [-cips] [file ...]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
@ -30,7 +30,7 @@
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)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
|
||||
.Dt UUENCODE 1
|
||||
@ -44,7 +44,7 @@
|
||||
.Op Ar file
|
||||
.Ar name
|
||||
.Nm uudecode
|
||||
.Op Fl cp
|
||||
.Op Fl cips
|
||||
.Op Ar
|
||||
.Sh DESCRIPTION
|
||||
.Nm Uuencode
|
||||
@ -86,10 +86,17 @@ The following options are available for
|
||||
Decode more than one uuencode'd file from
|
||||
.Ar file
|
||||
if possible.
|
||||
.It Fl i
|
||||
Do not overwrite files.
|
||||
.It Fl p
|
||||
Decode
|
||||
.Ar file
|
||||
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
|
||||
The following example packages up a source tree, compresses it,
|
||||
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 -
|
||||
.Ed
|
||||
.Sh SEE ALSO
|
||||
.Xr basename 1 ,
|
||||
.Xr compress 1 ,
|
||||
.Xr mail 1 ,
|
||||
.Xr uucp 1 ,
|
||||
|
Loading…
Reference in New Issue
Block a user