From 1daf624a7a99d096cf50fb7789e33d60472cfd3f Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sat, 10 Mar 2018 11:59:29 +0800 Subject: [PATCH] locate(1): Bring in some updates/fixes from FreeBSD * The default value of "FILESYSTEMS" option is now determined using lsvfs(1), which contains all local file systems that are not synthetic, loopback mounts or read-only. * New config option "PRUNEDIRS" in /etc/locate.rc with default value of ".git" to ignore the ".git" directories when making database. * Warn when locate.updatedb(8) is directly run by root * Some cleanups (no functional change) * Improve license declarations, fix white spaces and typos --- usr.bin/locate/Makefile | 1 - usr.bin/locate/Makefile.inc | 1 - usr.bin/locate/bigram/Makefile | 3 +- usr.bin/locate/bigram/locate.bigram.c | 6 ++-- usr.bin/locate/code/Makefile | 3 +- usr.bin/locate/locate/Makefile | 1 - usr.bin/locate/locate/concatdb.sh | 1 - usr.bin/locate/locate/locate.c | 2 +- usr.bin/locate/locate/locate.rc | 16 +++++++--- usr.bin/locate/locate/locate.updatedb.8 | 3 +- usr.bin/locate/locate/mklocatedb.sh | 5 +-- usr.bin/locate/locate/pathnames.h | 9 +++++- usr.bin/locate/locate/updatedb.sh | 54 +++++++++++++++++++++------------ 13 files changed, 65 insertions(+), 40 deletions(-) diff --git a/usr.bin/locate/Makefile b/usr.bin/locate/Makefile index 84badbcd4b..06d65d02f9 100644 --- a/usr.bin/locate/Makefile +++ b/usr.bin/locate/Makefile @@ -1,6 +1,5 @@ # @(#)Makefile 8.1 (Berkeley) 6/6/93 # $FreeBSD: src/usr.bin/locate/Makefile,v 1.6 1999/08/28 01:02:52 peter Exp $ -# $DragonFly: src/usr.bin/locate/Makefile,v 1.3 2004/01/31 06:56:44 dillon Exp $ SUBDIR= bigram code locate diff --git a/usr.bin/locate/Makefile.inc b/usr.bin/locate/Makefile.inc index 72cffb42fe..1d24a77d84 100644 --- a/usr.bin/locate/Makefile.inc +++ b/usr.bin/locate/Makefile.inc @@ -1,5 +1,4 @@ # $FreeBSD: src/usr.bin/locate/Makefile.inc,v 1.4 1999/08/28 01:02:52 peter Exp $ -# $DragonFly: src/usr.bin/locate/Makefile.inc,v 1.2 2003/06/17 04:29:28 dillon Exp $ LIBEXECDIR?= /usr/libexec WARNS?= 2 diff --git a/usr.bin/locate/bigram/Makefile b/usr.bin/locate/bigram/Makefile index d6717dd7cf..c599743005 100644 --- a/usr.bin/locate/bigram/Makefile +++ b/usr.bin/locate/bigram/Makefile @@ -1,9 +1,8 @@ # @(#)Makefile 8.1 (Berkeley) 6/6/93 # $FreeBSD: src/usr.bin/locate/bigram/Makefile,v 1.4 1999/08/28 01:02:53 peter Exp $ -# $DragonFly: src/usr.bin/locate/bigram/Makefile,v 1.3 2007/08/27 16:50:55 pavalos Exp $ PROG= locate.bigram -NOMAN= noman +NOMAN= BINDIR= ${LIBEXECDIR} CFLAGS+= -I${.CURDIR}/../locate diff --git a/usr.bin/locate/bigram/locate.bigram.c b/usr.bin/locate/bigram/locate.bigram.c index b4690a4312..1b61303809 100644 --- a/usr.bin/locate/bigram/locate.bigram.c +++ b/usr.bin/locate/bigram/locate.bigram.c @@ -1,4 +1,6 @@ /* + * SPDX-License-Identifier: BSD-4-Clause + * * Copyright (c) 1995 Wolfram Schneider . Berlin. * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -34,7 +36,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/usr.bin/locate/bigram/locate.bigram.c,v 1.11 1999/08/28 01:02:54 peter Exp $ + * $FreeBSD: head/usr.bin/locate/bigram/locate.bigram.c 325966 2017-11-18 14:26:50Z pfg $ * * @(#) Copyright (c) 1989, 1993 The Regents of the University of California. All rights reserved. * @(#)locate.bigram.c 8.1 (Berkeley) 6/6/93 @@ -60,7 +62,7 @@ static u_int bigram[UCHAR_MAX + 1][UCHAR_MAX + 1]; int main(void) { - u_char *cp; + u_char *cp; u_char *oldpath = buf1, *path = buf2; u_int i, j; diff --git a/usr.bin/locate/code/Makefile b/usr.bin/locate/code/Makefile index 232d2fdc81..2c3e8a2e1f 100644 --- a/usr.bin/locate/code/Makefile +++ b/usr.bin/locate/code/Makefile @@ -1,10 +1,9 @@ # @(#)Makefile 8.1 (Berkeley) 6/6/93 # $FreeBSD: src/usr.bin/locate/code/Makefile,v 1.4 1999/08/28 01:02:55 peter Exp $ -# $DragonFly: src/usr.bin/locate/code/Makefile,v 1.3 2007/08/27 16:50:55 pavalos Exp $ PROG= locate.code CFLAGS+=-I${.CURDIR}/../locate -NOMAN= noman +NOMAN= BINDIR= ${LIBEXECDIR} .include diff --git a/usr.bin/locate/locate/Makefile b/usr.bin/locate/locate/Makefile index a498763d29..9ce7dd6dd1 100644 --- a/usr.bin/locate/locate/Makefile +++ b/usr.bin/locate/locate/Makefile @@ -1,6 +1,5 @@ # @(#)Makefile 8.1 (Berkeley) 6/6/93 # $FreeBSD: src/usr.bin/locate/locate/Makefile,v 1.11.2.4 2002/08/07 16:32:01 ru Exp $ -# $DragonFly: src/usr.bin/locate/locate/Makefile,v 1.3 2007/08/27 16:50:55 pavalos Exp $ PROG= locate SRCS= util.c locate.c diff --git a/usr.bin/locate/locate/concatdb.sh b/usr.bin/locate/locate/concatdb.sh index 55bde0fe5e..a236332a8d 100644 --- a/usr.bin/locate/locate/concatdb.sh +++ b/usr.bin/locate/locate/concatdb.sh @@ -31,7 +31,6 @@ # Sequence of databases is important. # # $FreeBSD: src/usr.bin/locate/locate/concatdb.sh,v 1.10 2000/01/12 08:01:00 kris Exp $ -# $DragonFly: src/usr.bin/locate/locate/concatdb.sh,v 1.2 2003/06/17 04:29:28 dillon Exp $ # The directory containing locate subprograms : ${LIBEXECDIR:=/usr/libexec}; export LIBEXECDIR diff --git a/usr.bin/locate/locate/locate.c b/usr.bin/locate/locate/locate.c index 8d567eb5fd..c7477c1554 100644 --- a/usr.bin/locate/locate/locate.c +++ b/usr.bin/locate/locate/locate.c @@ -177,7 +177,7 @@ main(int argc, char **argv) /* no (valid) database as argument */ if (dbv == NULL || *dbv == NULL) { - /* try to read database from enviroment */ + /* try to read database from environment */ if ((path_fcodes = getenv("LOCATE_PATH")) == NULL || *path_fcodes == '\0') /* use default database */ diff --git a/usr.bin/locate/locate/locate.rc b/usr.bin/locate/locate/locate.rc index baf4727519..2d383055c7 100644 --- a/usr.bin/locate/locate/locate.rc +++ b/usr.bin/locate/locate/locate.rc @@ -1,8 +1,7 @@ # # /etc/locate.rc - command script for updatedb(8) # -# $FreeBSD: src/usr.bin/locate/locate/locate.rc,v 1.8 1999/08/28 01:02:59 peter Exp $ -# $DragonFly: src/usr.bin/locate/locate/locate.rc,v 1.3 2008/07/09 19:53:27 swildner Exp $ +# $FreeBSD: head/usr.bin/locate/locate/locate.rc 290742 2015-11-13 06:16:12Z des $ # # All commented values are the defaults @@ -16,12 +15,19 @@ # directories to be put in the database #SEARCHPATHS="/" -# directories unwanted in output +# paths unwanted in output #PRUNEPATHS="/tmp /usr/tmp /var/tmp" +# directories unwanted in output +#PRUNEDIRS=".git" + # filesystems allowed. Beware: a non-listed filesystem will be pruned # and if the SEARCHPATHS starts in such a filesystem locate will build # an empty database. # -# be careful if you add 'nfs' -#FILESYSTEMS="hammer hammer2 ufs" +# the default list contains all local file systems that are not synthetic, +# loopback mounts, or read-only, according to lsvfs. +# +# be careful if you add 'nfs' or other network file system types or file +# systems that generally reside on slow or removable devices like cd9660 +#FILESYSTEMS="ufs hammer hammer2" diff --git a/usr.bin/locate/locate/locate.updatedb.8 b/usr.bin/locate/locate/locate.updatedb.8 index 55c5f084f5..9d690bf7a7 100644 --- a/usr.bin/locate/locate/locate.updatedb.8 +++ b/usr.bin/locate/locate/locate.updatedb.8 @@ -28,8 +28,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/usr.bin/locate/locate/locate.updatedb.8,v 1.7.2.4 2003/02/25 20:31:18 trhodes Exp $ -.\" $DragonFly: src/usr.bin/locate/locate/locate.updatedb.8,v 1.3 2006/02/17 19:39:09 swildner Exp $ +.\" $FreeBSD: head/usr.bin/locate/locate/locate.updatedb.8 140420 2005-01-18 13:43:56Z ru $ .\" .Dd February 11, 1996 .Dt LOCATE.UPDATEDB 8 diff --git a/usr.bin/locate/locate/mklocatedb.sh b/usr.bin/locate/locate/mklocatedb.sh index 3415dfac80..59be339c42 100644 --- a/usr.bin/locate/locate/mklocatedb.sh +++ b/usr.bin/locate/locate/mklocatedb.sh @@ -1,5 +1,7 @@ #!/bin/sh # +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) September 1995 Wolfram Schneider . Berlin. # All rights reserved. # @@ -28,8 +30,7 @@ # # usage: mklocatedb [-presort] < filelist > database # -# $FreeBSD: src/usr.bin/locate/locate/mklocatedb.sh,v 1.13 2002/07/22 05:35:59 tjr Exp $ -# $DragonFly: src/usr.bin/locate/locate/mklocatedb.sh,v 1.3 2004/11/15 10:01:41 joerg Exp $ +# $FreeBSD: head/usr.bin/locate/locate/mklocatedb.sh 326276 2017-11-27 15:37:16Z pfg $ # The directory containing locate subprograms : ${LIBEXECDIR:=/usr/libexec}; export LIBEXECDIR diff --git a/usr.bin/locate/locate/pathnames.h b/usr.bin/locate/locate/pathnames.h index ecb11b8aff..4985aa0600 100644 --- a/usr.bin/locate/locate/pathnames.h +++ b/usr.bin/locate/locate/pathnames.h @@ -1,4 +1,6 @@ /* + * SPDX-License-Identifier: BSD-4-Clause + * * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,7 +12,11 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -27,6 +33,7 @@ * SUCH DAMAGE. * * @(#)pathnames.h 8.1 (Berkeley) 6/6/93 + * $FreeBSD: head/usr.bin/locate/locate/pathnames.h 325966 2017-11-18 14:26:50Z pfg $ */ #define _PATH_FCODES "/var/db/locate.database" diff --git a/usr.bin/locate/locate/updatedb.sh b/usr.bin/locate/locate/updatedb.sh index 35a53c2271..19ae6655c0 100644 --- a/usr.bin/locate/locate/updatedb.sh +++ b/usr.bin/locate/locate/updatedb.sh @@ -1,5 +1,7 @@ #!/bin/sh # +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# # Copyright (c) September 1995 Wolfram Schneider . Berlin. # All rights reserved. # @@ -26,9 +28,13 @@ # # updatedb - update locate database for local mounted filesystems # -# $FreeBSD: src/usr.bin/locate/locate/updatedb.sh,v 1.17 2000/01/12 08:01:01 kris Exp $ -# $DragonFly: src/usr.bin/locate/locate/updatedb.sh,v 1.3 2008/07/09 19:53:27 swildner Exp $ +# $FreeBSD: head/usr.bin/locate/locate/updatedb.sh 326276 2017-11-27 15:37:16Z pfg $ +if [ "$(id -u)" = "0" ]; then + echo ">>> WARNING" 1>&2 + echo ">>> Executing updatedb as root. This WILL reveal all filenames" 1>&2 + echo ">>> on your machine to all login users, which is a security risk." 1>&2 +fi : ${LOCATE_CONFIG="/etc/locate.rc"} if [ -f "$LOCATE_CONFIG" -a -r "$LOCATE_CONFIG" ]; then . $LOCATE_CONFIG @@ -48,13 +54,18 @@ PATH=$LIBEXECDIR:/bin:/usr/bin:$PATH; export PATH : ${FCODES:=/var/db/locate.database} # the database : ${SEARCHPATHS:="/"} # directories to be put in the database : ${PRUNEPATHS:="/tmp /usr/tmp /var/tmp"} # unwanted directories -: ${FILESYSTEMS:="hammer hammer2 ufs"} # allowed filesystems +: ${PRUNEDIRS:=".git"} # unwanted directories, in any parent +: ${FILESYSTEMS:="$(lsvfs | tail -n +3 | \ + egrep -vw "loopback|network|synthetic|read-only|0" | \ + cut -d " " -f1)"} # allowed filesystems : ${find:=find} -case X"$SEARCHPATHS" in - X) echo "$0: empty variable SEARCHPATHS"; exit 1;; esac -case X"$FILESYSTEMS" in - X) echo "$0: empty variable FILESYSTEMS"; exit 1;; esac +if [ -z "$SEARCHPATHS" ]; then + echo "$0: empty variable SEARCHPATHS" >&2; exit 1 +fi +if [ -z "$FILESYSTEMS" ]; then + echo "$0: empty variable FILESYSTEMS" >&2; exit 1 +fi # Make a list a paths to exclude in the locate run excludes="! (" or="" @@ -65,25 +76,30 @@ do done excludes="$excludes ) -prune" -case X"$PRUNEPATHS" in - X) ;; - *) for path in $PRUNEPATHS - do +if [ -n "$PRUNEPATHS" ]; then + for path in $PRUNEPATHS; do excludes="$excludes -or -path $path -prune" - done;; -esac + done +fi + +if [ -n "$PRUNEDIRS" ]; then + for dir in $PRUNEDIRS; do + excludes="$excludes -or -name $dir -type d -prune" + done +fi tmp=$TMPDIR/_updatedb$$ trap 'rm -f $tmp; rmdir $TMPDIR' 0 1 2 3 5 10 15 - + # search locally # echo $find $SEARCHPATHS $excludes -or -print && exit if $find -s $SEARCHPATHS $excludes -or -print 2>/dev/null | $mklocatedb -presort > $tmp then - case X"`$find $tmp -size -257c -print`" in - X) cat $tmp > $FCODES;; - *) echo "updatedb: locate database $tmp is empty" - exit 1 - esac + if [ -n "$($find $tmp -size -257c -print)" ]; then + echo "updatedb: locate database $tmp is empty" >&2 + exit 1 + else + cat $tmp > $FCODES # should be cp? + fi fi -- 2.11.4.GIT