From: "Pedro J. Lobo" <pjlobo@euitt.upm.es>

I've patched pg_dump.c and createdb to add support for password
authentication, using the '-u' switch as in psql. I have updated also the
man pages.
This commit is contained in:
Marc G. Fournier 1998-01-29 02:26:47 +00:00
parent 0427469f57
commit 2780576e36
4 changed files with 118 additions and 7 deletions

View File

@ -11,7 +11,7 @@
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/createdb/Attic/createdb.sh,v 1.7 1997/11/07 06:25:25 thomas Exp $
# $Header: /cvsroot/pgsql/src/bin/createdb/Attic/createdb.sh,v 1.8 1998/01/29 02:26:21 scrappy Exp $
#
#-------------------------------------------------------------------------
@ -31,6 +31,8 @@ fi
dbname=$USER
PASSWDOPT="";
while test -n "$1"
do
case $1 in
@ -39,6 +41,7 @@ do
-a) AUTHSYS=$2; shift;;
-h) PGHOST=$2; shift;;
-p) PGPORT=$2; shift;;
-u) PASSWDOPT=$1;;
-D) dbpath=$2; shift;;
-*) echo "$CMDNAME: unrecognized parameter $1"; usage=1;;
*) dbname=$1;;
@ -80,7 +83,7 @@ else
location="with location = '$dbpath'"
fi
psql -tq $AUTHOPT $PGHOSTOPT $PGPORTOPT -c "create database $dbname $location" template1
psql $PASSWDOPT -tq $AUTHOPT $PGHOSTOPT $PGPORTOPT -c "create database $dbname $location" template1
if [ $? -ne 0 ]; then
echo "$CMDNAME: database creation failed on $dbname."

View File

@ -21,7 +21,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.60 1998/01/16 23:20:39 momjian Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.61 1998/01/29 02:26:25 scrappy Exp $
*
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
*
@ -44,6 +44,10 @@
* - Added functions to free allocated memory used for retrieving
* indices,tables,inheritance,types,functions and aggregates.
* No more leaks reported by Purify.
*
*
* Modifications - 1/26/98 - pjlobo@euitt.upm.es
* - Added support for password authentication
*-------------------------------------------------------------------------
*/
@ -67,6 +71,10 @@
#include "strdup.h"
#endif
#ifdef HAVE_TERMIOS_H
#include <termios.h>
#endif
#include "pg_dump.h"
static void dumpSequence(FILE *fout, TableInfo tbinfo);
@ -134,6 +142,8 @@ usage(const char *progname)
"\t -v \t\t verbose\n");
fprintf(stderr,
"\t -z \t\t dump ACLs (grant/revoke)\n");
fprintf(stderr,
"\t -u \t\t use password authentication\n");
fprintf(stderr,
"\nIf dbname is not supplied, then the DATABASE environment "
"variable value is used.\n");
@ -455,6 +465,62 @@ dumpClasses(const TableInfo tblinfo[], const int numTables, FILE *fout,
}
static void
prompt_for_password(char *username, char *password)
{
int length;
#ifdef HAVE_TERMIOS_H
struct termios t_orig,
t;
#endif
printf("Username: ");
fgets(username, 9, stdin);
length = strlen(username);
/* skip rest of the line */
if (length > 0 && username[length - 1] != '\n')
{
static char buf[512];
do
{
fgets(buf, 512, stdin);
} while (buf[strlen(buf) - 1] != '\n');
}
if (length > 0 && username[length - 1] == '\n')
username[length - 1] = '\0';
printf("Password: ");
#ifdef HAVE_TERMIOS_H
tcgetattr(0, &t);
t_orig = t;
t.c_lflag &= ~ECHO;
tcsetattr(0, TCSADRAIN, &t);
#endif
fgets(password, 9, stdin);
#ifdef HAVE_TERMIOS_H
tcsetattr(0, TCSADRAIN, &t_orig);
#endif
length = strlen(password);
/* skip rest of the line */
if (length > 0 && password[length - 1] != '\n')
{
static char buf[512];
do
{
fgets(buf, 512, stdin);
} while (buf[strlen(buf) - 1] != '\n');
}
if (length > 0 && password[length - 1] == '\n')
password[length - 1] = '\0';
printf("\n\n");
}
int
main(int argc, char **argv)
@ -470,6 +536,11 @@ main(int argc, char **argv)
acls = 0;
TableInfo *tblinfo;
int numTables;
char connect_string[512] = "";
char tmp_string[128];
char username[64];
char password[64];
int use_password = 0;
g_verbose = false;
@ -481,7 +552,7 @@ main(int argc, char **argv)
progname = *argv;
while ((c = getopt(argc, argv, "adDf:h:op:st:vz")) != EOF)
while ((c = getopt(argc, argv, "adDf:h:op:st:vzu")) != EOF)
{
switch (c)
{
@ -520,6 +591,9 @@ main(int argc, char **argv)
case 'z': /* Dump oids */
acls = 1;
break;
case 'u':
use_password = 1;
break;
default:
usage(progname);
break;
@ -551,7 +625,31 @@ main(int argc, char **argv)
exit(2);
}
g_conn = PQsetdb(pghost, pgport, NULL, NULL, dbname);
/*g_conn = PQsetdb(pghost, pgport, NULL, NULL, dbname);*/
if (pghost != NULL) {
sprintf(tmp_string, "host=%s ", pghost);
strcat(connect_string, tmp_string);
}
if (pgport != NULL) {
sprintf(tmp_string, "port=%s ", pgport);
strcat(connect_string, tmp_string);
}
if (dbname != NULL) {
sprintf(tmp_string, "dbname=%s ", dbname);
strcat(connect_string, tmp_string);
}
if (use_password) {
prompt_for_password(username, password);
strcat(connect_string, "authtype=password ");
sprintf(tmp_string, "user=%s ", username);
strcat(connect_string, tmp_string);
sprintf(tmp_string, "password=%s ", password);
strcat(connect_string, tmp_string);
bzero(tmp_string, sizeof(tmp_string));
bzero(password, sizeof(password));
}
g_conn = PQconnectdb(connect_string);
bzero(connect_string, sizeof(connect_string));
/* check to see that the backend connection was successfully made */
if (PQstatus(g_conn) == CONNECTION_BAD)
{

View File

@ -1,6 +1,6 @@
.\" This is -*-nroff-*-
.\" XXX standard disclaimer belongs here....
.\" $Header: /cvsroot/pgsql/src/man/Attic/createdb.1,v 1.7 1998/01/26 01:42:42 scrappy Exp $
.\" $Header: /cvsroot/pgsql/src/man/Attic/createdb.1,v 1.8 1998/01/29 02:26:33 scrappy Exp $
.TH CREATEDB UNIX 11/05/95 PostgreSQL PostgreSQL
.SH NAME
createdb - create a database
@ -16,6 +16,8 @@ host]
.BR -p
port]
[\c
.BR "-u"]
[\c
.BR -D
location]
[dbname]
@ -77,6 +79,9 @@ extension on which the
is listening for connections. Defaults to 5432, or the value of the
.SM PGPORT
environment variable (if set).
.TP
.BR "-u"
Use password authentication. Prompts for username and password.
.SH EXAMPLES
.nf
# create the demo database using the postmaster on the local host, port 5432.

View File

@ -1,6 +1,6 @@
.\" This is -*-nroff-*-
.\" XXX standard disclaimer belongs here....
.\" $Header: /cvsroot/pgsql/src/man/Attic/pg_dump.1,v 1.9 1998/01/11 22:17:46 momjian Exp $
.\" $Header: /cvsroot/pgsql/src/man/Attic/pg_dump.1,v 1.10 1998/01/29 02:26:47 scrappy Exp $
.TH PG_DUMP UNIX 1/20/96 PostgreSQL PostgreSQL
.SH NAME
pg_dump - dumps out a Postgres database into a script file
@ -38,6 +38,8 @@ table]
[\c
.BR "-v"
]
[\c
.BR "-u"]
dbname
.in -5n
.SH DESCRIPTION
@ -89,6 +91,9 @@ Dump out only the schema, no data
.BR "-t" " table"
Dump for this table only
.TP
.BR "-u"
Use password authentication. Prompts for username and password.
.TP
.BR "-v" ""
Specifies verbose mode
.PP