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

Commitea88633

Browse files
committed
Add is_superuser parameter reporting, soon to be used by psql.
1 parent3e0bdfa commitea88633

File tree

8 files changed

+66
-25
lines changed

8 files changed

+66
-25
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.126 2003/06/22 00:29:29 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.127 2003/06/27 19:08:37 tgl Exp $
33
-->
44

55
<chapter id="libpq">
@@ -812,7 +812,8 @@ is not known.
812812
Parameters reported as of the current release include
813813
<literal>server_version</> (cannot change after startup);
814814
<literal>server_encoding</> (also not presently changeable after start);
815-
<literal>client_encoding</>, and
815+
<literal>client_encoding</>,
816+
<literal>is_superuser</>, and
816817
<literal>DateStyle</>.
817818
</para>
818819

‎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.38 2003/05/08 14:35:24 tgl Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/protocol.sgml,v 1.39 2003/06/27 19:08:37 tgl Exp $ -->
22

33
<chapter id="protocol">
44
<title>Frontend/Backend Protocol</title>
@@ -998,7 +998,8 @@
998998
<literal>server_version</> (a pseudo-parameter that cannot change after
999999
startup);
10001000
<literal>server_encoding</> (also not presently changeable after start);
1001-
<literal>client_encoding</>, and
1001+
<literal>client_encoding</>,
1002+
<literal>is_superuser</>, and
10021003
<literal>DateStyle</>.
10031004
This set might change in the future, or even become configurable.
10041005
Accordingly, a frontend should simply ignore ParameterStatus for

‎doc/src/sgml/ref/show.sgml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/show.sgml,v 1.27 2003/05/14 03:26:00 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/show.sgml,v 1.28 2003/06/27 19:08:37 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -97,6 +97,16 @@ SHOW ALL
9797
</para>
9898
</listitem>
9999
</varlistentry>
100+
101+
<varlistentry>
102+
<term><literal>IS_SUPERUSER</literal></term>
103+
<listitem>
104+
<para>
105+
True if the current session authorization identifier has
106+
superuser privileges.
107+
</para>
108+
</listitem>
109+
</varlistentry>
100110
</variablelist>
101111
</para>
102112
</listitem>

‎src/backend/commands/variable.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.78 2003/06/06 16:25:35 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.79 2003/06/27 19:08:37 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -721,25 +721,29 @@ assign_client_encoding(const char *value, bool doit, bool interactive)
721721
* When resetting session auth after an error, we can't expect to do catalog
722722
* lookups. Hence, the stored form of the value must provide a numeric userid
723723
* that can be re-used directly. We store the string in the form of
724-
* NAMEDATALEN 'x's followed by the numeric userid --- this cannot conflict
725-
* with any valid user name, because of the NAMEDATALEN limit on names.
724+
* NAMEDATALEN 'x's, followed by T or F to indicate superuserness, followed
725+
* by the numeric userid --- this cannot conflict with any valid user name,
726+
* because of the NAMEDATALEN limit on names.
726727
*/
727728
constchar*
728729
assign_session_authorization(constchar*value,booldoit,boolinteractive)
729730
{
730731
AclIdusesysid=0;
732+
boolis_superuser= false;
731733
char*result;
732734

733-
if (strspn(value,"x")==NAMEDATALEN)
735+
if (strspn(value,"x")==NAMEDATALEN&&
736+
(value[NAMEDATALEN]=='T'||value[NAMEDATALEN]=='F'))
734737
{
735738
/* might be a saved numeric userid */
736739
char*endptr;
737740

738-
usesysid= (AclId)strtoul(value+NAMEDATALEN,&endptr,10);
741+
usesysid= (AclId)strtoul(value+NAMEDATALEN+1,&endptr,10);
739742

740-
if (endptr!=value+NAMEDATALEN&&*endptr=='\0')
743+
if (endptr!=value+NAMEDATALEN+1&&*endptr=='\0')
741744
{
742-
/* syntactically valid, so use the numeric user ID */
745+
/* syntactically valid, so use the numeric user ID and flag */
746+
is_superuser= (value[NAMEDATALEN]=='T');
743747
}
744748
else
745749
usesysid=0;
@@ -771,20 +775,23 @@ assign_session_authorization(const char *value, bool doit, bool interactive)
771775
}
772776

773777
usesysid= ((Form_pg_shadow)GETSTRUCT(userTup))->usesysid;
774-
778+
is_superuser= ((Form_pg_shadow)GETSTRUCT(userTup))->usesuper;
779+
775780
ReleaseSysCache(userTup);
776781
}
777782

778783
if (doit)
779-
SetSessionAuthorization(usesysid);
784+
SetSessionAuthorization(usesysid,is_superuser);
780785

781786
result= (char*)malloc(NAMEDATALEN+32);
782787
if (!result)
783788
returnNULL;
784789

785790
memset(result,'x',NAMEDATALEN);
786791

787-
snprintf(result+NAMEDATALEN,32,"%lu", (unsigned long)usesysid);
792+
snprintf(result+NAMEDATALEN,32,"%c%lu",
793+
is_superuser ?'T' :'F',
794+
(unsigned long)usesysid);
788795

789796
returnresult;
790797
}

‎src/backend/utils/init/miscinit.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.103 2003/06/2714:45:30 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.104 2003/06/2719:08:37 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -553,9 +553,12 @@ InitializeSessionUserId(const char *username)
553553

554554
SetSessionUserId(usesysid);/* sets CurrentUserId too */
555555

556-
/* Record usernameas a config option too */
556+
/* Record usernameand superuser status as GUC settings too */
557557
SetConfigOption("session_authorization",username,
558558
PGC_BACKEND,PGC_S_OVERRIDE);
559+
SetConfigOption("is_superuser",
560+
AuthenticatedUserIsSuperuser ?"on" :"off",
561+
PGC_INTERNAL,PGC_S_OVERRIDE);
559562

560563
/*
561564
* Set up user-specific configuration variables. This is a good place
@@ -594,10 +597,13 @@ InitializeSessionUserIdStandalone(void)
594597
/*
595598
* Change session auth ID while running
596599
*
597-
* Only a superuser may set auth ID to something other than himself.
600+
* Only a superuser may set auth ID to something other than himself. Note
601+
* that in case of multiple SETs in a single session, the original userid's
602+
* superuserness is what matters. But we set the GUC variable is_superuser
603+
* to indicate whether the *current* session userid is a superuser.
598604
*/
599605
void
600-
SetSessionAuthorization(AclIduserid)
606+
SetSessionAuthorization(AclIduserid,boolis_superuser)
601607
{
602608
/* Must have authenticated already, else can't make permission check */
603609
AssertState(AclIdIsValid(AuthenticatedUserId));
@@ -608,6 +614,10 @@ SetSessionAuthorization(AclId userid)
608614

609615
SetSessionUserId(userid);
610616
SetUserId(userid);
617+
618+
SetConfigOption("is_superuser",
619+
is_superuser ?"on" :"off",
620+
PGC_INTERNAL,PGC_S_OVERRIDE);
611621
}
612622

613623

‎src/backend/utils/misc/check_guc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
## if an option is valid but shows up in only one file (guc.c but not
1717
## postgresql.conf.sample), it should be listed here so that it
1818
## can be ignored
19-
INTENTIONALLY_NOT_INCLUDED="pre_auth_delay lc_messages lc_monetary\
20-
lc_numeric lc_time seed server_encoding session_authorization\
21-
transaction_isolation transaction_read_only zero_damaged_pages"
19+
INTENTIONALLY_NOT_INCLUDED="autocommit debug_deadlocks exit_on_error\
20+
is_superuser lc_collate lc_ctype lc_messages lc_monetary lc_numeric lc_time\
21+
pre_auth_delay seed server_encoding server_version session_authorization\
22+
trace_lock_oidmin trace_lock_table trace_locks trace_lwlocks trace_notify\
23+
trace_userlocks transaction_isolation transaction_read_only\
24+
zero_damaged_pages"
2225

2326
### What options are listed in postgresql.conf.sample, but don't appear
2427
### in guc.c?

‎src/backend/utils/misc/guc.c

Lines changed: 10 additions & 1 deletion
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.131 2003/06/11 22:13:22 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.132 2003/06/27 19:08:38 tgl Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -138,6 +138,7 @@ static char *log_min_error_statement_str;
138138
staticchar*log_min_messages_str;
139139
staticchar*client_min_messages_str;
140140
staticboolphony_autocommit;
141+
staticboolsession_auth_is_superuser;
141142
staticdoublephony_random_seed;
142143
staticchar*client_encoding_string;
143144
staticchar*datestyle_string;
@@ -361,6 +362,13 @@ static struct config_bool
361362
true,NULL,NULL
362363
},
363364

365+
/* Not for general use --- used by SET SESSION AUTHORIZATION */
366+
{
367+
{"is_superuser",PGC_INTERNAL,GUC_REPORT |GUC_NO_SHOW_ALL |GUC_NO_RESET_ALL},
368+
&session_auth_is_superuser,
369+
false,NULL,NULL
370+
},
371+
364372
{
365373
{"tcpip_socket",PGC_POSTMASTER},&NetServer,
366374
false,NULL,NULL
@@ -894,6 +902,7 @@ static struct config_string
894902
"SQL_ASCII",NULL,NULL
895903
},
896904

905+
/* Can't be set in postgresql.conf */
897906
{
898907
{"server_version",PGC_INTERNAL,GUC_REPORT},
899908
&server_version_string,

‎src/include/miscadmin.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $Id: miscadmin.h,v 1.124 2003/06/2714:45:31 petere Exp $
15+
* $Id: miscadmin.h,v 1.125 2003/06/2719:08:38 tgl Exp $
1616
*
1717
* NOTES
1818
* some of the information in this file should be moved to
@@ -208,7 +208,7 @@ extern AclId GetSessionUserId(void);
208208
externvoidSetSessionUserId(AclIduserid);
209209
externvoidInitializeSessionUserId(constchar*username);
210210
externvoidInitializeSessionUserIdStandalone(void);
211-
externvoidSetSessionAuthorization(AclIduserid);
211+
externvoidSetSessionAuthorization(AclIduserid,boolis_superuser);
212212

213213
externvoidSetDataDir(constchar*dir);
214214

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp