Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
22a2c4b5
Commit
22a2c4b5
authored
20 years ago
by
Bruce Momjian
Browse files
Options
Downloads
Patches
Plain Diff
Erase MD5 user passwords when a user is renamed because the username is
used as salt for the MD5 password.
parent
d8f6973d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
doc/src/sgml/ref/alter_user.sgml
+4
-1
4 additions, 1 deletion
doc/src/sgml/ref/alter_user.sgml
src/backend/commands/user.c
+42
-13
42 additions, 13 deletions
src/backend/commands/user.c
with
46 additions
and
14 deletions
doc/src/sgml/ref/alter_user.sgml
+
4
−
1
View file @
22a2c4b5
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_user.sgml,v 1.3
2
200
3/11/29
1
9
:5
1:38 pgsql
Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_user.sgml,v 1.3
3
200
4/05/06
1
6
:5
9:16 momjian
Exp $
PostgreSQL documentation
-->
...
...
@@ -57,6 +57,9 @@ ALTER USER <replaceable class="PARAMETER">name</replaceable> RESET <replaceable>
The second variant changes the name of the user. Only a database
superuser can rename user accounts. The session user cannot be
renamed. (Connect as a different user if you need to do that.)
Because <literal>MD5</>-encrypted passwords use the username as
cryptographic salt, renaming a user clears their <literal>MD5</>
password.
</para>
<para>
...
...
This diff is collapsed.
Click to expand it.
src/backend/commands/user.c
+
42
−
13
View file @
22a2c4b5
...
...
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.1
39
2004/0
3/16 05:05:57
momjian Exp $
* $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.1
40
2004/0
5/06 16:59:16
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -959,8 +959,8 @@ AlterUserSet(AlterUserSetStmt *stmt)
(
errcode
(
ERRCODE_UNDEFINED_OBJECT
),
errmsg
(
"user
\"
%s
\"
does not exist"
,
stmt
->
user
)));
if
(
!
(
superuser
()
||
((
Form_pg_shadow
)
GETSTRUCT
(
oldtuple
))
->
usesysid
==
GetUserId
()))
if
(
!
(
superuser
()
||
((
Form_pg_shadow
)
GETSTRUCT
(
oldtuple
))
->
usesysid
==
GetUserId
()))
ereport
(
ERROR
,
(
errcode
(
ERRCODE_INSUFFICIENT_PRIVILEGE
),
errmsg
(
"permission denied"
)));
...
...
@@ -1157,16 +1157,25 @@ DropUser(DropUserStmt *stmt)
void
RenameUser
(
const
char
*
oldname
,
const
char
*
newname
)
{
HeapTuple
tup
;
HeapTuple
oldtuple
,
newtuple
;
TupleDesc
dsc
;
Relation
rel
;
Datum
datum
;
bool
isnull
;
Datum
repl_val
[
Natts_pg_shadow
];
char
repl_null
[
Natts_pg_shadow
];
char
repl_repl
[
Natts_pg_shadow
];
int
i
;
/* ExclusiveLock because we need to update the password file */
rel
=
heap_openr
(
ShadowRelationName
,
ExclusiveLock
);
dsc
=
RelationGetDescr
(
rel
);
tup
=
SearchSysCache
Copy
(
SHADOWNAME
,
old
tup
le
=
SearchSysCache
(
SHADOWNAME
,
CStringGetDatum
(
oldname
),
0
,
0
,
0
);
if
(
!
HeapTupleIsValid
(
tup
))
if
(
!
HeapTupleIsValid
(
old
tup
le
))
ereport
(
ERROR
,
(
errcode
(
ERRCODE_UNDEFINED_OBJECT
),
errmsg
(
"user
\"
%s
\"
does not exist"
,
oldname
)));
...
...
@@ -1177,7 +1186,7 @@ RenameUser(const char *oldname, const char *newname)
* not be an actual problem besides a little confusion, so think about
* this and decide.
*/
if
(((
Form_pg_shadow
)
GETSTRUCT
(
tup
))
->
usesysid
==
GetSessionUserId
())
if
(((
Form_pg_shadow
)
GETSTRUCT
(
old
tup
le
))
->
usesysid
==
GetSessionUserId
())
ereport
(
ERROR
,
(
errcode
(
ERRCODE_FEATURE_NOT_SUPPORTED
),
errmsg
(
"session user may not be renamed"
)));
...
...
@@ -1196,13 +1205,33 @@ RenameUser(const char *oldname, const char *newname)
(
errcode
(
ERRCODE_INSUFFICIENT_PRIVILEGE
),
errmsg
(
"must be superuser to rename users"
)));
/* rename */
namestrcpy
(
&
(((
Form_pg_shadow
)
GETSTRUCT
(
tup
))
->
usename
),
newname
);
simple_heap_update
(
rel
,
&
tup
->
t_self
,
tup
);
CatalogUpdateIndexes
(
rel
,
tup
);
for
(
i
=
0
;
i
<
Natts_pg_shadow
;
i
++
)
repl_repl
[
i
]
=
' '
;
repl_repl
[
Anum_pg_shadow_usename
-
1
]
=
'r'
;
repl_val
[
Anum_pg_shadow_usename
-
1
]
=
DirectFunctionCall1
(
namein
,
CStringGetDatum
(
newname
));
repl_null
[
Anum_pg_shadow_usename
-
1
]
=
' '
;
datum
=
heap_getattr
(
oldtuple
,
Anum_pg_shadow_passwd
,
dsc
,
&
isnull
);
if
(
!
isnull
&&
isMD5
(
DatumGetCString
(
DirectFunctionCall1
(
textout
,
datum
))))
{
/* MD5 uses the username as salt, so just clear it on a rename */
repl_repl
[
Anum_pg_shadow_passwd
-
1
]
=
'r'
;
repl_null
[
Anum_pg_shadow_passwd
-
1
]
=
'n'
;
ereport
(
NOTICE
,
(
errmsg
(
"MD5 password cleared because of user rename"
)));
}
newtuple
=
heap_modifytuple
(
oldtuple
,
rel
,
repl_val
,
repl_null
,
repl_repl
);
simple_heap_update
(
rel
,
&
oldtuple
->
t_self
,
newtuple
);
CatalogUpdateIndexes
(
rel
,
newtuple
);
ReleaseSysCache
(
oldtuple
);
heap_close
(
rel
,
NoLock
);
heap_freetuple
(
tup
);
user_file_update_needed
=
true
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment