Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 01 Nov 2007 19:53:18 -0400
From:      "Aryeh M. Friedman" <aryeh.friedman@gmail.com>
To:        freebsd-current@freebsd.org
Subject:   [PATCH] prevent install(1) from overwritting symlinks
Message-ID:  <472A66EE.6060407@gmail.com>

next in thread | raw e-mail | index | archive | help
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)) {




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?472A66EE.6060407>