xref: /illumos-gate/usr/src/cmd/tsol/misc/relabel.sh (revision 2a8bcb4e)
1f875b4ebSrica#!/bin/sh
2f875b4ebSrica#
3f875b4ebSrica# CDDL HEADER START
4f875b4ebSrica#
5f875b4ebSrica# The contents of this file are subject to the terms of the
6f875b4ebSrica# Common Development and Distribution License (the "License").
7f875b4ebSrica# You may not use this file except in compliance with the License.
8f875b4ebSrica#
9f875b4ebSrica# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10f875b4ebSrica# or http://www.opensolaris.org/os/licensing.
11f875b4ebSrica# See the License for the specific language governing permissions
12f875b4ebSrica# and limitations under the License.
13f875b4ebSrica#
14f875b4ebSrica# When distributing Covered Code, include this CDDL HEADER in each
15f875b4ebSrica# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16f875b4ebSrica# If applicable, add the following below this CDDL HEADER, with the
17f875b4ebSrica# fields enclosed by brackets "[]" replaced with your own identifying
18f875b4ebSrica# information: Portions Copyright [yyyy] [name of copyright owner]
19f875b4ebSrica#
20f875b4ebSrica# CDDL HEADER END
21f875b4ebSrica#
22f875b4ebSrica# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23f875b4ebSrica# Use is subject to license terms.
24f875b4ebSrica#
25f875b4ebSrica# This program is invoked to do the actual file transfer
26f875b4ebSrica# associated with an invocation of the setflabel(3TSOL) function.
27f875b4ebSrica#
28*2a8bcb4eSToomas Soome# It executes in the global zone with the user's identity and
29f875b4ebSrica# basic privileges plus the file_dac_search privilege.  This
30f875b4ebSrica# script should not not assume that stdio is available or that
31f875b4ebSrica# any particular environment variables are set.  In particular,
32f875b4ebSrica# the DISPLAY variable will not normally be pre-set.
33f875b4ebSrica#
34f875b4ebSrica# Authorization checks and zone limit privilege checks
35f875b4ebSrica# are done before calling this script. Auditing is done
36f875b4ebSrica# upon return.
37f875b4ebSrica#
38f875b4ebSrica##############################################################
39f875b4ebSrica#
40f875b4ebSrica# Calling sequence:
41f875b4ebSrica#
42f875b4ebSrica# $1 is the global zone real pathname of the source file
43f875b4ebSrica#
44f875b4ebSrica# $2 is the global zone real destination pathname
45f875b4ebSrica#
46f875b4ebSrica# Exit status:
47f875b4ebSrica#
48f875b4ebSrica# 0 on success
49f875b4ebSrica# 1 on error
50f875b4ebSrica#
51f875b4ebSrica##############################################################
52f875b4ebSrica#
53f875b4ebSrica# This script can be customized or replaced to perform
54f875b4ebSrica# additional processing such as tranquility checks, dirty
55f875b4ebSrica# word filtering, copying instead of moving, etc.
56f875b4ebSrica#
57f875b4ebSrica# By default it does a check to determine if the source file
58f875b4ebSrica# is in use by calling fuser(1). However, this check
59f875b4ebSrica# does not work for filesystems that were automounted in
60f875b4ebSrica# non-global zones.
61f875b4ebSrica#
62f875b4ebSrica# Perform a simple tranquility check
63f875b4ebSrica#
64f875b4ebSricainuse=`/usr/sbin/fuser $1 2>&1 | /usr/bin/cut -d ":" -f2`
65f875b4ebSricaif [ $inuse ]; then
66f875b4ebSrica#
67f875b4ebSrica#	file is in use
68f875b4ebSrica#
69f875b4ebSrica	exit 1
70f875b4ebSricaelse
71f875b4ebSrica#
72f875b4ebSrica# Perform an inter-zone move of the data
73f875b4ebSrica	/usr/bin/mv $1 $2
74f875b4ebSrica	exit $?
75f875b4ebSricafi
76