xref: /titanic_50/usr/src/lib/libsecdb/common/i.rbac (revision 1099afd7a24ed1f7d94bdae249576a66e1952d05)
1ead1f93eSLiane Praza#!/bin/sh
2ead1f93eSLiane Praza#
3ead1f93eSLiane Praza# CDDL HEADER START
4ead1f93eSLiane Praza#
5ead1f93eSLiane Praza# The contents of this file are subject to the terms of the
6ead1f93eSLiane Praza# Common Development and Distribution License (the "License").
7ead1f93eSLiane Praza# You may not use this file except in compliance with the License.
8ead1f93eSLiane Praza#
9ead1f93eSLiane Praza# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10ead1f93eSLiane Praza# or http://www.opensolaris.org/os/licensing.
11ead1f93eSLiane Praza# See the License for the specific language governing permissions
12ead1f93eSLiane Praza# and limitations under the License.
13ead1f93eSLiane Praza#
14ead1f93eSLiane Praza# When distributing Covered Code, include this CDDL HEADER in each
15ead1f93eSLiane Praza# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16ead1f93eSLiane Praza# If applicable, add the following below this CDDL HEADER, with the
17ead1f93eSLiane Praza# fields enclosed by brackets "[]" replaced with your own identifying
18ead1f93eSLiane Praza# information: Portions Copyright [yyyy] [name of copyright owner]
19ead1f93eSLiane Praza#
20ead1f93eSLiane Praza# CDDL HEADER END
21ead1f93eSLiane Praza#
22ead1f93eSLiane Praza# i.rbac
23ead1f93eSLiane Praza#
24*1099afd7SNathan Bush# Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
25ead1f93eSLiane Praza#
26ead1f93eSLiane Praza# class action script for "rbac" class files
27ead1f93eSLiane Praza# installed by pkgadd
28ead1f93eSLiane Praza#
29ead1f93eSLiane Praza# Files in "rbac" class:
30ead1f93eSLiane Praza#
31ead1f93eSLiane Praza# /etc/security/{prof_attr,exec_attr,auth_attr}
32ead1f93eSLiane Praza# /etc/user_attr
33ead1f93eSLiane Praza#
34ead1f93eSLiane Praza#  Allowable exit codes
35ead1f93eSLiane Praza#
36ead1f93eSLiane Praza# 0 - success
37ead1f93eSLiane Praza# 2 - warning or possible error condition. Installation continues. A warning
38ead1f93eSLiane Praza#     message is displayed at the time of completion.
39ead1f93eSLiane Praza#
40ead1f93eSLiane Praza
41ead1f93eSLiane Prazaumask 022
42ead1f93eSLiane Praza
43ead1f93eSLiane Prazatmp_dir=${TMPDIR:-/tmp}
44ead1f93eSLiane Praza
45ead1f93eSLiane PrazaPATH="/usr/bin:/usr/sbin:${PATH}"
46ead1f93eSLiane Prazaexport PATH
47ead1f93eSLiane Praza
48ead1f93eSLiane Prazabasename_cmd=basename
49ead1f93eSLiane Prazacp_cmd=cp
50ead1f93eSLiane Prazaegrep_cmd=egrep
51ead1f93eSLiane Prazamv_cmd=mv
52ead1f93eSLiane Prazanawk_cmd=nawk
53ead1f93eSLiane Prazarm_cmd=rm
54ead1f93eSLiane Prazased_cmd=sed
55ead1f93eSLiane Prazasort_cmd=sort
56ead1f93eSLiane Praza
57ead1f93eSLiane Praza# $1 is the type
58ead1f93eSLiane Praza# $2 is the "old/existing file"
59ead1f93eSLiane Praza# $3 is the "new (to be merged)" file
60ead1f93eSLiane Praza# $4 is the output file
61ead1f93eSLiane Praza# returns 0 on success
62ead1f93eSLiane Praza# returns 2 on failure if nawk fails with non-zero exit status
63ead1f93eSLiane Praza#
64ead1f93eSLiane Prazadbmerge() {
65ead1f93eSLiane Praza#
66ead1f93eSLiane Praza# Remove the ident lines.
67ead1f93eSLiane Praza#
68ead1f93eSLiane Praza	${egrep_cmd} -v '^#[pragma 	]*ident' $2 > $4.old 2>/dev/null
69ead1f93eSLiane Praza#
70ead1f93eSLiane Praza# If the new file has a Sun copyright, remove the Sun copyright from the old
71ead1f93eSLiane Praza# file.
72ead1f93eSLiane Praza#
73ead1f93eSLiane Praza	newcr=`${egrep_cmd} '^# Copyright.*Sun Microsystems, Inc.' $3 \
74ead1f93eSLiane Praza	    2>/dev/null`
75ead1f93eSLiane Praza	if [ -n "${newcr}" ]; then
76ead1f93eSLiane Praza		$sed_cmd -e '/^# Copyright.*Sun Microsystems, Inc./d' \
77ead1f93eSLiane Praza		    -e '/^# All rights reserved./d' \
78ead1f93eSLiane Praza		    -e '/^# Use is subject to license terms./d' \
79ead1f93eSLiane Praza		    $4.old > $4.$$ 2>/dev/null
80ead1f93eSLiane Praza		$mv_cmd $4.$$ $4.old
81ead1f93eSLiane Praza	fi
82ead1f93eSLiane Praza#
83ead1f93eSLiane Praza# If the new file has the CDDL, remove it from the old file.
84ead1f93eSLiane Praza#
85ead1f93eSLiane Praza	newcr=`${egrep_cmd} '^# CDDL HEADER START' $3 2>/dev/null`
86ead1f93eSLiane Praza	if [ -n "${newcr}" ]; then
87ead1f93eSLiane Praza		$sed_cmd -e '/^# CDDL HEADER START/,/^# CDDL HEADER END/d' \
88ead1f93eSLiane Praza		    $4.old > $4.$$ 2>/dev/null
89ead1f93eSLiane Praza		$mv_cmd $4.$$ $4.old
90ead1f93eSLiane Praza	fi
91ead1f93eSLiane Praza#
92ead1f93eSLiane Praza# Remove empty lines and multiple instances of these comments:
93ead1f93eSLiane Praza#
94ead1f93eSLiane Praza	$sed_cmd -e '/^# \/etc\/security\/exec_attr/d' -e '/^#$/d' \
95ead1f93eSLiane Praza		-e '/^# execution attributes for profiles./d' \
96ead1f93eSLiane Praza		-e '/^# See exec_attr(4)/d' \
97ead1f93eSLiane Praza		-e '/^# \/etc\/user_attr/d' \
98ead1f93eSLiane Praza		-e '/^# user attributes. see user_attr(4)/d' \
99ead1f93eSLiane Praza		-e '/^# \/etc\/security\/prof_attr/d' \
100ead1f93eSLiane Praza		-e '/^# profiles attributes. see prof_attr(4)/d' \
101ead1f93eSLiane Praza		-e '/^# See prof_attr(4)/d' \
102ead1f93eSLiane Praza		-e '/^# \/etc\/security\/auth_attr/d' \
103ead1f93eSLiane Praza		-e '/^# authorizations. see auth_attr(4)/d' \
104ead1f93eSLiane Praza		-e '/^# authorization attributes. see auth_attr(4)/d' \
105ead1f93eSLiane Praza		    $4.old > $4.$$
106ead1f93eSLiane Praza	$mv_cmd $4.$$ $4.old
107ead1f93eSLiane Praza#
108ead1f93eSLiane Praza# Retain old and new header comments.
109ead1f93eSLiane Praza#
110ead1f93eSLiane Praza	$sed_cmd -n -e '/^[^#]/,$d' -e '/^##/,$d' -e p $4.old > $4
111ead1f93eSLiane Praza	$rm_cmd $4.old
112ead1f93eSLiane Praza	$sed_cmd -n -e '/^[^#]/,$d' -e '/^##/,$d' -e p $3 >> $4
113ead1f93eSLiane Praza#
114ead1f93eSLiane Praza# Handle line continuations (trailing \)
115ead1f93eSLiane Praza#
116ead1f93eSLiane Praza 	$sed_cmd \
117ead1f93eSLiane Praza 	    -e '/\\$/{N;s/\\\n//;}'  -e '/\\$/{N;s/\\\n//;}' \
118ead1f93eSLiane Praza 	    -e '/\\$/{N;s/\\\n//;}'  -e '/\\$/{N;s/\\\n//;}' \
119ead1f93eSLiane Praza 	    -e '/\\$/{N;s/\\\n//;}'  -e '/\\$/{N;s/\\\n//;}' \
120ead1f93eSLiane Praza 	    $2 > $4.old
121ead1f93eSLiane Praza 	$sed_cmd \
122ead1f93eSLiane Praza 	    -e '/\\$/{N;s/\\\n//;}'  -e '/\\$/{N;s/\\\n//;}' \
123ead1f93eSLiane Praza 	    -e '/\\$/{N;s/\\\n//;}'  -e '/\\$/{N;s/\\\n//;}' \
124ead1f93eSLiane Praza 	    -e '/\\$/{N;s/\\\n//;}'  -e '/\\$/{N;s/\\\n//;}' \
125ead1f93eSLiane Praza 	    $3 > $4.new
126ead1f93eSLiane Praza#
127ead1f93eSLiane Praza#!/usr/bin/nawk -f
128ead1f93eSLiane Praza#
129ead1f93eSLiane Praza#       dbmerge type=[auth|prof|user|exec] old-file new-file
130ead1f93eSLiane Praza#
131ead1f93eSLiane Praza#       Merge two versions of an RBAC database file. The output
132ead1f93eSLiane Praza#       consists of the lines from the new-file, while preserving
133ead1f93eSLiane Praza#       user customizations in the old-file. Specifically, the
134ead1f93eSLiane Praza#       keyword/value section of each record contains the union
135ead1f93eSLiane Praza#       of the entries found in both files. The value for each
136ead1f93eSLiane Praza#       keyword is the value from the new-file, except for three
137ead1f93eSLiane Praza#       keywords ("auths", "profiles", "roles") where the values
138ead1f93eSLiane Praza#       from the old and new files are merged.
139ead1f93eSLiane Praza#
140ead1f93eSLiane Praza#	The output is run through sort except for the comments
141ead1f93eSLiane Praza#	which will appear first in the output.
142ead1f93eSLiane Praza#
143ead1f93eSLiane Praza#
144ead1f93eSLiane Praza	$nawk_cmd  '
145ead1f93eSLiane Praza
146ead1f93eSLiane PrazaBEGIN {
147ead1f93eSLiane Praza	FS=":"
148ead1f93eSLiane Praza}
149ead1f93eSLiane Praza
150ead1f93eSLiane Praza/^#/ || /^$/ {
151ead1f93eSLiane Praza	continue;
152ead1f93eSLiane Praza}
153ead1f93eSLiane Praza
154*1099afd7SNathan Bush{
155*1099afd7SNathan Bush	# For each input line, nawk automatically assigns the complete
156*1099afd7SNathan Bush	# line to $0 and also splits the line at field separators and
157*1099afd7SNathan Bush	# assigns each field to a variable $1..$n.  Assignment to $0
158*1099afd7SNathan Bush	# re-splits the line into the field variables.  Conversely,
159*1099afd7SNathan Bush	# assgnment to a variable $1..$n will cause $0 to be recomputed
160*1099afd7SNathan Bush	# from the field variable values.
161*1099afd7SNathan Bush	#
162*1099afd7SNathan Bush	# This code adds awareness of escaped field separators by using
163*1099afd7SNathan Bush	# a custom function to split the line into a temporary array.
164*1099afd7SNathan Bush	# It assigns the empty string to $0 to clear any excess field
165*1099afd7SNathan Bush	# variables, and assigns the desired elements of the temporary
166*1099afd7SNathan Bush	# array back to the field variables $1..$7.
167*1099afd7SNathan Bush	#
168*1099afd7SNathan Bush	# Subsequent code must not assign directly to $0 or the fields
169*1099afd7SNathan Bush	# will be re-split without regard to escaped field separators.
170*1099afd7SNathan Bush	split_escape($0, f, ":");
171*1099afd7SNathan Bush	$0 = "";
172*1099afd7SNathan Bush	$1 = f[1];
173*1099afd7SNathan Bush	$2 = f[2];
174*1099afd7SNathan Bush	$3 = f[3];
175*1099afd7SNathan Bush	$4 = f[4];
176*1099afd7SNathan Bush	$5 = f[5];
177*1099afd7SNathan Bush	$6 = f[6];
178*1099afd7SNathan Bush	$7 = f[7];
179*1099afd7SNathan Bush}
180*1099afd7SNathan Bush
181ead1f93eSLiane Prazatype == "auth" {
182ead1f93eSLiane Praza	key = $1 ":" $2 ":" $3 ;
183ead1f93eSLiane Praza	if (NR == FNR) {
184ead1f93eSLiane Praza		short_comment[key] = $4 ;
185ead1f93eSLiane Praza		long_comment[key] = $5;
186ead1f93eSLiane Praza		record[key] = $6;
187ead1f93eSLiane Praza	}
188ead1f93eSLiane Praza	else {
189ead1f93eSLiane Praza		if ( $4 != "" ) {
190ead1f93eSLiane Praza			short_comment[key] = $4 ;
191ead1f93eSLiane Praza		}
192ead1f93eSLiane Praza		if ( $5 != "" ) {
193ead1f93eSLiane Praza			long_comment[key] =  $5 ;
194ead1f93eSLiane Praza		}
195ead1f93eSLiane Praza		print key ":" short_comment[key] ":" long_comment[key] ":" \
196ead1f93eSLiane Praza		    merge_attrs(record[key], $6);
197ead1f93eSLiane Praza		delete record[key];
198ead1f93eSLiane Praza	}
199ead1f93eSLiane Praza}
200ead1f93eSLiane Praza
201ead1f93eSLiane Prazatype == "prof" {
202ead1f93eSLiane Praza	key = $1 ":" $2 ":" $3 ;
203ead1f93eSLiane Praza	if (NR == FNR) {
204ead1f93eSLiane Praza		comment[key] = $4;
205ead1f93eSLiane Praza		record[key] = $5;
206ead1f93eSLiane Praza	}
207ead1f93eSLiane Praza	else {
208ead1f93eSLiane Praza		if ( $4 != "" ) {
209ead1f93eSLiane Praza			comment[key] = $4 ;
210ead1f93eSLiane Praza		}
211ead1f93eSLiane Praza		if (key != "::") {
212ead1f93eSLiane Praza			print key ":" comment[key] ":" \
213ead1f93eSLiane Praza			    merge_attrs(record[key], $5);
214ead1f93eSLiane Praza		}
215ead1f93eSLiane Praza		delete record[key];
216ead1f93eSLiane Praza	}
217ead1f93eSLiane Praza}
218ead1f93eSLiane Praza
219ead1f93eSLiane Prazatype == "exec" {
220ead1f93eSLiane Praza	key = $1 ":" $2 ":" $3 ":" $4 ":" $5 ":" $6 ;
221ead1f93eSLiane Praza	# Substitute new entries, do not merge.
222ead1f93eSLiane Praza	record[key] = $7;
223ead1f93eSLiane Praza}
224ead1f93eSLiane Praza
225ead1f93eSLiane Prazatype == "user" {
226ead1f93eSLiane Praza	key = $1 ":" $2 ":" $3 ":" $4 ;
227ead1f93eSLiane Praza	if (NR == FNR)
228ead1f93eSLiane Praza		record[key] = $5;
229ead1f93eSLiane Praza	else {
230ead1f93eSLiane Praza		print key ":" merge_attrs(record[key], $5);
231ead1f93eSLiane Praza		delete record[key];
232ead1f93eSLiane Praza	}
233ead1f93eSLiane Praza}
234ead1f93eSLiane Praza
235ead1f93eSLiane PrazaEND {
236ead1f93eSLiane Praza	for (key in record) {
237ead1f93eSLiane Praza		if (type == "prof") {
238ead1f93eSLiane Praza			if (key != "::") {
239ead1f93eSLiane Praza				print key ":" comment[key] ":" record[key];
240ead1f93eSLiane Praza			}
241ead1f93eSLiane Praza		} else
242ead1f93eSLiane Praza			if (type == "auth") {
243ead1f93eSLiane Praza				print key ":" short_comment[key] ":"  \
244ead1f93eSLiane Praza				    long_comment[key] ":" record[key];
245ead1f93eSLiane Praza			} else
246ead1f93eSLiane Praza				print key ":" record[key];
247ead1f93eSLiane Praza		}
248ead1f93eSLiane Praza}
249ead1f93eSLiane Praza
250ead1f93eSLiane Prazafunction merge_attrs(old, new, cnt, new_cnt, i, j, list, new_list, keyword)
251ead1f93eSLiane Praza{
252*1099afd7SNathan Bush	cnt = split_escape(old, list, ";");
253*1099afd7SNathan Bush	new_cnt = split_escape(new, new_list, ";");
254ead1f93eSLiane Praza	for (i = 1; i <= new_cnt; i++) {
255ead1f93eSLiane Praza		keyword = substr(new_list[i], 1, index(new_list[i], "=")-1);
256ead1f93eSLiane Praza		for (j = 1; j <= cnt; j++) {
257ead1f93eSLiane Praza			if (match(list[j], "^" keyword "=")) {
258ead1f93eSLiane Praza				list[j] = merge_values(keyword, list[j],
259ead1f93eSLiane Praza				    new_list[i]);
260ead1f93eSLiane Praza				break;
261ead1f93eSLiane Praza			}
262ead1f93eSLiane Praza		}
263ead1f93eSLiane Praza		if (j > cnt)
264ead1f93eSLiane Praza			list[++cnt] = new_list[i];
265ead1f93eSLiane Praza	}
266ead1f93eSLiane Praza
267ead1f93eSLiane Praza	return unsplit(list, cnt, ";"); \
268ead1f93eSLiane Praza}
269ead1f93eSLiane Praza
270ead1f93eSLiane Prazafunction merge_values(keyword, old, new, cnt, new_cnt, i, j, list, new_list, d)
271ead1f93eSLiane Praza{
272ead1f93eSLiane Praza	if (keyword != "auths" && keyword != "profiles")
273ead1f93eSLiane Praza		return new;
274ead1f93eSLiane Praza
275ead1f93eSLiane Praza	cnt = split(substr(old, length(keyword)+2), list, ",");
276ead1f93eSLiane Praza	new_cnt = split(substr(new, length(keyword)+2), new_list, ",");
277ead1f93eSLiane Praza
278ead1f93eSLiane Praza	# If the existing list contains "All", remove it and add it
279ead1f93eSLiane Praza	# to the new list; that way "All" will appear at the only valid
280ead1f93eSLiane Praza	# location, the end of the list.
281ead1f93eSLiane Praza	if (keyword == "profiles") {
282ead1f93eSLiane Praza		d = 0;
283ead1f93eSLiane Praza		for (i = 1; i <= cnt; i++) {
284ead1f93eSLiane Praza			if (list[i] != "All")
285ead1f93eSLiane Praza				list[++d] = list[i];
286ead1f93eSLiane Praza		}
287ead1f93eSLiane Praza		if (cnt != d) {
288ead1f93eSLiane Praza			new_list[++new_cnt] = "All";
289ead1f93eSLiane Praza			cnt = d;
290ead1f93eSLiane Praza		}
291ead1f93eSLiane Praza	}
292ead1f93eSLiane Praza	for (i = 1; i <= new_cnt; i++) {
293ead1f93eSLiane Praza		for (j = 1; j <= cnt; j++) {
294ead1f93eSLiane Praza			if (list[j] == new_list[i])
295ead1f93eSLiane Praza				break;
296ead1f93eSLiane Praza		}
297ead1f93eSLiane Praza		if (j > cnt)
298ead1f93eSLiane Praza			list[++cnt] = new_list[i];
299ead1f93eSLiane Praza	}
300ead1f93eSLiane Praza
301ead1f93eSLiane Praza	return keyword "=" unsplit(list, cnt, ",");
302ead1f93eSLiane Praza}
303ead1f93eSLiane Praza
304*1099afd7SNathan Bush# This function is similar to the nawk built-in split() function,
305*1099afd7SNathan Bush# except that a "\" character may be used to escape any subsequent
306*1099afd7SNathan Bush# character, so that the escaped character will not be treated as a
307*1099afd7SNathan Bush# field separator or as part of a field separator regular expression.
308*1099afd7SNathan Bush# The "\" characters will remain in the elements of the output array
309*1099afd7SNathan Bush# variable upon completion.
310*1099afd7SNathan Bushfunction split_escape(str, list, fs, cnt, saved, sep)
311*1099afd7SNathan Bush{
312*1099afd7SNathan Bush	# default to global FS
313*1099afd7SNathan Bush	if (fs == "")
314*1099afd7SNathan Bush		fs = FS;
315*1099afd7SNathan Bush	# initialize empty list, cnt, saved
316*1099afd7SNathan Bush	split("", list, " ");
317*1099afd7SNathan Bush	cnt = 0;
318*1099afd7SNathan Bush	saved = "";
319*1099afd7SNathan Bush	# track whether last token was a field separator
320*1099afd7SNathan Bush	sep = 0;
321*1099afd7SNathan Bush	# nonzero str length indicates more string left to scan
322*1099afd7SNathan Bush	while (length(str)) {
323*1099afd7SNathan Bush		if (match(str, fs) == 1) {
324*1099afd7SNathan Bush			# field separator, terminates current field
325*1099afd7SNathan Bush			list[++cnt] = saved;
326*1099afd7SNathan Bush			saved = "";
327*1099afd7SNathan Bush			str = substr(str, RLENGTH + 1);
328*1099afd7SNathan Bush			sep = 1;
329*1099afd7SNathan Bush		} else if (substr(str, 1, 1) == "\\") {
330*1099afd7SNathan Bush			# escaped character
331*1099afd7SNathan Bush			saved = saved substr(str, 1, 2);
332*1099afd7SNathan Bush			str = substr(str, 3);
333*1099afd7SNathan Bush			sep = 0;
334*1099afd7SNathan Bush		} else {
335*1099afd7SNathan Bush			# regular character
336*1099afd7SNathan Bush			saved = saved substr(str, 1, 1);
337*1099afd7SNathan Bush			str = substr(str, 2);
338*1099afd7SNathan Bush			sep = 0;
339*1099afd7SNathan Bush		}
340*1099afd7SNathan Bush	}
341*1099afd7SNathan Bush	# if required, append final field to list
342*1099afd7SNathan Bush	if (sep || length(saved))
343*1099afd7SNathan Bush		list[++cnt] = saved;
344*1099afd7SNathan Bush
345*1099afd7SNathan Bush	return cnt;
346*1099afd7SNathan Bush}
347*1099afd7SNathan Bush
348ead1f93eSLiane Prazafunction unsplit(list, cnt, delim, str)
349ead1f93eSLiane Praza{
350ead1f93eSLiane Praza	str = list[1];
351ead1f93eSLiane Praza	for (i = 2; i <= cnt; i++)
352ead1f93eSLiane Praza		str = str delim list[i];
353ead1f93eSLiane Praza	return str;
354ead1f93eSLiane Praza}' \
355ead1f93eSLiane Praza	type=$1 $4.old $4.new > $4.unsorted
356ead1f93eSLiane Praza	rc=$?
357ead1f93eSLiane Praza	$sort_cmd < $4.unsorted >> $4
358ead1f93eSLiane Praza	return $rc
359ead1f93eSLiane Praza}
360ead1f93eSLiane Praza
361ead1f93eSLiane Praza# $1 is the merged file
362ead1f93eSLiane Praza# $2 is the target file
363ead1f93eSLiane Praza#
364ead1f93eSLiane Prazacommit() {
365ead1f93eSLiane Praza	# Make sure that the last mv uses rename(2) by first moving to
366ead1f93eSLiane Praza	# the same filesystem.
367ead1f93eSLiane Praza	$mv_cmd $1 $2.$$
368ead1f93eSLiane Praza	$mv_cmd $2.$$ $2
369ead1f93eSLiane Praza	return $?
370ead1f93eSLiane Praza}
371ead1f93eSLiane Praza
372ead1f93eSLiane Prazaoutfile=""
373ead1f93eSLiane Prazatype=""
374ead1f93eSLiane Prazaset_type_and_outfile() {
375ead1f93eSLiane Praza	#
376ead1f93eSLiane Praza	# Assumes basename $1 returns one of
377ead1f93eSLiane Praza	# prof_attr, exec_attr, auth_attr, or user_attr
378ead1f93eSLiane Praza	#
379ead1f93eSLiane Praza	fname=`$basename_cmd $1`
380ead1f93eSLiane Praza	type=`echo $fname | $sed_cmd -e s'/^\([a-z][a-z]*\)_attr$/\1/' `
381ead1f93eSLiane Praza	case "$type" in
382ead1f93eSLiane Praza		"prof"|"exec"|"user"|"auth") ;;
383ead1f93eSLiane Praza		*) return 2 ;;
384ead1f93eSLiane Praza	esac
385ead1f93eSLiane Praza
386ead1f93eSLiane Praza	outfile=$tmp_dir/rbac_${PKGINST}_${fname}_merge.$$
387ead1f93eSLiane Praza
388ead1f93eSLiane Praza	return 0
389ead1f93eSLiane Praza}
390ead1f93eSLiane Praza
391ead1f93eSLiane Prazacleanup() {
392ead1f93eSLiane Praza	$rm_cmd -f $outfile $outfile.old $outfile.new $outfile.unsorted
393ead1f93eSLiane Praza
394ead1f93eSLiane Praza	return 0
395ead1f93eSLiane Praza}
396ead1f93eSLiane Praza
397ead1f93eSLiane Prazaexit_status=0
398ead1f93eSLiane Praza
399ead1f93eSLiane Praza# main
400ead1f93eSLiane Praza
401ead1f93eSLiane Prazawhile read newfile oldfile ; do
402ead1f93eSLiane Praza	if [ -n "$PKGINST" ]
403ead1f93eSLiane Praza	then
404ead1f93eSLiane Praza		# Install the file in the "fragment" directory.
405ead1f93eSLiane Praza		mkdir -m 755 -p ${oldfile}.d
406ead1f93eSLiane Praza		rm -f ${oldfile}.d/"$PKGINST"
407ead1f93eSLiane Praza		cp $newfile ${oldfile}.d/"$PKGINST"
408ead1f93eSLiane Praza
409ead1f93eSLiane Praza		# Make sure that it is marked read-only.
410ead1f93eSLiane Praza		chmod a-w,a+r ${oldfile}.d/"$PKGINST"
411ead1f93eSLiane Praza
412ead1f93eSLiane Praza		# We also execute the rest of the i.rbac script.
413ead1f93eSLiane Praza	fi
414ead1f93eSLiane Praza
415ead1f93eSLiane Praza	if [ ! -f $oldfile ]; then
416ead1f93eSLiane Praza		cp $newfile $oldfile
417ead1f93eSLiane Praza	else
418ead1f93eSLiane Praza		set_type_and_outfile $newfile ||
419ead1f93eSLiane Praza			set_type_and_outfile $oldfile
420ead1f93eSLiane Praza		if [ $? -ne 0 ]; then
421ead1f93eSLiane Praza			echo "$0 : $newfile not one of" \
422ead1f93eSLiane Praza			    " prof_attr, exec_attr, auth_attr, user_attr"
423ead1f93eSLiane Praza			exit_status=2
424ead1f93eSLiane Praza			continue
425ead1f93eSLiane Praza		fi
426ead1f93eSLiane Praza
427ead1f93eSLiane Praza		dbmerge $type $oldfile $newfile $outfile
428ead1f93eSLiane Praza		if [ $? -ne 0 ]; then
429ead1f93eSLiane Praza			echo "$0 : failed to merge $newfile with $oldfile"
430ead1f93eSLiane Praza			cleanup
431ead1f93eSLiane Praza			exit_status=2
432ead1f93eSLiane Praza			continue
433ead1f93eSLiane Praza		fi
434ead1f93eSLiane Praza
435ead1f93eSLiane Praza		commit $outfile $oldfile
436ead1f93eSLiane Praza		if [ $? -ne 0 ]; then
437ead1f93eSLiane Praza			echo "$0 : failed to mv $outfile to $2"
438ead1f93eSLiane Praza			cleanup
439ead1f93eSLiane Praza			exit_status=2
440ead1f93eSLiane Praza			continue
441ead1f93eSLiane Praza		fi
442ead1f93eSLiane Praza
443ead1f93eSLiane Praza		cleanup
444ead1f93eSLiane Praza	fi
445ead1f93eSLiane Prazadone
446ead1f93eSLiane Praza
447ead1f93eSLiane Prazaif [ "$1" = "ENDOFCLASS" ]; then
448ead1f93eSLiane Praza	exit 0
449ead1f93eSLiane Prazafi
450ead1f93eSLiane Praza
451ead1f93eSLiane Prazaexit $exit_status
452