summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Hall <halex@cvs.openbsd.org>2014-07-11 16:01:42 +0000
committerAlexander Hall <halex@cvs.openbsd.org>2014-07-11 16:01:42 +0000
commit5a20f405f353b48380275914477659c7b2d2f871 (patch)
treee3f9ab6cfe62883435f49d665c12c79c4ac4929e
parente1e97a7aafe936ad1f3926e07355776eb3517041 (diff)
make dump support DUIDs for command line arguments and /etc/dumpdates (using
the new shiny -U switch) dumpdates part originating from, and discussed with, Maximilian Fillinger seems reasonable to krw@, "get it in" deraadt@
-rw-r--r--include/protocols/dumprestore.h6
-rw-r--r--sbin/dump/Makefile4
-rw-r--r--sbin/dump/dump.813
-rw-r--r--sbin/dump/dump.h4
-rw-r--r--sbin/dump/itime.c6
-rw-r--r--sbin/dump/main.c48
6 files changed, 62 insertions, 19 deletions
diff --git a/include/protocols/dumprestore.h b/include/protocols/dumprestore.h
index 7789a84c55f..9a94a0c9e1e 100644
--- a/include/protocols/dumprestore.h
+++ b/include/protocols/dumprestore.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dumprestore.h,v 1.9 2009/12/15 13:11:42 halex Exp $ */
+/* $OpenBSD: dumprestore.h,v 1.10 2014/07/11 16:01:40 halex Exp $ */
/* $NetBSD: dumprestore.h,v 1.14 2005/12/26 19:01:47 perry Exp $ */
/*
@@ -152,8 +152,8 @@ union u_spcl {
#define DR_NEWHEADER 0x0001 /* new format tape header */
#define DR_NEWINODEFMT 0x0002 /* new format inodes on tape */
-#define DUMPOUTFMT "%-16s %c %s" /* for printf */
+#define DUMPOUTFMT "%-18s %c %s" /* for printf */
/* name, level, ctime(date) */
-#define DUMPINFMT "%16s %c %[^\n]\n" /* inverse for scanf */
+#define DUMPINFMT "%18s %c %[^\n]\n" /* inverse for scanf */
#endif /* !_PROTOCOLS_DUMPRESTORE_H_ */
diff --git a/sbin/dump/Makefile b/sbin/dump/Makefile
index 829b5ba39da..aeae6cadd24 100644
--- a/sbin/dump/Makefile
+++ b/sbin/dump/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.11 2013/01/06 21:59:28 martynas Exp $
+# $OpenBSD: Makefile,v 1.12 2014/07/11 16:01:41 halex Exp $
# dump.h header file
# itime.c reads /etc/dumpdates
@@ -14,6 +14,8 @@
PROG= dump
LINKS= ${BINDIR}/dump ${BINDIR}/rdump
CFLAGS+=-DRDUMP
+DPADD+= ${LIBUTIL}
+LDADD+= -lutil
SRCS= itime.c main.c optr.c dumprmt.c tape.c traverse.c
MAN= dump.8
MLINKS+=dump.8 rdump.8
diff --git a/sbin/dump/dump.8 b/sbin/dump/dump.8
index e5e0dd7c7de..5725d35aa0e 100644
--- a/sbin/dump/dump.8
+++ b/sbin/dump/dump.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: dump.8,v 1.46 2014/05/30 20:48:21 stephan Exp $
+.\" $OpenBSD: dump.8,v 1.47 2014/07/11 16:01:41 halex Exp $
.\" $NetBSD: dump.8,v 1.17 1997/06/05 11:15:06 lukem Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
@@ -31,7 +31,7 @@
.\"
.\" @(#)dump.8 8.1 (Berkeley) 6/16/93
.\"
-.Dd $Mdocdate: May 30 2014 $
+.Dd $Mdocdate: July 11 2014 $
.Dt DUMP 8
.Os
.Sh NAME
@@ -40,7 +40,7 @@
.Sh SYNOPSIS
.Nm dump
.Bk -words
-.Op Fl 0123456789acnSuWw
+.Op Fl 0123456789acnSUuWw
.Op Fl B Ar records
.Op Fl b Ar blocksize
.Op Fl d Ar density
@@ -229,6 +229,13 @@ The
flag is mutually exclusive from the
.Fl u
flag.
+.It Fl U
+Use the
+.Xr disklabel 8
+UID instead of the device name when updating
+.Pa /etc/dumpdates
+and when searching for the date of the latest
+lower-level dump.
.It Fl u
Update the file
.Pa /etc/dumpdates
diff --git a/sbin/dump/dump.h b/sbin/dump/dump.h
index 4a72c2f9102..59ad7c0ea86 100644
--- a/sbin/dump/dump.h
+++ b/sbin/dump/dump.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dump.h,v 1.20 2014/06/13 20:43:06 naddy Exp $ */
+/* $OpenBSD: dump.h,v 1.21 2014/07/11 16:01:41 halex Exp $ */
/* $NetBSD: dump.h,v 1.11 1997/06/05 11:13:20 lukem Exp $ */
/*-
@@ -56,9 +56,11 @@ char *disk; /* name of the disk file */
char *tape; /* name of the tape file */
char *dumpdates; /* name of the file containing dump date information*/
char *temp; /* name of the file for doing rewrite of dumpdates */
+char *duid; /* duid of the disk being dumped */
char lastlevel; /* dump level of previous dump */
char level; /* dump level of this dump */
int uflag; /* update flag */
+int Uflag; /* use duids in dumpdates flag */
int diskfd; /* disk file descriptor */
int tapefd; /* tape file descriptor */
int pipeout; /* true => output to standard output */
diff --git a/sbin/dump/itime.c b/sbin/dump/itime.c
index d64422b5bb8..b8c5edb0e48 100644
--- a/sbin/dump/itime.c
+++ b/sbin/dump/itime.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: itime.c,v 1.17 2009/10/27 23:59:32 deraadt Exp $ */
+/* $OpenBSD: itime.c,v 1.18 2014/07/11 16:01:41 halex Exp $ */
/* $NetBSD: itime.c,v 1.4 1997/04/15 01:09:50 lukem Exp $ */
/*-
@@ -124,7 +124,7 @@ getdumptime(void)
int i;
char *fname;
- fname = disk;
+ fname = Uflag ? duid : disk;
#ifdef FDEBUG
msg("Looking for name %s in dumpdates = %s for level = %c\n",
fname, dumpdates, level);
@@ -164,7 +164,7 @@ putdumptime(void)
quit("cannot rewrite %s: %s\n", dumpdates, strerror(errno));
fd = fileno(df);
(void) flock(fd, LOCK_EX);
- fname = disk;
+ fname = Uflag ? duid : disk;
free((char *)ddatev);
ddatev = 0;
nddates = 0;
diff --git a/sbin/dump/main.c b/sbin/dump/main.c
index 3f878ea546b..cdc62885d28 100644
--- a/sbin/dump/main.c
+++ b/sbin/dump/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.51 2014/06/13 20:43:06 naddy Exp $ */
+/* $OpenBSD: main.c,v 1.52 2014/07/11 16:01:41 halex Exp $ */
/* $NetBSD: main.c,v 1.14 1997/06/05 11:13:24 lukem Exp $ */
/*-
@@ -54,6 +54,7 @@
#include <string.h>
#include <time.h>
#include <unistd.h>
+#include <util.h>
#include "dump.h"
#include "pathnames.h"
@@ -94,8 +95,9 @@ main(int argc, char *argv[])
ino_t maxino;
time_t t;
int dirlist;
- char *toplevel, *str, *mount_point = NULL;
+ char *toplevel, *str, *mount_point = NULL, *realpath;
int just_estimate = 0;
+ u_int64_t zero_uid = 0;
spcl.c_date = (int64_t)time(NULL);
@@ -112,7 +114,7 @@ main(int argc, char *argv[])
usage();
obsolete(&argc, &argv);
- while ((ch = getopt(argc, argv, "0123456789aB:b:cd:f:h:ns:ST:uWw")) != -1)
+ while ((ch = getopt(argc, argv, "0123456789aB:b:cd:f:h:ns:ST:UuWw")) != -1)
switch (ch) {
/* dump level */
case '0': case '1': case '2': case '3': case '4':
@@ -180,6 +182,10 @@ main(int argc, char *argv[])
lastlevel = '?';
break;
+ case 'U':
+ Uflag = 1; /* use duids */
+ break;
+
case 'u': /* update /etc/dumpdates */
uflag = 1;
break;
@@ -213,6 +219,16 @@ main(int argc, char *argv[])
for (i = 0; i < argc; i++) {
struct stat sb;
+ /* Convert potential duid into a device name */
+ if ((diskfd = opendev(argv[i], O_RDONLY | O_NOFOLLOW, 0,
+ &realpath)) >= 0) {
+ argv[i] = strdup(realpath);
+ if (argv[i] == NULL) {
+ msg("Cannot malloc realpath\n");
+ exit(X_STARTUP);
+ }
+ (void)close(diskfd);
+ }
if (lstat(argv[i], &sb) == -1) {
msg("Cannot lstat %s: %s\n", argv[i], strerror(errno));
exit(X_STARTUP);
@@ -370,6 +386,26 @@ main(int argc, char *argv[])
(void)gethostname(spcl.c_host, sizeof(spcl.c_host));
spcl.c_level = level - '0';
spcl.c_type = TS_TAPE;
+
+ if ((diskfd = open(disk, O_RDONLY)) < 0) {
+ msg("Cannot open %s\n", disk);
+ exit(X_STARTUP);
+ }
+ if (ioctl(diskfd, DIOCGDINFO, (char *)&lab) < 0)
+ err(1, "ioctl (DIOCGDINFO)");
+ if (!Uflag)
+ ;
+ else if (memcmp(lab.d_uid, &zero_uid, sizeof(lab.d_uid)) == 0) {
+ msg("Cannot find DUID of disk %s\n", disk);
+ exit(X_STARTUP);
+ } else if (asprintf(&duid,
+ "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx.%c",
+ lab.d_uid[0], lab.d_uid[1], lab.d_uid[2], lab.d_uid[3],
+ lab.d_uid[4], lab.d_uid[5], lab.d_uid[6], lab.d_uid[7],
+ disk[strlen(disk)-1]) == -1) {
+ msg("Cannot malloc duid\n");
+ exit(X_STARTUP);
+ }
if (!Tflag)
getdumptime(); /* /etc/dumpdates snarfed */
@@ -387,10 +423,6 @@ main(int argc, char *argv[])
else
msgtail("to %s\n", tape);
- if ((diskfd = open(disk, O_RDONLY)) < 0) {
- msg("Cannot open %s\n", disk);
- exit(X_STARTUP);
- }
if (ioctl(diskfd, DIOCGPDINFO, (char *)&lab) < 0)
err(1, "ioctl (DIOCGPDINFO)");
sync();
@@ -561,7 +593,7 @@ usage(void)
{
extern char *__progname;
- (void)fprintf(stderr, "usage: %s [-0123456789acnSuWw] [-B records] "
+ (void)fprintf(stderr, "usage: %s [-0123456789acnSUuWw] [-B records] "
"[-b blocksize] [-d density]\n"
"\t[-f file] [-h level] [-s feet] "
"[-T date] files-to-dump\n",