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