head	1.32;
access;
symbols
	REL7_3_21:1.29.2.1
	REL7_3_20:1.29.2.1
	REL7_3_19:1.29.2.1
	REL7_3_18:1.29.2.1
	REL7_3_17:1.29.2.1
	REL7_3_16:1.29.2.1
	REL7_3_15:1.29.2.1
	REL7_3_14:1.29.2.1
	REL7_3_13:1.29.2.1
	REL7_3_12:1.29.2.1
	REL7_3_11:1.29.2.1
	REL7_2_8:1.22
	REL7_3_10:1.29.2.1
	REL7_2_7:1.22
	REL7_3_9:1.29.2.1
	REL7_3_8:1.29.2.1
	REL7_2_6:1.22
	REL7_2_5:1.22
	REL7_3_7:1.29.2.1
	REL7_3_6:1.29.2.1
	REL7_3_5:1.29.2.1
	REL7_3_4:1.29.2.1
	REL7_3_2:1.29
	REL7_2_4:1.22
	REL7_3_STABLE:1.29.0.2
	REL7_2_3:1.22
	REL7_2_STABLE:1.22.0.2
	REL7_2:1.22
	REL7_2_RC2:1.22
	REL7_2_RC1:1.22
	REL7_2_BETA5:1.22
	REL7_2_BETA4:1.22
	REL7_2_BETA3:1.22
	REL7_2_BETA2:1.22
	REL7_2_BETA1:1.22
	REL7_1_2:1.17
	REL7_1_STABLE:1.17.0.2
	REL7_1_BETA:1.15
	REL7_1_BETA3:1.15
	REL7_1_BETA2:1.15
	REL7_1:1.17
	REL7_0_PATCHES:1.9.0.2
	REL7_0:1.9;
locks; strict;
comment	@# @;


1.32
date	2003.03.18.22.19.46;	author petere;	state dead;
branches;
next	1.31;

1.31
date	2003.02.19.03.52.57;	author momjian;	state Exp;
branches;
next	1.30;

1.30
date	2003.02.13.05.37.44;	author momjian;	state Exp;
branches;
next	1.29;

1.29
date	2002.10.18.22.05.36;	author petere;	state Exp;
branches
	1.29.2.1;
next	1.28;

1.28
date	2002.10.16.03.44.28;	author momjian;	state Exp;
branches;
next	1.27;

1.27
date	2002.10.16.03.24.09;	author momjian;	state Exp;
branches;
next	1.26;

1.26
date	2002.06.20.20.29.42;	author momjian;	state Exp;
branches;
next	1.25;

1.25
date	2002.04.12.09.42.31;	author momjian;	state Exp;
branches;
next	1.24;

1.24
date	2002.04.12.09.37.10;	author momjian;	state Exp;
branches;
next	1.23;

1.23
date	2002.02.18.05.48.44;	author momjian;	state Exp;
branches;
next	1.22;

1.22
date	2001.09.30.22.17.51;	author momjian;	state Exp;
branches;
next	1.21;

1.21
date	2001.09.22.04.28.12;	author momjian;	state Exp;
branches;
next	1.20;

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

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

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

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

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

1.15
date	2000.11.25.19.05.44;	author petere;	state Exp;
branches;
next	1.14;

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

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

1.12
date	2000.11.11.22.59.48;	author petere;	state Exp;
branches;
next	1.11;

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

1.10
date	2000.06.09.15.50.53;	author momjian;	state Exp;
branches;
next	1.9;

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

1.8
date	2000.01.19.20.08.36;	author petere;	state Exp;
branches;
next	1.7;

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

1.6
date	2000.01.14.22.11.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	;

1.29.2.1
date	2003.05.16.15.17.02;	author tgl;	state Exp;
branches;
next	;


desc
@@


1.32
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
#-------------------------------------------------------------------------
#
# createuser--
#    Utility for creating a user in 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/createuser,v 1.31 2003/02/19 03:52:57 momjian Exp $
#
# Note - this should NOT be setuid.
#
#-------------------------------------------------------------------------

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

NewUser=
SysID=
CanAddUser=
CanCreateDb=
PwPrompt=
Password=
PSQLOPT=
Encrypted=	# blank uses default

# 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 creating.
	--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"
		;;
# options converted into SQL command	
        --createdb|-d)
		CanCreateDb=t
		;;
        --no-createdb|-D)
		CanCreateDb=f
		;;
        --adduser|-a)
		CanAddUser=t
		;;
        --no-adduser|-A)
		CanAddUser=f
		;;
        --sysid|-i)
                SysID="$2"
                shift;;
        --sysid=*)
                SysID=`echo "$1" | sed 's/^--sysid=//'`
                ;;
        --encrypted|-E)
		Encrypted=t
		;;
        --unencrypted|-N)
		Encrypted=f
		;;
        -i*)
                SysID=`echo "$1" | sed 's/^-i//'`
                ;;
	--pwprompt|--pw|-P)
		PwPrompt=t
		;;
	-*)
		echo "$CMDNAME: invalid option: $1" 1>&2
                echo "Try '$CMDNAME --help' for more information." 1>&2
		exit 1
		;;
         *)
		NewUser="$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 creates a new PostgreSQL user."
        echo
	echo "Usage:"
        echo "  $CMDNAME [OPTION]... [USERNAME]"
        echo
	echo "Options:"
	echo "  -a, --adduser             user can add new users"
	echo "  -A, --no-adduser          user cannot add new users"
	echo "  -d, --createdb            user can create new databases"
	echo "  -D, --no-createdb         user cannot create databases"
	echo "  -P, --pwprompt            assign a password to new user"
	echo "  -E, --encrypted           encrypt stored password"
	echo "  -N, --unencrypted         do no encrypt stored password"
	echo "  -i, --sysid=SYSID         select sysid for new user"     
	echo "  -e, --echo                show the query being sent to the backend"
	echo "  -q, --quiet               don't write any messages"
	echo "  --help                    show this help, then exit"
	echo
	echo "Connection options:"
	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 create)"
	echo "  -W, --password            prompt for password to connect"
	echo
        echo "If one of -a, -A, -d, -D, and USERNAME is not specified, you will"
        echo "be prompted interactively."
        echo
	echo "Report bugs to <pgsql-bugs@@postgresql.org>."
	exit 0
fi

if [ "$SysID" ]; then
        if [ "$SysID" != "`echo $SysID | sed 's/[^0-9]//g'`" ]; then
                echo "$CMDNAME: user sysid must be a positive number" 1>&2
                exit 1
        fi
fi

# Don't want to leave the user blind if he breaks
# during password entry.

trap 'stty echo >/dev/null 2>&1; echo; exit 1' 1 2 3 15

# Get missing user attributes

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

if [ "$PwPrompt" ]; then
	$ECHO_N "Enter password for user \"$NewUser\": "$ECHO_C
        stty -echo >/dev/null 2>&1
        IFS="$NL"
        read FirstPw
        IFS="$_IFS"
        stty echo >/dev/null 2>&1
        echo
        $ECHO_N "Enter it again: "$ECHO_C
        stty -echo >/dev/null 2>&1
        IFS="$NL"
        read SecondPw
        IFS="$_IFS"
        stty echo >/dev/null 2>&1
        echo
        if [ "$FirstPw" != "$SecondPw" ]; then
            echo "Passwords didn't match." 1>&2
            exit 1
        fi
	Password="$FirstPw"
fi

if [ -z "$CanCreateDb" ]; then
	$ECHO_N "Shall the new user be allowed to create databases? (y/n) "$ECHO_C
	read REPLY
	[ "$?" -ne 0 ] && exit 1
	if [ "$REPLY" = "y" -o "$REPLY" = "Y" ]; then
		CanCreateDb=t
	else
		CanCreateDb=f
	fi
fi

if [ -z "$CanAddUser" ]; then
	$ECHO_N "Shall the new user be allowed to create more new users? (y/n) "$ECHO_C
	read REPLY
	[ "$?" -ne 0 ] && exit 1
	if [ "$REPLY" = "y" -o "$REPLY" = "Y" ]; then
		CanAddUser=t
	else
		CanAddUser=f
	fi
fi


#
# build SQL command
#
NewUser=`echo "$NewUser" | sed 's/\"/\\\"/g'`
Password=`echo "$Password" | sed 's/\"/\\\"/g'`

QUERY="CREATE USER \"$NewUser\""

SUBQUERY=
[ "$SysID" ] &&    SUBQUERY="$SUBQUERY SYSID $SysID"
[ "$Encrypted" = t ] &&   SUBQUERY="$SUBQUERY ENCRYPTED"
[ "$Encrypted" = f ] &&   SUBQUERY="$SUBQUERY UNENCRYPTED"
[ "$Password" ] &&        SUBQUERY="$SUBQUERY PASSWORD '$Password'"
[ "$SUBQUERY" ] &&        QUERY="$QUERY WITH $SUBQUERY"

[ "$CanCreateDb" = t ] && QUERY="$QUERY CREATEDB"
[ "$CanCreateDb" = f ] && QUERY="$QUERY NOCREATEDB"
[ "$CanAddUser" = t ] &&  QUERY="$QUERY CREATEUSER"
[ "$CanAddUser" = f ] &&  QUERY="$QUERY NOCREATEUSER"

${PATHNAME}psql -c "SET autocommit TO 'on';$QUERY" -d template1 $PSQLOPT
if [ "$?" -ne 0 ]; then
	echo "$CMDNAME: creation of user \"$NewUser\" failed" 1>&2
	exit 1
fi
		
exit 0
@


1.31
log
@At present it is impossible to kill createuser except with kill -9

Oliver Elphick
@
text
@d12 1
a12 1
#    $Header: /cvsroot/pgsql-server/src/bin/scripts/createuser,v 1.30 2003/02/13 05:37:44 momjian Exp $
@


1.30
log
@This patch fixes an error in the usage message for 'clusterdb', and
makes a few editorial changes to the documentation.


Neil Conway
@
text
@d12 1
a12 1
#    $Header: /cvsroot/pgsql-server/src/bin/scripts/createuser,v 1.29 2002/10/18 22:05:36 petere Exp $
d182 1
a182 1
trap 'stty echo >/dev/null 2>&1' 1 2 3 15
@


1.29
log
@Improve formatting of --help output.
@
text
@d12 1
a12 1
#    $Header: /cvsroot/pgsql-server/src/bin/scripts/createuser,v 1.28 2002/10/16 03:44:28 momjian Exp $
d156 2
a157 2
        echo "  -q, --quiet               don't write any messages"
	echo " --help                     show this help, then exit"
@


1.29.2.1
log
@Back-patch fix to allow createuser to exit on control-C (Oliver Elphick)
@
text
@d12 1
a12 1
#    $Header: /cvsroot/pgsql-server/src/bin/scripts/createuser,v 1.29 2002/10/18 22:05:36 petere Exp $
d182 1
a182 1
trap 'stty echo >/dev/null 2>&1; echo; exit 1' 1 2 3 15
@


1.28
log
@Improve appearance of SET command.
@
text
@d12 1
a12 1
#    $Header: /cvsroot/pgsql-server/src/bin/scripts/createuser,v 1.27 2002/10/16 03:24:09 momjian Exp $
d144 1
a144 1
        echo "  $CMDNAME [options] [username]"
d147 11
a157 14
	echo "  -d, --createdb                  User can create new databases"
	echo "  -D, --no-createdb               User cannot create databases"
	echo "  -a, --adduser                   User can add new users"
	echo "  -A, --no-adduser                User cannot add new users"
	echo "  -i, --sysid=SYSID               Select sysid for new user"     
	echo "  -P, --pwprompt                  Assign a password to new user"
	echo "  -E, --encrypted                 Encrypt stored password"
	echo "  -N, --unencrypted               Do no encrypt stored password"
	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 create)"
	echo "  -W, --password                  Prompt for password to connect"
	echo "  -e, --echo                      Show the query being sent to the backend"
        echo "  -q, --quiet                     Don't write any messages"
d159 7
a165 1
        echo "If one of -d, -D, -a, -A, and 'username' is not specified, you will"
@


1.27
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/createuser,v 1.26 2002/06/20 20:29:42 momjian Exp $
d256 1
a256 1
${PATHNAME}psql -c "SET autocommit = 'on';$QUERY" -d template1 $PSQLOPT
@


1.26
log
@Update copyright to 2002.
@
text
@d12 1
a12 1
#    $Header: /cvsroot/pgsql/src/bin/scripts/createuser,v 1.25 2002/04/12 09:42:31 momjian Exp $
d256 1
a256 1
${PATHNAME}psql -c "$QUERY" -d template1 $PSQLOPT
@


1.25
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/createuser,v 1.24 2002/04/12 09:37:10 momjian Exp $
@


1.24
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/createuser,v 1.23 2002/02/18 05:48:44 momjian Exp $
d30 4
d185 3
a187 1
	read NewUser
d194 1
d196 1
d201 1
d203 1
@


1.23
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/createuser,v 1.22 2001/09/30 22:17:51 momjian Exp $
d19 1
a19 1
PATHNAME=`echo $0 | sed "s,$CMDNAME\$,,"`
d57 1
a57 1
                PSQLOPT="$PSQLOPT -h "`echo $1 | sed 's/^--host=//'`
d66 1
a66 1
                PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'`
d77 1
a77 1
                PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--username=//'`
@


1.22
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/createuser,v 1.21 2001/09/22 04:28:12 momjian Exp $
d126 5
@


1.21
log
@sbasename $0 is now basename "$0"
@
text
@d12 1
a12 1
#    $Header: /cvsroot/pgsql/src/bin/scripts/createuser,v 1.20 2001/08/26 04:19:46 momjian Exp $
d42 1
a42 1
while [ $# -gt 0 ]
d177 1
a177 1
	[ $? -ne 0 ] && exit 1
d201 1
a201 1
	[ $? -ne 0 ] && exit 1
d212 1
a212 1
	[ $? -ne 0 ] && exit 1
d242 1
a242 1
if [ $? -ne 0 ]; then
@


1.20
log
@Add single-letter encryption options for createuser.  Update createuser --help.
@
text
@d12 1
a12 1
#    $Header: /home/projects/pgsql/cvsroot/pgsql/src/bin/scripts/createuser,v 1.19 2001/08/26 03:46:58 momjian Exp $
d18 1
a18 1
CMDNAME=`basename $0`
@


1.19
log
@Put createuser ENCRYPTED/UNENCRYPTED in the proper place in the query.
@
text
@d12 1
a12 1
#    $Header: /home/projects/pgsql/cvsroot/pgsql/src/bin/scripts/createuser,v 1.18 2001/08/25 17:46:11 momjian Exp $
d107 1
a107 1
        --encrypted)
d110 1
a110 1
        --unencrypted)
d144 2
@


1.18
log
@Add ENCRYPTED/UNENCRYPTED control in createuser script.
@
text
@d12 1
a12 1
#    $Header: /home/projects/pgsql/cvsroot/pgsql/src/bin/scripts/createuser,v 1.17 2001/02/18 18:34:01 momjian Exp $
d229 3
a231 1
[ "$Password" ] && SUBQUERY="$SUBQUERY PASSWORD '$Password'"
a237 2
[ "$Encrypted" = t ] &&   QUERY="$QUERY ENCRYPTED"
[ "$Encrypted" = f ] &&   QUERY="$QUERY UNENCRYPTED"
@


1.17
log
@Add copyright mentions, per Tom Lane.
@
text
@d12 1
a12 1
#    $Header: /home/projects/pgsql/cvsroot/pgsql/src/bin/scripts/createuser,v 1.16 2001/01/21 05:16:45 momjian Exp $
d28 1
d107 6
d236 2
@


1.16
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/createuser,v 1.15 2000/11/25 19:05:44 petere Exp $
@


1.15
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/createuser,v 1.14 2000/11/13 23:37:53 momjian Exp $
d100 1
a100 1
                SysID=$2
d103 1
a103 1
                SysID=`echo $1 | sed 's/^--sysid=//'`
d106 1
a106 1
                SysID=`echo $1 | sed 's/^-i//'`
d117 1
a117 1
		NewUser=$1
d185 1
a185 1
	Password=$FirstPw
d192 1
a192 1
	if [ $REPLY = "y" -o $REPLY = "Y" ]; then
d203 1
a203 1
	if [ $REPLY = "y" -o $REPLY = "Y" ]; then
d214 2
a215 2
NewUser=`echo $NewUser | sed 's/\"/\\\"/g'`
Password=`echo $Password | sed 's/\"/\\\"/g'`
@


1.14
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/createuser,v 1.13 2000/11/13 15:18:14 momjian Exp $
d113 1
a113 1
                echo "Try '$CMDNAME -?' for help." 1>&2
@


1.13
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/createuser,v 1.12 2000/11/11 22:59:48 petere Exp $
a65 9
	--unixsocket|-k)
		PSQLOPT="$PSQLOPT -k $2"
		shift;;
        -k*)
                PSQLOPT="$PSQLOPT $1"
                ;;
        --unixsocket=*)
                PSQLOPT="$PSQLOPT -k "`echo $1 | sed 's/^--unixsocket=//'`
                ;;
a137 1
	echo "  -k, --unixsocket=PATH           Database server Unix-domain socket name"
@


1.12
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/createuser,v 1.11 2000/06/12 03:40:49 momjian Exp $
d66 9
d147 1
@


1.11
log
@Back out pg_shadow changes to allow create table and locking permissions.
@
text
@d11 1
a11 1
#    $Header: /home/projects/pgsql/cvsroot/pgsql/src/bin/scripts/createuser,v 1.9 2000/03/25 14:36:58 momjian Exp $
d112 2
a113 2
		echo "$CMDNAME: invalid option: $1"
                echo "Try -? for help."
d143 3
d152 1
a152 1
                echo "$CMDNAME: user sysid must be a positive number"
d182 1
a182 1
            echo "Passwords didn't match."
d231 1
a231 1
	echo "$CMDNAME: creation of user \"$NewUser\" failed"
@


1.10
log
@ I have large database and with this DB work more users and I very need
more restriction for fretful users. The current PG allow define only
NO-CREATE-DB and NO-CREATE-USER restriction, but for some users I need
NO-CREATE-TABLE and NO-LOCK-TABLE.

This patch add to current code NOCREATETABLE and NOLOCKTABLE feature:

CREATE USER username
    [ WITH
     [ SYSID uid ]
     [ PASSWORD 'password' ] ]
    [ CREATEDB   | NOCREATEDB ] [ CREATEUSER | NOCREATEUSER ]
->  [ CREATETABLE | NOCREATETABLE ] [ LOCKTABLE | NOLOCKTABLE ]
    ...etc.

 If CREATETABLE or LOCKTABLE is not specific in CREATE USER command,
as default is set CREATETABLE or LOCKTABLE (true).

 A user with NOCREATETABLE restriction can't call CREATE TABLE or
SELECT INTO commands, only create temp table is allow for him.

                                                Karel
@
text
@a23 2
CanCreateTab=
CanLockTab=
a92 12
        --createtable|-t)
		CanCreateTab=t
		;;
        --no-createtable|-T)
		CanCreateTab=f
		;;	
        --locktable|-l)
		CanLockTab=t
		;;
        --no-locktable|-L)
		CanLockTab=f
		;;			
a131 4
	echo "  -t, --createtable               User can create new tables"
	echo "  -T, --no-createtable            User cannot create tables"	
	echo "  -l, --locktable                 User can lock tables"
	echo "  -L, --no-locktable              User cannot lock tables"	
a206 21
if [ -z "$CanCreateTab" ]; then
	$ECHO_N "Shall the new user be allowed to create tables? (y/n) "$ECHO_C
	read REPLY
	[ $? -ne 0 ] && exit 1
	if [ $REPLY = "y" -o $REPLY = "Y" ]; then
		CanCreateTab=t
	else
		CanCreateTab=f
	fi
fi

if [ -z "$CanLockTab" ]; then
	$ECHO_N "Shall the new user be allowed to lock tables? (y/n) "$ECHO_C
	read REPLY
	[ $? -ne 0 ] && exit 1
	if [ $REPLY = "y" -o $REPLY = "Y" ]; then
		CanLockTab=t
	else
		CanLockTab=f
	fi
fi
a224 5
[ "$CanCreateTab" = t ] && QUERY="$QUERY CREATETABLE"
[ "$CanCreateTab" = f ] && QUERY="$QUERY NOCREATETABLE"
[ "$CanLockTab" = t ] && QUERY="$QUERY LOCKTABLE"
[ "$CanLockTab" = f ] && QUERY="$QUERY NOLOCKTABLE"

@


1.9
log
@More changes of >& to 2>&1
@
text
@d11 1
a11 1
#    $Header: /usr/local/cvsroot/pgsql/src/bin/scripts/createuser,v 1.8 2000/01/19 20:08:36 petere Exp $
d24 2
d95 12
d146 4
d225 21
d264 5
@


1.8
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/createuser,v 1.6 2000/01/14 22:11:36 petere Exp $
d157 1
a157 1
trap 'stty echo >& /dev/null' 1 2 3 15
d169 1
a169 1
        stty -echo >& /dev/null
d171 1
a171 1
        stty echo >& /dev/null
d174 1
a174 1
        stty -echo >& /dev/null
d176 1
a176 1
        stty echo >& /dev/null
@


1.7
log
@Removed MBFLAGS from makefiles since it's now done in include/config.h.
@
text
@d18 1
d68 2
a69 2
	--user|--username|-U)
		PSQLOPT="$PSQLOPT -U '$2'"
a73 3
        --user=*)
                PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--user=//'`
                ;;
d112 1
a112 1
		echo "$CMDNAME: unrecognized option: $1"
d124 6
a129 2
	echo "Usage: $CMDNAME [options] [username]"
	echo ""
d140 4
a143 2
#???	echo "  -e,          --echo             "
        echo "  -q,          --quiet            Don't write any messages"
d226 1
a226 1
psql $PSQLOPT -d template1 -c "$QUERY"
@


1.6
log
@* User management commands no longer user pg_exec_query_dest -> more robust

* Let unprivileged users change their own passwords.

* The password is now an Sconst in the parser, which better reflects its text datatype and also
forces users to quote them.

* If your password is NULL you won't be written to the password file, meaning you can't connect
until you have a password set up (if you use password authentication).

* When you drop a user that owns a database you get an error. The database is not gone.
@
text
@d11 1
a11 1
#    $Header: /usr/local/cvsroot/pgsql/src/bin/scripts/createuser,v 1.5 2000/01/12 19:36:36 petere Exp $
d150 5
d165 14
a178 1
	read Password
@


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/createuser,v 1.4 1999/12/16 20:10:02 momjian Exp $
d196 1
a196 1
[ "$Password" ] && SUBQUERY="$SUBQUERY PASSWORD \"$Password\""
@


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/createuser,v 1.3 1999/12/07 22:41:44 momjian Exp $
d44 1
d114 2
a115 1
		echo "$CMDNAME: Unrecognized option: $1. Try -? for help."
a125 1
	echo ""
d128 13
a140 15
	echo "    -h HOSTNAME, --host=HOSTNAME     "
	echo "    -p PORT,     --port=PORT         "
	echo "    -d,          --createdb          "
	echo "    -D,          --no-createdb       "
	echo "    -a,          --adduser           "
	echo "    -A,          --no-adduser        "
	echo "    -i SYSID,    --sysid=SYSID       "     
	echo "    -P,          --pwprompt          "
	echo "    -U USERNAME, --username=USERNAME (for connect to db)"
	echo "    -W,          --password          (for connect to db)"
	echo "    -e,          --echo              "
        echo "    -q,          --quiet             "   
	echo "    -?,          --help              "
	echo ""
	exit 1
d145 1
a145 1
                echo "$CMDNAME: User sysid must be a positive number."
d206 1
a206 1
	echo "$CMDNAME: Creation of user \"$NewUser\" 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/createuser/createuser.sh,v 1.12 1999/07/30 18:09:49 momjian Exp $
a43 1
		break
d123 19
a141 6

# Help

if [ "$usage" ]; then
	echo "Usage: $CMDNAME [-h server] [-p port] [-d|-D] [-a|-A] [-P] [-i id] [username]"
	exit 0
a142 1

@


1.2
log
@Fix echo -n and read -r in scripts.
@
text
@d11 1
a11 1
#    $Header: /usr/local/cvsroot/pgsql/src/bin/scripts/createuser,v 1.1 1999/12/04 04:53:21 momjian Exp $
d38 1
d50 6
d59 23
a81 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"
#		;;
d101 9
d128 1
a128 1
	echo "Usage: $CMDNAME [-h <server>] [-p <port>] [-d|-D] [-a|-A] [-P] [username]"
d133 7
d149 1
a149 1
	$ECHO_N "Enter password for user $NewUser: "$ECHO_C
d154 1
a154 1
	$ECHO_N "Is the new user allowed to create databases? (y/n) "$ECHO_C
d179 3
d184 5
a188 1
[ "$Password" ] &&        QUERY="$QUERY WITH PASSWORD \"$Password\""
@


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/createuser/createuser.sh,v 1.12 1999/07/30 18:09:49 momjian Exp $
d27 10
d105 2
a106 2
	echo -n "Enter name of user to add: "
	read -r NewUser
d111 2
a112 2
	echo -n "Enter password for user $NewUser: "
	read -r Password
d116 2
a117 2
	echo -n "Is the new user allowed to create databases? (y/n) "
	read -r
d127 2
a128 2
	echo -n "Shall the new user be allowed to create more new users? (y/n) "
	read -r
d155 1
a155 1
exit 0@
