Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 13 Aug 2001 10:43:36 +0200 (CEST)
From:      Sascha Blank <sblank@addcom.de>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/29671: restore changes attributes of directories despite "-N" flag
Message-ID:  <200108130843.f7D8haJ10262@ally.privat.de>

next in thread | raw e-mail | index | archive | help

>Number:         29671
>Category:       bin
>Synopsis:       restore changes attributes of directories despite "-N" flag
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Aug 13 02:00:03 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Sascha Blank
>Release:        FreeBSD 4.4-PRERELEASE i386
>Organization:
none
>Environment:

System: FreeBSD ally.privat.de 4.4-PRERELEASE FreeBSD 4.4-PRERELEASE #0:
Sat Aug 11 11:46:42 CEST 2001 sblank@ally.privat.de:/disc2/releng-4/obj/
disc2/releng-4/src/sys/ALLY i386

# ident /usr/src/sbin/restore/dirs.c

/usr/src/sbin/restore/dirs.c:
     $FreeBSD: src/sbin/restore/dirs.c,v 1.14.2.3 2001/08/01 08:57:43
     obrien Exp $

Attention: This bug is likely to affect 5.0-CURRENT as well!


>Description:

According to the restore manpage:

	-N	Do the extraction normally, but do not actually write
		any changes to disk.  This can be used to check the integrity of
		dump media or other test purposes.

This is _not_ true for the "Set directory mode, owner, and times" pass
that happens last during the restore process.


>How-To-Repeat:

I can reproduce it the with these steps:

1st) % ls -ld /home/sblank /home/sblank/tmp
drwxr-xr-x  42 sblank  users  3584 11 Aug 11:54 /home/sblank
drwx------   2 sblank  users   512 11 Aug 15:39 /home/sblank/tmp

2nd) % cd ~sblank

3rd) % su root

4th) # pwd
/home/sblank

5th) # restore -rNv -f ... a backup of your '/' filesystem

6th) # ls -ld /home/sblank /home/sblank/tmp
drwxr-xr-x  42 root    wheel  3584 11 Aug 11:54 /home/sblank
drwxrwxrwt   2 root    wheel   512 11 Aug 15:39 /home/sblank/tmp


The change of the attributes happens because the "Set directory mode, owner,
and times" pass ignores the -N flag.  Normaly you don't notice unless it
tries to change the attribues of a directory that happens to live under
the same name relative to the directory where you have started restore
from.

To explain this particular example: The "Set directory mode, owner, and
times" pass also runs across the directories "." and "./tmp" during its
course.  Since I have started restore from my home directory every
directory that is found on the backup is looked up to see if it already
exists relative to my home directory.  Since "/home/sblank/." and
"/home/sblank/tmp" happen to exist in this case, they are changed to
what the backup says.  The result of this can be seen in step 6.

Attention: Though it might look like this problem can only happen when
restore is run by root, this is not strictly true: looking at the code
in "setdirmodes" one can see that the chmod() and utimes() calls can
even succeed when restore is run by an unpriviledged user.  Though no
real damage can be done in this case it might be surprising nonetheless
to see that certain directories suddenly have other attributes than
expected.


>Fix:

Make the routine "setdirmodes" in dirs.c respect the "-N" flag.

*** /usr/src/sbin/restore/my-dirs.c	Wed Aug  1 10:57:43 2001
--- /usr/src/sbin/restore/dirs.c	Mon Aug 13 09:51:33 2001
***************
*** 630,639 ****
  			panic("cannot find directory inode %d\n", node.ino);
  		} else {
  			cp = myname(ep);
! 			(void) chown(cp, node.uid, node.gid);
! 			(void) chmod(cp, node.mode);
! 			utimes(cp, node.timep);
! 			(void) chflags(cp, node.flags);
  			ep->e_flags &= ~NEW;
  		}
  	}
--- 630,641 ----
  			panic("cannot find directory inode %d\n", node.ino);
  		} else {
  			cp = myname(ep);
! 			if (!Nflag) {
! 				(void) chown(cp, node.uid, node.gid);
! 				(void) chmod(cp, node.mode);
! 				utimes(cp, node.timep);
! 				(void) chflags(cp, node.flags);
! 			}
  			ep->e_flags &= ~NEW;
  		}
  	}
>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200108130843.f7D8haJ10262>