Revert commit 66c0185a3 and follow-on patches.
[pgsql.git] / contrib / sepgsql / launcher
blob85f60fd84f3241f312252413d200ad140d0b12fc
1 #!/bin/sh
3 # A wrapper script to launch psql command in regression test
5 # Copyright (c) 2010-2024, PostgreSQL Global Development Group
7 # -------------------------------------------------------------------------
9 if [ $# -lt 1 ]; then
10 echo "usage: `basename $0` <command> [options...]"
11 exit 1
14 RUNCON=`which runcon`
15 if [ ! -e "$RUNCON" ]; then
16 echo "runcon command is not found"
17 exit 1
21 # Read SQL from stdin
23 TEMP=`mktemp`
24 CONTEXT="unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255"
26 while IFS='\\n' read LINE
28 if echo "$LINE" | grep -q "^-- @SECURITY-CONTEXT="; then
29 if [ -s "$TEMP" ]; then
30 if [ -n "$CONTEXT" ]; then
31 "$RUNCON" "$CONTEXT" $* < "$TEMP"
32 else
33 $* < $TEMP
35 truncate -s0 $TEMP
37 CONTEXT=`echo "$LINE" | sed 's/^-- @SECURITY-CONTEXT=//g'`
38 LINE="SELECT sepgsql_getcon(); -- confirm client privilege"
40 echo "$LINE" >> $TEMP
41 done
43 if [ -s "$TEMP" ]; then
44 if [ -n "$CONTEXT" ]; then
45 "$RUNCON" "$CONTEXT" $* < "$TEMP"
46 else
47 $* < $TEMP
51 # cleanup temp file
52 rm -f $TEMP