From owner-freebsd-bugs Fri Nov 28 06:10:04 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id GAA14580 for bugs-outgoing; Fri, 28 Nov 1997 06:10:04 -0800 (PST) (envelope-from owner-freebsd-bugs) Received: (from gnats@localhost) by hub.freebsd.org (8.8.7/8.8.7) id GAA14574; Fri, 28 Nov 1997 06:10:01 -0800 (PST) (envelope-from gnats) Resent-Date: Fri, 28 Nov 1997 06:10:01 -0800 (PST) Resent-Message-Id: <199711281410.GAA14574@hub.freebsd.org> Resent-From: gnats (GNATS Management) Resent-To: freebsd-bugs Resent-Reply-To: FreeBSD-gnats@FreeBSD.ORG, ejh@eas.slu.edu 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 X-Send-Pr-Version: 3.2 Subject: bin/5173: restore ought to deal with root setable file flags Sender: owner-freebsd-bugs@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk >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: