From owner-svn-src-stable@freebsd.org Mon Apr 16 15:57:20 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 94C7FF8E482; Mon, 16 Apr 2018 15:57:19 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3367468F03; Mon, 16 Apr 2018 15:57:19 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2E3E01F757; Mon, 16 Apr 2018 15:57:19 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w3GFvJTf082945; Mon, 16 Apr 2018 15:57:19 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w3GFvILp082943; Mon, 16 Apr 2018 15:57:18 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <201804161557.w3GFvILp082943@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Mon, 16 Apr 2018 15:57:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r332585 - stable/11/etc/autofs X-SVN-Group: stable-11 X-SVN-Commit-Author: trasz X-SVN-Commit-Paths: stable/11/etc/autofs X-SVN-Commit-Revision: 332585 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Apr 2018 15:57:20 -0000 Author: trasz Date: Mon Apr 16 15:57:18 2018 New Revision: 332585 URL: https://svnweb.freebsd.org/changeset/base/332585 Log: MFC r325392: Add NIS automounter map, which supports rewriting of self-hosted locations to make them nullfs. PR: 221010 Added: stable/11/etc/autofs/include_nis - copied unchanged from r325392, head/etc/autofs/include_nis Modified: stable/11/etc/autofs/Makefile Directory Properties: stable/11/ (props changed) Modified: stable/11/etc/autofs/Makefile ============================================================================== --- stable/11/etc/autofs/Makefile Mon Apr 16 15:54:38 2018 (r332584) +++ stable/11/etc/autofs/Makefile Mon Apr 16 15:57:18 2018 (r332585) @@ -1,6 +1,6 @@ # $FreeBSD$ -FILES= include_ldap special_hosts special_media special_noauto special_null +FILES= include_ldap include_nis special_hosts special_media special_noauto special_null NO_OBJ= FILESDIR= /etc/autofs Copied: stable/11/etc/autofs/include_nis (from r325392, head/etc/autofs/include_nis) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/etc/autofs/include_nis Mon Apr 16 15:57:18 2018 (r332585, copy of r325392, head/etc/autofs/include_nis) @@ -0,0 +1,180 @@ +#!/usr/bin/awk -f +#- +# Copyright (c) 2017 G. Paul Ziemba +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 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. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +# +# /etc/autofs/include_nis +# +# automountd Directory Services script for NIS +# +# SYNOPSIS +# include_nis +# +# include_nis +# +# DESCRIPTION +# +# This script provides a Directory Services map for automountd +# based on NIS. Please see auto_master(5) for general information. +# +# The first form, with one argument, emits the entire named NIS map. +# The second form, with two arguments, emits the map entry for the +# key given in the second argument. +# +# This script attempts to determine the names and IP addresses +# of the local host. Map entries matching the local host are +# rewritten to specify nullfs mounts (instead of the default +# NFS) to reduce access overhead in the kernel. +# +# If a map entry contains multiple location fields, it is not changed. +# + + +# Populate list of names and IP addrs thet mean "this host" +# into myhostnames array +BEGIN { + # + # Set self hostnames + # + + "hostname -s" | getline; + myhostnames[$0] = 1; + + "hostname -f" | getline; + myhostnames[$0] = 1; + + myhostnames["localhost"] = 1 + + "hostname -f" | getline; + localdomain=$0 + myhostnames["localhost."localdomain] = 1 + + while ("ifconfig" | getline) { + if ($1 == "inet") { + myhostnames[$2] = 1; + } + } + + # debug +# print "--- hostname list start ----" +# for (i in myhostnames) { +# print i +# } +# print "--- hostname list end ----" + + if (ARGC == 2) { + # mapname only + while ("ypcat -k " ARGV[1] | getline) { + proc_mapline(1) + } + } + if (ARGC == 3) { + # mapname and keyname + while ("ypmatch " ARGV[2] " " ARGV[1] | getline) { + proc_mapline(0) + } + } + exit 0 +} + +function is_self(hostname) +{ + if (myhostnames[hostname]) { + return 1 + } + return 0 +} + +# +# Lines are of the form [key] [-opts] location1 [... locationN] +# +# indicate index of key field with first positional parameter +# 1 means keyfield is the first field +# 0 means keyfield is not present +# +function proc_mapline(keyfield) +{ + optionsfield = 0 + locationfield = 0 + locationcount = 0 + + for (i=keyfield+1; i <= NF; ++i) { + if (!optionsfield) { + if ($i ~ /^-/) { + # the first options field found on the line + optionsfield = i; + continue + } + } + # Assumption: location contains colon (":") + if (optionsfield && ($i ~ /:/) && ($i !~ /^-/)) { + ++locationcount + if (!locationfield) { + # the first location field found on the line + locationfield = i + } + } + } + + # + # If location not found, do not modify. + # + # If there is more than one location, do not modify. Rationale: + # Options are applied to all locations. We ca not have "nullfs" + # for only some locations and "nfs" for others for a given + # map key (i.e., a line). The usual reason for multiple + # locations is for redundancy using replicated volumes on + # multiple hosts, so multiple hosts imply fstype=nfs (the + # FreeBSD default for automounter maps). + # + # Hypothetically there could be a map entry with multiple + # locations all with host parts matching "me". In that case, + # it would be safe to rewrite the locations and specify + # nullfs, but the code does not handle this case. + # + if (locationcount == 1) { + # + # We have a line with exactly one location field + # + # Assumption: location has no more than one colon (":") + # + n=split($locationfield,location,":") + if (is_self(location[1])) { + $locationfield = ":" location[2] + if (optionsfield) { + # append to existing options + $optionsfield = $optionsfield ",fstype=nullfs" + } else { + # sneak in ahead of location + $locationfield = "-fstype=nullfs " $locationfield + } + } + } + + print +}