xref: /onnv-gate/usr/src/lib/libsecdb/common/i.rbac (revision 12690)
111838SLiane.Praza@Sun.COM#!/bin/sh
211838SLiane.Praza@Sun.COM#
311838SLiane.Praza@Sun.COM# CDDL HEADER START
411838SLiane.Praza@Sun.COM#
511838SLiane.Praza@Sun.COM# The contents of this file are subject to the terms of the
611838SLiane.Praza@Sun.COM# Common Development and Distribution License (the "License").
711838SLiane.Praza@Sun.COM# You may not use this file except in compliance with the License.
811838SLiane.Praza@Sun.COM#
911838SLiane.Praza@Sun.COM# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1011838SLiane.Praza@Sun.COM# or http://www.opensolaris.org/os/licensing.
1111838SLiane.Praza@Sun.COM# See the License for the specific language governing permissions
1211838SLiane.Praza@Sun.COM# and limitations under the License.
1311838SLiane.Praza@Sun.COM#
1411838SLiane.Praza@Sun.COM# When distributing Covered Code, include this CDDL HEADER in each
1511838SLiane.Praza@Sun.COM# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1611838SLiane.Praza@Sun.COM# If applicable, add the following below this CDDL HEADER, with the
1711838SLiane.Praza@Sun.COM# fields enclosed by brackets "[]" replaced with your own identifying
1811838SLiane.Praza@Sun.COM# information: Portions Copyright [yyyy] [name of copyright owner]
1911838SLiane.Praza@Sun.COM#
2011838SLiane.Praza@Sun.COM# CDDL HEADER END
2111838SLiane.Praza@Sun.COM#
2211838SLiane.Praza@Sun.COM# i.rbac
2311838SLiane.Praza@Sun.COM#
24*12690Snathan.bush@oracle.com# Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2511838SLiane.Praza@Sun.COM#
2611838SLiane.Praza@Sun.COM# class action script for "rbac" class files
2711838SLiane.Praza@Sun.COM# installed by pkgadd
2811838SLiane.Praza@Sun.COM#
2911838SLiane.Praza@Sun.COM# Files in "rbac" class:
3011838SLiane.Praza@Sun.COM#
3111838SLiane.Praza@Sun.COM# /etc/security/{prof_attr,exec_attr,auth_attr}
3211838SLiane.Praza@Sun.COM# /etc/user_attr
3311838SLiane.Praza@Sun.COM#
3411838SLiane.Praza@Sun.COM#  Allowable exit codes
3511838SLiane.Praza@Sun.COM#
3611838SLiane.Praza@Sun.COM# 0 - success
3711838SLiane.Praza@Sun.COM# 2 - warning or possible error condition. Installation continues. A warning
3811838SLiane.Praza@Sun.COM#     message is displayed at the time of completion.
3911838SLiane.Praza@Sun.COM#
4011838SLiane.Praza@Sun.COM
4111838SLiane.Praza@Sun.COMumask 022
4211838SLiane.Praza@Sun.COM
4311838SLiane.Praza@Sun.COMtmp_dir=${TMPDIR:-/tmp}
4411838SLiane.Praza@Sun.COM
4511838SLiane.Praza@Sun.COMPATH="/usr/bin:/usr/sbin:${PATH}"
4611838SLiane.Praza@Sun.COMexport PATH
4711838SLiane.Praza@Sun.COM
4811838SLiane.Praza@Sun.COMbasename_cmd=basename
4911838SLiane.Praza@Sun.COMcp_cmd=cp
5011838SLiane.Praza@Sun.COMegrep_cmd=egrep
5111838SLiane.Praza@Sun.COMmv_cmd=mv
5211838SLiane.Praza@Sun.COMnawk_cmd=nawk
5311838SLiane.Praza@Sun.COMrm_cmd=rm
5411838SLiane.Praza@Sun.COMsed_cmd=sed
5511838SLiane.Praza@Sun.COMsort_cmd=sort
5611838SLiane.Praza@Sun.COM
5711838SLiane.Praza@Sun.COM# $1 is the type
5811838SLiane.Praza@Sun.COM# $2 is the "old/existing file"
5911838SLiane.Praza@Sun.COM# $3 is the "new (to be merged)" file
6011838SLiane.Praza@Sun.COM# $4 is the output file
6111838SLiane.Praza@Sun.COM# returns 0 on success
6211838SLiane.Praza@Sun.COM# returns 2 on failure if nawk fails with non-zero exit status
6311838SLiane.Praza@Sun.COM#
6411838SLiane.Praza@Sun.COMdbmerge() {
6511838SLiane.Praza@Sun.COM#
6611838SLiane.Praza@Sun.COM# Remove the ident lines.
6711838SLiane.Praza@Sun.COM#
6811838SLiane.Praza@Sun.COM	${egrep_cmd} -v '^#[pragma 	]*ident' $2 > $4.old 2>/dev/null
6911838SLiane.Praza@Sun.COM#
7011838SLiane.Praza@Sun.COM# If the new file has a Sun copyright, remove the Sun copyright from the old
7111838SLiane.Praza@Sun.COM# file.
7211838SLiane.Praza@Sun.COM#
7311838SLiane.Praza@Sun.COM	newcr=`${egrep_cmd} '^# Copyright.*Sun Microsystems, Inc.' $3 \
7411838SLiane.Praza@Sun.COM	    2>/dev/null`
7511838SLiane.Praza@Sun.COM	if [ -n "${newcr}" ]; then
7611838SLiane.Praza@Sun.COM		$sed_cmd -e '/^# Copyright.*Sun Microsystems, Inc./d' \
7711838SLiane.Praza@Sun.COM		    -e '/^# All rights reserved./d' \
7811838SLiane.Praza@Sun.COM		    -e '/^# Use is subject to license terms./d' \
7911838SLiane.Praza@Sun.COM		    $4.old > $4.$$ 2>/dev/null
8011838SLiane.Praza@Sun.COM		$mv_cmd $4.$$ $4.old
8111838SLiane.Praza@Sun.COM	fi
8211838SLiane.Praza@Sun.COM#
8311838SLiane.Praza@Sun.COM# If the new file has the CDDL, remove it from the old file.
8411838SLiane.Praza@Sun.COM#
8511838SLiane.Praza@Sun.COM	newcr=`${egrep_cmd} '^# CDDL HEADER START' $3 2>/dev/null`
8611838SLiane.Praza@Sun.COM	if [ -n "${newcr}" ]; then
8711838SLiane.Praza@Sun.COM		$sed_cmd -e '/^# CDDL HEADER START/,/^# CDDL HEADER END/d' \
8811838SLiane.Praza@Sun.COM		    $4.old > $4.$$ 2>/dev/null
8911838SLiane.Praza@Sun.COM		$mv_cmd $4.$$ $4.old
9011838SLiane.Praza@Sun.COM	fi
9111838SLiane.Praza@Sun.COM#
9211838SLiane.Praza@Sun.COM# Remove empty lines and multiple instances of these comments:
9311838SLiane.Praza@Sun.COM#
9411838SLiane.Praza@Sun.COM	$sed_cmd -e '/^# \/etc\/security\/exec_attr/d' -e '/^#$/d' \
9511838SLiane.Praza@Sun.COM		-e '/^# execution attributes for profiles./d' \
9611838SLiane.Praza@Sun.COM		-e '/^# See exec_attr(4)/d' \
9711838SLiane.Praza@Sun.COM		-e '/^# \/etc\/user_attr/d' \
9811838SLiane.Praza@Sun.COM		-e '/^# user attributes. see user_attr(4)/d' \
9911838SLiane.Praza@Sun.COM		-e '/^# \/etc\/security\/prof_attr/d' \
10011838SLiane.Praza@Sun.COM		-e '/^# profiles attributes. see prof_attr(4)/d' \
10111838SLiane.Praza@Sun.COM		-e '/^# See prof_attr(4)/d' \
10211838SLiane.Praza@Sun.COM		-e '/^# \/etc\/security\/auth_attr/d' \
10311838SLiane.Praza@Sun.COM		-e '/^# authorizations. see auth_attr(4)/d' \
10411838SLiane.Praza@Sun.COM		-e '/^# authorization attributes. see auth_attr(4)/d' \
10511838SLiane.Praza@Sun.COM		    $4.old > $4.$$
10611838SLiane.Praza@Sun.COM	$mv_cmd $4.$$ $4.old
10711838SLiane.Praza@Sun.COM#
10811838SLiane.Praza@Sun.COM# Retain old and new header comments.
10911838SLiane.Praza@Sun.COM#
11011838SLiane.Praza@Sun.COM	$sed_cmd -n -e '/^[^#]/,$d' -e '/^##/,$d' -e p $4.old > $4
11111838SLiane.Praza@Sun.COM	$rm_cmd $4.old
11211838SLiane.Praza@Sun.COM	$sed_cmd -n -e '/^[^#]/,$d' -e '/^##/,$d' -e p $3 >> $4
11311838SLiane.Praza@Sun.COM#
11411838SLiane.Praza@Sun.COM# Handle line continuations (trailing \)
11511838SLiane.Praza@Sun.COM#
11611838SLiane.Praza@Sun.COM 	$sed_cmd \
11711838SLiane.Praza@Sun.COM 	    -e '/\\$/{N;s/\\\n//;}'  -e '/\\$/{N;s/\\\n//;}' \
11811838SLiane.Praza@Sun.COM 	    -e '/\\$/{N;s/\\\n//;}'  -e '/\\$/{N;s/\\\n//;}' \
11911838SLiane.Praza@Sun.COM 	    -e '/\\$/{N;s/\\\n//;}'  -e '/\\$/{N;s/\\\n//;}' \
12011838SLiane.Praza@Sun.COM 	    $2 > $4.old
12111838SLiane.Praza@Sun.COM 	$sed_cmd \
12211838SLiane.Praza@Sun.COM 	    -e '/\\$/{N;s/\\\n//;}'  -e '/\\$/{N;s/\\\n//;}' \
12311838SLiane.Praza@Sun.COM 	    -e '/\\$/{N;s/\\\n//;}'  -e '/\\$/{N;s/\\\n//;}' \
12411838SLiane.Praza@Sun.COM 	    -e '/\\$/{N;s/\\\n//;}'  -e '/\\$/{N;s/\\\n//;}' \
12511838SLiane.Praza@Sun.COM 	    $3 > $4.new
12611838SLiane.Praza@Sun.COM#
12711838SLiane.Praza@Sun.COM#!/usr/bin/nawk -f
12811838SLiane.Praza@Sun.COM#
12911838SLiane.Praza@Sun.COM#       dbmerge type=[auth|prof|user|exec] old-file new-file
13011838SLiane.Praza@Sun.COM#
13111838SLiane.Praza@Sun.COM#       Merge two versions of an RBAC database file. The output
13211838SLiane.Praza@Sun.COM#       consists of the lines from the new-file, while preserving
13311838SLiane.Praza@Sun.COM#       user customizations in the old-file. Specifically, the
13411838SLiane.Praza@Sun.COM#       keyword/value section of each record contains the union
13511838SLiane.Praza@Sun.COM#       of the entries found in both files. The value for each
13611838SLiane.Praza@Sun.COM#       keyword is the value from the new-file, except for three
13711838SLiane.Praza@Sun.COM#       keywords ("auths", "profiles", "roles") where the values
13811838SLiane.Praza@Sun.COM#       from the old and new files are merged.
13911838SLiane.Praza@Sun.COM#
14011838SLiane.Praza@Sun.COM#	The output is run through sort except for the comments
14111838SLiane.Praza@Sun.COM#	which will appear first in the output.
14211838SLiane.Praza@Sun.COM#
14311838SLiane.Praza@Sun.COM#
14411838SLiane.Praza@Sun.COM	$nawk_cmd  '
14511838SLiane.Praza@Sun.COM
14611838SLiane.Praza@Sun.COMBEGIN {
14711838SLiane.Praza@Sun.COM	FS=":"
14811838SLiane.Praza@Sun.COM}
14911838SLiane.Praza@Sun.COM
15011838SLiane.Praza@Sun.COM/^#/ || /^$/ {
15111838SLiane.Praza@Sun.COM	continue;
15211838SLiane.Praza@Sun.COM}
15311838SLiane.Praza@Sun.COM
154*12690Snathan.bush@oracle.com{
155*12690Snathan.bush@oracle.com	# For each input line, nawk automatically assigns the complete
156*12690Snathan.bush@oracle.com	# line to $0 and also splits the line at field separators and
157*12690Snathan.bush@oracle.com	# assigns each field to a variable $1..$n.  Assignment to $0
158*12690Snathan.bush@oracle.com	# re-splits the line into the field variables.  Conversely,
159*12690Snathan.bush@oracle.com	# assgnment to a variable $1..$n will cause $0 to be recomputed
160*12690Snathan.bush@oracle.com	# from the field variable values.
161*12690Snathan.bush@oracle.com	#
162*12690Snathan.bush@oracle.com	# This code adds awareness of escaped field separators by using
163*12690Snathan.bush@oracle.com	# a custom function to split the line into a temporary array.
164*12690Snathan.bush@oracle.com	# It assigns the empty string to $0 to clear any excess field
165*12690Snathan.bush@oracle.com	# variables, and assigns the desired elements of the temporary
166*12690Snathan.bush@oracle.com	# array back to the field variables $1..$7.
167*12690Snathan.bush@oracle.com	#
168*12690Snathan.bush@oracle.com	# Subsequent code must not assign directly to $0 or the fields
169*12690Snathan.bush@oracle.com	# will be re-split without regard to escaped field separators.
170*12690Snathan.bush@oracle.com	split_escape($0, f, ":");
171*12690Snathan.bush@oracle.com	$0 = "";
172*12690Snathan.bush@oracle.com	$1 = f[1];
173*12690Snathan.bush@oracle.com	$2 = f[2];
174*12690Snathan.bush@oracle.com	$3 = f[3];
175*12690Snathan.bush@oracle.com	$4 = f[4];
176*12690Snathan.bush@oracle.com	$5 = f[5];
177*12690Snathan.bush@oracle.com	$6 = f[6];
178*12690Snathan.bush@oracle.com	$7 = f[7];
179*12690Snathan.bush@oracle.com}
180*12690Snathan.bush@oracle.com
18111838SLiane.Praza@Sun.COMtype == "auth" {
18211838SLiane.Praza@Sun.COM	key = $1 ":" $2 ":" $3 ;
18311838SLiane.Praza@Sun.COM	if (NR == FNR) {
18411838SLiane.Praza@Sun.COM		short_comment[key] = $4 ;
18511838SLiane.Praza@Sun.COM		long_comment[key] = $5;
18611838SLiane.Praza@Sun.COM		record[key] = $6;
18711838SLiane.Praza@Sun.COM	}
18811838SLiane.Praza@Sun.COM	else {
18911838SLiane.Praza@Sun.COM		if ( $4 != "" ) {
19011838SLiane.Praza@Sun.COM			short_comment[key] = $4 ;
19111838SLiane.Praza@Sun.COM		}
19211838SLiane.Praza@Sun.COM		if ( $5 != "" ) {
19311838SLiane.Praza@Sun.COM			long_comment[key] =  $5 ;
19411838SLiane.Praza@Sun.COM		}
19511838SLiane.Praza@Sun.COM		print key ":" short_comment[key] ":" long_comment[key] ":" \
19611838SLiane.Praza@Sun.COM		    merge_attrs(record[key], $6);
19711838SLiane.Praza@Sun.COM		delete record[key];
19811838SLiane.Praza@Sun.COM	}
19911838SLiane.Praza@Sun.COM}
20011838SLiane.Praza@Sun.COM
20111838SLiane.Praza@Sun.COMtype == "prof" {
20211838SLiane.Praza@Sun.COM	key = $1 ":" $2 ":" $3 ;
20311838SLiane.Praza@Sun.COM	if (NR == FNR) {
20411838SLiane.Praza@Sun.COM		comment[key] = $4;
20511838SLiane.Praza@Sun.COM		record[key] = $5;
20611838SLiane.Praza@Sun.COM	}
20711838SLiane.Praza@Sun.COM	else {
20811838SLiane.Praza@Sun.COM		if ( $4 != "" ) {
20911838SLiane.Praza@Sun.COM			comment[key] = $4 ;
21011838SLiane.Praza@Sun.COM		}
21111838SLiane.Praza@Sun.COM		if (key != "::") {
21211838SLiane.Praza@Sun.COM			print key ":" comment[key] ":" \
21311838SLiane.Praza@Sun.COM			    merge_attrs(record[key], $5);
21411838SLiane.Praza@Sun.COM		}
21511838SLiane.Praza@Sun.COM		delete record[key];
21611838SLiane.Praza@Sun.COM	}
21711838SLiane.Praza@Sun.COM}
21811838SLiane.Praza@Sun.COM
21911838SLiane.Praza@Sun.COMtype == "exec" {
22011838SLiane.Praza@Sun.COM	key = $1 ":" $2 ":" $3 ":" $4 ":" $5 ":" $6 ;
22111838SLiane.Praza@Sun.COM	# Substitute new entries, do not merge.
22211838SLiane.Praza@Sun.COM	record[key] = $7;
22311838SLiane.Praza@Sun.COM}
22411838SLiane.Praza@Sun.COM
22511838SLiane.Praza@Sun.COMtype == "user" {
22611838SLiane.Praza@Sun.COM	key = $1 ":" $2 ":" $3 ":" $4 ;
22711838SLiane.Praza@Sun.COM	if (NR == FNR)
22811838SLiane.Praza@Sun.COM		record[key] = $5;
22911838SLiane.Praza@Sun.COM	else {
23011838SLiane.Praza@Sun.COM		print key ":" merge_attrs(record[key], $5);
23111838SLiane.Praza@Sun.COM		delete record[key];
23211838SLiane.Praza@Sun.COM	}
23311838SLiane.Praza@Sun.COM}
23411838SLiane.Praza@Sun.COM
23511838SLiane.Praza@Sun.COMEND {
23611838SLiane.Praza@Sun.COM	for (key in record) {
23711838SLiane.Praza@Sun.COM		if (type == "prof") {
23811838SLiane.Praza@Sun.COM			if (key != "::") {
23911838SLiane.Praza@Sun.COM				print key ":" comment[key] ":" record[key];
24011838SLiane.Praza@Sun.COM			}
24111838SLiane.Praza@Sun.COM		} else
24211838SLiane.Praza@Sun.COM			if (type == "auth") {
24311838SLiane.Praza@Sun.COM				print key ":" short_comment[key] ":"  \
24411838SLiane.Praza@Sun.COM				    long_comment[key] ":" record[key];
24511838SLiane.Praza@Sun.COM			} else
24611838SLiane.Praza@Sun.COM				print key ":" record[key];
24711838SLiane.Praza@Sun.COM		}
24811838SLiane.Praza@Sun.COM}
24911838SLiane.Praza@Sun.COM
25011838SLiane.Praza@Sun.COMfunction merge_attrs(old, new, cnt, new_cnt, i, j, list, new_list, keyword)
25111838SLiane.Praza@Sun.COM{
252*12690Snathan.bush@oracle.com	cnt = split_escape(old, list, ";");
253*12690Snathan.bush@oracle.com	new_cnt = split_escape(new, new_list, ";");
25411838SLiane.Praza@Sun.COM	for (i = 1; i <= new_cnt; i++) {
25511838SLiane.Praza@Sun.COM		keyword = substr(new_list[i], 1, index(new_list[i], "=")-1);
25611838SLiane.Praza@Sun.COM		for (j = 1; j <= cnt; j++) {
25711838SLiane.Praza@Sun.COM			if (match(list[j], "^" keyword "=")) {
25811838SLiane.Praza@Sun.COM				list[j] = merge_values(keyword, list[j],
25911838SLiane.Praza@Sun.COM				    new_list[i]);
26011838SLiane.Praza@Sun.COM				break;
26111838SLiane.Praza@Sun.COM			}
26211838SLiane.Praza@Sun.COM		}
26311838SLiane.Praza@Sun.COM		if (j > cnt)
26411838SLiane.Praza@Sun.COM			list[++cnt] = new_list[i];
26511838SLiane.Praza@Sun.COM	}
26611838SLiane.Praza@Sun.COM
26711838SLiane.Praza@Sun.COM	return unsplit(list, cnt, ";"); \
26811838SLiane.Praza@Sun.COM}
26911838SLiane.Praza@Sun.COM
27011838SLiane.Praza@Sun.COMfunction merge_values(keyword, old, new, cnt, new_cnt, i, j, list, new_list, d)
27111838SLiane.Praza@Sun.COM{
27211838SLiane.Praza@Sun.COM	if (keyword != "auths" && keyword != "profiles")
27311838SLiane.Praza@Sun.COM		return new;
27411838SLiane.Praza@Sun.COM
27511838SLiane.Praza@Sun.COM	cnt = split(substr(old, length(keyword)+2), list, ",");
27611838SLiane.Praza@Sun.COM	new_cnt = split(substr(new, length(keyword)+2), new_list, ",");
27711838SLiane.Praza@Sun.COM
27811838SLiane.Praza@Sun.COM	# If the existing list contains "All", remove it and add it
27911838SLiane.Praza@Sun.COM	# to the new list; that way "All" will appear at the only valid
28011838SLiane.Praza@Sun.COM	# location, the end of the list.
28111838SLiane.Praza@Sun.COM	if (keyword == "profiles") {
28211838SLiane.Praza@Sun.COM		d = 0;
28311838SLiane.Praza@Sun.COM		for (i = 1; i <= cnt; i++) {
28411838SLiane.Praza@Sun.COM			if (list[i] != "All")
28511838SLiane.Praza@Sun.COM				list[++d] = list[i];
28611838SLiane.Praza@Sun.COM		}
28711838SLiane.Praza@Sun.COM		if (cnt != d) {
28811838SLiane.Praza@Sun.COM			new_list[++new_cnt] = "All";
28911838SLiane.Praza@Sun.COM			cnt = d;
29011838SLiane.Praza@Sun.COM		}
29111838SLiane.Praza@Sun.COM	}
29211838SLiane.Praza@Sun.COM	for (i = 1; i <= new_cnt; i++) {
29311838SLiane.Praza@Sun.COM		for (j = 1; j <= cnt; j++) {
29411838SLiane.Praza@Sun.COM			if (list[j] == new_list[i])
29511838SLiane.Praza@Sun.COM				break;
29611838SLiane.Praza@Sun.COM		}
29711838SLiane.Praza@Sun.COM		if (j > cnt)
29811838SLiane.Praza@Sun.COM			list[++cnt] = new_list[i];
29911838SLiane.Praza@Sun.COM	}
30011838SLiane.Praza@Sun.COM
30111838SLiane.Praza@Sun.COM	return keyword "=" unsplit(list, cnt, ",");
30211838SLiane.Praza@Sun.COM}
30311838SLiane.Praza@Sun.COM
304*12690Snathan.bush@oracle.com# This function is similar to the nawk built-in split() function,
305*12690Snathan.bush@oracle.com# except that a "\" character may be used to escape any subsequent
306*12690Snathan.bush@oracle.com# character, so that the escaped character will not be treated as a
307*12690Snathan.bush@oracle.com# field separator or as part of a field separator regular expression.
308*12690Snathan.bush@oracle.com# The "\" characters will remain in the elements of the output array
309*12690Snathan.bush@oracle.com# variable upon completion.
310*12690Snathan.bush@oracle.comfunction split_escape(str, list, fs, cnt, saved, sep)
311*12690Snathan.bush@oracle.com{
312*12690Snathan.bush@oracle.com	# default to global FS
313*12690Snathan.bush@oracle.com	if (fs == "")
314*12690Snathan.bush@oracle.com		fs = FS;
315*12690Snathan.bush@oracle.com	# initialize empty list, cnt, saved
316*12690Snathan.bush@oracle.com	split("", list, " ");
317*12690Snathan.bush@oracle.com	cnt = 0;
318*12690Snathan.bush@oracle.com	saved = "";
319*12690Snathan.bush@oracle.com	# track whether last token was a field separator
320*12690Snathan.bush@oracle.com	sep = 0;
321*12690Snathan.bush@oracle.com	# nonzero str length indicates more string left to scan
322*12690Snathan.bush@oracle.com	while (length(str)) {
323*12690Snathan.bush@oracle.com		if (match(str, fs) == 1) {
324*12690Snathan.bush@oracle.com			# field separator, terminates current field
325*12690Snathan.bush@oracle.com			list[++cnt] = saved;
326*12690Snathan.bush@oracle.com			saved = "";
327*12690Snathan.bush@oracle.com			str = substr(str, RLENGTH + 1);
328*12690Snathan.bush@oracle.com			sep = 1;
329*12690Snathan.bush@oracle.com		} else if (substr(str, 1, 1) == "\\") {
330*12690Snathan.bush@oracle.com			# escaped character
331*12690Snathan.bush@oracle.com			saved = saved substr(str, 1, 2);
332*12690Snathan.bush@oracle.com			str = substr(str, 3);
333*12690Snathan.bush@oracle.com			sep = 0;
334*12690Snathan.bush@oracle.com		} else {
335*12690Snathan.bush@oracle.com			# regular character
336*12690Snathan.bush@oracle.com			saved = saved substr(str, 1, 1);
337*12690Snathan.bush@oracle.com			str = substr(str, 2);
338*12690Snathan.bush@oracle.com			sep = 0;
339*12690Snathan.bush@oracle.com		}
340*12690Snathan.bush@oracle.com	}
341*12690Snathan.bush@oracle.com	# if required, append final field to list
342*12690Snathan.bush@oracle.com	if (sep || length(saved))
343*12690Snathan.bush@oracle.com		list[++cnt] = saved;
344*12690Snathan.bush@oracle.com
345*12690Snathan.bush@oracle.com	return cnt;
346*12690Snathan.bush@oracle.com}
347*12690Snathan.bush@oracle.com
34811838SLiane.Praza@Sun.COMfunction unsplit(list, cnt, delim, str)
34911838SLiane.Praza@Sun.COM{
35011838SLiane.Praza@Sun.COM	str = list[1];
35111838SLiane.Praza@Sun.COM	for (i = 2; i <= cnt; i++)
35211838SLiane.Praza@Sun.COM		str = str delim list[i];
35311838SLiane.Praza@Sun.COM	return str;
35411838SLiane.Praza@Sun.COM}' \
35511838SLiane.Praza@Sun.COM	type=$1 $4.old $4.new > $4.unsorted
35611838SLiane.Praza@Sun.COM	rc=$?
35711838SLiane.Praza@Sun.COM	$sort_cmd < $4.unsorted >> $4
35811838SLiane.Praza@Sun.COM	return $rc
35911838SLiane.Praza@Sun.COM}
36011838SLiane.Praza@Sun.COM
36111838SLiane.Praza@Sun.COM# $1 is the merged file
36211838SLiane.Praza@Sun.COM# $2 is the target file
36311838SLiane.Praza@Sun.COM#
36411838SLiane.Praza@Sun.COMcommit() {
36511838SLiane.Praza@Sun.COM	# Make sure that the last mv uses rename(2) by first moving to
36611838SLiane.Praza@Sun.COM	# the same filesystem.
36711838SLiane.Praza@Sun.COM	$mv_cmd $1 $2.$$
36811838SLiane.Praza@Sun.COM	$mv_cmd $2.$$ $2
36911838SLiane.Praza@Sun.COM	return $?
37011838SLiane.Praza@Sun.COM}
37111838SLiane.Praza@Sun.COM
37211838SLiane.Praza@Sun.COMoutfile=""
37311838SLiane.Praza@Sun.COMtype=""
37411838SLiane.Praza@Sun.COMset_type_and_outfile() {
37511838SLiane.Praza@Sun.COM	#
37611838SLiane.Praza@Sun.COM	# Assumes basename $1 returns one of
37711838SLiane.Praza@Sun.COM	# prof_attr, exec_attr, auth_attr, or user_attr
37811838SLiane.Praza@Sun.COM	#
37911838SLiane.Praza@Sun.COM	fname=`$basename_cmd $1`
38011838SLiane.Praza@Sun.COM	type=`echo $fname | $sed_cmd -e s'/^\([a-z][a-z]*\)_attr$/\1/' `
38111838SLiane.Praza@Sun.COM	case "$type" in
38211838SLiane.Praza@Sun.COM		"prof"|"exec"|"user"|"auth") ;;
38311838SLiane.Praza@Sun.COM		*) return 2 ;;
38411838SLiane.Praza@Sun.COM	esac
38511838SLiane.Praza@Sun.COM
38611838SLiane.Praza@Sun.COM	outfile=$tmp_dir/rbac_${PKGINST}_${fname}_merge.$$
38711838SLiane.Praza@Sun.COM
38811838SLiane.Praza@Sun.COM	return 0
38911838SLiane.Praza@Sun.COM}
39011838SLiane.Praza@Sun.COM
39111838SLiane.Praza@Sun.COMcleanup() {
39211838SLiane.Praza@Sun.COM	$rm_cmd -f $outfile $outfile.old $outfile.new $outfile.unsorted
39311838SLiane.Praza@Sun.COM
39411838SLiane.Praza@Sun.COM	return 0
39511838SLiane.Praza@Sun.COM}
39611838SLiane.Praza@Sun.COM
39711838SLiane.Praza@Sun.COMexit_status=0
39811838SLiane.Praza@Sun.COM
39911838SLiane.Praza@Sun.COM# main
40011838SLiane.Praza@Sun.COM
40111838SLiane.Praza@Sun.COMwhile read newfile oldfile ; do
40211838SLiane.Praza@Sun.COM	if [ -n "$PKGINST" ]
40311838SLiane.Praza@Sun.COM	then
40411838SLiane.Praza@Sun.COM		# Install the file in the "fragment" directory.
40511838SLiane.Praza@Sun.COM		mkdir -m 755 -p ${oldfile}.d
40611838SLiane.Praza@Sun.COM		rm -f ${oldfile}.d/"$PKGINST"
40711838SLiane.Praza@Sun.COM		cp $newfile ${oldfile}.d/"$PKGINST"
40811838SLiane.Praza@Sun.COM
40911838SLiane.Praza@Sun.COM		# Make sure that it is marked read-only.
41011838SLiane.Praza@Sun.COM		chmod a-w,a+r ${oldfile}.d/"$PKGINST"
41111838SLiane.Praza@Sun.COM
41211838SLiane.Praza@Sun.COM		# We also execute the rest of the i.rbac script.
41311838SLiane.Praza@Sun.COM	fi
41411838SLiane.Praza@Sun.COM
41511838SLiane.Praza@Sun.COM	if [ ! -f $oldfile ]; then
41611838SLiane.Praza@Sun.COM		cp $newfile $oldfile
41711838SLiane.Praza@Sun.COM	else
41811838SLiane.Praza@Sun.COM		set_type_and_outfile $newfile ||
41911838SLiane.Praza@Sun.COM			set_type_and_outfile $oldfile
42011838SLiane.Praza@Sun.COM		if [ $? -ne 0 ]; then
42111838SLiane.Praza@Sun.COM			echo "$0 : $newfile not one of" \
42211838SLiane.Praza@Sun.COM			    " prof_attr, exec_attr, auth_attr, user_attr"
42311838SLiane.Praza@Sun.COM			exit_status=2
42411838SLiane.Praza@Sun.COM			continue
42511838SLiane.Praza@Sun.COM		fi
42611838SLiane.Praza@Sun.COM
42711838SLiane.Praza@Sun.COM		dbmerge $type $oldfile $newfile $outfile
42811838SLiane.Praza@Sun.COM		if [ $? -ne 0 ]; then
42911838SLiane.Praza@Sun.COM			echo "$0 : failed to merge $newfile with $oldfile"
43011838SLiane.Praza@Sun.COM			cleanup
43111838SLiane.Praza@Sun.COM			exit_status=2
43211838SLiane.Praza@Sun.COM			continue
43311838SLiane.Praza@Sun.COM		fi
43411838SLiane.Praza@Sun.COM
43511838SLiane.Praza@Sun.COM		commit $outfile $oldfile
43611838SLiane.Praza@Sun.COM		if [ $? -ne 0 ]; then
43711838SLiane.Praza@Sun.COM			echo "$0 : failed to mv $outfile to $2"
43811838SLiane.Praza@Sun.COM			cleanup
43911838SLiane.Praza@Sun.COM			exit_status=2
44011838SLiane.Praza@Sun.COM			continue
44111838SLiane.Praza@Sun.COM		fi
44211838SLiane.Praza@Sun.COM
44311838SLiane.Praza@Sun.COM		cleanup
44411838SLiane.Praza@Sun.COM	fi
44511838SLiane.Praza@Sun.COMdone
44611838SLiane.Praza@Sun.COM
44711838SLiane.Praza@Sun.COMif [ "$1" = "ENDOFCLASS" ]; then
44811838SLiane.Praza@Sun.COM	exit 0
44911838SLiane.Praza@Sun.COMfi
45011838SLiane.Praza@Sun.COM
45111838SLiane.Praza@Sun.COMexit $exit_status
452