From owner-freebsd-hackers@FreeBSD.ORG Fri Sep 23 18:02:17 2005 Return-Path: X-Original-To: freebsd-hackers@FreeBSD.org Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 320B016A41F for ; Fri, 23 Sep 2005 18:02:17 +0000 (GMT) (envelope-from dougb@FreeBSD.org) Received: from mail1.fluidhosting.com (mail1.fluidhosting.com [204.14.90.61]) by mx1.FreeBSD.org (Postfix) with SMTP id 5F37A43D48 for ; Fri, 23 Sep 2005 18:02:16 +0000 (GMT) (envelope-from dougb@FreeBSD.org) Received: (qmail 75363 invoked by uid 399); 23 Sep 2005 18:02:15 -0000 Received: from localhost (HELO ?192.168.1.101?) (dougb@dougbarton.net@127.0.0.1) by localhost with SMTP; 23 Sep 2005 18:02:15 -0000 Message-ID: <43344324.10202@FreeBSD.org> Date: Fri, 23 Sep 2005 11:02:12 -0700 From: Doug Barton Organization: http://www.FreeBSD.org/ User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050908) X-Accept-Language: en-us, en MIME-Version: 1.0 To: freebsd-hackers@FreeBSD.org X-Enigmail-Version: 0.92.0.0 Content-Type: multipart/mixed; boundary="------------090401060105060209040000" Cc: Subject: Fixing an error condition for 'rm -P' X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Sep 2005 18:02:17 -0000 This is a multi-part message in MIME format. --------------090401060105060209040000 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit I have rm aliased to '/bin/rm -P', mostly for fun, but I like the idea. There is an oddity however when you use the -P flag, and the file is not writable. The check() function in rm.c specifically ignores this condition, and lets the thing fail later in the program. I think this is bad on an objective level, but it definitely leads to annoying problems for the user when you hit this condition. I therefore propose the attached patch. Doug -- This .signature sanitized for your protection --------------090401060105060209040000 Content-Type: text/plain; name="rm-P-errx.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="rm-P-errx.diff" Index: rm.c =================================================================== RCS file: /usr/local/ncvs/src/bin/rm/rm.c,v retrieving revision 1.52 diff -u -r1.52 rm.c --- rm.c 13 Nov 2004 04:07:01 -0000 1.52 +++ rm.c 23 Sep 2005 08:29:38 -0000 @@ -452,11 +452,8 @@ * talking to a terminal, ask. Symbolic links are excluded * because their permissions are meaningless. Check stdin_ok * first because we may not have stat'ed the file. - * Also skip this check if the -P option was specified because - * we will not be able to overwrite file contents and will - * barf later. */ - if (!stdin_ok || S_ISLNK(sp->st_mode) || Pflag || + if (!stdin_ok || S_ISLNK(sp->st_mode) || (!access(name, W_OK) && !(sp->st_flags & (SF_APPEND|SF_IMMUTABLE)) && (!(sp->st_flags & (UF_APPEND|UF_IMMUTABLE)) || !uid))) @@ -464,6 +461,9 @@ strmode(sp->st_mode, modep); if ((flagsp = fflagstostr(sp->st_flags)) == NULL) err(1, "fflagstostr"); + if (Pflag) + errx(1, + "-P was specified, but %s is not writable", path); (void)fprintf(stderr, "override %s%s%s/%s %s%sfor %s? ", modep + 1, modep[9] == ' ' ? "" : " ", user_from_uid(sp->st_uid, 0), --------------090401060105060209040000--