xref: /onnv-gate/usr/src/cmd/cmd-crypto/scripts/i.kmfconf (revision 5626:1f8878c75f54)
1*5626Shylee#
2*5626Shylee# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
3*5626Shylee# Use is subject to license terms.
4*5626Shylee#
5*5626Shylee# CDDL HEADER START
6*5626Shylee#
7*5626Shylee# The contents of this file are subject to the terms of the
8*5626Shylee# Common Development and Distribution License (the "License").
9*5626Shylee# You may not use this file except in compliance with the License.
10*5626Shylee#
11*5626Shylee# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
12*5626Shylee# or http://www.opensolaris.org/os/licensing.
13*5626Shylee# See the License for the specific language governing permissions
14*5626Shylee# and limitations under the License.
15*5626Shylee#
16*5626Shylee# When distributing Covered Code, include this CDDL HEADER in each
17*5626Shylee# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
18*5626Shylee# If applicable, add the following below this CDDL HEADER, with the
19*5626Shylee# fields enclosed by brackets "[]" replaced with your own identifying
20*5626Shylee# information: Portions Copyright [yyyy] [name of copyright owner]
21*5626Shylee#
22*5626Shylee# CDDL HEADER END
23*5626Shylee#
24*5626Shylee# ident	"%Z%%M%	%I%	%E% SMI"
25*5626Shylee#
26*5626Shylee# Class action script for "kmfconf" class files.
27*5626Shylee#
28*5626Shylee# This script appends the input file from the package to the
29*5626Shylee# /etc/crypto/kmf.conf file.
30*5626Shylee#
31*5626Shylee# The syntax of the input file is
32*5626Shylee# keystore:modulepath=path[;option=option_str]
33*5626Shylee#
34*5626Shylee#
35*5626Shyleepkg_start="# Start $PKGINST"
36*5626Shyleepkg_end="# End $PKGINST"
37*5626Shyleetmpfile=/tmp/$$kmfconf
38*5626Shyleeerror=no
39*5626Shylee
40*5626Shyleewhile read src dest
41*5626Shyleedo
42*5626Shylee	[ "$src" = /dev/null ] && continue
43*5626Shylee
44*5626Shylee	if [ -f "$dest" ]
45*5626Shylee	then
46*5626Shylee		# For multiple input files; exit if error occurred in previous
47*5626Shylee		# input file.
48*5626Shylee		if [ "$error" = yes ]
49*5626Shylee		then
50*5626Shylee			echo "$0: failed to update $lastdest for $PKGINST."
51*5626Shylee			exit 2
52*5626Shylee		fi
53*5626Shylee		lastdest=$dest
54*5626Shylee
55*5626Shylee		#
56*5626Shylee		# If the package has been already installed, remove old entries
57*5626Shylee		#
58*5626Shylee		start=0;
59*5626Shylee		end=0;
60*5626Shylee		egrep -s "$pkg_start" $dest && start=1
61*5626Shylee		egrep -s "$pkg_end" $dest && end=1
62*5626Shylee
63*5626Shylee		if [ $start -ne $end ]
64*5626Shylee		then
65*5626Shylee			echo "$0: missing Start or End delimiters for \
66*5626Shylee			    $PKGINST in $dest."
67*5626Shylee			echo "$0: $dest may be corrupted and was not updated."
68*5626Shylee			error=yes
69*5626Shylee			continue
70*5626Shylee		fi
71*5626Shylee
72*5626Shylee		if [ $start -eq 1 ]
73*5626Shylee		then
74*5626Shylee			sed -e "/$pkg_start/,/$pkg_end/d" $dest > $tmpfile \
75*5626Shylee                        || error=yes
76*5626Shylee		else
77*5626Shylee			cp $dest $tmpfile || error=yes
78*5626Shylee		fi
79*5626Shylee
80*5626Shylee		#
81*5626Shylee		# Check the input file syntax (should at least contain
82*5626Shylee		# ":module_path=").  Then append the input entries with the
83*5626Shylee		#scc package delimiters.
84*5626Shylee		#
85*5626Shylee		line_count=`wc -l $src | awk '{ print $1}'`
86*5626Shylee		file_count=`grep ":modulepath=" $src | wc -l`
87*5626Shylee		if [ $line_count -ne $file_count ]
88*5626Shylee		then
89*5626Shylee			echo "$0: Syntax Error - $src for $PKGINST."
90*5626Shylee			error=yes
91*5626Shylee			continue
92*5626Shylee		else
93*5626Shylee			echo "$pkg_start" >> $tmpfile || error=yes
94*5626Shylee			cat $src >> $tmpfile || error=yes
95*5626Shylee			echo "$pkg_end" >> $tmpfile || error=yes
96*5626Shylee		fi
97*5626Shylee
98*5626Shylee		# Install the updated config file and clean up the tmp file
99*5626Shylee                if [ "$error" = no ]
100*5626Shylee                then
101*5626Shylee			mv $tmpfile $dest || error=yes
102*5626Shylee		fi
103*5626Shylee		rm -f $tmpfile
104*5626Shylee	else
105*5626Shylee		echo "$0: ERROR - $dest doesn't exist for $PKGINST."
106*5626Shylee		exit 2
107*5626Shylee	fi
108*5626Shyleedone
109*5626Shylee
110*5626Shyleeif [ "$error" = yes ]
111*5626Shyleethen
112*5626Shylee	echo "$0: ERROR - failed to update $lastdest for $PKGINST."
113*5626Shylee	exit 2
114*5626Shyleefi
115*5626Shylee
116*5626Shyleeexit 0
117