<commit_before>#!/bin/sh
#-------------------------------------------------------------------------
#
# destroyuser.sh--
#    utility for destroying a user from the POSTGRES database.
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
#    $Header: /cvsroot/pgsql/src/bin/destroyuser/Attic/destroyuser.sh,v 1.9 1998/08/22 05:19:21 momjian Exp $
#
# Note - this should NOT be setuid.
#
#-------------------------------------------------------------------------

CMDNAME=`basename $0`

if [ -z "$USER" ]; then
    if [ -z "$LOGNAME" ]; then
	if [ -z "`whoami`" ]; then
	    echo "$CMDNAME: cannot determine user name"
	    exit 1
	fi
    else
	USER=$LOGNAME
	export USER
    fi
fi

while (test -n "$1")
do
    case $1 in 
	-a) AUTHSYS=$2; shift;;
        -h) PGHOST=$2; shift;;
        -p) PGPORT=$2; shift;;
         *) DELUSER=$1;;
    esac
    shift;
done

if [ -z "$AUTHSYS" ]; then
  AUTHOPT=""
else
  AUTHOPT="-a $AUTHSYS"
fi

if [ -z "$PGHOST" ]; then
  PGHOSTOPT=""
else
  PGHOSTOPT="-h $PGHOST"
fi

if [ -z "$PGPORT" ]; then
  PGPORTOPT=""
else
  PGPORTOPT="-p $PGPORT"
fi

PARGS="-tq $AUTHOPT $PGHOSTOPT $PGPORTOPT"

#
# generate the first part of the actual monitor command
#
PSQL="psql $PARGS"


#
# see if user $USER is allowed to create new users.  Only a user who can
# create users can delete them.
#

QUERY="select usesuper from pg_user where usename = '$USER'"
ADDUSER=`$PSQL -c "$QUERY" template1`

if [ $? -ne 0 ]
then
    echo "$CMDNAME: database access failed."
    exit 1
fi

if [ $ADDUSER != "t" ]
then
    echo "$CMDNAME: $USER cannot delete users."
fi

#
# get the user name of the user to delete.  Make sure it exists.
#

if [ -z "$DELUSER" ]
then
    echo OPT_DASH_N_PARAM "Enter name of user to delete ---> OPT_BACKSLASH_C_PARAM"
    read DELUSER
fi

QUERY="select usesysid from pg_user where usename = '$DELUSER'"

RES=`$PSQL -c "$QUERY" template1`

if [ $? -ne 0 ]
then
    echo "$CMDNAME: database access failed."
    exit 1
fi

if [ ! -n "$RES" ]
then
    echo "$CMDNAME: user "\"$DELUSER\"" does not exist."
    exit 1
fi

SYSID=`echo $RES | sed 's/ //g'`

#
# destroy the databases owned by the deleted user.  First, use this query
# to find out what they are.
#

QUERY="select datname from pg_database where datdba = '$SYSID'::oid"
       

ALLDBS=`$PSQL -c "$QUERY" template1`

if [ $? -ne 0 ]
then
    echo "$CMDNAME: database access failed - exiting..."
    exit 1
fi


#
# don't try to delete template1!
#

for i in $ALLDBS
do
    if [ $i != "template1" ]
    then
        DBLIST="$DBLIST $i"
    fi
done

if [ -n "$DBLIST" ]
then
    echo "User $DELUSER owned the following databases:"
    echo $DBLIST
    echo

#
# Now we warn the DBA that deleting this user will destroy a bunch of databases
#

    yn=f
    while [ $yn != y -a $yn != n ]
    do
        echo OPT_DASH_N_PARAM "Deleting user $DELUSER will destroy them. Continue (y/n)? OPT_BACKSLASH_C_PARAM"
        read yn
    done

    if [ $yn = n ]
    then
        echo "$CMDNAME: exiting"
        exit 1
    fi

    #
    # now actually destroy the databases
    #

    for i in $DBLIST
    do
        echo "destroying database $i"

        QUERY="drop database $i"
        $PSQL -c "$QUERY" template1
        if [ $? -ne 0 ]
        then
            echo "$CMDNAME: drop database on $i failed - exiting"
            exit 1
        fi
    done
fi

QUERY="delete from pg_shadow where usename = '$DELUSER'"

$PSQL -c "$QUERY" template1
if [ $? -ne 0 ]
then
    echo "$CMDNAME: delete of user $DELUSER was UNSUCCESSFUL"
else
    echo "$CMDNAME: delete of user $DELUSER was successful."
fi

exit 0
<commit_msg>Fix message delimiters for substitution by sed script during installation.  They were missing a "PG_" prefix so were not substituted properly.<commit_after>#!/bin/sh
#-------------------------------------------------------------------------
#
# destroyuser.sh--
#    utility for destroying a user from the POSTGRES database.
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
#    $Header: /cvsroot/pgsql/src/bin/destroyuser/Attic/destroyuser.sh,v 1.10 1998/09/01 15:57:00 thomas Exp $
#
# Note - this should NOT be setuid.
#
#-------------------------------------------------------------------------

CMDNAME=`basename $0`

if [ -z "$USER" ]; then
    if [ -z "$LOGNAME" ]; then
	if [ -z "`whoami`" ]; then
	    echo "$CMDNAME: cannot determine user name"
	    exit 1
	fi
    else
	USER=$LOGNAME
	export USER
    fi
fi

while (test -n "$1")
do
    case $1 in 
	-a) AUTHSYS=$2; shift;;
        -h) PGHOST=$2; shift;;
        -p) PGPORT=$2; shift;;
         *) DELUSER=$1;;
    esac
    shift;
done

if [ -z "$AUTHSYS" ]; then
  AUTHOPT=""
else
  AUTHOPT="-a $AUTHSYS"
fi

if [ -z "$PGHOST" ]; then
  PGHOSTOPT=""
else
  PGHOSTOPT="-h $PGHOST"
fi

if [ -z "$PGPORT" ]; then
  PGPORTOPT=""
else
  PGPORTOPT="-p $PGPORT"
fi

PARGS="-tq $AUTHOPT $PGHOSTOPT $PGPORTOPT"

#
# generate the first part of the actual monitor command
#
PSQL="psql $PARGS"


#
# see if user $USER is allowed to create new users.  Only a user who can
# create users can delete them.
#

QUERY="select usesuper from pg_user where usename = '$USER'"
ADDUSER=`$PSQL -c "$QUERY" template1`

if [ $? -ne 0 ]
then
    echo "$CMDNAME: database access failed."
    exit 1
fi

if [ $ADDUSER != "t" ]
then
    echo "$CMDNAME: $USER cannot delete users."
fi

#
# get the user name of the user to delete.  Make sure it exists.
#

if [ -z "$DELUSER" ]
then
    echo PG_OPT_DASH_N_PARAM "Enter name of user to delete ---> PG_OPT_BACKSLASH_C_PARAM"
    read DELUSER
fi

QUERY="select usesysid from pg_user where usename = '$DELUSER'"

RES=`$PSQL -c "$QUERY" template1`

if [ $? -ne 0 ]
then
    echo "$CMDNAME: database access failed."
    exit 1
fi

if [ ! -n "$RES" ]
then
    echo "$CMDNAME: user "\"$DELUSER\"" does not exist."
    exit 1
fi

SYSID=`echo $RES | sed 's/ //g'`

#
# destroy the databases owned by the deleted user.  First, use this query
# to find out what they are.
#

QUERY="select datname from pg_database where datdba = '$SYSID'::oid"
       

ALLDBS=`$PSQL -c "$QUERY" template1`

if [ $? -ne 0 ]
then
    echo "$CMDNAME: database access failed - exiting..."
    exit 1
fi


#
# don't try to delete template1!
#

for i in $ALLDBS
do
    if [ $i != "template1" ]
    then
        DBLIST="$DBLIST $i"
    fi
done

if [ -n "$DBLIST" ]
then
    echo "User $DELUSER owned the following databases:"
    echo $DBLIST
    echo

#
# Now we warn the DBA that deleting this user will destroy a bunch of databases
#

    yn=f
    while [ $yn != y -a $yn != n ]
    do
        echo PG_OPT_DASH_N_PARAM "Deleting user $DELUSER will destroy them. Continue (y/n)? PG_OPT_BACKSLASH_C_PARAM"
        read yn
    done

    if [ $yn = n ]
    then
        echo "$CMDNAME: exiting"
        exit 1
    fi

    #
    # now actually destroy the databases
    #

    for i in $DBLIST
    do
        echo "destroying database $i"

        QUERY="drop database $i"
        $PSQL -c "$QUERY" template1
        if [ $? -ne 0 ]
        then
            echo "$CMDNAME: drop database on $i failed - exiting"
            exit 1
        fi
    done
fi

QUERY="delete from pg_shadow where usename = '$DELUSER'"

$PSQL -c "$QUERY" template1
if [ $? -ne 0 ]
then
    echo "$CMDNAME: delete of user $DELUSER was UNSUCCESSFUL"
else
    echo "$CMDNAME: delete of user $DELUSER was successful."
fi

exit 0

{'fraction_non_alphanumeric': 0.15828502089793717, 'fraction_numerical': 0.012808413105028987, 'mean_word_length': 2.2506573181419807, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5881068', 'n_tokens_mistral': 2686, 'n_tokens_neox': 2593, 'n_words': 912}