From ejh@eas.slu.edu Fri Nov 28 06:09:34 1997 Received: from mnw.eas.slu.edu (mnw.eas.slu.edu [165.134.8.248]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id GAA14528 for ; Fri, 28 Nov 1997 06:09:33 -0800 (PST) (envelope-from ejh@eas.slu.edu) Received: from ejhstl.eas.slu.edu (ejhstl.eas.slu.edu [165.134.8.100]) by mnw.eas.slu.edu (8.8.8/8.8.8) with ESMTP id IAA27905 for ; Fri, 28 Nov 1997 08:09:17 -0600 (CST) Received: (from ejh@localhost) by ejhstl.eas.slu.edu (8.8.7/8.6.9) id IAA05074; Fri, 28 Nov 1997 08:09:21 -0600 (CST) Message-Id: <199711281409.IAA05074@ejhstl.eas.slu.edu> Date: Fri, 28 Nov 1997 08:09:21 -0600 (CST) From: ejh@eas.slu.edu Reply-To: ejh@eas.slu.edu To: FreeBSD-gnats-submit@freebsd.org Subject: restore ought to deal with root setable file flags X-Send-Pr-Version: 3.2 >Number: 5173 >Category: bin >Synopsis: [patch] [request] restore(8) ought to deal with root setable file flags >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: closed >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri Nov 28 06:10:00 PST 1997 >Closed-Date: Fri May 23 18:59:55 UTC 2008 >Last-Modified: Fri May 23 18:59:55 UTC 2008 >Originator: Eric J. Haug >Release: FreeBSD 3.0-CURRENT i386 >Organization: Saint Louis University >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 { >Release-Note: >Audit-Trail: State-Changed-From-To: open->suspended State-Changed-By: phk State-Changed-When: Wed May 27 02:51:24 PDT 1998 State-Changed-Why: Awaiting committer State-Changed-From-To: suspended->closed State-Changed-By: mckusick State-Changed-When: Fri May 23 18:56:51 UTC 2008 State-Changed-Why: This problem was fixed by John Polstra in revision 1.6 on 1998/07/09 in response to a similar bug reported by Matthew Thyer . http://www.freebsd.org/cgi/query-pr.cgi?pr=5173 >Unformatted: