Module Name: othersrc
Committed By: agc
Date: Sat Jun 25 17:05:35 UTC 2011
Modified Files:
othersrc/external/bsd/mat/dist: frontends.c mat.1 mat.c mat.h matpax.1
othersrc/external/bsd/mat/mat: Makefile
Log Message:
Add a substitution phase via -s '|regexp|replace|' to the tar and pax
frontends to mat(1) and libmat(3). This allows filenames to be
manipulated on entry to or exit from an archive, so that entries can
be created in the mat archive with generic filenames (such as
"@extractiondir@" or similar), which can be manipulated when
extracting archive components accordingly.
The substitution pattern uses the first character of the argument as
the delimiter, which can itself be escaped using the '\\' character,
should anyone be massochistic as to want to use the '/' character to
delimit file and directory names in a substitution pattern. Extended
regular expressions (NOT wildcards, fnmatch or glob patterns) are
used to match file name patterns.
The same archive security and integirty checks are made for archives
when extracting or listing, so it will not be possible to extract any
archive which has been constructed with a component name starting with
a '/', or which contains the "/../" pattern. Should such a pattern be
wanted or needed, (and the big question there is "WHY???????"), then a
generic pattern can be substituted at mat archive creation time, and
the extracting user will explicitly need to specify that pattern at
extraction time. This is, however, really not advised, and a
different way of creating the mat archive should be found.
Also change the mat(1) (and mattar(1)) man pages to use better and
more real-life examples.
Add tests for the -s functionality.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 othersrc/external/bsd/mat/dist/frontends.c \
othersrc/external/bsd/mat/dist/mat.c
cvs rdiff -u -r1.7 -r1.8 othersrc/external/bsd/mat/dist/mat.1
cvs rdiff -u -r1.3 -r1.4 othersrc/external/bsd/mat/dist/mat.h
cvs rdiff -u -r1.4 -r1.5 othersrc/external/bsd/mat/dist/matpax.1
cvs rdiff -u -r1.3 -r1.4 othersrc/external/bsd/mat/mat/Makefile
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: othersrc/external/bsd/mat/dist/frontends.c
diff -u othersrc/external/bsd/mat/dist/frontends.c:1.2 othersrc/external/bsd/mat/dist/frontends.c:1.3
--- othersrc/external/bsd/mat/dist/frontends.c:1.2 Tue Jun 21 04:21:24 2011
+++ othersrc/external/bsd/mat/dist/frontends.c Sat Jun 25 17:05:34 2011
@@ -109,6 +109,38 @@
return ok;
}
+/* compile the regular expression we have */
+static int
+compile_subst(mat_t *mat, char *arg)
+{
+ char *mid;
+ char *s;
+
+ for (s = arg + 1 ; *s && *s != *arg ; s++) {
+ if (*s == '\\') {
+ s += 1;
+ }
+ }
+ (void) snprintf(mat->from, sizeof(mat->from), "%.*s",
+ (int)(s - arg) - 1, arg + 1);
+ for (mid = s++ ; *s && *s != *arg ; s++) {
+ if (*s == '\\') {
+ s += 1;
+ }
+ }
+ (void) snprintf(mat->to, sizeof(mat->to), "%.*s",
+ (int)(s - mid) - 1, mid + 1);
+ if ((mat->re = calloc(sizeof(regex_t), 1)) == NULL) {
+ (void) fprintf(stderr, "bad calloc '%s'\n", mat->from);
+ return 0;
+ }
+ if (regcomp(mat->re, mat->from, REG_EXTENDED) != 0) {
+ (void) fprintf(stderr, "bad regexp '%s'\n", mat->from);
+ return 0;
+ }
+ return 1;
+}
+
/***************************************************************************/
/* tar personality for mat */
@@ -138,7 +170,7 @@
(void) snprintf(newarg, sizeof(newarg), "-%s", argv[1]);
argv[1] = newarg;
}
- while ((i = getopt(argc, argv, "C:T:Vacf:ptvx")) != -1) {
+ while ((i = getopt(argc, argv, "C:T:Vacf:ps:tvx")) != -1) {
switch(i) {
case 'C':
dir = optarg;
@@ -161,6 +193,11 @@
case 'p':
mat.preserve = 1;
break;
+ case 's':
+ if (!compile_subst(&mat, optarg)) {
+ return 0;
+ }
+ break;
case 't':
action = "list";
break;
@@ -286,7 +323,7 @@
ok = 1;
action = "list";
deltemp = 0;
- while ((i = getopt(argc, argv, "C:Vaf:lrwv")) != -1) {
+ while ((i = getopt(argc, argv, "C:Vaf:lrs:wv")) != -1) {
switch(i) {
case 'C':
dir = optarg;
@@ -306,6 +343,12 @@
case 'r':
action = "extract";
break;
+ case 's':
+ if (!compile_subst(&mat, optarg)) {
+ (void) fprintf(stderr, "bad regexp '%s'\n", optarg);
+ return 0;
+ }
+ break;
case 'w':
action = "create";
break;
Index: othersrc/external/bsd/mat/dist/mat.c
diff -u othersrc/external/bsd/mat/dist/mat.c:1.2 othersrc/external/bsd/mat/dist/mat.c:1.3
--- othersrc/external/bsd/mat/dist/mat.c:1.2 Tue Jun 21 04:21:24 2011
+++ othersrc/external/bsd/mat/dist/mat.c Sat Jun 25 17:05:34 2011
@@ -31,6 +31,7 @@
#include <grp.h>
#include <inttypes.h>
#include <pwd.h>
+#include <regex.h>
#include <sha2.h>
#include <stdio.h>
#include <stdlib.h>
@@ -70,10 +71,11 @@
/* structure used in extracting components from archives */
typedef struct extract_t {
- uint64_t off; /* offset in archive */
- int preserve; /* preserve file times and owners */
- int extract; /* really extract? */
+ uint64_t off; /* offset in archive */
+ int preserve; /* preserve file times and owners */
+ int extract; /* really extract? */
uint8_t *s; /* archive itself */
+ char newpath[MAT_PATH_MAX]; /* if it needs to change */
} extract_t;
/* byte-swap 32 bits, if necessary */
@@ -355,12 +357,35 @@
return 1;
}
+/* substitute for the name */
+static int
+substname(mat_t *mat, extract_t *extract, const char *name)
+{
+ regmatch_t matches[10];
+
+ if (mat->re && regexec(mat->re, name, 10, matches, 0) == 0) {
+ (void) snprintf(extract->newpath, sizeof(extract->newpath), "%.*s%.*s%.*s",
+ (int)matches[0].rm_so, name,
+ (int)strlen(mat->to), mat->to,
+ (int)strlen(&name[matches[0].rm_eo]), &name[matches[0].rm_eo]);
+ return 1;
+ }
+ return 0;
+}
+
/* extract a hardlink from the archive */
static int
-extract_link(extract_t *archive, matent_t *ent, const char *name)
+extract_link(mat_t *mat, extract_t *archive, matent_t *ent, const char *name)
{
if (archive->extract) {
+ if (substname(mat, archive, name)) {
+ name = archive->newpath;
+ }
(void) unlink(name);
+ if (!intermediates(name)) {
+ (void) fprintf(stderr, "can't create intermediate dirs '%s'\n", name);
+ return 0;
+ }
if (link((char *)&archive->s[archive->off], name) < 0) {
(void) fprintf(stderr, "can't link '%s'\n", name);
return 0;
@@ -377,13 +402,20 @@
/* extract a file from the archive */
static int
-extract_file(extract_t *archive, matent_t *ent, const char *name)
+extract_file(mat_t *mat, extract_t *archive, matent_t *ent, const char *name)
{
struct timeval tv[2];
FILE *fp;
if (archive->extract) {
+ if (substname(mat, archive, name)) {
+ name = archive->newpath;
+ }
(void) unlink(name);
+ if (!intermediates(name)) {
+ (void) fprintf(stderr, "can't create intermediate dirs '%s'\n", name);
+ return 0;
+ }
if ((fp = fopen(name, "w")) == NULL) {
(void) fprintf(stderr, "can't create '%s'\n", name);
return 0;
@@ -417,12 +449,19 @@
/* extract a symlink from the archive */
static int
-extract_symlink(extract_t *archive, matent_t *ent, const char *name)
+extract_symlink(mat_t *mat, extract_t *archive, matent_t *ent, const char *name)
{
struct timeval tv[2];
if (archive->extract) {
+ if (substname(mat, archive, name)) {
+ name = archive->newpath;
+ }
(void) unlink(name);
+ if (!intermediates(name)) {
+ (void) fprintf(stderr, "can't create intermediate dirs '%s'\n", name);
+ return 0;
+ }
if (symlink((char *)&archive->s[archive->off], name) < 0) {
(void) fprintf(stderr, "can't symlink '%s'\n", name);
return 0;
@@ -449,9 +488,16 @@
/* extract a directory from the archive */
static int
-extract_dir(extract_t *archive, matent_t *ent, const char *name)
+extract_dir(mat_t *mat, extract_t *archive, matent_t *ent, const char *name)
{
if (archive->extract) {
+ if (substname(mat, archive, name)) {
+ name = archive->newpath;
+ }
+ if (!intermediates(name)) {
+ (void) fprintf(stderr, "can't create intermediate dirs '%s'\n", name);
+ return 0;
+ }
if (mkdir(name, ent->meta.mode & 07777) < 0) {
(void) fprintf(stderr, "can't mkdir '%s'\n", name);
return 0;
@@ -466,9 +512,16 @@
/* extract a special device from the archive */
static int
-extract_special(extract_t *archive, matent_t *ent, const char *name)
+extract_special(mat_t *mat, extract_t *archive, matent_t *ent, const char *name)
{
if (archive->extract) {
+ if (substname(mat, archive, name)) {
+ name = archive->newpath;
+ }
+ if (!intermediates(name)) {
+ (void) fprintf(stderr, "can't create intermediate dirs '%s'\n", name);
+ return 0;
+ }
if (mknod(name, ent->meta.mode & 07777, ent->meta.dev) < 0) {
(void) fprintf(stderr, "can't mkdir '%s'\n", name);
return 0;
@@ -481,6 +534,25 @@
return 1;
}
+/* translate old file name to new one */
+static int
+write_meta_info(mat_t *mat, matent_t *ent, const char *f)
+{
+ regmatch_t matches[10];
+ char newpath[MAT_PATH_MAX];
+
+ if (mat->re && regexec(mat->re, f, 10, matches, 0) == 0) {
+ ent->meta.namelen = snprintf(newpath, sizeof(newpath), "%.*s%.*s%.*s",
+ (int)matches[0].rm_so, f,
+ (int)strlen(mat->to), mat->to,
+ (int)strlen(&f[matches[0].rm_eo]), &f[matches[0].rm_eo]) + 1;
+ f = newpath;
+ }
+ writemeta(fileno(mat->fp), ent);
+ write(fileno(mat->fp), f, ent->meta.namelen);
+ return 1;
+}
+
/*******************************************************************************/
/* add an entry to the archive */
@@ -556,8 +628,7 @@
(void) fprintf(stderr, "can't mmap '%s'\n", f);
return 0;
}
- writemeta(fileno(mat->fp), &ent);
- write(fileno(mat->fp), f, ent.meta.namelen);
+ write_meta_info(mat, &ent, f);
write(fileno(mat->fp), mapped, (size_t)st.st_size);
digest_update(ent.digest, mapped, (size_t)st.st_size);
if (ent.meta.nlink > 1 && original) {
@@ -571,8 +642,7 @@
case 'h':
/* store hardlink to primary */
ent.meta.linklen = mat->links[primary].namelen;
- writemeta(fileno(mat->fp), &ent);
- write(fileno(mat->fp), f, ent.meta.namelen);
+ write_meta_info(mat, &ent, f);
write(fileno(mat->fp), mat->links[primary].name, (size_t)ent.meta.linklen);
/* get digest from primary */
(void) memcpy(ent.digest, mat->links[primary].digest, sizeof(ent.digest));
@@ -585,20 +655,17 @@
}
newpath[cc] = 0x0;
ent.meta.linklen = (uint32_t)(cc + 1);
- writemeta(fileno(mat->fp), &ent);
- write(fileno(mat->fp), f, ent.meta.namelen);
+ write_meta_info(mat, &ent, f);
write(fileno(mat->fp), newpath, (size_t)ent.meta.linklen);
digest_update(ent.digest, (uint8_t *)newpath, (size_t)ent.meta.linklen);
write(fileno(mat->fp), ent.digest, sizeof(ent.digest));
break;
case 'b':
case 'c':
- writemeta(fileno(mat->fp), &ent);
- write(fileno(mat->fp), f, ent.meta.namelen);
+ write_meta_info(mat, &ent, f);
break;
case 'd':
- writemeta(fileno(mat->fp), &ent);
- write(fileno(mat->fp), f, ent.meta.namelen);
+ write_meta_info(mat, &ent, f);
if (mat->recursing) {
if ((dirp = opendir(f)) == NULL) {
(void) fprintf(stderr, "can't opendir '%s'\n", f);
@@ -841,34 +908,30 @@
name = (char *)&archive.s[archive.off];
archive.off += ent.meta.namelen;
archive.extract = (pat == NULL) ? 1 : (fnmatch(pat, name, FNM_PATHNAME) == 0);
- if (archive.extract && !intermediates(name)) {
- (void) fprintf(stderr, "can't create intermediate dirs '%s'\n", name);
- return 0;
- }
switch(ent.meta.type) {
case 'h':
- if (!extract_link(&archive, &ent, name)) {
+ if (!extract_link(mat, &archive, &ent, name)) {
return 0;
}
break;
case 'f':
- if (!extract_file(&archive, &ent, name)) {
+ if (!extract_file(mat, &archive, &ent, name)) {
return 0;
}
break;
case 'l':
- if (!extract_symlink(&archive, &ent, name)) {
+ if (!extract_symlink(mat, &archive, &ent, name)) {
return 0;
}
break;
case 'd':
- if (!extract_dir(&archive, &ent, name)) {
+ if (!extract_dir(mat, &archive, &ent, name)) {
return 0;
}
break;
case 'b':
case 'c':
- if (!extract_special(&archive, &ent, name)) {
+ if (!extract_special(mat, &archive, &ent, name)) {
return 0;
}
break;
Index: othersrc/external/bsd/mat/dist/mat.1
diff -u othersrc/external/bsd/mat/dist/mat.1:1.7 othersrc/external/bsd/mat/dist/mat.1:1.8
--- othersrc/external/bsd/mat/dist/mat.1:1.7 Tue Jun 21 09:45:10 2011
+++ othersrc/external/bsd/mat/dist/mat.1 Sat Jun 25 17:05:34 2011
@@ -1,4 +1,4 @@
-.\" $NetBSD: mat.1,v 1.7 2011/06/21 09:45:10 wiz Exp $
+.\" $NetBSD: mat.1,v 1.8 2011/06/25 17:05:34 agc Exp $
.\"
.\" Copyright (c) 2011 Alistair Crooks <[email protected]>
.\" All rights reserved.
@@ -23,7 +23,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.
.\"
-.Dd June 20, 2011
+.Dd June 25, 2011
.Dt MATTAR 1
.Os
.Sh NAME
@@ -34,6 +34,7 @@
.Op Fl acptVvx
.Op Fl C Ar directory
.Op Fl f Ar archive
+.Op Fl s Ar substitution
.Op Fl T Ar template
.Op Ar file ...
.Sh DESCRIPTION
@@ -90,6 +91,18 @@
Setuid and setgid bits are only preserved
if the program is run with an effective
uid of 0.
+.It Fl s Ar substition
+The pathnames on entry or exit to the archive, depending on whether
+the archive is being created or used to extract components, are modified
+using an
+.Dv old
+and
+.Dv new
+subsitution pattern, in a similar manner to
+.Xr sed 1
+The first non-whitespace character of the pattern is taken to be the delimiter
+for the patterns, which itself can be escaped using the backslash character.
+Extended regular expressions are used to match the path names.
.It Fl T Ar template
takes the names of the entries to be included in the archive
from the template file provided.
@@ -138,132 +151,100 @@
the archive.
.Sh EXAMPLES
.Bd -literal
-% mattar cvf mat.mat .
-ignoring attempt to add ourselves './mat.mat'
-% l
-total 56
-drwxr-xr-x 6 agc agc 512 Jun 14 19:37 .
-drwxr-xr-x 92 agc agc 2048 Jun 14 19:09 ..
-drwxr-xr-x 2 agc agc 512 Jun 14 17:56 CVS
--rw-r--r-- 1 agc agc 147 Jun 14 17:55 Makefile
-drwxr-xr-x 3 agc agc 512 Jun 14 18:04 dist
-drwxr-xr-x 3 agc agc 512 Jun 14 19:36 libmat
-drwxr-xr-x 3 agc agc 512 Jun 14 19:36 mat
--rw-r--r-- 1 agc agc 42743 Jun 14 19:37 mat.mat
-% mattar tvf mat.mat
-drwxr-xr-x 6 agc agc 512 Jun 14 19:37 .
-drwxr-xr-x 2 agc agc 512 Jun 14 17:56 ./CVS
--rw-r--r-- 1 agc agc 13 Jun 12 08:25 ./CVS/Root
--rw-r--r-- 1 agc agc 4 Jun 14 17:24 ./CVS/Repository
--rw-r--r-- 1 agc agc 75 Jun 14 17:56 ./CVS/Entries
-drwxr-xr-x 3 agc agc 512 Jun 14 18:04 ./dist
-drwxr-xr-x 2 agc agc 512 Jun 14 19:35 ./dist/CVS
--rw-r--r-- 1 agc agc 13 Jun 12 08:25 ./dist/CVS/Root
--rw-r--r-- 1 agc agc 9 Jun 14 17:24 ./dist/CVS/Repository
--rw-r--r-- 1 agc agc 320 Jun 14 19:35 ./dist/CVS/Entries
--rw-r--r-- 1 agc agc 711 Jun 14 17:36 ./dist/Makefile
--rw-r--r-- 1 agc agc 3031 Jun 14 17:04 ./dist/mat.h
--rw-r--r-- 1 agc agc 645 Jun 14 18:09 ./dist/TODO
--rw-r--r-- 1 agc agc 5315 Jun 14 17:04 ./dist/main.c
--rw-r--r-- 1 agc agc 19394 Jun 14 18:43 ./dist/mat.c
--rw-r--r-- 1 agc agc 233 Jun 14 14:21 ./dist/template
--rw-r--r-- 1 agc agc 2857 Jun 14 17:54 ./dist/mat.1
--rw-r--r-- 1 agc agc 3043 Jun 14 19:34 ./dist/libmat.3
-drwxr-xr-x 3 agc agc 512 Jun 14 19:36 ./libmat
-drwxr-xr-x 2 agc agc 512 Jun 14 17:41 ./libmat/CVS
--rw-r--r-- 1 agc agc 13 Jun 14 17:37 ./libmat/CVS/Root
--rw-r--r-- 1 agc agc 11 Jun 14 17:37 ./libmat/CVS/Repository
--rw-r--r-- 1 agc agc 89 Jun 14 17:41 ./libmat/CVS/Entries
--rw-r--r-- 1 agc agc 249 Jun 14 17:40 ./libmat/Makefile
--rw-r--r-- 1 agc agc 16 Jun 14 17:38 ./libmat/shlib_version
-drwxr-xr-x 3 agc agc 512 Jun 14 19:36 ./mat
-drwxr-xr-x 2 agc agc 512 Jun 14 18:03 ./mat/CVS
--rw-r--r-- 1 agc agc 13 Jun 14 17:41 ./mat/CVS/Root
--rw-r--r-- 1 agc agc 8 Jun 14 17:41 ./mat/CVS/Repository
--rw-r--r-- 1 agc agc 43 Jun 14 18:03 ./mat/CVS/Entries
--rw-r--r-- 1 agc agc 1431 Jun 14 18:03 ./mat/Makefile
--rw-r--r-- 1 agc agc 147 Jun 14 17:55 ./Makefile
-% mattar tvvf mat.mat
-drwxr-xr-x 6 agc agc 512 Jun 14 19:37 0000000000000000000000000000000000000000000000000000000000000000 .
-drwxr-xr-x 2 agc agc 512 Jun 14 17:56 0000000000000000000000000000000000000000000000000000000000000000 ./CVS
--rw-r--r-- 1 agc agc 13 Jun 12 08:25 166857728b590b94b0a42bec1cf9383efa940f9c2f1cb52a530490b7f5c32dcd ./CVS/Root
--rw-r--r-- 1 agc agc 4 Jun 14 17:24 89075f24aacd15ed685233843a67cab5967af3e1a563747904b935f4bf878e32 ./CVS/Repository
--rw-r--r-- 1 agc agc 75 Jun 14 17:56 a668f3e3b4a123827ab57cf4b62502976aef870b35e14a26fe25013e9d264bee ./CVS/Entries
-drwxr-xr-x 3 agc agc 512 Jun 14 18:04 0000000000000000000000000000000000000000000000000000000000000000 ./dist
-drwxr-xr-x 2 agc agc 512 Jun 14 19:35 0000000000000000000000000000000000000000000000000000000000000000 ./dist/CVS
--rw-r--r-- 1 agc agc 13 Jun 12 08:25 166857728b590b94b0a42bec1cf9383efa940f9c2f1cb52a530490b7f5c32dcd ./dist/CVS/Root
--rw-r--r-- 1 agc agc 9 Jun 14 17:24 471828df0fcdf7585b9c33c96413a31bf4d17a6d60b5cd2899ec2a625ef3c18c ./dist/CVS/Repository
--rw-r--r-- 1 agc agc 320 Jun 14 19:35 f16d0aea208f8a34a847578d72f80fd05f8b337c01a500a9ff427ecf9aa3d822 ./dist/CVS/Entries
--rw-r--r-- 1 agc agc 711 Jun 14 17:36 82ca8eeb2129eb3f8c98daaf73fff16bdbf929e048a3e5176eb00a1ee571b3a2 ./dist/Makefile
--rw-r--r-- 1 agc agc 3031 Jun 14 17:04 44c52e404f56ec2ef30304c9f318bf17ba41c224b12540a756088f628bff41a8 ./dist/mat.h
--rw-r--r-- 1 agc agc 645 Jun 14 18:09 e456b0232a41f97f2c371b0fda97920ff241e069e2bf836ff1f4f814c41ebf2c ./dist/TODO
--rw-r--r-- 1 agc agc 5315 Jun 14 17:04 e4ec34c59b8ad693d98af3696bf07c0f77906cf888b587c6c1c07813a85a9ca9 ./dist/main.c
--rw-r--r-- 1 agc agc 19394 Jun 14 18:43 066de6110e34ffd05fb43ccf64bb30331e1b4b658522f4f335acef560a734ede ./dist/mat.c
--rw-r--r-- 1 agc agc 233 Jun 14 14:21 a8299778046ea832bf4dab052be5d98d9267eb2c48e1823580a3b0d7acd12c38 ./dist/template
--rw-r--r-- 1 agc agc 2857 Jun 14 17:54 006614f5fcf4f67b775daa3da5215645ba26fcfdddf3910f4eb84281f97e83b0 ./dist/mat.1
--rw-r--r-- 1 agc agc 3043 Jun 14 19:34 7b891f6115ed2d2a2732f3f38a6213a99c2353daa9ad11eccdaf2739f6a415f5 ./dist/libmat.3
-drwxr-xr-x 3 agc agc 512 Jun 14 19:36 0000000000000000000000000000000000000000000000000000000000000000 ./libmat
-drwxr-xr-x 2 agc agc 512 Jun 14 17:41 0000000000000000000000000000000000000000000000000000000000000000 ./libmat/CVS
--rw-r--r-- 1 agc agc 13 Jun 14 17:37 166857728b590b94b0a42bec1cf9383efa940f9c2f1cb52a530490b7f5c32dcd ./libmat/CVS/Root
--rw-r--r-- 1 agc agc 11 Jun 14 17:37 e2ea90f5b007dcf752693bae48ec7cb2cc19db9d27d6b37b6215661ab79297d0 ./libmat/CVS/Repository
--rw-r--r-- 1 agc agc 89 Jun 14 17:41 d7c66fa66f9b0b6d658c0bdef87aee4afc9f1e6cab136bc3c73529eaab355369 ./libmat/CVS/Entries
--rw-r--r-- 1 agc agc 249 Jun 14 17:40 3012b542bfe695e5a2f5cda7fa2290df04682c5b9f913eba9ff1e9540c04b7b1 ./libmat/Makefile
--rw-r--r-- 1 agc agc 16 Jun 14 17:38 e890d6f049bf629a099b839db624f73c017e0214bf5dbd1651be48116f958ccc ./libmat/shlib_version
-drwxr-xr-x 3 agc agc 512 Jun 14 19:36 0000000000000000000000000000000000000000000000000000000000000000 ./mat
-drwxr-xr-x 2 agc agc 512 Jun 14 18:03 0000000000000000000000000000000000000000000000000000000000000000 ./mat/CVS
--rw-r--r-- 1 agc agc 13 Jun 14 17:41 166857728b590b94b0a42bec1cf9383efa940f9c2f1cb52a530490b7f5c32dcd ./mat/CVS/Root
--rw-r--r-- 1 agc agc 8 Jun 14 17:41 8e452cf495144a39e4a38b9670c4065c4f9339d7abb526e5b6d744ca3a5704f2 ./mat/CVS/Repository
--rw-r--r-- 1 agc agc 43 Jun 14 18:03 413243c976e9059d58e29c9e4bb6eaeb3a36cde7d432e5302011d5c4c4b67580 ./mat/CVS/Entries
--rw-r--r-- 1 agc agc 1431 Jun 14 18:03 095fc09044339b1b799ec1a5c6b4504f3aaf54945b6289db349c5b508b261b2d ./mat/Makefile
--rw-r--r-- 1 agc agc 147 Jun 14 17:55 732f8946219bf812a28ccfde09d270b7e2483fc3e9273e5e04b51ed30ec05e4b ./Makefile
-% xz mat.mat
-% ls -al mat.mat.xz
--rw-r--r-- 1 agc agc 11232 Jun 14 19:43 mat.mat.xz
-% circa mat.mat.xz > mat.mat.xz.circa
-% ls -al mat.mat*
--rw-r--r-- 1 agc agc 11232 Jun 14 19:43 mat.mat.xz
--rw-r--r-- 1 agc agc 15688 Jun 14 19:43 mat.mat.xz.circa
-% circa -d < *.circa | xz -d | mattar tvvf -
-drwxr-xr-x 6 agc agc 512 Jun 14 19:43 0000000000000000000000000000000000000000000000000000000000000000 .
-drwxr-xr-x 2 agc agc 512 Jun 14 17:56 0000000000000000000000000000000000000000000000000000000000000000 ./CVS
--rw-r--r-- 1 agc agc 13 Jun 12 08:25 166857728b590b94b0a42bec1cf9383efa940f9c2f1cb52a530490b7f5c32dcd ./CVS/Root
--rw-r--r-- 1 agc agc 4 Jun 14 17:24 89075f24aacd15ed685233843a67cab5967af3e1a563747904b935f4bf878e32 ./CVS/Repository
--rw-r--r-- 1 agc agc 75 Jun 14 17:56 a668f3e3b4a123827ab57cf4b62502976aef870b35e14a26fe25013e9d264bee ./CVS/Entries
-drwxr-xr-x 3 agc agc 512 Jun 14 18:04 0000000000000000000000000000000000000000000000000000000000000000 ./dist
-drwxr-xr-x 2 agc agc 512 Jun 14 19:40 0000000000000000000000000000000000000000000000000000000000000000 ./dist/CVS
--rw-r--r-- 1 agc agc 13 Jun 12 08:25 166857728b590b94b0a42bec1cf9383efa940f9c2f1cb52a530490b7f5c32dcd ./dist/CVS/Root
--rw-r--r-- 1 agc agc 9 Jun 14 17:24 471828df0fcdf7585b9c33c96413a31bf4d17a6d60b5cd2899ec2a625ef3c18c ./dist/CVS/Repository
--rw-r--r-- 1 agc agc 320 Jun 14 19:40 cbfcd9a73c431f335c10a0272f8db82e105eec4b74ebf7acfd69304e5ae5998c ./dist/CVS/Entries
--rw-r--r-- 1 agc agc 711 Jun 14 17:36 82ca8eeb2129eb3f8c98daaf73fff16bdbf929e048a3e5176eb00a1ee571b3a2 ./dist/Makefile
--rw-r--r-- 1 agc agc 3031 Jun 14 17:04 44c52e404f56ec2ef30304c9f318bf17ba41c224b12540a756088f628bff41a8 ./dist/mat.h
--rw-r--r-- 1 agc agc 645 Jun 14 18:09 e456b0232a41f97f2c371b0fda97920ff241e069e2bf836ff1f4f814c41ebf2c ./dist/TODO
--rw-r--r-- 1 agc agc 5315 Jun 14 17:04 e4ec34c59b8ad693d98af3696bf07c0f77906cf888b587c6c1c07813a85a9ca9 ./dist/main.c
--rw-r--r-- 1 agc agc 19394 Jun 14 18:43 066de6110e34ffd05fb43ccf64bb30331e1b4b658522f4f335acef560a734ede ./dist/mat.c
--rw-r--r-- 1 agc agc 233 Jun 14 14:21 a8299778046ea832bf4dab052be5d98d9267eb2c48e1823580a3b0d7acd12c38 ./dist/template
--rw-r--r-- 1 agc agc 9663 Jun 14 19:39 765e2d6729b1e222ecee69ed7ee10c45a5e94c74367ac0d28ffad149e492567b ./dist/mat.1
--rw-r--r-- 1 agc agc 3043 Jun 14 19:34 7b891f6115ed2d2a2732f3f38a6213a99c2353daa9ad11eccdaf2739f6a415f5 ./dist/libmat.3
-drwxr-xr-x 3 agc agc 512 Jun 14 19:36 0000000000000000000000000000000000000000000000000000000000000000 ./libmat
-drwxr-xr-x 2 agc agc 512 Jun 14 17:41 0000000000000000000000000000000000000000000000000000000000000000 ./libmat/CVS
--rw-r--r-- 1 agc agc 13 Jun 14 17:37 166857728b590b94b0a42bec1cf9383efa940f9c2f1cb52a530490b7f5c32dcd ./libmat/CVS/Root
--rw-r--r-- 1 agc agc 11 Jun 14 17:37 e2ea90f5b007dcf752693bae48ec7cb2cc19db9d27d6b37b6215661ab79297d0 ./libmat/CVS/Repository
--rw-r--r-- 1 agc agc 89 Jun 14 17:41 d7c66fa66f9b0b6d658c0bdef87aee4afc9f1e6cab136bc3c73529eaab355369 ./libmat/CVS/Entries
--rw-r--r-- 1 agc agc 249 Jun 14 17:40 3012b542bfe695e5a2f5cda7fa2290df04682c5b9f913eba9ff1e9540c04b7b1 ./libmat/Makefile
--rw-r--r-- 1 agc agc 16 Jun 14 17:38 e890d6f049bf629a099b839db624f73c017e0214bf5dbd1651be48116f958ccc ./libmat/shlib_version
-drwxr-xr-x 3 agc agc 512 Jun 14 19:36 0000000000000000000000000000000000000000000000000000000000000000 ./mat
-drwxr-xr-x 2 agc agc 512 Jun 14 18:03 0000000000000000000000000000000000000000000000000000000000000000 ./mat/CVS
--rw-r--r-- 1 agc agc 13 Jun 14 17:41 166857728b590b94b0a42bec1cf9383efa940f9c2f1cb52a530490b7f5c32dcd ./mat/CVS/Root
--rw-r--r-- 1 agc agc 8 Jun 14 17:41 8e452cf495144a39e4a38b9670c4065c4f9339d7abb526e5b6d744ca3a5704f2 ./mat/CVS/Repository
--rw-r--r-- 1 agc agc 43 Jun 14 18:03 413243c976e9059d58e29c9e4bb6eaeb3a36cde7d432e5302011d5c4c4b67580 ./mat/CVS/Entries
--rw-r--r-- 1 agc agc 1431 Jun 14 18:03 095fc09044339b1b799ec1a5c6b4504f3aaf54945b6289db349c5b508b261b2d ./mat/Makefile
--rw-r--r-- 1 agc agc 147 Jun 14 17:55 732f8946219bf812a28ccfde09d270b7e2483fc3e9273e5e04b51ed30ec05e4b ./Makefile
+% cp /etc/group group
+% ln -s Makefile m
+% mat cvf archive.mat group m /etc/group
+can't stat './etc/group'
+% mat tf archive.mat
+group
+m
+% mat tvf archive.mat
+-rw-r--r-- 1 agc agc 510 Jun 24 03:03 group
+lrwxr-xr-x 1 agc agc 8 Jun 24 03:03 m -> Makefile
+% mat tvvf archive.mat
+-rw-r--r-- 1 agc agc 510 Jun 24 03:03 d8008905d91a083115b2fb8bd469a36a94f07f9cafeb88c17a44add769d3c0a0 group
+lrwxr-xr-x 1 agc agc 8 Jun 24 03:03 7a6378e1ee1f9098b9fb5219e6bb2ae17df33230171ee5c2a56f0cc4335d5dfd m -> Makefile
+% mat cvf archive2.mat group m /etc/group dir
+can't stat './etc/group'
+can't stat 'dir'
+% mat tvvf archive2.mat
+-rw-r--r-- 1 agc agc 510 Jun 24 03:03 d8008905d91a083115b2fb8bd469a36a94f07f9cafeb88c17a44add769d3c0a0 group
+lrwxr-xr-x 1 agc agc 8 Jun 24 03:03 7a6378e1ee1f9098b9fb5219e6bb2ae17df33230171ee5c2a56f0cc4335d5dfd m -> Makefile
+% mat Vf archive2.mat
+% mat tvvf - < archive2.mat
+-rw-r--r-- 1 agc agc 510 Jun 24 03:03 d8008905d91a083115b2fb8bd469a36a94f07f9cafeb88c17a44add769d3c0a0 group
+lrwxr-xr-x 1 agc agc 8 Jun 24 03:03 7a6378e1ee1f9098b9fb5219e6bb2ae17df33230171ee5c2a56f0cc4335d5dfd m -> Makefile
+% mat cvf archive2.mat group m archive2.mat /etc/group dir
+ignoring attempt to add ourselves 'archive2.mat'
+can't stat './etc/group'
+can't stat 'dir'
+% mkdir d
+% cd d && mat xvf ../archive.mat
+group
+m
+% mat cvf matty -T ../dist/template
+% env LD_LIBRARY_PATH=/usr/othersrc/external/bsd/mat/libmat ./mat tvvf matty
+drwxr-xr-x 2 root wheel 512 Jun 24 03:03 0000000000000000000000000000000000000000000000000000000000000000 ./d
+-rw-r--r-- 1 root wheel 510 Jun 24 03:03 d8008905d91a083115b2fb8bd469a36a94f07f9cafeb88c17a44add769d3c0a0 ./d/group
+lrwxr-xr-x 1 root wheel 8 Jun 24 03:03 7a6378e1ee1f9098b9fb5219e6bb2ae17df33230171ee5c2a56f0cc4335d5dfd ./d/m -> Makefile
+% mkdir e
+% cd e && sudo mat xvf ../matty -p
+./d
+./d/group
+./d/m
+% cd e && ls -ald d d/*
+drwxr-xr-x 2 root wheel 512 Jun 24 03:04 d
+-rw-r--r-- 1 root wheel 510 Jun 24 03:03 d/group
+lrwxr-xr-x 1 root wheel 8 Jun 24 03:03 d/m -> Makefile
+% mkdir a
+% cp Makefile a
+% cd a && ln Makefile m1
+% cd a && ln Makefile m2
+% cd a && ln Makefile m3
+% mat cvf a.mat a
+% mat tvvf a.mat
+drwxr-xr-x 2 agc agc 512 Jun 24 03:04 0000000000000000000000000000000000000000000000000000000000000000 a
+-rw-r--r-- 4 agc agc 2447 Jun 24 03:04 a9fd05bbc6545aed0e95c74143bdedf5cb347f24ac0378df4cd5fce136c00c84 a/Makefile
+-rw-r--r-- 4 agc agc 2447 Jun 24 03:04 a9fd05bbc6545aed0e95c74143bdedf5cb347f24ac0378df4cd5fce136c00c84 a/m1 == a/Makefile
+-rw-r--r-- 4 agc agc 2447 Jun 24 03:04 a9fd05bbc6545aed0e95c74143bdedf5cb347f24ac0378df4cd5fce136c00c84 a/m2 == a/Makefile
+-rw-r--r-- 4 agc agc 2447 Jun 24 03:04 a9fd05bbc6545aed0e95c74143bdedf5cb347f24ac0378df4cd5fce136c00c84 a/m3 == a/Makefile
+% mkdir b
+% cd b && mat xvf ../a.mat
+a
+a/Makefile
+a/m1
+a/m2
+a/m3
+% cd b && mat xvf ../archive2.mat m
+m
+% cd d && mat avvf ../archive2.mat > archive2.audit
+% cd d && mat tvvf ../archive2.mat > archive2.list
+% diff d/archive2.list d/archive2.audit
+% mat avvf a.mat
+drwxr-xr-x 2 agc agc 512 Jun 24 03:04 0000000000000000000000000000000000000000000000000000000000000000 a
+-rw-r--r-- 4 agc agc 2447 Jun 24 03:04 a9fd05bbc6545aed0e95c74143bdedf5cb347f24ac0378df4cd5fce136c00c84 a/Makefile
+-rw-r--r-- 4 agc agc 2447 Jun 24 03:04 a9fd05bbc6545aed0e95c74143bdedf5cb347f24ac0378df4cd5fce136c00c84 a/m1 == a/Makefile
+-rw-r--r-- 4 agc agc 2447 Jun 24 03:04 a9fd05bbc6545aed0e95c74143bdedf5cb347f24ac0378df4cd5fce136c00c84 a/m2 == a/Makefile
+-rw-r--r-- 4 agc agc 2447 Jun 24 03:04 a9fd05bbc6545aed0e95c74143bdedf5cb347f24ac0378df4cd5fce136c00c84 a/m3 == a/Makefile
+% mat cvf 13.mat -s '|^|umpalumpa/|' Makefile Makefile Makefile
+% mat tvvf 13.mat
+-rw-r--r-- 1 agc agc 2447 Jun 24 02:54 a9fd05bbc6545aed0e95c74143bdedf5cb347f24ac0378df4cd5fce136c00c84 umpalumpa/Makefile
+-rw-r--r-- 1 agc agc 2447 Jun 24 02:54 a9fd05bbc6545aed0e95c74143bdedf5cb347f24ac0378df4cd5fce136c00c84 umpalumpa/Makefile
+-rw-r--r-- 1 agc agc 2447 Jun 24 02:54 a9fd05bbc6545aed0e95c74143bdedf5cb347f24ac0378df4cd5fce136c00c84 umpalumpa/Makefile
+% mat xvf 13.mat -s '|umpalumpa|13|'
+umpalumpa/Makefile
+umpalumpa/Makefile
+umpalumpa/Makefile
%
.Ed
.Sh SEE ALSO
.Xr matpax 1 ,
.Xr pax 1 ,
+.Xr sed 1 ,
.Xr tar 1 ,
.Xr libmat 3 ,
-.Xr sha2 3
+.Xr sha2 3 ,
+.Xr re_format 7
.Sh HISTORY
The
.Nm
Index: othersrc/external/bsd/mat/dist/mat.h
diff -u othersrc/external/bsd/mat/dist/mat.h:1.3 othersrc/external/bsd/mat/dist/mat.h:1.4
--- othersrc/external/bsd/mat/dist/mat.h:1.3 Tue Jun 21 04:21:24 2011
+++ othersrc/external/bsd/mat/dist/mat.h Sat Jun 25 17:05:34 2011
@@ -90,6 +90,9 @@
int preserve; /* restore user and group info */
uint32_t linkc; /* # of hard links */
matlink_t links[MAT_LINKTAB_SIZE]; /* hard link entries */
+ char from[MAT_PATH_MAX]; /* path to change from */
+ char to[MAT_PATH_MAX]; /* path to change to */
+ void *re; /* pointer to compiled regexp */
} mat_t;
int mat_init(mat_t */*mat*/, const char */*f*/, const char */*mode*/);
Index: othersrc/external/bsd/mat/dist/matpax.1
diff -u othersrc/external/bsd/mat/dist/matpax.1:1.4 othersrc/external/bsd/mat/dist/matpax.1:1.5
--- othersrc/external/bsd/mat/dist/matpax.1:1.4 Tue Jun 21 09:45:49 2011
+++ othersrc/external/bsd/mat/dist/matpax.1 Sat Jun 25 17:05:34 2011
@@ -1,4 +1,4 @@
-.\" $NetBSD: matpax.1,v 1.4 2011/06/21 09:45:49 wiz Exp $
+.\" $NetBSD: matpax.1,v 1.5 2011/06/25 17:05:34 agc Exp $
.\"
.\" Copyright (c) 2011 Alistair Crooks <[email protected]>
.\" All rights reserved.
@@ -23,7 +23,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.
.\"
-.Dd June 20, 2011
+.Dd June 25, 2011
.Dt MATPAX 1
.Os
.Sh NAME
@@ -34,6 +34,7 @@
.Op Fl alrVvw
.Op Fl C Ar directory
.Op Fl f Ar archive
+.Op Fl s Ar substition
.Op Ar file ...
.Sh DESCRIPTION
The
@@ -83,6 +84,18 @@
list the archive
.It Fl r
extract the named components from the archive.
+.It Fl s Ar substition
+The pathnames on entry or exit to the archive, depending on whether
+the archive is being created or used to extract components, are modified
+using an
+.Dv old
+and
+.Dv new
+subsitution pattern, in a similar manner to
+.Xr sed 1
+The first non-whitespace character of the pattern is taken to be the delimiter
+for the patterns, which itself can be escaped using the backslash character.
+Extended regular expressions are used to match the path names.
.It Fl V
verify the archive does not contain dangerous
entries which could compromise a machine if the archive
Index: othersrc/external/bsd/mat/mat/Makefile
diff -u othersrc/external/bsd/mat/mat/Makefile:1.3 othersrc/external/bsd/mat/mat/Makefile:1.4
--- othersrc/external/bsd/mat/mat/Makefile:1.3 Tue Jun 21 04:21:25 2011
+++ othersrc/external/bsd/mat/mat/Makefile Sat Jun 25 17:05:35 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.3 2011/06/21 04:21:25 agc Exp $
+# $NetBSD: Makefile,v 1.4 2011/06/25 17:05:35 agc Exp $
.include <bsd.own.mk>
@@ -62,3 +62,6 @@
cd d && env LD_LIBRARY_PATH=${LIBMATDIR} ../${PROG} tvvf ../archive2.mat > archive2.list
-diff d/archive2.list d/archive2.audit
env LD_LIBRARY_PATH=${LIBMATDIR} ./${PROG} avvf a.mat
+ env LD_LIBRARY_PATH=${LIBMATDIR} ./${PROG} cvf 13.mat -s '|^|umpalumpa/|' Makefile Makefile Makefile
+ env LD_LIBRARY_PATH=${LIBMATDIR} ./${PROG} tvvf 13.mat
+ env LD_LIBRARY_PATH=${LIBMATDIR} ./${PROG} xvf 13.mat -s '|umpalumpa|13|'