xref: /titanic_50/usr/src/tools/elfsign/elfsigncmp.sh (revision 0a47c91c895e274dd0990009919e30e984364a8b)
1#! /usr/bin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# ident	"%Z%%M%	%I%	%E% SMI"
25#
26# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29
30prog=$0
31pd=`dirname $prog`
32MACH=`uname -p`
33elfcmp=$pd/elfcmp
34elfsign=$pd/$MACH/elfsign
35
36aopt=
37copt=
38eopt=
39Fopt=
40kopt=
41vopt=
42
43Usage() {
44	echo "Usage: $prog {sign|verify} [-v] [-a]" \
45		"[-c <cert>] [-k <key>] [-F <format>] -e <elf>" 1>&2
46	exit 1
47}
48
49if [ $# -lt 1 ]; then
50	Usage
51	fi
52cmd=$1
53shift
54
55while getopts "ac:e:F:k:v" opt ; do
56	case $opt in
57	a)	aopt=-a;;
58	c)	copt="$OPTARG";;
59	e)	eopt="$OPTARG";;
60	F)	Fopt="$OPTARG";;
61	k)	kopt="$OPTARG";;
62	v)	vopt=-v;;
63	\?)	Usage;;
64	esac
65done
66
67case X$eopt in X) Usage;; esac
68
69tmpe=$eopt.e$$
70tmpo=$eopt.o$$
71
72cpq() {
73	cp -p $1 $2 > /dev/null 2>&1
74}
75
76restore() {
77	cpq $tmpe $eopt
78}
79
80cleanup() {
81	restore
82	rm -f $tmpe $tmpo
83}
84
85trap cleanup 1 2 3 13 15
86
87cpq $eopt $tmpe
88
89eval $elfsign $cmd $aopt $vopt ${copt:+-c} ${copt} ${kopt:+-k} ${kopt} \
90	${Fopt:+-F} ${Fopt} -e ${eopt}
91rv=$?
92
93case $cmd:$rv in
94sign:0)
95	if $elfcmp -v -S $tmpe $eopt > $tmpo 2>&1
96	then
97		: # all's fine
98	else
99		rv=$?
100		echo "Warning: elfcmp failed: $eopt" 1>&2
101		cat ${tmpo} 1>&2
102		echo "current directory: `pwd`" 1>&2
103		restore
104		cpq ${eopt} ${eopt}.elfcmp.failed.$$
105	fi
106	;;
107sign:*)
108	restore
109	cpq ${eopt} ${eopt}.elfsign.failed.$$
110	;;
111esac
112
113rm -f $tmpe $tmpo
114exit $rv
115