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