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

Commit1c1c58c

Browse files
committed
Add SET SESSION AUTHORIZATION command.
1 parentc50aa9d commit1c1c58c

File tree

10 files changed

+179
-16
lines changed

10 files changed

+179
-16
lines changed

‎doc/src/sgml/ref/allfiles.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.29 2001/05/0819:28:01 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.30 2001/05/0821:06:42 petere Exp $
33
Postgres documentation
44
Complete list of usable sgml source files in this directory.
55
-->
@@ -98,6 +98,7 @@ Complete list of usable sgml source files in this directory.
9898
<!entity selectInto system "select_into.sgml">
9999
<!entity set system "set.sgml">
100100
<!entity setConstraints system "set_constraints.sgml">
101+
<!entity setSessionAuth system "set_session_auth.sgml">
101102
<!entity setTransaction system "set_transaction.sgml">
102103
<!entity show system "show.sgml">
103104
<!entity truncate system "truncate.sgml">
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/set_session_auth.sgml,v 1.1 2001/05/08 21:06:42 petere Exp $ -->
2+
<refentry id="SQL-SET-SESSION-AUTHORIZATION">
3+
<docinfo>
4+
<date>2001-04-21</date>
5+
</docinfo>
6+
7+
<refmeta>
8+
<refentrytitle>SET SESSION AUTHORIZATION</refentrytitle>
9+
<refmiscinfo>SQL - Language Statements</refmiscinfo>
10+
</refmeta>
11+
12+
<refnamediv>
13+
<refname>SET SESSION AUTHORIZATION</refname>
14+
<refpurpose>Set the session user identifier and the current user identifier
15+
of the current SQL-session context</refpurpose>
16+
</refnamediv>
17+
18+
<refsynopsisdiv>
19+
<synopsis>
20+
SET SESSION AUTHORIZATION '<parameter>username</parameter>'
21+
</synopsis>
22+
</refsynopsisdiv>
23+
24+
<refsect1>
25+
<title>Description</title>
26+
27+
<para>
28+
This command sets the session user identifier and the current user
29+
identifer of the current SQL-session context to be
30+
<parameter>username</parameter>.
31+
</para>
32+
33+
<para>
34+
The session user identifier is initially set to be the (possibly
35+
authenticated) user name provided by the client. The current user
36+
identifier is normally equal to the session user identifier, but
37+
may change temporarily in the context of <quote>setuid</quote>
38+
functions and similar mechanisms. The current user identifer is
39+
relevant for permission checking.
40+
</para>
41+
42+
<para>
43+
Execution of this command is only permitted if the initial session
44+
user (the <firstterm>authenticated user</firstterm>) had the
45+
superuser privilege. This permission is kept for the duration of a
46+
connection; for example, it is possible to temporarily become an
47+
unprivileged user and later switch back to become a superuser.
48+
</para>
49+
</refsect1>
50+
51+
<refsect1>
52+
<title>Examples</title>
53+
54+
<screen>
55+
<userinput>SELECT SESSION_USER, CURRENT_USER;</userinput>
56+
current_user | session_user
57+
--------------+--------------
58+
peter | peter
59+
60+
<userinput>SET SESSION AUTHORIZATION 'paul';</userinput>
61+
62+
<userinput>SELECT SESSION_USER, CURRENT_USER;</userinput>
63+
current_user | session_user
64+
--------------+--------------
65+
paul | paul
66+
</screen>
67+
</refsect1>
68+
69+
<refsect1>
70+
<title>Compatibility</title>
71+
72+
<simpara>SQL99</simpara>
73+
74+
<para>
75+
SQL99 allows some other expressions to appear in place of the
76+
literal <parameter>username</parameter> which are not important in
77+
practice. <application>PostgreSQL</application> allows identifier
78+
syntax (<literal>"username"</literal>), which SQL does not. SQL
79+
does not allow this command during a transaction;
80+
<application>PostgreSQL</application> does not make
81+
this restriction because there is no reason to. The
82+
privileges necessary to execute this command are left
83+
implementation-defined by the standard.
84+
</para>
85+
</refsect1>
86+
</refentry>
87+
88+
<!-- Keep this comment at the end of the file
89+
Local variables:
90+
mode:sgml
91+
sgml-omittag:nil
92+
sgml-shorttag:t
93+
sgml-minimize-attributes:nil
94+
sgml-always-quote-attributes:t
95+
sgml-indent-step:1
96+
sgml-indent-data:t
97+
sgml-parent-document:nil
98+
sgml-default-dtd-file:"../reference.ced"
99+
sgml-exposed-tags:nil
100+
sgml-local-catalogs:("/usr/lib/sgml/catalog")
101+
sgml-local-ecat-files:nil
102+
End:
103+
-->

‎doc/src/sgml/reference.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- reference.sgml
2-
$Header: /cvsroot/pgsql/doc/src/sgml/reference.sgml,v 1.16 2001/05/07 00:43:14 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/reference.sgml,v 1.17 2001/05/08 21:06:42 petere Exp $
33

44
PostgreSQL Reference Manual
55
-->
@@ -84,6 +84,7 @@ PostgreSQL Reference Manual
8484
&selectInto;
8585
&set;
8686
&setConstraints;
87+
&setSessionAuth;
8788
&setTransaction;
8889
&show;
8990
&truncate;
@@ -131,7 +132,6 @@ Disable this chapter until we have more functions documented.
131132
&dropuser;
132133
&ecpgRef;
133134
&pgAccess;
134-
&pgAdmin;
135135
&pgConfig;
136136
&pgDump;
137137
&pgDumpall;

‎src/backend/commands/variable.c

Lines changed: 3 additions & 1 deletion
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.47 2001/03/29 19:03:57 petere Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.48 2001/05/08 21:06:42 petere Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -721,6 +721,8 @@ SetPGVariable(const char *name, const char *value)
721721
parse_server_encoding(mvalue);
722722
elseif (strcasecmp(name,"seed")==0)
723723
parse_random_seed(mvalue);
724+
elseif (strcasecmp(name,"session_authorization")==0)
725+
SetSessionAuthorization(value);
724726
else
725727
SetConfigOption(name,value,superuser() ?PGC_SUSET :PGC_USERSET);
726728

‎src/backend/parser/gram.y

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.223 2001/05/07 00:43:23 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.224 2001/05/08 21:06:42 petere Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -259,7 +259,7 @@ static void doNegateFloat(Value *v);
259259

260260
%type<ival>Iconst
261261
%type<str>Sconst,comment_text
262-
%type<str>UserId,opt_boolean,var_value,zone_value
262+
%type<str>UserId,opt_boolean,var_value,zone_value,Ident_or_Sconst
263263
%type<str>ColId,ColLabel,TokenId
264264

265265
%type<node>TableConstraint
@@ -292,7 +292,7 @@ static void doNegateFloat(Value *v);
292292
*/
293293

294294
/* Keywords (in SQL92 reserved words)*/
295-
%tokenABSOLUTE,ACTION,ADD,ALL,ALTER,AND,ANY,AS,ASC,AT,
295+
%tokenABSOLUTE,ACTION,ADD,ALL,ALTER,AND,ANY,AS,ASC,AT,AUTHORIZATION,
296296
BEGIN_TRANS,BETWEEN,BOTH,BY,
297297
CASCADE,CASE,CAST,CHAR,CHARACTER,CHECK,CLOSE,
298298
COALESCE,COLLATE,COLUMN,COMMIT,
@@ -761,6 +761,13 @@ VariableSetStmt: SET ColId TO var_value
761761
n->value =$3;
762762
$$ = (Node *) n;
763763
}
764+
|SETSESSIONAUTHORIZATIONIdent_or_Sconst
765+
{
766+
VariableSetStmt *n = makeNode(VariableSetStmt);
767+
n->name ="session_authorization";
768+
n->value =$4;
769+
$$ = (Node *) n;
770+
}
764771
;
765772

766773
opt_level:READCOMMITTED{$$ ="committed"; }
@@ -837,6 +844,10 @@ opt_encoding: Sconst{ $$ = $1; }
837844
|/*EMPTY*/{$$ =NULL; }
838845
;
839846

847+
Ident_or_Sconst:IDENT{$$ =$1; }
848+
|SCONST{$$ =$1; }
849+
850+
840851
VariableShowStmt:SHOWColId
841852
{
842853
VariableShowStmt *n = makeNode(VariableShowStmt);
@@ -5459,6 +5470,7 @@ TokenId: ABSOLUTE{ $$ = "absolute"; }
54595470
|AGGREGATE{$$ ="aggregate"; }
54605471
|ALTER{$$ ="alter"; }
54615472
|AT{$$ ="at"; }
5473+
|AUTHORIZATION{$$ ="authorization"; }
54625474
|BACKWARD{$$ ="backward"; }
54635475
|BEFORE{$$ ="before"; }
54645476
|BEGIN_TRANS{$$ ="begin"; }

‎src/backend/parser/keywords.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.91 2001/05/07 00:43:23 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.92 2001/05/08 21:06:43 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -44,6 +44,7 @@ static ScanKeyword ScanKeywords[] = {
4444
{"as",AS},
4545
{"asc",ASC},
4646
{"at",AT},
47+
{"authorization",AUTHORIZATION},
4748
{"backward",BACKWARD},
4849
{"before",BEFORE},
4950
{"begin",BEGIN_TRANS},

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

Lines changed: 29 additions & 2 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.65 2001/04/16 02:42:01 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.66 2001/05/08 21:06:43 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -354,6 +354,7 @@ convertstr(unsigned char *buff, int len, int dest)
354354
staticOidCurrentUserId=InvalidOid;
355355
staticOidSessionUserId=InvalidOid;
356356

357+
staticboolAuthenticatedUserIsSuperuser= false;
357358

358359
/*
359360
* This function is relevant for all privilege checks.
@@ -397,7 +398,7 @@ SetSessionUserId(Oid newid)
397398

398399

399400
void
400-
SetSessionUserIdFromUserName(constchar*username)
401+
InitializeSessionUserId(constchar*username)
401402
{
402403
HeapTupleuserTup;
403404

@@ -407,6 +408,9 @@ SetSessionUserIdFromUserName(const char *username)
407408
*/
408409
AssertState(!IsBootstrapProcessingMode());
409410

411+
/* call only once */
412+
AssertState(!OidIsValid(SessionUserId));
413+
410414
userTup=SearchSysCache(SHADOWNAME,
411415
PointerGetDatum(username),
412416
0,0,0);
@@ -415,6 +419,29 @@ SetSessionUserIdFromUserName(const char *username)
415419

416420
SetSessionUserId(((Form_pg_shadow)GETSTRUCT(userTup))->usesysid);
417421

422+
AuthenticatedUserIsSuperuser= ((Form_pg_shadow)GETSTRUCT(userTup))->usesuper;
423+
424+
ReleaseSysCache(userTup);
425+
}
426+
427+
428+
429+
voidSetSessionAuthorization(constchar*username)
430+
{
431+
HeapTupleuserTup;
432+
433+
if (!AuthenticatedUserIsSuperuser)
434+
elog(ERROR,"permission denied");
435+
436+
userTup=SearchSysCache(SHADOWNAME,
437+
PointerGetDatum(username),
438+
0,0,0);
439+
if (!HeapTupleIsValid(userTup))
440+
elog(ERROR,"user \"%s\" does not exist",username);
441+
442+
SetSessionUserId(((Form_pg_shadow)GETSTRUCT(userTup))->usesysid);
443+
SetUserId(((Form_pg_shadow)GETSTRUCT(userTup))->usesysid);
444+
418445
ReleaseSysCache(userTup);
419446
}
420447

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

Lines changed: 2 additions & 2 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/postinit.c,v 1.84 2001/04/21 18:29:29 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.85 2001/05/08 21:06:43 petere Exp $
1212
*
1313
*
1414
*-------------------------------------------------------------------------
@@ -341,7 +341,7 @@ InitPostgres(const char *dbname, const char *username)
341341
if (bootstrap)
342342
SetSessionUserId(geteuid());
343343
else
344-
SetSessionUserIdFromUserName(username);
344+
InitializeSessionUserId(username);
345345

346346
/*
347347
* Unless we are bootstrapping, double-check that InitMyDatabaseInfo()

‎src/bin/psql/tab-complete.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.31 2001/05/07 19:31:33 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.32 2001/05/08 21:06:43 petere Exp $
77
*/
88

99
/*----------------------------------------------------------------------
@@ -201,7 +201,7 @@ psql_completion(char *text, int start, int end)
201201
/* these SET arguments are known in gram.y */
202202
"CONSTRAINTS",
203203
"NAMES",
204-
"SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL",
204+
"SESSION",
205205
"TRANSACTION ISOLATION LEVEL",
206206
/* these are treated in backend/commands/variable.c */
207207
"DateStyle",
@@ -646,6 +646,22 @@ psql_completion(char *text, int start, int end)
646646

647647
COMPLETE_WITH_LIST(constraint_list);
648648
}
649+
/* Complete SET SESSION with AUTHORIZATION or CHARACTERISTICS... */
650+
elseif (strcasecmp(prev2_wd,"SET")==0&&strcasecmp(prev_wd,"SESSION")==0)
651+
{
652+
char*my_list[]= {"AUTHORIZATION",
653+
"CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL",
654+
NULL};
655+
656+
COMPLETE_WITH_LIST(my_list);
657+
}
658+
/* Complete SET SESSION AUTHORIZATION with username */
659+
elseif (strcasecmp(prev3_wd,"SET")==0
660+
&&strcasecmp(prev2_wd,"SESSION")==0
661+
&&strcasecmp(prev_wd,"AUTHORIZATION")==0)
662+
{
663+
COMPLETE_WITH_QUERY(Query_for_list_of_users);
664+
}
649665
/* Complete SET <var> with "TO" */
650666
elseif (strcasecmp(prev2_wd,"SET")==0&&
651667
strcasecmp(prev4_wd,"UPDATE")!=0)

‎src/include/miscadmin.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $Id: miscadmin.h,v 1.83 2001/03/22 04:00:25 momjian Exp $
15+
* $Id: miscadmin.h,v 1.84 2001/05/08 21:06:43 petere Exp $
1616
*
1717
* NOTES
1818
* some of the information in this file should be moved to
@@ -208,7 +208,8 @@ extern OidGetUserId(void);
208208
externvoidSetUserId(Oiduserid);
209209
externOidGetSessionUserId(void);
210210
externvoidSetSessionUserId(Oiduserid);
211-
externvoidSetSessionUserIdFromUserName(constchar*username);
211+
externvoidInitializeSessionUserId(constchar*username);
212+
externvoidSetSessionAuthorization(constchar*username);
212213

213214
externvoidSetDataDir(constchar*dir);
214215

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp