Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2780576

Browse files
committed
From: "Pedro J. Lobo" <pjlobo@euitt.upm.es>
I've patched pg_dump.c and createdb to add support for passwordauthentication, using the '-u' switch as in psql. I have updated also theman pages.
1 parent0427469 commit2780576

File tree

4 files changed

+118
-7
lines changed

4 files changed

+118
-7
lines changed

‎src/bin/createdb/createdb.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
#
1313
# IDENTIFICATION
14-
# $Header: /cvsroot/pgsql/src/bin/createdb/Attic/createdb.sh,v 1.7 1997/11/07 06:25:25 thomas Exp $
14+
# $Header: /cvsroot/pgsql/src/bin/createdb/Attic/createdb.sh,v 1.8 1998/01/29 02:26:21 scrappy Exp $
1515
#
1616
#-------------------------------------------------------------------------
1717

@@ -31,6 +31,8 @@ fi
3131

3232
dbname=$USER
3333

34+
PASSWDOPT="";
35+
3436
whiletest -n"$1"
3537
do
3638
case$1in
@@ -39,6 +41,7 @@ do
3941
-a) AUTHSYS=$2;shift;;
4042
-h) PGHOST=$2;shift;;
4143
-p) PGPORT=$2;shift;;
44+
-u) PASSWDOPT=$1;;
4245
-D) dbpath=$2;shift;;
4346
-*)echo"$CMDNAME: unrecognized parameter$1"; usage=1;;
4447
*) dbname=$1;;
@@ -80,7 +83,7 @@ else
8083
location="with location = '$dbpath'"
8184
fi
8285

83-
psql -tq$AUTHOPT$PGHOSTOPT$PGPORTOPT -c"create database$dbname$location" template1
86+
psql$PASSWDOPT-tq$AUTHOPT$PGHOSTOPT$PGPORTOPT -c"create database$dbname$location" template1
8487

8588
if [$?-ne 0 ];then
8689
echo"$CMDNAME: database creation failed on$dbname."

‎src/bin/pg_dump/pg_dump.c

Lines changed: 101 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
*
2323
* IDENTIFICATION
24-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.60 1998/01/16 23:20:39 momjian Exp $
24+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.61 1998/01/29 02:26:25 scrappy Exp $
2525
*
2626
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2727
*
@@ -44,6 +44,10 @@
4444
* - Added functions to free allocated memory used for retrieving
4545
* indices,tables,inheritance,types,functions and aggregates.
4646
* No more leaks reported by Purify.
47+
*
48+
*
49+
* Modifications - 1/26/98 - pjlobo@euitt.upm.es
50+
* - Added support for password authentication
4751
*-------------------------------------------------------------------------
4852
*/
4953

@@ -67,6 +71,10 @@
6771
#include"strdup.h"
6872
#endif
6973

74+
#ifdefHAVE_TERMIOS_H
75+
#include<termios.h>
76+
#endif
77+
7078
#include"pg_dump.h"
7179

7280
staticvoiddumpSequence(FILE*fout,TableInfotbinfo);
@@ -134,6 +142,8 @@ usage(const char *progname)
134142
"\t -v \t\t verbose\n");
135143
fprintf(stderr,
136144
"\t -z \t\t dump ACLs (grant/revoke)\n");
145+
fprintf(stderr,
146+
"\t -u \t\t use password authentication\n");
137147
fprintf(stderr,
138148
"\nIf dbname is not supplied, then the DATABASE environment "
139149
"variable value is used.\n");
@@ -455,6 +465,62 @@ dumpClasses(const TableInfo tblinfo[], const int numTables, FILE *fout,
455465
}
456466

457467

468+
staticvoid
469+
prompt_for_password(char*username,char*password)
470+
{
471+
intlength;
472+
473+
#ifdefHAVE_TERMIOS_H
474+
structtermiost_orig,
475+
t;
476+
477+
#endif
478+
479+
printf("Username: ");
480+
fgets(username,9,stdin);
481+
length=strlen(username);
482+
/* skip rest of the line */
483+
if (length>0&&username[length-1]!='\n')
484+
{
485+
staticcharbuf[512];
486+
487+
do
488+
{
489+
fgets(buf,512,stdin);
490+
}while (buf[strlen(buf)-1]!='\n');
491+
}
492+
if (length>0&&username[length-1]=='\n')
493+
username[length-1]='\0';
494+
495+
printf("Password: ");
496+
#ifdefHAVE_TERMIOS_H
497+
tcgetattr(0,&t);
498+
t_orig=t;
499+
t.c_lflag &= ~ECHO;
500+
tcsetattr(0,TCSADRAIN,&t);
501+
#endif
502+
fgets(password,9,stdin);
503+
#ifdefHAVE_TERMIOS_H
504+
tcsetattr(0,TCSADRAIN,&t_orig);
505+
#endif
506+
507+
length=strlen(password);
508+
/* skip rest of the line */
509+
if (length>0&&password[length-1]!='\n')
510+
{
511+
staticcharbuf[512];
512+
513+
do
514+
{
515+
fgets(buf,512,stdin);
516+
}while (buf[strlen(buf)-1]!='\n');
517+
}
518+
if (length>0&&password[length-1]=='\n')
519+
password[length-1]='\0';
520+
521+
printf("\n\n");
522+
}
523+
458524

459525
int
460526
main(intargc,char**argv)
@@ -470,6 +536,11 @@ main(int argc, char **argv)
470536
acls=0;
471537
TableInfo*tblinfo;
472538
intnumTables;
539+
charconnect_string[512]="";
540+
chartmp_string[128];
541+
charusername[64];
542+
charpassword[64];
543+
intuse_password=0;
473544

474545
g_verbose= false;
475546

@@ -481,7 +552,7 @@ main(int argc, char **argv)
481552

482553
progname=*argv;
483554

484-
while ((c=getopt(argc,argv,"adDf:h:op:st:vz"))!=EOF)
555+
while ((c=getopt(argc,argv,"adDf:h:op:st:vzu"))!=EOF)
485556
{
486557
switch (c)
487558
{
@@ -520,6 +591,9 @@ main(int argc, char **argv)
520591
case'z':/* Dump oids */
521592
acls=1;
522593
break;
594+
case'u':
595+
use_password=1;
596+
break;
523597
default:
524598
usage(progname);
525599
break;
@@ -551,7 +625,31 @@ main(int argc, char **argv)
551625
exit(2);
552626
}
553627

554-
g_conn=PQsetdb(pghost,pgport,NULL,NULL,dbname);
628+
/*g_conn = PQsetdb(pghost, pgport, NULL, NULL, dbname);*/
629+
if (pghost!=NULL) {
630+
sprintf(tmp_string,"host=%s ",pghost);
631+
strcat(connect_string,tmp_string);
632+
}
633+
if (pgport!=NULL) {
634+
sprintf(tmp_string,"port=%s ",pgport);
635+
strcat(connect_string,tmp_string);
636+
}
637+
if (dbname!=NULL) {
638+
sprintf(tmp_string,"dbname=%s ",dbname);
639+
strcat(connect_string,tmp_string);
640+
}
641+
if (use_password) {
642+
prompt_for_password(username,password);
643+
strcat(connect_string,"authtype=password ");
644+
sprintf(tmp_string,"user=%s ",username);
645+
strcat(connect_string,tmp_string);
646+
sprintf(tmp_string,"password=%s ",password);
647+
strcat(connect_string,tmp_string);
648+
bzero(tmp_string,sizeof(tmp_string));
649+
bzero(password,sizeof(password));
650+
}
651+
g_conn=PQconnectdb(connect_string);
652+
bzero(connect_string,sizeof(connect_string));
555653
/* check to see that the backend connection was successfully made */
556654
if (PQstatus(g_conn)==CONNECTION_BAD)
557655
{

‎src/man/createdb.1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" This is -*-nroff-*-
22
.\" XXX standard disclaimer belongs here....
3-
.\" $Header: /cvsroot/pgsql/src/man/Attic/createdb.1,v 1.7 1998/01/26 01:42:42 scrappy Exp $
3+
.\" $Header: /cvsroot/pgsql/src/man/Attic/createdb.1,v 1.8 1998/01/29 02:26:33 scrappy Exp $
44
.TH CREATEDB UNIX 11/05/95 PostgreSQL PostgreSQL
55
.SH NAME
66
createdb - create a database
@@ -16,6 +16,8 @@ host]
1616
.BR -p
1717
port]
1818
[\c
19+
.BR"-u"]
20+
[\c
1921
.BR -D
2022
location]
2123
[dbname]
@@ -77,6 +79,9 @@ extension on which the
7779
is listening for connections. Defaults to 5432, or the value of the
7880
.SMPGPORT
7981
environment variable (if set).
82+
.TP
83+
.BR"-u"
84+
Use password authentication. Prompts for username and password.
8085
.SH EXAMPLES
8186
.nf
8287
# create the demo database using the postmaster on the local host, port 5432.

‎src/man/pg_dump.1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" This is -*-nroff-*-
22
.\" XXX standard disclaimer belongs here....
3-
.\" $Header: /cvsroot/pgsql/src/man/Attic/pg_dump.1,v 1.9 1998/01/11 22:17:46 momjian Exp $
3+
.\" $Header: /cvsroot/pgsql/src/man/Attic/pg_dump.1,v 1.10 1998/01/29 02:26:47 scrappy Exp $
44
.TH PG_DUMP UNIX 1/20/96 PostgreSQL PostgreSQL
55
.SH NAME
66
pg_dump - dumps out a Postgres database into a script file
@@ -38,6 +38,8 @@ table]
3838
[\c
3939
.BR"-v"
4040
]
41+
[\c
42+
.BR"-u"]
4143
dbname
4244
.in-5n
4345
.SH DESCRIPTION
@@ -89,6 +91,9 @@ Dump out only the schema, no data
8991
.BR"-t"" table"
9092
Dump for this table only
9193
.TP
94+
.BR"-u"
95+
Use password authentication. Prompts for username and password.
96+
.TP
9297
.BR"-v"""
9398
Specifies verbose mode
9499
.PP

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp