From: millert Date: Sat, 5 Apr 1997 22:36:12 +0000 (+0000) Subject: Strip leading '/' of pathnames (only in tar mode). -S option turns X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c7e58f96ee9aaf9cd3d54c77db359a0966b16221;p=openbsd Strip leading '/' of pathnames (only in tar mode). -S option turns this off like GNU tar. --- diff --git a/bin/pax/extern.h b/bin/pax/extern.h index 2e3fea87f98..a7204242206 100644 --- a/bin/pax/extern.h +++ b/bin/pax/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.11 1997/03/02 09:46:43 tholo Exp $ */ +/* $OpenBSD: extern.h,v 1.12 1997/04/05 22:36:12 millert Exp $ */ /* $NetBSD: extern.h,v 1.5 1996/03/26 23:54:16 mrg Exp $ */ /*- @@ -232,6 +232,7 @@ extern int pmtime; extern int nodirs; extern int pmode; extern int pids; +extern int rmleadslash; extern int exit_val; extern int docrc; extern char *dirptr; diff --git a/bin/pax/options.c b/bin/pax/options.c index 13036656dd1..23ae6cf9927 100644 --- a/bin/pax/options.c +++ b/bin/pax/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.19 1997/04/04 20:54:50 millert Exp $ */ +/* $OpenBSD: options.c,v 1.20 1997/04/05 22:36:14 millert Exp $ */ /* $NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: options.c,v 1.19 1997/04/04 20:54:50 millert Exp $"; +static char rcsid[] = "$OpenBSD: options.c,v 1.20 1997/04/05 22:36:14 millert Exp $"; #endif #endif /* not lint */ @@ -600,11 +600,16 @@ tar_options(argc, argv) register int c; int fstdin = 0; + /* + * Set default values. + */ + rmleadslash = 1; + /* * process option flags */ while ((c = getoldopt(argc, argv, - "b:cef:hmopruts:vwxzBC:HLPXZ014578")) + "b:cef:hmopruts:vwxzBC:HLPSXZ014578")) != EOF) { switch(c) { case 'b': @@ -743,6 +748,12 @@ tar_options(argc, argv) */ Lflag = 0; break; + case 'S': + /* + * do not remove leading '/' from pathnames + */ + rmleadslash = 0; + break; case 'X': /* * do not pass over mount points in the file system diff --git a/bin/pax/pat_rep.c b/bin/pax/pat_rep.c index 3b0206ebb6f..7bd5e6c5587 100644 --- a/bin/pax/pat_rep.c +++ b/bin/pax/pat_rep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pat_rep.c,v 1.7 1997/03/30 08:28:10 millert Exp $ */ +/* $OpenBSD: pat_rep.c,v 1.8 1997/04/05 22:36:15 millert Exp $ */ /* $NetBSD: pat_rep.c,v 1.4 1995/03/21 09:07:33 cgd Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)pat_rep.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: pat_rep.c,v 1.7 1997/03/30 08:28:10 millert Exp $"; +static char rcsid[] = "$OpenBSD: pat_rep.c,v 1.8 1997/04/05 22:36:15 millert Exp $"; #endif #endif /* not lint */ @@ -671,6 +671,38 @@ mod_name(arcn) { register int res = 0; + /* + * Strip off leading '/' if appropriate. + * Currently, this option is only set for the tar format. + */ + if (rmleadslash && arcn->name[0] == '/') { + if (arcn->name[1] == '\0') { + arcn->name[0] = '.'; + } else { + (void)memmove(arcn->name, &arcn->name[1], + strlen(arcn->name)); + arcn->nlen--; + } + if (rmleadslash < 2) { + rmleadslash = 2; + paxwarn(0, "Removing leading / from absolute path names in the archive"); + } + } + if (rmleadslash && arcn->ln_name[0] == '/' && + (arcn->type == PAX_HLK || arcn->type == PAX_HRG)) { + if (arcn->ln_name[1] == '\0') { + arcn->ln_name[0] = '.'; + } else { + (void)memmove(arcn->ln_name, &arcn->ln_name[1], + strlen(arcn->ln_name)); + arcn->ln_nlen--; + } + if (rmleadslash < 2) { + rmleadslash = 2; + paxwarn(0, "Removing leading / from absolute path names in the archive"); + } + } + /* * IMPORTANT: We have a problem. what do we do with symlinks? * Modifying a hard link name makes sense, as we know the file it diff --git a/bin/pax/pax.c b/bin/pax/pax.c index 1fd965a1aff..a8e624685d2 100644 --- a/bin/pax/pax.c +++ b/bin/pax/pax.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pax.c,v 1.6 1997/03/02 09:46:49 tholo Exp $ */ +/* $OpenBSD: pax.c,v 1.7 1997/04/05 22:36:17 millert Exp $ */ /* $NetBSD: pax.c,v 1.5 1996/03/26 23:54:20 mrg Exp $ */ /*- @@ -48,7 +48,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)pax.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: pax.c,v 1.6 1997/03/02 09:46:49 tholo Exp $"; +static char rcsid[] = "$OpenBSD: pax.c,v 1.7 1997/04/05 22:36:17 millert Exp $"; #endif #endif /* not lint */ @@ -97,6 +97,7 @@ int pmtime = 1; /* preserve file modification times */ int nodirs; /* do not create directories as needed */ int pmode; /* preserve file mode bits */ int pids; /* preserve file uid/gid */ +int rmleadslash = 0; /* remove leading '/' from pathnames */ int exit_val; /* exit value */ int docrc; /* check/create file crc */ char *dirptr; /* destination dir in a copy */ diff --git a/bin/pax/tar.1 b/bin/pax/tar.1 index 891d740063f..1010e49f5e6 100644 --- a/bin/pax/tar.1 +++ b/bin/pax/tar.1 @@ -27,7 +27,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.\" $OpenBSD: tar.1,v 1.7 1997/04/04 20:54:52 millert Exp $ +.\" $OpenBSD: tar.1,v 1.8 1997/04/05 22:36:18 millert Exp $ .\" .Dd June 11, 1996 .Dt TAR 1 @@ -36,8 +36,8 @@ .Nm tar .Nd tape archiver .Sh SYNOPSIS -.Nm tar -.No [-]{crtux}[befhmopvwzHLPXZ014578] +.Nm +.No [-]{crtux}[befhmopvwzHLPSXZ014578] .Op Ar archive .Op Ar blocksize .\" XXX how to do this right? @@ -51,7 +51,7 @@ .Op Ar file2... .Sh DESCRIPTION The -.Nm tar +.Nm command creates, adds files to, or extracts files from an archive file in \*Qtar\*U format. A tar archive is often stored on a magnetic tape, but can be a floppy or a regular @@ -85,7 +85,7 @@ flags may be used: .Bl -tag -width Ar .It Fl b Ar "blocking factor" Set blocking factor to use for the archive, -.Nm tar +.Nm uses 512 byte blocks. The default is 20, the maximum is 63. .It Fl e Stop after first error. @@ -99,7 +99,7 @@ or directories. Do not preserve modification time. .It Fl o Don't write directory information that the older (V7) style -.Nm tar +.Nm is enable to decode. .It Fl p Preserve user id, group id, file mode, access and modification @@ -155,7 +155,7 @@ are not selected and will be skipped. Verbose operation mode. .It Fl w Interactively rename files. This option causes -.Nm tar +.Nm to prompt the user for the filename to use when storing or extracting files in an archive. .It Fl z @@ -171,6 +171,9 @@ Follow symlinks given on command line only. Follow all symlinks. .It Fl P Do not follow any symlinks. +.It Fl S +Do not strip leading slashes (``/'') from pathnames. +The default is to strip leading slashes. .It Fl X Do not cross mount points in the file system. .It Fl Z @@ -192,7 +195,7 @@ The default archive name .Sh AUTHOR Keith Muller at the University of California, San Diego .Sh ERRORS -.Nm tar +.Nm will exit with one of the following values: .Bl -tag -width 2n .It 0 @@ -202,7 +205,7 @@ An error occured. .El .Pp Whenever -.Nm tar +.Nm cannot create a file or a link when extracting an archive or cannot find a file while writing an archive, or cannot preserve the user ID, group ID, file mode or access and modification times when the @@ -210,14 +213,14 @@ ID, group ID, file mode or access and modification times when the options is specified, a diagnostic message is written to standard error and a non-zero exit value will be returned, but processing will continue. In the case where -.Nm tar +.Nm cannot create a link to a file, -.Nm tar +.Nm will not create a second copy of the file. .Pp If the extraction of a file from an archive is prematurely terminated by a signal or error, -.Nm tar +.Nm may have only partially extracted the file the user wanted. Additionally, the file modes of extracted files and directories may have incorrect file bits, and the modification and access times may @@ -225,6 +228,6 @@ be wrong. .Pp If the creation of an archive is prematurely terminated by a signal or error, -.Nm tar +.Nm may have only partially created the archive which may violate the specific archive format specification. diff --git a/bin/pax/tar.c b/bin/pax/tar.c index 6d2b3f908da..c51d0cfae9e 100644 --- a/bin/pax/tar.c +++ b/bin/pax/tar.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tar.c,v 1.8 1997/04/02 00:31:58 millert Exp $ */ +/* $OpenBSD: tar.c,v 1.9 1997/04/05 22:36:19 millert Exp $ */ /* $NetBSD: tar.c,v 1.5 1995/03/21 09:07:49 cgd Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)tar.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: tar.c,v 1.8 1997/04/02 00:31:58 millert Exp $"; +static char rcsid[] = "$OpenBSD: tar.c,v 1.9 1997/04/05 22:36:19 millert Exp $"; #endif #endif /* not lint */ @@ -636,7 +636,7 @@ tar_wr(arcn) */ hd = (HD_TAR *)hdblk; zf_strncpy(hd->name, arcn->name, sizeof(hd->name) - 1); - arcn->name[sizeof(hd->name) - 1] = '\0'; + hd->name[sizeof(hd->name) - 1] = '\0'; arcn->pad = 0; if (arcn->type == PAX_DIR) {