summaryrefslogtreecommitdiffstats
path: root/sbin/restore/interactive.c
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/restore/interactive.c')
-rw-r--r--sbin/restore/interactive.c72
1 files changed, 30 insertions, 42 deletions
diff --git a/sbin/restore/interactive.c b/sbin/restore/interactive.c
index 76aa74f..9e8b9ae 100644
--- a/sbin/restore/interactive.c
+++ b/sbin/restore/interactive.c
@@ -32,16 +32,16 @@
*/
#ifndef lint
-static char sccsid[] = "@(#)interactive.c 8.5 (Berkeley) 5/1/95";
+static char sccsid[] = "@(#)interactive.c 8.1 (Berkeley) 6/5/93";
#endif /* not lint */
#include <sys/param.h>
#include <sys/time.h>
#include <sys/stat.h>
+#include <ufs/ffs/fs.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h>
-#include <ufs/ffs/fs.h>
#include <protocols/dumprestore.h>
#include <setjmp.h>
@@ -82,10 +82,10 @@ struct arglist {
static char *copynext __P((char *, char *));
static int fcmp __P((const void *, const void *));
static void formatf __P((struct afile *, int));
-static void getcmd __P((char *, char *, char *, struct arglist *));
+static void getcmd __P((char *, char *, char *, int, struct arglist *));
struct dirent *glob_readdir __P((RST_DIR *dirp));
static int glob_stat __P((const char *, struct stat *));
-static void mkentry __P((char *, struct direct *, struct afile *));
+static void mkentry __P((struct direct *, struct afile *));
static void printlist __P((char *, char *));
/*
@@ -109,7 +109,7 @@ runcmdshell()
arglist.glob.gl_closedir = (void *)rst_closedir;
arglist.glob.gl_lstat = glob_stat;
arglist.glob.gl_stat = glob_stat;
- canon("/", curdir);
+ canon("/", curdir, sizeof(curdir));
loop:
if (setjmp(reset) != 0) {
if (arglist.freeglob != 0) {
@@ -121,7 +121,7 @@ loop:
volno = 0;
}
runshell = 1;
- getcmd(curdir, cmd, name, &arglist);
+ getcmd(curdir, cmd, name, sizeof(name), &arglist);
switch (cmd[0]) {
/*
* Add elements to the extraction list.
@@ -300,9 +300,10 @@ loop:
* eliminate any embedded ".." components.
*/
static void
-getcmd(curdir, cmd, name, ap)
+getcmd(curdir, cmd, name, size, ap)
char *curdir, *cmd, *name;
struct arglist *ap;
+ int size;
{
register char *cp;
static char input[BUFSIZ];
@@ -357,7 +358,7 @@ getnext:
* If it is an absolute pathname, canonicalize it and return it.
*/
if (rawname[0] == '/') {
- canon(rawname, name);
+ canon(rawname, name, size);
} else {
/*
* For relative pathnames, prepend the current directory to
@@ -366,7 +367,7 @@ getnext:
(void) strcpy(output, curdir);
(void) strcat(output, "/");
(void) strcat(output, rawname);
- canon(output, name);
+ canon(output, name, size);
}
if (glob(name, GLOB_ALTDIRFUNC, NULL, &ap->glob) < 0)
fprintf(stderr, "%s: out of memory\n", ap->cmd);
@@ -438,8 +439,9 @@ copynext(input, output)
* remove any imbedded "." and ".." components.
*/
void
-canon(rawname, canonname)
+canon(rawname, canonname, len)
char *rawname, *canonname;
+ int len;
{
register char *cp, *np;
@@ -449,6 +451,11 @@ canon(rawname, canonname)
(void) strcpy(canonname, ".");
else
(void) strcpy(canonname, "./");
+ if (strlen(canonname) + strlen(rawname) >= len) {
+ fprintf(stderr, "canonname: not enough bufferspace\n");
+ done(1);
+ }
+
(void) strcat(canonname, rawname);
/*
* Eliminate multiple and trailing '/'s
@@ -496,17 +503,15 @@ printlist(name, basename)
register struct direct *dp;
struct afile single;
RST_DIR *dirp;
- int entries, len, namelen;
- char locname[MAXPATHLEN + 1];
+ int entries, len;
dp = pathsearch(name);
- if (dp == NULL || (!dflag && TSTINO(dp->d_ino, dumpmap) == 0) ||
- (!vflag && dp->d_ino == WINO))
+ if (dp == NULL || (!dflag && TSTINO(dp->d_ino, dumpmap) == 0))
return;
if ((dirp = rst_opendir(name)) == NULL) {
entries = 1;
list = &single;
- mkentry(name, dp, list);
+ mkentry(dp, list);
len = strlen(basename) + 1;
if (strlen(name) - len > single.len) {
freename(single.fname);
@@ -528,28 +533,17 @@ printlist(name, basename)
fprintf(stderr, "%s:\n", name);
entries = 0;
listp = list;
- (void) strncpy(locname, name, MAXPATHLEN);
- (void) strncat(locname, "/", MAXPATHLEN);
- namelen = strlen(locname);
while (dp = rst_readdir(dirp)) {
- if (dp == NULL)
+ if (dp == NULL || dp->d_ino == 0)
break;
if (!dflag && TSTINO(dp->d_ino, dumpmap) == 0)
continue;
- if (!vflag && (dp->d_ino == WINO ||
- strcmp(dp->d_name, ".") == 0 ||
+ if (vflag == 0 &&
+ (strcmp(dp->d_name, ".") == 0 ||
strcmp(dp->d_name, "..") == 0))
continue;
- locname[namelen] = '\0';
- if (namelen + dp->d_namlen >= MAXPATHLEN) {
- fprintf(stderr, "%s%s: name exceeds %d char\n",
- locname, dp->d_name, MAXPATHLEN);
- } else {
- (void) strncat(locname, dp->d_name,
- (int)dp->d_namlen);
- mkentry(locname, dp, listp++);
- entries++;
- }
+ mkentry(dp, listp++);
+ entries++;
}
rst_closedir(dirp);
if (entries == 0) {
@@ -572,8 +566,7 @@ printlist(name, basename)
* Read the contents of a directory.
*/
static void
-mkentry(name, dp, fp)
- char *name;
+mkentry(dp, fp)
struct direct *dp;
register struct afile *fp;
{
@@ -588,7 +581,7 @@ mkentry(name, dp, fp)
fp->len = cp - fp->fname;
if (dflag && TSTINO(fp->fnum, dumpmap) == 0)
fp->prefix = '^';
- else if ((np = lookupname(name)) != NULL && (np->e_flags & NEW))
+ else if ((np = lookupino(fp->fnum)) != NULL && (np->e_flags & NEW))
fp->prefix = '*';
else
fp->prefix = ' ';
@@ -616,10 +609,6 @@ mkentry(name, dp, fp)
fp->postfix = '#';
break;
- case DT_WHT:
- fp->postfix = '%';
- break;
-
case DT_UNKNOWN:
case DT_DIR:
if (inodetype(dp->d_ino) == NODE)
@@ -715,7 +704,7 @@ glob_readdir(dirp)
static struct dirent adirent;
while ((dp = rst_readdir(dirp)) != NULL) {
- if (!vflag && dp->d_ino == WINO)
+ if (dp->d_ino == 0)
continue;
if (dflag || TSTINO(dp->d_ino, dumpmap))
break;
@@ -724,7 +713,7 @@ glob_readdir(dirp)
return (NULL);
adirent.d_fileno = dp->d_ino;
adirent.d_namlen = dp->d_namlen;
- memmove(adirent.d_name, dp->d_name, dp->d_namlen + 1);
+ bcopy(dp->d_name, adirent.d_name, dp->d_namlen + 1);
return (&adirent);
}
@@ -739,8 +728,7 @@ glob_stat(name, stp)
register struct direct *dp;
dp = pathsearch(name);
- if (dp == NULL || (!dflag && TSTINO(dp->d_ino, dumpmap) == 0) ||
- (!vflag && dp->d_ino == WINO))
+ if (dp == NULL || (!dflag && TSTINO(dp->d_ino, dumpmap) == 0))
return (-1);
if (inodetype(dp->d_ino) == NODE)
stp->st_mode = IFDIR;
OpenPOWER on IntegriCloud