head	1.22;
access;
symbols
	REL7_3_21:1.21
	REL7_3_20:1.21
	REL7_3_19:1.21
	REL7_3_18:1.21
	REL7_3_17:1.21
	REL7_3_16:1.21
	REL7_3_15:1.21
	REL7_3_14:1.21
	REL7_3_13:1.21
	REL7_3_12:1.21
	REL7_3_11:1.21
	REL7_2_8:1.14
	REL7_3_10:1.21
	REL7_2_7:1.14
	REL7_3_9:1.21
	REL7_3_8:1.21
	REL7_2_6:1.14
	REL7_2_5:1.14
	REL7_3_7:1.21
	REL7_3_6:1.21
	REL7_3_5:1.21
	REL7_3_4:1.21
	REL7_3_2:1.21
	REL7_2_4:1.14
	REL7_3_STABLE:1.21.0.2
	REL7_2_3:1.14
	REL7_2_STABLE:1.14.0.2
	REL7_2:1.14
	REL7_2_RC2:1.14
	REL7_2_RC1:1.14
	REL7_2_BETA5:1.14
	REL7_2_BETA4:1.14
	REL7_2_BETA3:1.14
	REL7_2_BETA2:1.14
	REL7_2_BETA1:1.14
	REL7_1_2:1.12
	REL7_1_STABLE:1.12.0.2
	REL7_1_BETA:1.10
	REL7_1_BETA3:1.10
	REL7_1_BETA2:1.10
	REL7_1:1.12
	REL7_0_PATCHES:1.6.0.2
	REL7_0:1.6;
locks; strict;
comment	@# @;


1.22
date	2003.03.18.22.19.47;	author petere;	state dead;
branches;
next	1.21;

1.21
date	2002.10.18.22.05.36;	author petere;	state Exp;
branches;
next	1.20;

1.20
date	2002.10.16.03.44.28;	author momjian;	state Exp;
branches;
next	1.19;

1.19
date	2002.10.16.03.24.09;	author momjian;	state Exp;
branches;
next	1.18;

1.18
date	2002.06.20.20.29.42;	author momjian;	state Exp;
branches;
next	1.17;

1.17
date	2002.04.12.09.42.32;	author momjian;	state Exp;
branches;
next	1.16;

1.16
date	2002.04.12.09.37.11;	author momjian;	state Exp;
branches;
next	1.15;

1.15
date	2002.02.18.05.48.45;	author momjian;	state Exp;
branches;
next	1.14;

1.14
date	2001.09.30.22.17.51;	author momjian;	state Exp;
branches;
next	1.13;

1.13
date	2001.09.22.04.28.12;	author momjian;	state Exp;
branches;
next	1.12;

1.12
date	2001.02.18.18.34.02;	author momjian;	state Exp;
branches;
next	1.11;

1.11
date	2001.01.21.05.16.45;	author momjian;	state Exp;
branches;
next	1.10;

1.10
date	2000.11.25.19.05.44;	author petere;	state Exp;
branches;
next	1.9;

1.9
date	2000.11.13.23.37.53;	author momjian;	state Exp;
branches;
next	1.8;

1.8
date	2000.11.13.15.18.14;	author momjian;	state Exp;
branches;
next	1.7;

1.7
date	2000.11.11.22.59.48;	author petere;	state Exp;
branches;
next	1.6;

1.6
date	2000.01.19.20.08.36;	author petere;	state Exp;
branches;
next	1.5;

1.5
date	2000.01.12.19.36.36;	author petere;	state Exp;
branches;
next	1.4;

1.4
date	99.12.16.20.10.02;	author momjian;	state Exp;
branches;
next	1.3;

1.3
date	99.12.07.22.41.44;	author momjian;	state Exp;
branches;
next	1.2;

1.2
date	99.12.05.20.52.54;	author momjian;	state Exp;
branches;
next	1.1;

1.1
date	99.12.04.04.53.21;	author momjian;	state Exp;
branches;
next	;


desc
@@


1.22
log
@Reimplement create and drop scripts in C, to reduce repetitive
connections, increase robustness, add NLS, and prepare for Windows port.
(vacuumdb and clusterdb will follow later.)
@
text
@#!/bin/sh
#-------------------------------------------------------------------------
#
# dropuser--
#    Utility for removing a user from the PostgreSQL database.
#
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
#    $Header: /cvsroot/pgsql-server/src/bin/scripts/dropuser,v 1.21 2002/10/18 22:05:36 petere Exp $
#
# Note - this should NOT be setuid.
#
#-------------------------------------------------------------------------

CMDNAME=`basename "$0"`
PATHNAME=`echo "$0" | sed "s,$CMDNAME\$,,"`

PSQLOPT=
forcedel=t
DelUser=

# These handle spaces/tabs in identifiers
_IFS="$IFS"
NL="
"
# Check for echo -n vs echo \c

if echo '\c' | grep -s c >/dev/null 2>&1
then
    ECHO_N="echo -n"
    ECHO_C=""
else
    ECHO_N="echo"
    ECHO_C='\c'
fi


while [ "$#" -gt 0 ]
do
    case "$1" in
	--help|-\?)
		usage=t
                break
		;;
# options passed on to psql
	--host|-h)
		PSQLOPT="$PSQLOPT -h $2"
		shift;;
        -h*)
                PSQLOPT="$PSQLOPT $1"
                ;;
        --host=*)
                PSQLOPT="$PSQLOPT -h `echo \"$1\" | sed 's/^--host=//'`"
                ;;
	--port|-p)
		PSQLOPT="$PSQLOPT -p $2"
		shift;;
        -p*)
                PSQLOPT="$PSQLOPT $1"
                ;;
        --port=*)
                PSQLOPT="$PSQLOPT -p `echo \"$1\" | sed 's/^--port=//'`"
                ;;
# Note: These two specify the user to connect as (like in psql),
#       not the user you're dropping.
	--username|-U)
		PSQLOPT="$PSQLOPT -U $2"
		shift;;
        -U*)
                PSQLOPT="$PSQLOPT $1"
                ;;
        --username=*)
                PSQLOPT="$PSQLOPT -U `echo \"$1\" | sed 's/^--username=//'`"
                ;;
	--password|-W)
		PSQLOPT="$PSQLOPT -W"
		;;
	--echo|-e)
		PSQLOPT="$PSQLOPT -e"
		;;
	--quiet|-q)
		PSQLOPT="$PSQLOPT -o /dev/null"
		;;
# other options
	--interactive|-i)
		forcedel=f
		;;
	-*)
		echo "$CMDNAME: invalid option: $1" 1>&2
                echo "Try '$CMDNAME --help' for more information." 1>&2
		exit 1
		;;
         *)
		DelUser="$1"
		if [ "$#" -ne 1 ]; then
			echo "$CMDNAME: invalid option: $2" 1>&2
	                echo "Try '$CMDNAME --help' for more information." 1>&2
			exit 1
		fi
		;;
    esac
    shift;
done


if [ "$usage" ]; then
	echo "$CMDNAME removes a PostgreSQL user."
        echo
	echo "Usage:"
        echo "  $CMDNAME [OPTION]... [USERNAME]"
        echo
	echo "Options:"
        echo "  -e, --echo                show the query being sent to the backend"
	echo "  -i, --interactive         prompt before deleting anything"
        echo "  -q, --quiet               don't write any messages"
	echo "  -h, --host=HOSTNAME       database server host"
	echo "  -p, --port=PORT           database server port"
	echo "  -U, --username=USERNAME   user name to connect as (not the one to drop)"
	echo "  -W, --password            prompt for password to connect"
	echo " --help                     show this help, then exit"
	echo
	echo "Report bugs to <pgsql-bugs@@postgresql.org>."
	exit 0
fi

# Prompt for username if missing

if [ -z "$DelUser" ]; then
	$ECHO_N "Enter name of user to delete: "$ECHO_C
        IFS="$NL"
        read DelUser
        IFS="$_IFS"
	[ "$?" -ne 0 ] && exit 1
fi


if [ "$forcedel" = f ]; then
	echo "User \"$DelUser\" will be permanently deleted."
	$ECHO_N "Are you sure? (y/n) "$ECHO_C
	read REPLY

	[ "$?" -eq 1 ] && exit 1
	[ "$REPLY" != "y" -a "$REPLY" != "Y" ] && exit 0
fi


DelUser=`echo "$DelUser" | sed 's/\"/\\\"/g'`

${PATHNAME}psql $PSQLOPT -d template1 -c "SET autocommit TO 'on';DROP USER \"$DelUser\""

if [ "$?" -ne 0 ]; then
	echo "$CMDNAME: deletion of user \"$DelUser\" failed" 1>&2
	exit 1
fi

exit 0
@


1.21
log
@Improve formatting of --help output.
@
text
@d12 1
a12 1
#    $Header: /cvsroot/pgsql-server/src/bin/scripts/dropuser,v 1.20 2002/10/16 03:44:28 momjian Exp $
@


1.20
log
@Improve appearance of SET command.
@
text
@d12 1
a12 1
#    $Header: /cvsroot/pgsql-server/src/bin/scripts/dropuser,v 1.19 2002/10/16 03:24:09 momjian Exp $
d113 1
a113 1
        echo "  $CMDNAME [options] [username]"
d116 8
a123 7
	echo "  -h, --host=HOSTNAME             Database server host"
	echo "  -p, --port=PORT                 Database server port"
	echo "  -U, --username=USERNAME         Username to connect as (not the one to drop)"
	echo "  -W, --password                  Prompt for password to connect"
	echo "  -i, --interactive               Prompt before deleting anything"
        echo "  -e, --echo                      Show the query being sent to the backend"
        echo "  -q, --quiet                     Don't write any messages"
@


1.19
log
@Fix script to handle autocommit = 'off' by prepending autocommit 'on' to
the start of the psql commandline.  This is better than adding BEGIN/END
because it handles multiple queries well, and allows the return code for
psql to return the proper value.
@
text
@d12 1
a12 1
#    $Header: /cvsroot/pgsql-server/src/bin/scripts/dropuser,v 1.18 2002/06/20 20:29:42 momjian Exp $
d151 1
a151 1
${PATHNAME}psql $PSQLOPT -d template1 -c "SET autocommit = 'on';DROP USER \"$DelUser\""
@


1.18
log
@Update copyright to 2002.
@
text
@d12 1
a12 1
#    $Header: /cvsroot/pgsql/src/bin/scripts/dropuser,v 1.17 2002/04/12 09:42:32 momjian Exp $
d151 1
a151 1
${PATHNAME}psql $PSQLOPT -d template1 -c "DROP USER \"$DelUser\""
@


1.17
log
@Allow prompting of create/drop user to handle spaces.
@
text
@d7 1
a7 1
# Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
d12 1
a12 1
#    $Header: /cvsroot/pgsql/src/bin/scripts/dropuser,v 1.16 2002/04/12 09:37:11 momjian Exp $
@


1.16
log
@Allow dropdb and others to use identifiers with spaces;  IFS cleanup for
pg_dumpall.
@
text
@d12 1
a12 1
#    $Header: /cvsroot/pgsql/src/bin/scripts/dropuser,v 1.15 2002/02/18 05:48:45 momjian Exp $
d25 4
d132 3
a134 1
	read DelUser
@


1.15
log
@Fix param handling of create* admin scripts as described months ago.
Properly handles default values.
@
text
@d12 1
a12 1
#    $Header: /cvsroot/pgsql/src/bin/scripts/dropuser,v 1.14 2001/09/30 22:17:51 momjian Exp $
d19 1
a19 1
PATHNAME=`echo $0 | sed "s,$CMDNAME\$,,"`
d52 1
a52 1
                PSQLOPT="$PSQLOPT -h "`echo $1 | sed 's/^--host=//'`
d61 1
a61 1
                PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'`
d72 1
a72 1
                PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--username=//'`
@


1.14
log
@These are further fixes for double quotes missing in the various shell
scripts.

Justin Clift
@
text
@d12 1
a12 1
#    $Header: /cvsroot/pgsql/src/bin/scripts/dropuser,v 1.13 2001/09/22 04:28:12 momjian Exp $
d94 5
@


1.13
log
@sbasename $0 is now basename "$0"
@
text
@d12 1
a12 1
#    $Header: /cvsroot/pgsql/src/bin/scripts/dropuser,v 1.12 2001/02/18 18:34:02 momjian Exp $
d37 1
a37 1
while [ $# -gt 0 ]
d124 1
a124 1
	[ $? -ne 0 ] && exit 1
d133 1
a133 1
	[ $? -eq 1 ] && exit 1
d142 1
a142 1
if [ $? -ne 0 ]; then
@


1.12
log
@Add copyright mentions, per Tom Lane.
@
text
@d12 1
a12 1
#    $Header: /home/projects/pgsql/cvsroot/pgsql/src/bin/scripts/dropuser,v 1.11 2001/01/21 05:16:45 momjian Exp $
d18 1
a18 1
CMDNAME=`basename $0`
@


1.11
log
@Put quotes around environment variables.
@
text
@d7 2
a8 1
# Copyright (c) 1994, Regents of the University of California
d12 1
a12 1
#    $Header: /home/projects/pgsql/cvsroot/pgsql/src/bin/scripts/dropuser,v 1.10 2000/11/25 19:05:44 petere Exp $
@


1.10
log
@Advertise --help (rather than '-?') as help option (problems with csh).
Accept --help even if no general long options support exists.
@
text
@d11 1
a11 1
#    $Header: /home/projects/pgsql/cvsroot/pgsql/src/bin/scripts/dropuser,v 1.9 2000/11/13 23:37:53 momjian Exp $
d137 1
a137 1
DelUser=`echo $DelUser | sed 's/\"/\\\"/g'`
@


1.9
log
@Remove -k unix socketpath option from client side, allow hostname with
leading slash to behave as a unix socket path.
@
text
@d11 1
a11 1
#    $Header: /home/projects/pgsql/cvsroot/pgsql/src/bin/scripts/dropuser,v 1.8 2000/11/13 15:18:14 momjian Exp $
d88 1
a88 1
                echo "Try '$CMDNAME -?' for help." 1>&2
@


1.8
log
@UUNET is looking into offering PostgreSQL as a part of a managed web
hosting product, on both shared and dedicated machines.  We currently
offer Oracle and MySQL, and it would be a nice middle-ground.
However, as shipped, PostgreSQL lacks the following features we need
that MySQL has:

1. The ability to listen only on a particular IP address.  Each
   hosting customer has their own IP address, on which all of their
   servers (http, ftp, real media, etc.) run.
2. The ability to place the Unix-domain socket in a mode 700 directory.
   This allows us to automatically create an empty database, with an
   empty DBA password, for new or upgrading customers without having
   to interactively set a DBA password and communicate it to (or from)
   the customer.  This in turn cuts down our install and upgrade times.
3. The ability to connect to the Unix-domain socket from within a
   change-rooted environment.  We run CGI programs chrooted to the
   user's home directory, which is another reason why we need to be
   able to specify where the Unix-domain socket is, instead of /tmp.
4. The ability to, if run as root, open a pid file in /var/run as
   root, and then setuid to the desired user.  (mysqld -u can almost
   do this; I had to patch it, too).

The patch below fixes problem 1-3.  I plan to address #4, also, but
haven't done so yet.  These diffs are big enough that they should give
the PG development team something to think about in the meantime :-)
Also, I'm about to leave for 2 weeks' vacation, so I thought I'd get
out what I have, which works (for the problems it tackles), now.

With these changes, we can set up and run PostgreSQL with scripts the
same way we can with apache or proftpd or mysql.

In summary, this patch makes the following enhancements:

1. Adds an environment variable PGUNIXSOCKET, analogous to MYSQL_UNIX_PORT,
   and command line options -k --unix-socket to the relevant programs.
2. Adds a -h option to postmaster to set the hostname or IP address to
   listen on instead of the default INADDR_ANY.
3. Extends some library interfaces to support the above.
4. Fixes a few memory leaks in PQconnectdb().

The default behavior is unchanged from stock 7.0.2; if you don't use
any of these new features, they don't change the operation.

David J. MacKenzie
@
text
@d11 1
a11 1
#    $Header: /home/projects/pgsql/cvsroot/pgsql/src/bin/scripts/dropuser,v 1.7 2000/11/11 22:59:48 petere Exp $
a61 9
	--unixsocket|-k)
		PSQLOPT="$PSQLOPT -k $2"
		shift;;
        -k*)
                PSQLOPT="$PSQLOPT $1"
                ;;
        --unixsocket=*)
                PSQLOPT="$PSQLOPT -k "`echo $1 | sed 's/^--unixsocket=//'`
                ;;
a107 1
	echo "  -k, --unixsocket=PATH           Database server Unix-domain socket name"
@


1.7
log
@Make sure shell scripts send error messages to stderr.
Improve help output.
Teach droplang to remove 'pltclu'.
@
text
@d11 1
a11 1
#    $Header: /home/projects/pgsql/cvsroot/pgsql/src/bin/scripts/dropuser,v 1.6 2000/01/19 20:08:36 petere Exp $
d62 9
d117 1
@


1.6
log
@another round of user interface cleanups
removed pg_id
fixed a few bugs in the scripts
@
text
@d11 1
a11 1
#    $Header: /usr/local/cvsroot/pgsql/src/bin/scripts/dropuser,v 1.5 2000/01/12 19:36:36 petere Exp $
d87 2
a88 2
		echo "$CMDNAME: invalid option: $1"
                echo "Try -? for help."
d142 1
a142 1
	echo "$CMDNAME: deletion of user \"$DelUser\" failed"
@


1.5
log
@Fixed a few "fixes" and bugs. Adjusted messages and options to GNU suggestions.
@
text
@d11 1
a11 1
#    $Header: /usr/local/cvsroot/pgsql/src/bin/scripts/dropuser,v 1.4 1999/12/16 20:10:02 momjian Exp $
d18 2
d64 2
a65 2
	--user|--username|-U)
		PSQLOPT="$PSQLOPT -U '$2'"
a69 3
        --user=*)
                PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--user=//'`
                ;;
d87 2
a88 1
		echo "$CMDNAME: Unrecognized option: $1. Try -? for help."
d100 6
a105 3
	echo ""
	echo "Usage: $CMDNAME [options] [username]"
	echo ""
d111 4
a114 2
#???	echo "  -e,          --echo             "
        echo "  -q,          --quiet            Don't write any messages"
d128 1
a128 1
	echo "User \"$DelUser\" and any owned databases will be permanently deleted."
d139 1
a139 1
psql $PSQLOPT -d template1 -c "DROP USER \"$DelUser\""
@


1.4
log
@Hi,

I sending promised patch with:

        * getopt_long() - for pg_dump (portable)

        * and "Usage: " changes in scripts in src/bin/
          - this changes are cosmetic only, not change any
          feature ...etc.

 All PostgreSQL routines (scripts) support now long options and
help's output is alike for all scripts and all support -? or --help.

                                                Karel

Karel Zak <zakkr@@zf.jcu.cz>              http://home.zf.jcu.cz/~zakkr/
@
text
@d11 1
a11 1
#    $Header: /usr/local/cvsroot/pgsql/src/bin/scripts/dropuser,v 1.3 1999/12/07 22:41:44 momjian Exp $
d39 1
d103 8
a110 10
	echo "    -h HOSTNAME, --host=HOSTNAME     "
	echo "    -p PORT,     --port=PORT         "
	echo "    -u USERNAME, --username=USERNAME (for connect to db)"
	echo "    -W,          --password          "
	echo "    -e,          --echo              "
        echo "    -q,          --quiet             "
	echo "    -i,          --interactive       "   
	echo "    -?,          --help              "
	echo ""
	exit 1
d137 1
a137 1
	echo "$CMDNAME: Deletion of user \"$DelUser\" failed."
@


1.3
log
@Okay, that should put us back in sync. These two patches (src & doc) are
against the sources from one hour ago and contain all the portable and
up
to date stuff.

A few other CVS "householding" things you might want to take care of:

* Remove the src/bin/cleardbdir directory

* Remove the file src/bin/psql/sql_help.h from the repository, as it is
a derived file and is build by the release_prep.

Peter Eisentraut
@
text
@d11 1
a11 1
#    $Header: /usr/local/cvsroot/pgsql/src/bin/destroyuser/destroyuser.sh,v 1.11 1999/03/14 16:00:55 momjian Exp $
a38 1
		break
a97 2
# Help

d99 13
a111 2
	echo "Usage: $CMDNAME [-h server] [-p port] [-i] [username]"
	exit 0
@


1.2
log
@Fix echo -n and read -r in scripts.
@
text
@d5 1
a5 1
#    Utility for remocing a user from the PostgreSQL database.
d11 1
a11 1
#    $Header: /usr/local/cvsroot/pgsql/src/bin/scripts/dropuser,v 1.1 1999/12/04 04:53:21 momjian Exp $
d20 1
d33 1
d45 6
d54 23
a76 8
# Uncomment these lines if you need the -U and -W options.
# They are confusing in this context, however.
#	--user|--username|-U)
#		PSQLOPT="$PSQLOPT -U $2"
#		shift;;
#	--password|-W)
#		PSQLOPT="$PSQLOPT -W"
#		;;
d102 1
a102 1
	echo "Usage: $CMDNAME [-h <server>] [-p <port>] [-i] [username]"
d110 1
a110 1
	read NewUser
d124 2
@


1.1
log
@New scripts for create/drop user/db from Peter Eisentraut
@
text
@d11 1
a11 1
#    $Header: /usr/local/cvsroot/pgsql/src/bin/destroyuser/destroyuser.sh,v 1.11 1999/03/14 16:00:55 momjian Exp $
d21 11
d86 2
a87 2
	echo -n "Enter name of user to delete: "
	read -r NewUser
d94 2
a95 2
	echo -n "Are you sure? (y/n) "
	read -r
@
