diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index fd06b51905cfd6093390d9181ba3f111ae2db006..27bb09e8201b4e73421f4e842537a9962b1add32 100644 --- a/doc/src/sgml/libpq.sgml +++ b/doc/src/sgml/libpq.sgml @@ -1,5 +1,5 @@ <!-- -$Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.134 2003/09/01 23:04:49 petere Exp $ +$Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.135 2003/09/03 22:05:01 petere Exp $ --> <chapter id="libpq"> @@ -857,7 +857,8 @@ is not known. Parameters reported as of the current release include <literal>server_version</> (cannot change after startup); <literal>client_encoding</>, -<literal>is_superuser</>, and +<literal>is_superuser</>, +<literal>session_authorization</literal>, and <literal>DateStyle</>. </para> diff --git a/doc/src/sgml/protocol.sgml b/doc/src/sgml/protocol.sgml index 5127bd66d529f7b76d9b435f929bbfbd6713b297..09768a46cf7b78b55b486e50d3b484616033ae88 100644 --- a/doc/src/sgml/protocol.sgml +++ b/doc/src/sgml/protocol.sgml @@ -1,4 +1,4 @@ -<!-- $Header: /cvsroot/pgsql/doc/src/sgml/protocol.sgml,v 1.42 2003/09/01 23:04:49 petere Exp $ --> +<!-- $Header: /cvsroot/pgsql/doc/src/sgml/protocol.sgml,v 1.43 2003/09/03 22:05:07 petere Exp $ --> <chapter id="protocol"> <title>Frontend/Backend Protocol</title> @@ -1006,7 +1006,8 @@ <literal>server_version</> (a pseudo-parameter that cannot change after startup); <literal>client_encoding</>, - <literal>is_superuser</>, and + <literal>is_superuser</>, + <literal>session_authorization</literal>, and <literal>DateStyle</>. This set might change in the future, or even become configurable. Accordingly, a frontend should simply ignore ParameterStatus for diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index 35e33e7fe219425c0228b5f48538d174aedbce3b..1d6da0e3b2d98d7fa98a1d6a1ffff26ccdc9bd5f 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -1,5 +1,5 @@ <!-- -$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.95 2003/08/31 17:32:24 petere Exp $ +$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.96 2003/09/03 22:05:08 petere Exp $ PostgreSQL documentation --> @@ -2214,8 +2214,14 @@ testdb=> <userinput>\set content '\'' `sed -e "s/'/\\\\\\'/g" < my_file.txt` '\' <varlistentry> <term><literal>%n</literal></term> - <listitem><para>The user name you are connected as (not your local system - user name).</para></listitem> + <listitem> + <para> + The database session user name. (The expansion of this + value might change during a database session as the result + of the command <command>SET SESSION + AUTHORIZATION</command>.) + </para> + </listitem> </varlistentry> <varlistentry> @@ -2231,8 +2237,15 @@ testdb=> <userinput>\set content '\'' `sed -e "s/'/\\\\\\'/g" < my_file.txt` '\' <varlistentry> <term><literal>%#</literal></term> - <listitem><para>If the current user is a database superuser, then a - <literal>#</literal>, otherwise a <literal>></literal>.</para></listitem> + <listitem> + <para> + If the session user is a database superuser, then a + <literal>#</literal>, otherwise a <literal>></literal>. + (The expansion of this value might change during a database + session as the result of the command <command>SET SESSION + AUTHORIZATION</command>.) + </para> + </listitem> </varlistentry> <varlistentry> diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index fbf7cc5bff898ec2590ea1aae380a1a99971836d..f75711511755d5f3a5c438b77bfa6bfdddfa4007 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -10,7 +10,7 @@ * Written by Peter Eisentraut <peter_e@gmx.net>. * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.153 2003/09/01 23:04:49 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.154 2003/09/03 22:05:08 petere Exp $ * *-------------------------------------------------------------------- */ @@ -1501,7 +1501,7 @@ static struct config_string ConfigureNamesString[] = {"session_authorization", PGC_USERSET, UNGROUPED, gettext_noop("Current session userid"), NULL, - GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE + GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE }, &session_authorization_string, NULL, assign_session_authorization, show_session_authorization diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index cead3c6590438c75f62c165877ac24fa74871bee..70551a2a3d56b494b5237a4fcb350f539de49c26 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2003, PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.72 2003/08/14 18:48:35 tgl Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.73 2003/09/03 22:05:08 petere Exp $ */ #include "postgres_fe.h" #include "common.h" @@ -724,3 +724,26 @@ is_superuser(void) return false; } + + +/* + * Return the session user of the current connection. + * + * Note: this will correctly detect the session user only with a + * protocol-3.0 or newer backend; otherwise it will return the + * connection user. + */ +const char * +session_username(void) +{ + const char *val; + + if (!pset.db) + return NULL; + + val = PQparameterStatus(pset.db, "session_authorization"); + if (val) + return val; + else + return PQuser(pset.db); +} diff --git a/src/bin/psql/common.h b/src/bin/psql/common.h index 08ec84acdf2556f1e8904c0a9405c883c2029312..f5719bb258422b6081ea2847b912cec31ee69b63 100644 --- a/src/bin/psql/common.h +++ b/src/bin/psql/common.h @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2003, PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.28 2003/08/08 04:52:21 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.29 2003/09/03 22:05:09 petere Exp $ */ #ifndef COMMON_H #define COMMON_H @@ -37,6 +37,7 @@ extern PGresult *PSQLexec(const char *query, bool start_xact); extern bool SendQuery(const char *query); extern bool is_superuser(void); +extern const char *session_username(void); /* Parse a numeric character code from the string pointed at by *buf, e.g. * one written as 0x0c (hexadecimal) or 015 (octal); advance *buf to the last diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.c index 4e9eb36c8008f51832a772b46d95e6d0b5ac15c0..fbc0f44381f11c7449939acc6044612e51dddd83 100644 --- a/src/bin/psql/prompt.c +++ b/src/bin/psql/prompt.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2003, PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.28 2003/08/04 23:59:40 tgl Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.29 2003/09/03 22:05:09 petere Exp $ */ #include "postgres_fe.h" #include "prompt.h" @@ -160,7 +160,7 @@ get_prompt(promptStatus_t status) /* DB server user name */ case 'n': if (pset.db) - strncpy(buf, PQuser(pset.db), MAX_PROMPT_SIZE); + strncpy(buf, session_username(), MAX_PROMPT_SIZE); break; case '0':