From owner-freebsd-hackers@FreeBSD.ORG Fri Sep 23 08:40:13 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 18F4616A41F for ; Fri, 23 Sep 2005 08:40:13 +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 8DF7B43D46 for ; Fri, 23 Sep 2005 08:40:12 +0000 (GMT) (envelope-from dougb@FreeBSD.org) Received: (qmail 77494 invoked by uid 399); 23 Sep 2005 08:40:11 -0000 Received: from localhost (HELO ?192.168.1.101?) (dougb@dougbarton.net@127.0.0.1) by localhost with SMTP; 23 Sep 2005 08:40:11 -0000 Message-ID: <4333BF64.8060800@FreeBSD.org> Date: Fri, 23 Sep 2005 01:40:04 -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/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig30CFA0F9AC8D39308ACE893B" 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 08:40:13 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig30CFA0F9AC8D39308ACE893B Content-Type: multipart/mixed; boundary="------------090205000709030308020100" This is a multi-part message in MIME format. --------------090205000709030308020100 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 --------------090205000709030308020100 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), --------------090205000709030308020100-- --------------enig30CFA0F9AC8D39308ACE893B Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (FreeBSD) iD8DBQFDM79oyIakK9Wy8PsRAoMpAJ9xXeZVocG3G4dvR020VsX5xQQw5QCgnFfU yebHKrFRZTzt2RIgEEgDNrc= =KVoZ -----END PGP SIGNATURE----- --------------enig30CFA0F9AC8D39308ACE893B--