Skip to content

Commit 29a2014

Browse files
committed
Pass session_authorization to the client and make psql update its prompt
accordingly.
1 parent 4e85f76 commit 29a2014

File tree

7 files changed

+54
-15
lines changed

7 files changed

+54
-15
lines changed

doc/src/sgml/libpq.sgml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.134 2003/09/01 23:04:49 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.135 2003/09/03 22:05:01 petere Exp $
33
-->
44

55
<chapter id="libpq">
@@ -857,7 +857,8 @@ is not known.
857857
Parameters reported as of the current release include
858858
<literal>server_version</> (cannot change after startup);
859859
<literal>client_encoding</>,
860-
<literal>is_superuser</>, and
860+
<literal>is_superuser</>,
861+
<literal>session_authorization</literal>, and
861862
<literal>DateStyle</>.
862863
</para>
863864

doc/src/sgml/protocol.sgml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/protocol.sgml,v 1.42 2003/09/01 23:04:49 petere Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/protocol.sgml,v 1.43 2003/09/03 22:05:07 petere Exp $ -->
22

33
<chapter id="protocol">
44
<title>Frontend/Backend Protocol</title>
@@ -1006,7 +1006,8 @@
10061006
<literal>server_version</> (a pseudo-parameter that cannot change after
10071007
startup);
10081008
<literal>client_encoding</>,
1009-
<literal>is_superuser</>, and
1009+
<literal>is_superuser</>,
1010+
<literal>session_authorization</literal>, and
10101011
<literal>DateStyle</>.
10111012
This set might change in the future, or even become configurable.
10121013
Accordingly, a frontend should simply ignore ParameterStatus for

doc/src/sgml/ref/psql-ref.sgml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.95 2003/08/31 17:32:24 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.96 2003/09/03 22:05:08 petere Exp $
33
PostgreSQL documentation
44
-->
55

@@ -2214,8 +2214,14 @@ testdb=> <userinput>\set content '\'' `sed -e "s/'/\\\\\\'/g" < my_file.txt` '\'
22142214

22152215
<varlistentry>
22162216
<term><literal>%n</literal></term>
2217-
<listitem><para>The user name you are connected as (not your local system
2218-
user name).</para></listitem>
2217+
<listitem>
2218+
<para>
2219+
The database session user name. (The expansion of this
2220+
value might change during a database session as the result
2221+
of the command <command>SET SESSION
2222+
AUTHORIZATION</command>.)
2223+
</para>
2224+
</listitem>
22192225
</varlistentry>
22202226

22212227
<varlistentry>
@@ -2231,8 +2237,15 @@ testdb=> <userinput>\set content '\'' `sed -e "s/'/\\\\\\'/g" < my_file.txt` '\'
22312237

22322238
<varlistentry>
22332239
<term><literal>%#</literal></term>
2234-
<listitem><para>If the current user is a database superuser, then a
2235-
<literal>#</literal>, otherwise a <literal>&gt;</literal>.</para></listitem>
2240+
<listitem>
2241+
<para>
2242+
If the session user is a database superuser, then a
2243+
<literal>#</literal>, otherwise a <literal>&gt;</literal>.
2244+
(The expansion of this value might change during a database
2245+
session as the result of the command <command>SET SESSION
2246+
AUTHORIZATION</command>.)
2247+
</para>
2248+
</listitem>
22362249
</varlistentry>
22372250

22382251
<varlistentry>

src/backend/utils/misc/guc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.153 2003/09/01 23:04:49 petere Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.154 2003/09/03 22:05:08 petere Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -1501,7 +1501,7 @@ static struct config_string ConfigureNamesString[] =
15011501
{"session_authorization", PGC_USERSET, UNGROUPED,
15021502
gettext_noop("Current session userid"),
15031503
NULL,
1504-
GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
1504+
GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
15051505
},
15061506
&session_authorization_string,
15071507
NULL, assign_session_authorization, show_session_authorization

src/bin/psql/common.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.72 2003/08/14 18:48:35 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.73 2003/09/03 22:05:08 petere Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "common.h"
@@ -724,3 +724,26 @@ is_superuser(void)
724724

725725
return false;
726726
}
727+
728+
729+
/*
730+
* Return the session user of the current connection.
731+
*
732+
* Note: this will correctly detect the session user only with a
733+
* protocol-3.0 or newer backend; otherwise it will return the
734+
* connection user.
735+
*/
736+
const char *
737+
session_username(void)
738+
{
739+
const char *val;
740+
741+
if (!pset.db)
742+
return NULL;
743+
744+
val = PQparameterStatus(pset.db, "session_authorization");
745+
if (val)
746+
return val;
747+
else
748+
return PQuser(pset.db);
749+
}

src/bin/psql/common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.28 2003/08/08 04:52:21 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.29 2003/09/03 22:05:09 petere Exp $
77
*/
88
#ifndef COMMON_H
99
#define COMMON_H
@@ -37,6 +37,7 @@ extern PGresult *PSQLexec(const char *query, bool start_xact);
3737
extern bool SendQuery(const char *query);
3838

3939
extern bool is_superuser(void);
40+
extern const char *session_username(void);
4041

4142
/* Parse a numeric character code from the string pointed at by *buf, e.g.
4243
* one written as 0x0c (hexadecimal) or 015 (octal); advance *buf to the last

src/bin/psql/prompt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.28 2003/08/04 23:59:40 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.29 2003/09/03 22:05:09 petere Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "prompt.h"
@@ -160,7 +160,7 @@ get_prompt(promptStatus_t status)
160160
/* DB server user name */
161161
case 'n':
162162
if (pset.db)
163-
strncpy(buf, PQuser(pset.db), MAX_PROMPT_SIZE);
163+
strncpy(buf, session_username(), MAX_PROMPT_SIZE);
164164
break;
165165

166166
case '0':

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy