Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
f5df006a
Commit
f5df006a
authored
Jul 25, 2005
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add username for psql password prompt, if the username was specified.
Adrian Maier
parent
9ad9e694
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
6 deletions
+28
-6
src/bin/psql/command.c
src/bin/psql/command.c
+14
-3
src/bin/psql/startup.c
src/bin/psql/startup.c
+14
-3
No files found.
src/bin/psql/command.c
View file @
f5df006a
...
...
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.15
0 2005/07/18 20:57:53
momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.15
1 2005/07/25 17:17:41
momjian Exp $
*/
#include "postgres_fe.h"
#include "command.h"
...
...
@@ -911,6 +911,7 @@ do_connect(const char *new_dbname, const char *new_user)
const
char
*
dbparam
=
NULL
;
const
char
*
userparam
=
NULL
;
const
char
*
pwparam
=
NULL
;
char
*
password_prompt
=
NULL
;
char
*
prompted_password
=
NULL
;
bool
need_pass
;
bool
success
=
false
;
...
...
@@ -930,9 +931,18 @@ do_connect(const char *new_dbname, const char *new_user)
else
userparam
=
new_user
;
if
(
userparam
==
NULL
)
password_prompt
=
strdup
(
"Password: "
);
else
{
password_prompt
=
malloc
(
strlen
(
"Password for user %s: "
)
-
2
+
strlen
(
userparam
)
+
1
);
sprintf
(
password_prompt
,
"Password for user %s: "
,
userparam
);
}
/* need to prompt for password? */
if
(
pset
.
getPassword
)
pwparam
=
prompted_password
=
simple_prompt
(
"Password: "
,
100
,
false
);
pwparam
=
prompted_password
=
simple_prompt
(
password_prompt
,
100
,
false
);
/*
* Use old password (if any) if no new one given and we are
...
...
@@ -956,11 +966,12 @@ do_connect(const char *new_dbname, const char *new_user)
need_pass
=
true
;
free
(
prompted_password
);
prompted_password
=
NULL
;
pwparam
=
prompted_password
=
simple_prompt
(
"Password: "
,
100
,
false
);
pwparam
=
prompted_password
=
simple_prompt
(
password_prompt
,
100
,
false
);
}
}
while
(
need_pass
);
free
(
prompted_password
);
free
(
password_prompt
);
/*
* If connection failed, try at least keep the old one. That's
...
...
src/bin/psql/startup.c
View file @
f5df006a
...
...
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.1
19 2005/07/14 08:42:37
momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.1
20 2005/07/25 17:17:41
momjian Exp $
*/
#include "postgres_fe.h"
...
...
@@ -106,6 +106,7 @@ main(int argc, char *argv[])
char
*
username
=
NULL
;
char
*
password
=
NULL
;
char
*
password_prompt
=
NULL
;
bool
need_pass
;
set_pglocale_pgservice
(
argv
[
0
],
"psql"
);
...
...
@@ -188,8 +189,17 @@ main(int argc, char *argv[])
username
=
pg_strdup
(
options
.
username
);
}
if
(
options
.
username
==
NULL
)
password_prompt
=
strdup
(
"Password: "
);
else
{
password_prompt
=
malloc
(
strlen
(
"Password for user %s: "
)
-
2
+
strlen
(
options
.
username
)
+
1
);
sprintf
(
password_prompt
,
"Password for user %s: "
,
options
.
username
);
}
if
(
pset
.
getPassword
)
password
=
simple_prompt
(
"Password: "
,
100
,
false
);
password
=
simple_prompt
(
password_prompt
,
100
,
false
);
/* loop until we have a password if requested by backend */
do
...
...
@@ -207,12 +217,13 @@ main(int argc, char *argv[])
need_pass
=
true
;
free
(
password
);
password
=
NULL
;
password
=
simple_prompt
(
"Password: "
,
100
,
false
);
password
=
simple_prompt
(
password_prompt
,
100
,
false
);
}
}
while
(
need_pass
);
free
(
username
);
free
(
password
);
free
(
password_prompt
);
if
(
PQstatus
(
pset
.
db
)
==
CONNECTION_BAD
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment