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# 2412690Snathan.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# 127*13091Snathan.bush@oracle.com# The nawk script below processes the old and new files using up to 128*13091Snathan.bush@oracle.com# three passes. If the old file is empty, only the final pass over 129*13091Snathan.bush@oracle.com# the new file is required. 130*13091Snathan.bush@oracle.com# 131*13091Snathan.bush@oracle.com if [ -s $4.old ]; then 132*13091Snathan.bush@oracle.com nawk_pass1=$4.old 133*13091Snathan.bush@oracle.com nawk_pass2=$4.new 134*13091Snathan.bush@oracle.com nawk_pass3=$4.new 135*13091Snathan.bush@oracle.com else 136*13091Snathan.bush@oracle.com nawk_pass1= 137*13091Snathan.bush@oracle.com nawk_pass2= 138*13091Snathan.bush@oracle.com nawk_pass3=$4.new 139*13091Snathan.bush@oracle.com fi 140*13091Snathan.bush@oracle.com# 14111838SLiane.Praza@Sun.COM#!/usr/bin/nawk -f 14211838SLiane.Praza@Sun.COM# 143*13091Snathan.bush@oracle.com# dbmerge type=[auth|prof|user|exec] [ old-file new-file ] new-file 14411838SLiane.Praza@Sun.COM# 14511838SLiane.Praza@Sun.COM# Merge two versions of an RBAC database file. The output 14611838SLiane.Praza@Sun.COM# consists of the lines from the new-file, while preserving 147*13091Snathan.bush@oracle.com# user customizations in the old-file. 148*13091Snathan.bush@oracle.com# 149*13091Snathan.bush@oracle.com# Entries in the new-file replace corresponding entries in the 150*13091Snathan.bush@oracle.com# old-file, except as follows: For exec_attr, all old entries 151*13091Snathan.bush@oracle.com# for profiles contained in the new-file are discarded. For 152*13091Snathan.bush@oracle.com# user_attr, the "root" entry from the old-file is retained, 153*13091Snathan.bush@oracle.com# and new keywords from the new-file are merged into it. 154*13091Snathan.bush@oracle.com# 155*13091Snathan.bush@oracle.com# Records with the same key field(s) are merged, so that the 156*13091Snathan.bush@oracle.com# keyword/value section of each output record contains the union 157*13091Snathan.bush@oracle.com# of the keywords found in all input records with the same key 158*13091Snathan.bush@oracle.com# field(s). For selected multi-value keywords [1] the values from 159*13091Snathan.bush@oracle.com# the new-file are merged with retained values from the old-file. 160*13091Snathan.bush@oracle.com# Otherwise, the value for each keyword is the final value found 161*13091Snathan.bush@oracle.com# in the new-file, except for keywords in the user_attr entry for 162*13091Snathan.bush@oracle.com# "root" where values from the old-file are always retained. 163*13091Snathan.bush@oracle.com# 164*13091Snathan.bush@oracle.com# [1] The following file type and keyword combinations are merged: 165*13091Snathan.bush@oracle.com# prof_attr: auths, profiles, privs 166*13091Snathan.bush@oracle.com# user_attr: auths, profiles, roles 16711838SLiane.Praza@Sun.COM# 16811838SLiane.Praza@Sun.COM# The output is run through sort except for the comments 16911838SLiane.Praza@Sun.COM# which will appear first in the output. 17011838SLiane.Praza@Sun.COM# 17111838SLiane.Praza@Sun.COM# 17211838SLiane.Praza@Sun.COM $nawk_cmd ' 17311838SLiane.Praza@Sun.COM 174*13091Snathan.bush@oracle.com# This script may be invoked with up to three file names. Each file 175*13091Snathan.bush@oracle.com# name corresponds to a separate processing pass. The passes are 176*13091Snathan.bush@oracle.com# defined as follows: 177*13091Snathan.bush@oracle.com# 178*13091Snathan.bush@oracle.com# Pass 1: Read existing data. 179*13091Snathan.bush@oracle.com# Data from the old-file is read into memory. 180*13091Snathan.bush@oracle.com# 181*13091Snathan.bush@oracle.com# Pass 2: Remove obsolete data. 182*13091Snathan.bush@oracle.com# Discard any data from the old-file that is part of profiles that 183*13091Snathan.bush@oracle.com# are also in the new-file. (As a special case, the user_attr entry 184*13091Snathan.bush@oracle.com# for 'root' is always retained.) 185*13091Snathan.bush@oracle.com# 186*13091Snathan.bush@oracle.com# Pass 3: Merge new data. 187*13091Snathan.bush@oracle.com# Data from the new-file is merged with the remaining old-file data. 188*13091Snathan.bush@oracle.com# (As a special case, exec_attr entries are replaced, not merged.) 189*13091Snathan.bush@oracle.com 19011838SLiane.Praza@Sun.COMBEGIN { 191*13091Snathan.bush@oracle.com # The variable 'pass' specifies which type of processing to perform. 192*13091Snathan.bush@oracle.com # When processing only one file, skip passes 1 and 2. 193*13091Snathan.bush@oracle.com if (ARGC == 3) 194*13091Snathan.bush@oracle.com pass += 2; 195*13091Snathan.bush@oracle.com 196*13091Snathan.bush@oracle.com # The array 'keyword_behavior' specifies the special treatment of 197*13091Snathan.bush@oracle.com # [type, keyword] combinations subject to value merging. 198*13091Snathan.bush@oracle.com keyword_behavior["prof", "auths"] = "merge"; 199*13091Snathan.bush@oracle.com keyword_behavior["prof", "profiles"] = "merge"; 200*13091Snathan.bush@oracle.com keyword_behavior["prof", "privs"] = "merge"; 201*13091Snathan.bush@oracle.com keyword_behavior["user", "auths"] = "merge"; 202*13091Snathan.bush@oracle.com keyword_behavior["user", "profiles"] = "merge"; 203*13091Snathan.bush@oracle.com keyword_behavior["user", "roles"] = "merge"; 204*13091Snathan.bush@oracle.com 20511838SLiane.Praza@Sun.COM FS=":" 20611838SLiane.Praza@Sun.COM} 20711838SLiane.Praza@Sun.COM 208*13091Snathan.bush@oracle.com# When FNR (current file record number) is 1 it indicates that nawk 209*13091Snathan.bush@oracle.com# is starting to read the next file specified on its command line, 210*13091Snathan.bush@oracle.com# and is beginning the next processing pass. 211*13091Snathan.bush@oracle.comFNR == 1 { 212*13091Snathan.bush@oracle.com pass++; 213*13091Snathan.bush@oracle.com} 214*13091Snathan.bush@oracle.com 21511838SLiane.Praza@Sun.COM/^#/ || /^$/ { 21611838SLiane.Praza@Sun.COM continue; 21711838SLiane.Praza@Sun.COM} 21811838SLiane.Praza@Sun.COM 21912690Snathan.bush@oracle.com{ 22012690Snathan.bush@oracle.com # For each input line, nawk automatically assigns the complete 22112690Snathan.bush@oracle.com # line to $0 and also splits the line at field separators and 22212690Snathan.bush@oracle.com # assigns each field to a variable $1..$n. Assignment to $0 22312690Snathan.bush@oracle.com # re-splits the line into the field variables. Conversely, 22412690Snathan.bush@oracle.com # assgnment to a variable $1..$n will cause $0 to be recomputed 22512690Snathan.bush@oracle.com # from the field variable values. 22612690Snathan.bush@oracle.com # 22712690Snathan.bush@oracle.com # This code adds awareness of escaped field separators by using 22812690Snathan.bush@oracle.com # a custom function to split the line into a temporary array. 22912690Snathan.bush@oracle.com # It assigns the empty string to $0 to clear any excess field 23012690Snathan.bush@oracle.com # variables, and assigns the desired elements of the temporary 23112690Snathan.bush@oracle.com # array back to the field variables $1..$7. 23212690Snathan.bush@oracle.com # 23312690Snathan.bush@oracle.com # Subsequent code must not assign directly to $0 or the fields 23412690Snathan.bush@oracle.com # will be re-split without regard to escaped field separators. 23512690Snathan.bush@oracle.com split_escape($0, f, ":"); 23612690Snathan.bush@oracle.com $0 = ""; 23712690Snathan.bush@oracle.com $1 = f[1]; 23812690Snathan.bush@oracle.com $2 = f[2]; 23912690Snathan.bush@oracle.com $3 = f[3]; 24012690Snathan.bush@oracle.com $4 = f[4]; 24112690Snathan.bush@oracle.com $5 = f[5]; 24212690Snathan.bush@oracle.com $6 = f[6]; 24312690Snathan.bush@oracle.com $7 = f[7]; 24412690Snathan.bush@oracle.com} 24512690Snathan.bush@oracle.com 24611838SLiane.Praza@Sun.COMtype == "auth" { 24711838SLiane.Praza@Sun.COM key = $1 ":" $2 ":" $3 ; 248*13091Snathan.bush@oracle.com if (pass == 1) { 24911838SLiane.Praza@Sun.COM short_comment[key] = $4 ; 25011838SLiane.Praza@Sun.COM long_comment[key] = $5; 25111838SLiane.Praza@Sun.COM record[key] = $6; 252*13091Snathan.bush@oracle.com } else if (pass == 2) { 253*13091Snathan.bush@oracle.com delete short_comment[key]; 254*13091Snathan.bush@oracle.com delete long_comment[key]; 255*13091Snathan.bush@oracle.com delete record[key]; 256*13091Snathan.bush@oracle.com } else if (pass == 3) { 25711838SLiane.Praza@Sun.COM if ( $4 != "" ) { 25811838SLiane.Praza@Sun.COM short_comment[key] = $4 ; 25911838SLiane.Praza@Sun.COM } 26011838SLiane.Praza@Sun.COM if ( $5 != "" ) { 26111838SLiane.Praza@Sun.COM long_comment[key] = $5 ; 26211838SLiane.Praza@Sun.COM } 263*13091Snathan.bush@oracle.com record[key] = merge_attrs(record[key], $6); 26411838SLiane.Praza@Sun.COM } 26511838SLiane.Praza@Sun.COM} 26611838SLiane.Praza@Sun.COM 26711838SLiane.Praza@Sun.COMtype == "prof" { 26811838SLiane.Praza@Sun.COM key = $1 ":" $2 ":" $3 ; 269*13091Snathan.bush@oracle.com if (pass == 1) { 27011838SLiane.Praza@Sun.COM comment[key] = $4; 27111838SLiane.Praza@Sun.COM record[key] = $5; 272*13091Snathan.bush@oracle.com } else if (pass == 2) { 273*13091Snathan.bush@oracle.com delete comment[key]; 274*13091Snathan.bush@oracle.com delete record[key]; 275*13091Snathan.bush@oracle.com } else if (pass == 3) { 27611838SLiane.Praza@Sun.COM if ( $4 != "" ) { 27711838SLiane.Praza@Sun.COM comment[key] = $4 ; 27811838SLiane.Praza@Sun.COM } 27911838SLiane.Praza@Sun.COM if (key != "::") { 280*13091Snathan.bush@oracle.com record[key] = merge_attrs(record[key], $5); 28111838SLiane.Praza@Sun.COM } 28211838SLiane.Praza@Sun.COM } 28311838SLiane.Praza@Sun.COM} 28411838SLiane.Praza@Sun.COM 28511838SLiane.Praza@Sun.COMtype == "exec" { 28611838SLiane.Praza@Sun.COM key = $1 ":" $2 ":" $3 ":" $4 ":" $5 ":" $6 ; 287*13091Snathan.bush@oracle.com if (pass == 1) { 288*13091Snathan.bush@oracle.com record[key] = $7; 289*13091Snathan.bush@oracle.com } else if (pass == 2) { 290*13091Snathan.bush@oracle.com # For exec_attr, deletion is based on the 'name' field only, 291*13091Snathan.bush@oracle.com # so that all old entries for the profile are removed. 292*13091Snathan.bush@oracle.com for (oldkey in record) { 293*13091Snathan.bush@oracle.com split_escape(oldkey, oldkey_fields, ":"); 294*13091Snathan.bush@oracle.com if (oldkey_fields[1] == $1) 295*13091Snathan.bush@oracle.com delete record[oldkey]; 296*13091Snathan.bush@oracle.com } 297*13091Snathan.bush@oracle.com } else if (pass == 3) { 298*13091Snathan.bush@oracle.com # Substitute new entries, do not merge. 299*13091Snathan.bush@oracle.com record[key] = $7; 300*13091Snathan.bush@oracle.com } 30111838SLiane.Praza@Sun.COM} 30211838SLiane.Praza@Sun.COM 30311838SLiane.Praza@Sun.COMtype == "user" { 30411838SLiane.Praza@Sun.COM key = $1 ":" $2 ":" $3 ":" $4 ; 305*13091Snathan.bush@oracle.com if (pass == 1) { 30611838SLiane.Praza@Sun.COM record[key] = $5; 307*13091Snathan.bush@oracle.com } else if (pass == 2) { 308*13091Snathan.bush@oracle.com if ($1 != "root") 309*13091Snathan.bush@oracle.com delete record[key]; 310*13091Snathan.bush@oracle.com } else if (pass == 3) { 311*13091Snathan.bush@oracle.com record[key] = merge_attrs(record[key], $5); 31211838SLiane.Praza@Sun.COM } 31311838SLiane.Praza@Sun.COM} 31411838SLiane.Praza@Sun.COM 31511838SLiane.Praza@Sun.COMEND { 31611838SLiane.Praza@Sun.COM for (key in record) { 31711838SLiane.Praza@Sun.COM if (type == "prof") { 31811838SLiane.Praza@Sun.COM if (key != "::") { 31911838SLiane.Praza@Sun.COM print key ":" comment[key] ":" record[key]; 32011838SLiane.Praza@Sun.COM } 32111838SLiane.Praza@Sun.COM } else 32211838SLiane.Praza@Sun.COM if (type == "auth") { 32311838SLiane.Praza@Sun.COM print key ":" short_comment[key] ":" \ 32411838SLiane.Praza@Sun.COM long_comment[key] ":" record[key]; 32511838SLiane.Praza@Sun.COM } else 32611838SLiane.Praza@Sun.COM print key ":" record[key]; 32711838SLiane.Praza@Sun.COM } 32811838SLiane.Praza@Sun.COM} 32911838SLiane.Praza@Sun.COM 33011838SLiane.Praza@Sun.COMfunction merge_attrs(old, new, cnt, new_cnt, i, j, list, new_list, keyword) 33111838SLiane.Praza@Sun.COM{ 33212690Snathan.bush@oracle.com cnt = split_escape(old, list, ";"); 33312690Snathan.bush@oracle.com new_cnt = split_escape(new, new_list, ";"); 33411838SLiane.Praza@Sun.COM for (i = 1; i <= new_cnt; i++) { 33511838SLiane.Praza@Sun.COM keyword = substr(new_list[i], 1, index(new_list[i], "=")-1); 33611838SLiane.Praza@Sun.COM for (j = 1; j <= cnt; j++) { 33711838SLiane.Praza@Sun.COM if (match(list[j], "^" keyword "=")) { 33811838SLiane.Praza@Sun.COM list[j] = merge_values(keyword, list[j], 33911838SLiane.Praza@Sun.COM new_list[i]); 34011838SLiane.Praza@Sun.COM break; 34111838SLiane.Praza@Sun.COM } 34211838SLiane.Praza@Sun.COM } 34311838SLiane.Praza@Sun.COM if (j > cnt) 34411838SLiane.Praza@Sun.COM list[++cnt] = new_list[i]; 34511838SLiane.Praza@Sun.COM } 34611838SLiane.Praza@Sun.COM 34711838SLiane.Praza@Sun.COM return unsplit(list, cnt, ";"); \ 34811838SLiane.Praza@Sun.COM} 34911838SLiane.Praza@Sun.COM 35011838SLiane.Praza@Sun.COMfunction merge_values(keyword, old, new, cnt, new_cnt, i, j, list, new_list, d) 35111838SLiane.Praza@Sun.COM{ 352*13091Snathan.bush@oracle.com # Keywords with multivalued attributes that are subject to merging 353*13091Snathan.bush@oracle.com # are processed by the algorithm implemented further below. 354*13091Snathan.bush@oracle.com # Otherwise, the keyword is not subject to merging, and: 355*13091Snathan.bush@oracle.com # For user_attr, the existing value is retained. 356*13091Snathan.bush@oracle.com # For any other file, the new value is substituted. 357*13091Snathan.bush@oracle.com if (keyword_behavior[type, keyword] != "merge") { 358*13091Snathan.bush@oracle.com if (type == "user") { 359*13091Snathan.bush@oracle.com return old; 360*13091Snathan.bush@oracle.com } else { 361*13091Snathan.bush@oracle.com return new; 362*13091Snathan.bush@oracle.com } 363*13091Snathan.bush@oracle.com } 36411838SLiane.Praza@Sun.COM 36511838SLiane.Praza@Sun.COM cnt = split(substr(old, length(keyword)+2), list, ","); 36611838SLiane.Praza@Sun.COM new_cnt = split(substr(new, length(keyword)+2), new_list, ","); 36711838SLiane.Praza@Sun.COM 36811838SLiane.Praza@Sun.COM # If the existing list contains "All", remove it and add it 36911838SLiane.Praza@Sun.COM # to the new list; that way "All" will appear at the only valid 37011838SLiane.Praza@Sun.COM # location, the end of the list. 37111838SLiane.Praza@Sun.COM if (keyword == "profiles") { 37211838SLiane.Praza@Sun.COM d = 0; 37311838SLiane.Praza@Sun.COM for (i = 1; i <= cnt; i++) { 37411838SLiane.Praza@Sun.COM if (list[i] != "All") 37511838SLiane.Praza@Sun.COM list[++d] = list[i]; 37611838SLiane.Praza@Sun.COM } 37711838SLiane.Praza@Sun.COM if (cnt != d) { 37811838SLiane.Praza@Sun.COM new_list[++new_cnt] = "All"; 37911838SLiane.Praza@Sun.COM cnt = d; 38011838SLiane.Praza@Sun.COM } 38111838SLiane.Praza@Sun.COM } 38211838SLiane.Praza@Sun.COM for (i = 1; i <= new_cnt; i++) { 38311838SLiane.Praza@Sun.COM for (j = 1; j <= cnt; j++) { 38411838SLiane.Praza@Sun.COM if (list[j] == new_list[i]) 38511838SLiane.Praza@Sun.COM break; 38611838SLiane.Praza@Sun.COM } 38711838SLiane.Praza@Sun.COM if (j > cnt) 38811838SLiane.Praza@Sun.COM list[++cnt] = new_list[i]; 38911838SLiane.Praza@Sun.COM } 39011838SLiane.Praza@Sun.COM 39111838SLiane.Praza@Sun.COM return keyword "=" unsplit(list, cnt, ","); 39211838SLiane.Praza@Sun.COM} 39311838SLiane.Praza@Sun.COM 39412690Snathan.bush@oracle.com# This function is similar to the nawk built-in split() function, 39512690Snathan.bush@oracle.com# except that a "\" character may be used to escape any subsequent 39612690Snathan.bush@oracle.com# character, so that the escaped character will not be treated as a 39712690Snathan.bush@oracle.com# field separator or as part of a field separator regular expression. 39812690Snathan.bush@oracle.com# The "\" characters will remain in the elements of the output array 39912690Snathan.bush@oracle.com# variable upon completion. 40012690Snathan.bush@oracle.comfunction split_escape(str, list, fs, cnt, saved, sep) 40112690Snathan.bush@oracle.com{ 40212690Snathan.bush@oracle.com # default to global FS 40312690Snathan.bush@oracle.com if (fs == "") 40412690Snathan.bush@oracle.com fs = FS; 40512690Snathan.bush@oracle.com # initialize empty list, cnt, saved 40612690Snathan.bush@oracle.com split("", list, " "); 40712690Snathan.bush@oracle.com cnt = 0; 40812690Snathan.bush@oracle.com saved = ""; 40912690Snathan.bush@oracle.com # track whether last token was a field separator 41012690Snathan.bush@oracle.com sep = 0; 41112690Snathan.bush@oracle.com # nonzero str length indicates more string left to scan 41212690Snathan.bush@oracle.com while (length(str)) { 41312690Snathan.bush@oracle.com if (match(str, fs) == 1) { 41412690Snathan.bush@oracle.com # field separator, terminates current field 41512690Snathan.bush@oracle.com list[++cnt] = saved; 41612690Snathan.bush@oracle.com saved = ""; 41712690Snathan.bush@oracle.com str = substr(str, RLENGTH + 1); 41812690Snathan.bush@oracle.com sep = 1; 41912690Snathan.bush@oracle.com } else if (substr(str, 1, 1) == "\\") { 42012690Snathan.bush@oracle.com # escaped character 42112690Snathan.bush@oracle.com saved = saved substr(str, 1, 2); 42212690Snathan.bush@oracle.com str = substr(str, 3); 42312690Snathan.bush@oracle.com sep = 0; 42412690Snathan.bush@oracle.com } else { 42512690Snathan.bush@oracle.com # regular character 42612690Snathan.bush@oracle.com saved = saved substr(str, 1, 1); 42712690Snathan.bush@oracle.com str = substr(str, 2); 42812690Snathan.bush@oracle.com sep = 0; 42912690Snathan.bush@oracle.com } 43012690Snathan.bush@oracle.com } 43112690Snathan.bush@oracle.com # if required, append final field to list 43212690Snathan.bush@oracle.com if (sep || length(saved)) 43312690Snathan.bush@oracle.com list[++cnt] = saved; 43412690Snathan.bush@oracle.com 43512690Snathan.bush@oracle.com return cnt; 43612690Snathan.bush@oracle.com} 43712690Snathan.bush@oracle.com 43811838SLiane.Praza@Sun.COMfunction unsplit(list, cnt, delim, str) 43911838SLiane.Praza@Sun.COM{ 44011838SLiane.Praza@Sun.COM str = list[1]; 44111838SLiane.Praza@Sun.COM for (i = 2; i <= cnt; i++) 44211838SLiane.Praza@Sun.COM str = str delim list[i]; 44311838SLiane.Praza@Sun.COM return str; 44411838SLiane.Praza@Sun.COM}' \ 445*13091Snathan.bush@oracle.com type=$1 $nawk_pass1 $nawk_pass2 $nawk_pass3 > $4.unsorted 44611838SLiane.Praza@Sun.COM rc=$? 44711838SLiane.Praza@Sun.COM $sort_cmd < $4.unsorted >> $4 44811838SLiane.Praza@Sun.COM return $rc 44911838SLiane.Praza@Sun.COM} 45011838SLiane.Praza@Sun.COM 45111838SLiane.Praza@Sun.COM# $1 is the merged file 45211838SLiane.Praza@Sun.COM# $2 is the target file 45311838SLiane.Praza@Sun.COM# 45411838SLiane.Praza@Sun.COMcommit() { 45511838SLiane.Praza@Sun.COM # Make sure that the last mv uses rename(2) by first moving to 45611838SLiane.Praza@Sun.COM # the same filesystem. 45711838SLiane.Praza@Sun.COM $mv_cmd $1 $2.$$ 45811838SLiane.Praza@Sun.COM $mv_cmd $2.$$ $2 45911838SLiane.Praza@Sun.COM return $? 46011838SLiane.Praza@Sun.COM} 46111838SLiane.Praza@Sun.COM 46211838SLiane.Praza@Sun.COMoutfile="" 46311838SLiane.Praza@Sun.COMtype="" 46411838SLiane.Praza@Sun.COMset_type_and_outfile() { 46511838SLiane.Praza@Sun.COM # 46611838SLiane.Praza@Sun.COM # Assumes basename $1 returns one of 46711838SLiane.Praza@Sun.COM # prof_attr, exec_attr, auth_attr, or user_attr 46811838SLiane.Praza@Sun.COM # 46911838SLiane.Praza@Sun.COM fname=`$basename_cmd $1` 47011838SLiane.Praza@Sun.COM type=`echo $fname | $sed_cmd -e s'/^\([a-z][a-z]*\)_attr$/\1/' ` 47111838SLiane.Praza@Sun.COM case "$type" in 47211838SLiane.Praza@Sun.COM "prof"|"exec"|"user"|"auth") ;; 47311838SLiane.Praza@Sun.COM *) return 2 ;; 47411838SLiane.Praza@Sun.COM esac 47511838SLiane.Praza@Sun.COM 47611838SLiane.Praza@Sun.COM outfile=$tmp_dir/rbac_${PKGINST}_${fname}_merge.$$ 47711838SLiane.Praza@Sun.COM 47811838SLiane.Praza@Sun.COM return 0 47911838SLiane.Praza@Sun.COM} 48011838SLiane.Praza@Sun.COM 48111838SLiane.Praza@Sun.COMcleanup() { 48211838SLiane.Praza@Sun.COM $rm_cmd -f $outfile $outfile.old $outfile.new $outfile.unsorted 48311838SLiane.Praza@Sun.COM 48411838SLiane.Praza@Sun.COM return 0 48511838SLiane.Praza@Sun.COM} 48611838SLiane.Praza@Sun.COM 48711838SLiane.Praza@Sun.COMexit_status=0 48811838SLiane.Praza@Sun.COM 48911838SLiane.Praza@Sun.COM# main 49011838SLiane.Praza@Sun.COM 49111838SLiane.Praza@Sun.COMwhile read newfile oldfile ; do 49211838SLiane.Praza@Sun.COM if [ -n "$PKGINST" ] 49311838SLiane.Praza@Sun.COM then 49411838SLiane.Praza@Sun.COM # Install the file in the "fragment" directory. 49511838SLiane.Praza@Sun.COM mkdir -m 755 -p ${oldfile}.d 49611838SLiane.Praza@Sun.COM rm -f ${oldfile}.d/"$PKGINST" 49711838SLiane.Praza@Sun.COM cp $newfile ${oldfile}.d/"$PKGINST" 49811838SLiane.Praza@Sun.COM 49911838SLiane.Praza@Sun.COM # Make sure that it is marked read-only. 50011838SLiane.Praza@Sun.COM chmod a-w,a+r ${oldfile}.d/"$PKGINST" 50111838SLiane.Praza@Sun.COM 50211838SLiane.Praza@Sun.COM # We also execute the rest of the i.rbac script. 50311838SLiane.Praza@Sun.COM fi 50411838SLiane.Praza@Sun.COM 50511838SLiane.Praza@Sun.COM if [ ! -f $oldfile ]; then 50611838SLiane.Praza@Sun.COM cp $newfile $oldfile 50711838SLiane.Praza@Sun.COM else 50811838SLiane.Praza@Sun.COM set_type_and_outfile $newfile || 50911838SLiane.Praza@Sun.COM set_type_and_outfile $oldfile 51011838SLiane.Praza@Sun.COM if [ $? -ne 0 ]; then 51111838SLiane.Praza@Sun.COM echo "$0 : $newfile not one of" \ 51211838SLiane.Praza@Sun.COM " prof_attr, exec_attr, auth_attr, user_attr" 51311838SLiane.Praza@Sun.COM exit_status=2 51411838SLiane.Praza@Sun.COM continue 51511838SLiane.Praza@Sun.COM fi 51611838SLiane.Praza@Sun.COM 51711838SLiane.Praza@Sun.COM dbmerge $type $oldfile $newfile $outfile 51811838SLiane.Praza@Sun.COM if [ $? -ne 0 ]; then 51911838SLiane.Praza@Sun.COM echo "$0 : failed to merge $newfile with $oldfile" 52011838SLiane.Praza@Sun.COM cleanup 52111838SLiane.Praza@Sun.COM exit_status=2 52211838SLiane.Praza@Sun.COM continue 52311838SLiane.Praza@Sun.COM fi 52411838SLiane.Praza@Sun.COM 52511838SLiane.Praza@Sun.COM commit $outfile $oldfile 52611838SLiane.Praza@Sun.COM if [ $? -ne 0 ]; then 52711838SLiane.Praza@Sun.COM echo "$0 : failed to mv $outfile to $2" 52811838SLiane.Praza@Sun.COM cleanup 52911838SLiane.Praza@Sun.COM exit_status=2 53011838SLiane.Praza@Sun.COM continue 53111838SLiane.Praza@Sun.COM fi 53211838SLiane.Praza@Sun.COM 53311838SLiane.Praza@Sun.COM cleanup 53411838SLiane.Praza@Sun.COM fi 53511838SLiane.Praza@Sun.COMdone 53611838SLiane.Praza@Sun.COM 53711838SLiane.Praza@Sun.COMif [ "$1" = "ENDOFCLASS" ]; then 53811838SLiane.Praza@Sun.COM exit 0 53911838SLiane.Praza@Sun.COMfi 54011838SLiane.Praza@Sun.COM 54111838SLiane.Praza@Sun.COMexit $exit_status 542