Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Nov 1997 08:09:21 -0600 (CST)
From:      ejh@eas.slu.edu
To:        FreeBSD-gnats-submit@FreeBSD.ORG
Subject:   bin/5173: restore ought to deal with root setable file flags
Message-ID:  <199711281409.IAA05074@ejhstl.eas.slu.edu>
Resent-Message-ID: <199711281410.GAA14574@hub.freebsd.org>

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

>Number:         5173
>Category:       bin
>Synopsis:       restore ought to deal with root setable file flags
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Nov 28 06:10:00 PST 1997
>Last-Modified:
>Originator:     Eric J. Haug
>Organization:
Saint Louis University
>Release:        FreeBSD 3.0-CURRENT i386
>Environment:

	FreeBSD 3.0-CURRENT Nov 27 1997

>Description:

    restore fails to create hard links to files with schg flag set.

>How-To-Repeat:

	create a dump file with two hard linked files with schg flag set
	restore the dump file
	note that an error is reported when the link is attempted.
	and that the second directory entry is not created

>Fix:
	
Apply the following diff to src/sbin/restore/utilities.c

*** utilities.c	1997/11/28 12:56:06	1.1
--- utilities.c	1997/11/28 13:52:38	1.3
***************
*** 199,202 ****
--- 199,218 ----
  
  /*
+  * check the files flags and change
+  */
+ u_int32_t
+ getflags(existing)
+ 	char *existing;
+ {
+ 	struct stat stb;
+ 	int rtv;
+ 
+ 	if ( stat(existing, &stb) == -1 )
+ 		return -1;
+ 	else
+ 		return (stb.st_flags & SF_SETTABLE);
+ }
+ 
+ /*
   * Create a link.
   */
***************
*** 206,209 ****
--- 222,226 ----
  	int type;
  {
+ 	u_int32_t flags;
  
  	if (type == SYMLINK) {
***************
*** 216,223 ****
--- 233,274 ----
  	} else if (type == HARDLINK) {
  		if (!Nflag && link(existing, new) < 0) {
+ 			if ( errno == EPERM ) {
+ 				if ( (flags = getflags(existing)) < 0 )
+ 					return(FAIL);
+ 				if ( flags ) {
+ 					if ( chflags(existing, 0L) < 0 ) {
+ 						return(FAIL);
+ 					} else {
+ 						fprintf(stderr,
+ 							"warning: zeroed flags on file %s", existing);
+ 					}
+ 					if ( link(existing, new) < 0) {
+ 						fprintf(stderr,
+ 							"warning: cannot create hard link after changing flags %s->%s: %s\n",
+ 							new, existing, strerror(errno));
+ 						if ( chflags(existing, flags) < 0 ) {
+ 							fprintf(stderr,
+ 								"warning: failed to reset flags on file %s", existing);
+ 						} else {
+ 							fprintf(stderr,
+ 								"warning: reset flags on file %s", existing);
+ 						}
+ 						return(FAIL);
+ 					}
+ 					if ( chflags(existing, flags) < 0 ) {
+ 						return(FAIL);
+ 					} else {
+ 						fprintf(stderr,
+ 							"warning: reset flags on file %s", existing);
+ 					}
+ 				} else {
+ 					return (FAIL);
+ 				}
+ 			} else {
  			fprintf(stderr,
  			    "warning: cannot create hard link %s->%s: %s\n",
  			    new, existing, strerror(errno));
  			return (FAIL);
+ 			}
  		}
  	} else {
>Audit-Trail:
>Unformatted:



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