Module Name: othersrc
Committed By: agc
Date: Mon Jun 20 14:58:54 UTC 2011
Modified Files:
othersrc/external/bsd/mat/dist: main.c mat.1 mat.h
othersrc/external/bsd/mat/libmat: Makefile
othersrc/external/bsd/mat/mat: Makefile
Added Files:
othersrc/external/bsd/mat/dist: frontends.c matpax.1
Log Message:
Abstract the mat/mattar frontend into its own function in frontends.c
Add a matpax frontend which uses a more pax-like interface
Add manual pages for matpax, fixup mat(1)
To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 othersrc/external/bsd/mat/dist/frontends.c \
othersrc/external/bsd/mat/dist/matpax.1
cvs rdiff -u -r1.1.1.1 -r1.2 othersrc/external/bsd/mat/dist/main.c \
othersrc/external/bsd/mat/dist/mat.h
cvs rdiff -u -r1.2 -r1.3 othersrc/external/bsd/mat/dist/mat.1
cvs rdiff -u -r1.1.1.1 -r1.2 othersrc/external/bsd/mat/libmat/Makefile
cvs rdiff -u -r1.1.1.1 -r1.2 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/main.c
diff -u othersrc/external/bsd/mat/dist/main.c:1.1.1.1 othersrc/external/bsd/mat/dist/main.c:1.2
--- othersrc/external/bsd/mat/dist/main.c:1.1.1.1 Sat Jun 18 04:53:13 2011
+++ othersrc/external/bsd/mat/dist/main.c Mon Jun 20 14:58:53 2011
@@ -22,9 +22,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.
*/
-#include <sys/types.h>
-
-#include <regex.h>
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -32,192 +30,39 @@
#include "mat.h"
-#ifndef TMPDIR
-#define TMPDIR "/tmp"
-#endif
-
-/* read input from stdin into a temp file */
-static int
-dostdin(const char *tmpdir, char *temp, size_t size)
-{
- ssize_t cc;
- char buf[BUFSIZ * 10];
- int fd;
-
- (void) snprintf(temp, size, "%s/mat.XXXXXX", tmpdir);
- if ((fd = mkstemp(temp)) < 0) {
- (void) fprintf(stderr, "can't make temporary file '%s'\n", temp);
- return -1;
- }
- while ((cc = read(STDIN_FILENO, buf, sizeof(buf))) > 0) {
- if (write(fd, buf, cc) != cc) {
- (void) fprintf(stderr, "short write to '%s'\n", temp);
- (void) unlink(temp);
- close(fd);
- return -1;
- }
- }
- return fd;
-}
-
-/* return non-zero if we're reading the archive */
-static int
-reading(const char *action)
-{
- return (strcmp(action, "verify") == 0 ||
- strcmp(action, "list") == 0 ||
- strcmp(action, "extract") == 0);
-}
-
-/* take a list of files from a metalog */
-static int
-read_metalog(mat_t *mat, char *metalog)
-{
- regmatch_t matches[10];
- regex_t r;
- FILE *fp;
- char buf[MAT_PATH_MAX * 2];
- char f[MAT_PATH_MAX];
- int ok;
-
- mat->recursing = 0;
- if ((fp = fopen(metalog, "r")) == NULL) {
- (void) fprintf(stderr, "can't open metalog '%s'\n", metalog);
- return 0;
- }
- (void) regcomp(&r, "^([^ \t]+)[ \t]+type=[a-z]*[ \t]+uname=([^ \t]+)[ \t]+gname=([^ \t\n]+)", REG_EXTENDED);
- for (ok = 1 ; fgets(buf, sizeof(buf), fp) != NULL ; ) {
- if (regexec(&r, buf, 10, matches, 0) == 0) {
- (void) snprintf(mat->user, sizeof(mat->user), "%.*s",
- (int)(matches[2].rm_eo - matches[2].rm_so),
- &buf[matches[2].rm_so]);
- (void) snprintf(mat->group, sizeof(mat->group), "%.*s",
- (int)(matches[3].rm_eo - matches[3].rm_so),
- &buf[matches[3].rm_so]);
- (void) snprintf(f, sizeof(f), "%.*s",
- (int)(matches[1].rm_eo - matches[1].rm_so),
- &buf[matches[1].rm_so]);
- if (!mat_add(mat, f)) {
- ok = 0;
- }
- }
- }
- (void) fclose(fp);
- regfree(&r);
- return ok;
-}
+/* struct to map string to mat frontend function */
+typedef struct map_t {
+ const char *s;
+ int (*func)(int, char **);
+} map_t;
+
+static map_t mappings[] = {
+ { "tar", mat_tar },
+ { "mtar", mat_tar },
+ { "mattar", mat_tar },
+ { "mat", mat_tar },
+ { "pax", mat_pax },
+ { "mpax", mat_pax },
+ { "matpax", mat_pax },
+ { NULL, NULL }
+};
int
main(int argc, char **argv)
{
- const char *action;
- mat_t mat;
- char newarg[256];
- char temp[MAT_PATH_MAX];
- char *metalog;
- char *dir;
- char *f;
- int deltemp;
- int fd;
- int ok;
- int i;
+ map_t *mp;
+ char *s;
- (void) memset(&mat, 0x0, sizeof(mat));
- action = NULL;
- f = NULL;
- metalog = NULL;
- dir = NULL;
- deltemp = 0;
- if (*argv[1] != '-') {
- (void) snprintf(newarg, sizeof(newarg), "-%s", argv[1]);
- argv[1] = newarg;
- }
- while ((i = getopt(argc, argv, "C:T:Vcf:ptvx")) != -1) {
- switch(i) {
- case 'C':
- dir = optarg;
- break;
- case 'T':
- metalog = optarg;
- break;
- case 'V':
- action = "verify";
- break;
- case 'c':
- action = "create";
- break;
- case 'f':
- f = optarg;
- break;
- case 'p':
- mat.preserve = 1;
- break;
- case 't':
- action = "list";
- break;
- case 'v':
- mat.verbose += 1;
- break;
- case 'x':
- action = "extract";
- break;
- default:
- break;
- }
- }
- if (action == NULL) {
- (void) fprintf(stderr, "No action specified\n");
- exit(EXIT_FAILURE);
- }
- if (reading(action) && strcmp(f, "-") == 0) {
- /* read archive from stdin */
- if ((fd = dostdin(TMPDIR, f = temp, sizeof(temp))) < 0) {
- exit(EXIT_FAILURE);
- }
- deltemp = 1;
- (void) close(fd);
- }
- if (!mat_init(&mat, f, action)) {
- (void) fprintf(stderr, "can't initialise mat\n");
- exit(EXIT_FAILURE);
- }
- if (dir != NULL && chdir(dir) < 0) {
- (void) fprintf(stderr, "can't chdir to '%s'\n", dir);
- exit(EXIT_FAILURE);
- }
- if (metalog) {
- ok = read_metalog(&mat, metalog);
- } else if (argc == optind) {
- if (strcmp(action, "list") == 0) {
- ok = mat_list(&mat, NULL, stdout);
- } else if (strcmp(action, "verify") == 0) {
- ok = mat_verify(&mat);
- } else if (strcmp(action, "extract") == 0) {
- ok = mat_extract(&mat, NULL);
- } else {
- (void) fprintf(stderr, "unknown action specified (%s)\n", action);
- exit(EXIT_FAILURE);
- }
+ if ((s = strrchr(*argv, '/')) == NULL) {
+ s = *argv;
} else {
- for (ok = 1, i = optind ; i < argc ; i++) {
- if (strcmp(action, "create") == 0) {
- if (!mat_add(&mat, argv[i])) {
- ok = 0;
- }
- } else if (strcmp(action, "extract") == 0) {
- if (!mat_extract(&mat, argv[i])) {
- ok = 0;
- }
- } else if (strcmp(action, "list") == 0) {
- if (!mat_list(&mat, argv[i], stdout)) {
- ok = 0;
- }
- }
- }
+ s += 1;
}
- (void) mat_end(&mat);
- if (deltemp) {
- (void) unlink(temp);
+ for (mp = mappings ; mp->s ; mp++) {
+ if (strcasecmp(s, mp->s) == 0) {
+ exit((*mp->func)(argc, argv) ? EXIT_SUCCESS : EXIT_FAILURE);
+ }
}
- exit((ok) ? EXIT_SUCCESS : EXIT_FAILURE);
+ (void) fprintf(stderr, "command '%s' not found\n", s);
+ exit(EXIT_FAILURE);
}
Index: othersrc/external/bsd/mat/dist/mat.h
diff -u othersrc/external/bsd/mat/dist/mat.h:1.1.1.1 othersrc/external/bsd/mat/dist/mat.h:1.2
--- othersrc/external/bsd/mat/dist/mat.h:1.1.1.1 Sat Jun 18 04:53:13 2011
+++ othersrc/external/bsd/mat/dist/mat.h Mon Jun 20 14:58:53 2011
@@ -100,4 +100,10 @@
int mat_verify(mat_t */*mat*/);
int mat_extract(mat_t */*mat*/, const char */*pat*/);
+int mat_tar(int /*argc*/, char **/*argv*/);
+int mat_vtar(char */*arg*/, ...);
+
+int mat_pax(int /*argc*/, char **/*argv*/);
+int mat_vpax(char */*arg*/, ...);
+
#endif
Index: othersrc/external/bsd/mat/dist/mat.1
diff -u othersrc/external/bsd/mat/dist/mat.1:1.2 othersrc/external/bsd/mat/dist/mat.1:1.3
--- othersrc/external/bsd/mat/dist/mat.1:1.2 Sat Jun 18 05:10:17 2011
+++ othersrc/external/bsd/mat/dist/mat.1 Mon Jun 20 14:58:53 2011
@@ -1,4 +1,4 @@
-.\" $NetBSD: mat.1,v 1.2 2011/06/18 05:10:17 wiz Exp $
+.\" $NetBSD: mat.1,v 1.3 2011/06/20 14:58:53 agc Exp $
.\"
.\" Copyright (c) 2011 Alistair Crooks <[email protected]>
.\" All rights reserved.
@@ -23,18 +23,18 @@
.\" (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 2, 2011
-.Dt MAT 1
+.Dd June 19, 2011
+.Dt MATTAR 1
.Os
.Sh NAME
-.Nm mat
+.Nm mattar
.Nd minimalist archive tool program
.Sh SYNOPSIS
.Nm
-.Op Fl cptVvx
+.Op Fl Vcptvx
.Op Fl C Ar directory
-.Op Fl f Ar archive
.Op Fl T Ar template
+.Op Fl f Ar archive
.Op Ar file ...
.Sh DESCRIPTION
The
@@ -56,8 +56,15 @@
perform an initial
.Xr chdir 2
into the specified directory before attempting to resolve any filenames.
-.It Fl c
-create the archive
+.It Fl T Ar template
+takes the names of the entries to be included in the archive
+from the template file provided.
+This template file is expected to be in the
+.Dv METALOG
+format, as generated during the
+.Nx
+.Dv build.sh
+phase.
.It Fl f Ar archive
Use the
.Xr libmat 3
@@ -69,6 +76,12 @@
or will be read from
.Dv stdin
depending on the action specified.
+.It Fl V
+verify the archive does not contain dangerous
+entries which could compromise a machine if the archive
+is extracted or listed.
+.It Fl c
+create the archive
.It Fl p
when extracting the components of the archive,
preserve the file owner and group information,
@@ -76,32 +89,17 @@
Setuid and setgid bits are only preserved
if the program is run with an effective
uid of 0.
-.It Fl T Ar template
-takes the names of the entries to be included in the archive
-from the template file provided.
-This template file is expected to be in the
-.Dv METALOG
-format, as generated during the
-.Nx
-.Dv build.sh
-phase.
.It Fl t
list the contents of the archive on stdout.
-.It Fl V
-verify the archive does not contain dangerous
-entries which could compromise a machine if the archive
-is extracted or listed.
.It Fl v
perform operations in a verbose manner.
-This option can be repeated to provide higher
+This option can be repeated to provide higher
levels of verbosity.
For instance, when listing entries,
a verbosity level of 2 will also show
the
.Xr SHA256 3
digests associated with the archive component.
-.It Fl x
-extract the contents of the archive.
.El
.Pp
.Nm
@@ -113,7 +111,7 @@
but without some of the constraints and limits
inherent in those archivers.
In addition,
-digests are used to make sure that the
+digests are used to make sure that the
contents of the archive remain the same as when the archive was made.
To protect against malicious archives, a sanity
check,
@@ -124,7 +122,7 @@
the archive.
.Sh EXAMPLES
.Bd -literal
-% mat cvf mat.mat .
+% mattar cvf mat.mat .
ignoring attempt to add ourselves './mat.mat'
% l
total 56
@@ -136,7 +134,7 @@
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
-% mat tvf 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
@@ -169,7 +167,7 @@
-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
-% mat tvvf mat.mat
+% 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
@@ -209,7 +207,7 @@
% 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 | mat tvvf -
+% 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
Index: othersrc/external/bsd/mat/libmat/Makefile
diff -u othersrc/external/bsd/mat/libmat/Makefile:1.1.1.1 othersrc/external/bsd/mat/libmat/Makefile:1.2
--- othersrc/external/bsd/mat/libmat/Makefile:1.1.1.1 Sat Jun 18 04:53:13 2011
+++ othersrc/external/bsd/mat/libmat/Makefile Mon Jun 20 14:58:53 2011
@@ -1,11 +1,11 @@
-# $NetBSD: Makefile,v 1.1.1.1 2011/06/18 04:53:13 agc Exp $
+# $NetBSD: Makefile,v 1.2 2011/06/20 14:58:53 agc Exp $
.include <bsd.own.mk>
USE_FORT?= yes
LIB= mat
-SRCS+= mat.c
+SRCS+= mat.c frontends.c
MAN= libmat.3
WARNS=4
Index: othersrc/external/bsd/mat/mat/Makefile
diff -u othersrc/external/bsd/mat/mat/Makefile:1.1.1.1 othersrc/external/bsd/mat/mat/Makefile:1.2
--- othersrc/external/bsd/mat/mat/Makefile:1.1.1.1 Sat Jun 18 04:53:13 2011
+++ othersrc/external/bsd/mat/mat/Makefile Mon Jun 20 14:58:54 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1.1.1 2011/06/18 04:53:13 agc Exp $
+# $NetBSD: Makefile,v 1.2 2011/06/20 14:58:54 agc Exp $
.include <bsd.own.mk>
@@ -12,7 +12,12 @@
LDADD+= -L${LIBMATDIR} -lmat
DPADD+= ${LIBMATDIR}/libmat.a
-MAN= mat.1
+LINKS+= ${BINDIR}/mat ${BINDIR}/mattar
+LINKS+= ${BINDIR}/mat ${BINDIR}/matpax
+
+MAN= mat.1 matpax.1
+
+MLINKS+= mat.1 mattar.1
WARNS= 4
Added files:
Index: othersrc/external/bsd/mat/dist/frontends.c
diff -u /dev/null othersrc/external/bsd/mat/dist/frontends.c:1.1
--- /dev/null Mon Jun 20 14:58:54 2011
+++ othersrc/external/bsd/mat/dist/frontends.c Mon Jun 20 14:58:53 2011
@@ -0,0 +1,374 @@
+/*-
+ * Copyright (c) 2011 Alistair Crooks <[email protected]>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/types.h>
+
+#include <regex.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "mat.h"
+
+#ifndef TMPDIR
+#define TMPDIR "/tmp"
+#endif
+
+/* read input from stdin into a temp file */
+static int
+dostdin(const char *tmpdir, char *temp, size_t size)
+{
+ ssize_t cc;
+ char buf[BUFSIZ * 10];
+ int fd;
+
+ (void) snprintf(temp, size, "%s/mat.XXXXXX", tmpdir);
+ if ((fd = mkstemp(temp)) < 0) {
+ (void) fprintf(stderr, "can't make temporary file '%s'\n", temp);
+ return -1;
+ }
+ while ((cc = read(STDIN_FILENO, buf, sizeof(buf))) > 0) {
+ if (write(fd, buf, (size_t)cc) != cc) {
+ (void) fprintf(stderr, "short write to '%s'\n", temp);
+ (void) unlink(temp);
+ close(fd);
+ return -1;
+ }
+ }
+ return fd;
+}
+
+/* return non-zero if we're reading the archive */
+static int
+reading(const char *action)
+{
+ return (strcmp(action, "verify") == 0 ||
+ strcmp(action, "list") == 0 ||
+ strcmp(action, "extract") == 0);
+}
+
+/* take a list of files from a metalog */
+static int
+read_metalog(mat_t *mat, char *metalog)
+{
+ regmatch_t matches[10];
+ regex_t r;
+ FILE *fp;
+ char buf[MAT_PATH_MAX * 2];
+ char f[MAT_PATH_MAX];
+ int ok;
+
+ mat->recursing = 0;
+ if ((fp = fopen(metalog, "r")) == NULL) {
+ (void) fprintf(stderr, "can't open metalog '%s'\n", metalog);
+ return 0;
+ }
+ (void) regcomp(&r, "^([^ \t]+)[ \t]+type=[a-z]*[ \t]+uname=([^ \t]+)[ \t]+gname=([^ \t\n]+)", REG_EXTENDED);
+ for (ok = 1 ; fgets(buf, (int)sizeof(buf), fp) != NULL ; ) {
+ if (regexec(&r, buf, 10, matches, 0) == 0) {
+ (void) snprintf(mat->user, sizeof(mat->user), "%.*s",
+ (int)(matches[2].rm_eo - matches[2].rm_so),
+ &buf[matches[2].rm_so]);
+ (void) snprintf(mat->group, sizeof(mat->group), "%.*s",
+ (int)(matches[3].rm_eo - matches[3].rm_so),
+ &buf[matches[3].rm_so]);
+ (void) snprintf(f, sizeof(f), "%.*s",
+ (int)(matches[1].rm_eo - matches[1].rm_so),
+ &buf[matches[1].rm_so]);
+ if (!mat_add(mat, f)) {
+ ok = 0;
+ }
+ }
+ }
+ (void) fclose(fp);
+ regfree(&r);
+ return ok;
+}
+
+/***************************************************************************/
+
+/* tar personality for mat */
+int
+mat_tar(int argc, char **argv)
+{
+ const char *action;
+ mat_t mat;
+ char newarg[MAT_PATH_MAX + 256];
+ char temp[MAT_PATH_MAX];
+ char cwd[MAT_PATH_MAX];
+ char *metalog;
+ char *dir;
+ char *f;
+ int deltemp;
+ int fd;
+ int ok;
+ int i;
+
+ (void) memset(&mat, 0x0, sizeof(mat));
+ action = NULL;
+ f = NULL;
+ metalog = NULL;
+ dir = NULL;
+ deltemp = 0;
+ if (*argv[1] != '-') {
+ (void) snprintf(newarg, sizeof(newarg), "-%s", argv[1]);
+ argv[1] = newarg;
+ }
+ while ((i = getopt(argc, argv, "C:T:Vcf:ptvx")) != -1) {
+ switch(i) {
+ case 'C':
+ dir = optarg;
+ break;
+ case 'T':
+ metalog = optarg;
+ break;
+ case 'V':
+ action = "verify";
+ break;
+ case 'c':
+ action = "create";
+ break;
+ case 'f':
+ f = optarg;
+ break;
+ case 'p':
+ mat.preserve = 1;
+ break;
+ case 't':
+ action = "list";
+ break;
+ case 'v':
+ mat.verbose += 1;
+ break;
+ case 'x':
+ action = "extract";
+ break;
+ default:
+ break;
+ }
+ }
+ if (action == NULL) {
+ (void) fprintf(stderr, "No action specified\n");
+ return 0;
+ }
+ if (reading(action) && strcmp(f, "-") == 0) {
+ /* read archive from stdin */
+ if ((fd = dostdin(TMPDIR, f = temp, sizeof(temp))) < 0) {
+ return 0;
+ }
+ deltemp = 1;
+ (void) close(fd);
+ }
+ if (!mat_init(&mat, f, action)) {
+ (void) fprintf(stderr, "can't initialise mat\n");
+ return 0;
+ }
+ getcwd(cwd, sizeof(cwd));
+ if (dir != NULL && chdir(dir) < 0) {
+ (void) fprintf(stderr, "can't chdir to '%s'\n", dir);
+ return 0;
+ }
+ if (metalog) {
+ ok = read_metalog(&mat, metalog);
+ } else if (argc == optind) {
+ if (strcmp(action, "list") == 0) {
+ ok = mat_list(&mat, NULL, stdout);
+ } else if (strcmp(action, "verify") == 0) {
+ ok = mat_verify(&mat);
+ } else if (strcmp(action, "extract") == 0) {
+ ok = mat_extract(&mat, NULL);
+ } else {
+ (void) fprintf(stderr, "unknown action specified (%s)\n", action);
+ return 0;
+ }
+ } else {
+ for (ok = 1, i = optind ; i < argc ; i++) {
+ if (strcmp(action, "create") == 0) {
+ if (!mat_add(&mat, argv[i])) {
+ ok = 0;
+ }
+ } else if (strcmp(action, "extract") == 0) {
+ if (!mat_extract(&mat, argv[i])) {
+ ok = 0;
+ }
+ } else if (strcmp(action, "list") == 0) {
+ if (!mat_list(&mat, argv[i], stdout)) {
+ ok = 0;
+ }
+ }
+ }
+ }
+ (void) mat_end(&mat);
+ if (deltemp) {
+ (void) unlink(temp);
+ }
+ if (dir != NULL && chdir(cwd) < 0) {
+ (void) fprintf(stderr, "can't chdir back to '%s'\n", cwd);
+ }
+ return ok;
+}
+
+#ifndef MAT_ARGC_MAX
+#define MAT_ARGC_MAX 2048
+#endif
+
+/* varargs version of tar */
+int
+mat_vtar(char *arg, ...)
+{
+ va_list args;
+ char *argv[MAT_ARGC_MAX];
+ char *s;
+ int argc;
+
+ argv[0] = arg;
+ va_start(args, arg);
+ for (argc = 1 ; (s = va_arg(args, char *)) != NULL && argc < MAT_ARGC_MAX ; argc++) {
+ argv[argc] = s;
+ }
+ va_end(args);
+ return mat_tar(argc, argv);
+}
+
+/* pax personality for mat */
+int
+mat_pax(int argc, char **argv)
+{
+ const char *action;
+ mat_t mat;
+ char temp[MAT_PATH_MAX];
+ char cwd[MAT_PATH_MAX];
+ char *metalog;
+ char *archive;
+ char *dir;
+ int deltemp;
+ int fd;
+ int ok;
+ int i;
+
+ (void) memset(&mat, 0x0, sizeof(mat));
+ dir = NULL;
+ metalog = NULL;
+ archive = NULL;
+ ok = 1;
+ action = "list";
+ deltemp = 0;
+ while ((i = getopt(argc, argv, "Vaf:ilrvw")) != -1) {
+ switch(i) {
+ case 'V':
+ action = "verify";
+ break;
+ case 'f':
+ archive = optarg;
+ break;
+ case 'l':
+ action = "list";
+ break;
+ case 'r':
+ action = "extract";
+ break;
+ case 'w':
+ action = "create";
+ break;
+ default:
+ (void) fprintf(stderr, "Unknown flag \"%c\"\n", i);
+ }
+ }
+ if (reading(action) && strcmp(archive, "-") == 0) {
+ /* read archive from stdin */
+ if ((fd = dostdin(TMPDIR, archive = temp, sizeof(temp))) < 0) {
+ return 0;
+ }
+ deltemp = 1;
+ (void) close(fd);
+ }
+ if (!mat_init(&mat, archive, action)) {
+ (void) fprintf(stderr, "can't initialise mat\n");
+ return 0;
+ }
+ getcwd(cwd, sizeof(cwd));
+ if (dir != NULL && chdir(dir) < 0) {
+ (void) fprintf(stderr, "can't chdir to '%s'\n", dir);
+ return 0;
+ }
+ if (metalog != NULL) {
+ ok = read_metalog(&mat, metalog);
+ } else if (argc == optind) {
+ if (strcmp(action, "list") == 0) {
+ ok = mat_list(&mat, NULL, stdout);
+ } else if (strcmp(action, "verify") == 0) {
+ ok = mat_verify(&mat);
+ } else if (strcmp(action, "extract") == 0) {
+ ok = mat_extract(&mat, NULL);
+ } else {
+ (void) fprintf(stderr, "unknown action specified (%s)\n", action);
+ return 0;
+ }
+ } else {
+ for (ok = 1, i = optind ; i < argc ; i++) {
+ if (strcmp(action, "create") == 0) {
+ if (!mat_add(&mat, argv[i])) {
+ ok = 0;
+ }
+ } else if (strcmp(action, "extract") == 0) {
+ if (!mat_extract(&mat, argv[i])) {
+ ok = 0;
+ }
+ } else if (strcmp(action, "list") == 0) {
+ if (!mat_list(&mat, argv[i], stdout)) {
+ ok = 0;
+ }
+ }
+ }
+ }
+ (void) mat_end(&mat);
+ if (deltemp) {
+ (void) unlink(temp);
+ }
+ if (dir != NULL && chdir(cwd) < 0) {
+ (void) fprintf(stderr, "can't chdir back to '%s'\n", cwd);
+ }
+ return ok;
+}
+
+/* varargs version of pax */
+int
+mat_vpax(char *arg, ...)
+{
+ va_list args;
+ char *argv[MAT_ARGC_MAX];
+ char *s;
+ int argc;
+
+ argv[0] = arg;
+ va_start(args, arg);
+ for (argc = 1 ; (s = va_arg(args, char *)) != NULL && argc < MAT_ARGC_MAX ; argc++) {
+ argv[argc] = s;
+ }
+ va_end(args);
+ return mat_pax(argc, argv);
+}
+
Index: othersrc/external/bsd/mat/dist/matpax.1
diff -u /dev/null othersrc/external/bsd/mat/dist/matpax.1:1.1
--- /dev/null Mon Jun 20 14:58:54 2011
+++ othersrc/external/bsd/mat/dist/matpax.1 Mon Jun 20 14:58:53 2011
@@ -0,0 +1,137 @@
+.\" $NetBSD: matpax.1,v 1.1 2011/06/20 14:58:53 agc Exp $
+.\"
+.\" Copyright (c) 2011 Alistair Crooks <[email protected]>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+.\" (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 19, 2011
+.Dt MATPAX 1
+.Os
+.Sh NAME
+.Nm matpax
+.Nd minimalist archive tool program with pax frontend
+.Sh SYNOPSIS
+.Nm
+.Op Fl Vcptvx
+.Op Fl C Ar directory
+.Op Fl T Ar template
+.Op Fl f Ar archive
+.Op Ar file ...
+.Sh DESCRIPTION
+The
+.Nm
+utility creates and manages
+.Xr libmat 3
+archives.
+Mat archives are similar to
+.Xr tar 1
+or
+.Xr pax 1
+archives, with the addition of embedded
+.Xr sha256 3
+digests to protect the contents of the archive.
+.Pp
+The options are as follows:
+.Bl -tag -width template123
+.It Fl C Ar directory
+perform an initial
+.Xr chdir 2
+into the specified directory before attempting to resolve any filenames.
+.It Fl T Ar template
+takes the names of the entries to be included in the archive
+from the template file provided.
+This template file is expected to be in the
+.Dv METALOG
+format, as generated during the
+.Nx
+.Dv build.sh
+phase.
+.It Fl f Ar archive
+Use the
+.Xr libmat 3
+file in the argument as the archive.
+If the archive given is the special value
+.Dq -
+then the archive will be created on
+.Dv stdout
+or will be read from
+.Dv stdin
+depending on the action specified.
+.It Fl V
+verify the archive does not contain dangerous
+entries which could compromise a machine if the archive
+is extracted or listed.
+.It Fl c
+create the archive
+.It Fl p
+when extracting the components of the archive,
+preserve the file owner and group information,
+as well as the file modes.
+Setuid and setgid bits are only preserved
+if the program is run with an effective
+uid of 0.
+.It Fl t
+list the contents of the archive on stdout.
+.It Fl v
+perform operations in a verbose manner.
+This option can be repeated to provide higher
+levels of verbosity.
+For instance, when listing entries,
+a verbosity level of 2 will also show
+the
+.Xr SHA256 3
+digests associated with the archive component.
+.El
+.Pp
+.Nm
+is intended to be used in the same way as
+portable archivers such as
+.Xr tar 1
+and
+.Xr pax 1
+but without some of the constraints and limits
+inherent in those archivers.
+In addition,
+digests are used to make sure that the
+contents of the archive remain the same as when the archive was made.
+To protect against malicious archives, a sanity
+check,
+invoked by the
+.Fl V
+argument, has been provided.
+The archive is verified before listing or extracting from
+the archive.
+.Sh EXAMPLES
+.Bd -literal
+.Ed
+.Sh SEE ALSO
+.Xr pax 1 ,
+.Xr tar 1 ,
+.Xr libmat 3 ,
+.Xr sha2 3
+.Sh HISTORY
+The
+.Nm
+utility appeared in
+.Nx 6.0 .
+.Sh AUTHORS
+.An Alistair Crooks Aq [email protected]