From owner-freebsd-current@FreeBSD.ORG Fri Nov 2 04:24:05 2007 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 02F4316A418 for ; Fri, 2 Nov 2007 04:24:05 +0000 (UTC) (envelope-from aryeh.friedman@gmail.com) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.231]) by mx1.freebsd.org (Postfix) with ESMTP id 91EE213C465 for ; Fri, 2 Nov 2007 04:24:04 +0000 (UTC) (envelope-from aryeh.friedman@gmail.com) Received: by wx-out-0506.google.com with SMTP id i29so615479wxd for ; Thu, 01 Nov 2007 21:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:content-type:content-transfer-encoding; bh=g/YRNcv4bsWbEBTHUwjSa1R6WnOfNOyNMPrHWCKCXI0=; b=WSU3vWRel0vhka0w3znJQmf0OM7uPUS2vWjMsYduSCMIQGTas+F+orYGNxqzv2pBay6877hBy28+O87yqyf/WASQkNxW2A3NckoV6BIsQXA3LB+i065MkaKiJ1eVVAq8TOmu2/T1W3P1F9MhXOaV6aRtZOe96875aqtQ45euPzE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:subject:content-type:content-transfer-encoding; b=m3MmB2CrA20KlFms0OGDlG7JCA2NNUcbWbw87haLx5vnrV+4Xb0fXUmI5P03lKzyw9nAkPpX+brOmU1ljkOOXBj29z8GRyvGIwcPqiVTbia4NSVWltMSXrGBcdaHRJzjkiTc0NQ/JdHO7aHp6n/zH3L6pi4hbWpCJ9THaeAlfmE= Received: by 10.70.27.5 with SMTP id a5mr1879006wxa.1193975667536; Thu, 01 Nov 2007 20:54:27 -0700 (PDT) Received: from ?192.168.2.2? ( [67.85.89.184]) by mx.google.com with ESMTPS id c29sm2220044elf.2007.11.01.20.54.25 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 01 Nov 2007 20:54:26 -0700 (PDT) Message-ID: <472A66EE.6060407@gmail.com> Date: Thu, 01 Nov 2007 19:53:18 -0400 From: "Aryeh M. Friedman" User-Agent: Thunderbird 2.0.0.6 (X11/20071031) MIME-Version: 1.0 To: freebsd-current@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: [PATCH] prevent install(1) from overwritting symlinks X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Nov 2007 04:24:05 -0000 The below patch is designed to keep install(1) from overwriting symbolic links. The motivation is if cups is installed some programs still expect lpr to be in /usr/bin thus when I install cups I backlink the /usr/local/bin versions of lp* to /usr/bin. When a build/installworld is done these links are overwritten and the sym links have to be performed again. This patch prevents the overwrite. This is my very first patch (of any kind [not just for FreeBSD]) so can people please tell me what I did right and what I did wrong in making it. Also tell me what improvements (if any) can be made to the patched code. --- src/usr.bin/xinstall/xinstall.c.orig 2007-11-01 18:46:45.000000000 -0400 +++ src/usr.bin/xinstall/xinstall.c 2007-11-01 19:44:43.000000000 -0400 @@ -268,7 +268,7 @@ void install(const char *from_name, const char *to_name, u_long fset, u_int flags) { - struct stat from_sb, temp_sb, to_sb; + struct stat from_sb, temp_sb, to_sb, to_lsb; struct timeval tvb[2]; int devnull, files_match, from_fd, serrno, target; int tempcopy, temp_fd, to_fd; @@ -299,6 +299,13 @@ } target = stat(to_name, &to_sb) == 0; + target = lstat(to_name, &to_lsb) == 0; + + if(S_ISLNK(to_lsb.st_mode)) { + printf("%s is a symbolic link not modified\n",to_name); + errno = EFTYPE; + return; + } /* Only install to regular files. */ if (target && !S_ISREG(to_sb.st_mode)) {