svc-rbac revision 8d0bff0b85e6c35d0d862cff1607cded58bf2341
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#! /usr/bin/sh
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# CDDL HEADER START
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# The contents of this file are subject to the terms of the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# Common Development and Distribution License (the "License").
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# You may not use this file except in compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# or http://www.opensolaris.org/os/licensing.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# See the License for the specific language governing permissions
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# When distributing Covered Code, include this CDDL HEADER in each
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# If applicable, add the following below this CDDL HEADER, with the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# fields enclosed by brackets "[]" replaced with your own identifying
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# information: Portions Copyright [yyyy] [name of copyright owner]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# CDDL HEADER END
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster. /lib/svc/share/smf_include.sh
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfiles='/etc/user_attr /etc/security/auth_attr /etc/security/exec_attr
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /etc/security/prof_attr'
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan FosterPKGINST=
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterexport PKGINST
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterirbac=/usr/sadm/install/scripts/i.rbac
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterif [ ! -x $irbac ]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterthen
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster echo "${irbac}: not found."
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster exit $SMF_EXIT_ERR_FATAL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfi
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fostercase "$1" in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterstart|refresh)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ;;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterstop)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster exit $SMF_EXIT_OK;;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster*)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster echo "Usage: $0 { start | refresh | stop }"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster exit $SMF_EXIT_ERR_FATAL;;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosteresac
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fostertmp_rbac=`/usr/bin/mktemp -d /tmp/rbac.XXXXXX`
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterif [ -z "$tmp_rbac" ]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterthen
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster echo "Could not create temporary directory."
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster exit $SMF_EXIT_ERR_FATAL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfi
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fostertmp_frag=$tmp_rbac/frag
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fostertmp_file=$tmp_rbac/file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfor f in $files
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterdo
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster d=${f}.d
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if [ ! -d ${d} ]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster then
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # No directory, nothing to do
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster continue
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster fi
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # cache user/owner of file to update
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ownergroup=`ls -ln $f | awk '{printf("%s:%s\n", $3, $4);'}`
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # List all the files in the directory and the destination file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # in the order of their timestamp. Older files are displayed
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # first. If a fragment file is listed before the destination
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # file, it is an older fragment that has already been processed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # If a fragment file is listed after the destination file, it is
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # new, and the destination file must be updated.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # Comments are processed separately from the other file contents.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # For new fragments only, the comments are processed as they are
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # encountered. For all fragments, the non-comment contents are
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # saved in a temporary file. After all fragments have been
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # processed, and only if new fragments were found, the contents
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # of the temporary file are processed. This ensures that older
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster # but still valid entries are retained in the destination file.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /usr/bin/rm -f $tmp_file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster new_frag=0
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster update=0
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for frag in `ls -tr $f $d/* 2> /dev/null`
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster do
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if [ "$frag" = "$f" ]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster then
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster new_frag=1
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster continue
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster fi
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if [ -f "$frag" ]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster then
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if [ $new_frag -eq 1 ]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster then
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /usr/bin/rm -f $tmp_frag
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /usr/bin/grep '^#' $frag > $tmp_frag
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster update=1
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster echo $tmp_frag $f | $irbac
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster fi
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /usr/bin/grep -v '^#' $frag >> $tmp_file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster fi
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster done
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if [ $update -eq 1 ]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster then
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster echo $tmp_file $f | $irbac
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster chown $ownergroup $f
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster fi
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterdone
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/usr/bin/rm -rf $tmp_rbac
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterexit $SMF_EXIT_OK
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster