aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/user.c36
-rw-r--r--src/backend/libpq/be-pqexec.c6
-rw-r--r--src/backend/libpq/crypt.c3
-rw-r--r--src/include/catalog/pg_user.h4
4 files changed, 35 insertions, 14 deletions
diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c
index 1a21a07598b..df1c8046d7e 100644
--- a/src/backend/commands/user.c
+++ b/src/backend/commands/user.c
@@ -152,11 +152,14 @@ void DefineUser(CreateUserStmt *stmt) {
/* Add the stuff here for groups.
*/
+ UpdatePgPwdFile(sql);
+
+ /* This goes after the UpdatePgPwdFile to be certain that two backends to not
+ * attempt to write to the pg_pwd file at the same time.
+ */
RelationUnsetLockForWrite(pg_user_rel);
heap_close(pg_user_rel);
- UpdatePgPwdFile(sql);
-
if (IsTransactionBlock() && !inblock)
EndTransactionBlock();
}
@@ -195,6 +198,10 @@ extern void AlterUser(AlterUserStmt *stmt) {
*/
pg_user_rel = heap_openr(UserRelationName);
pg_user_dsc = RelationGetTupleDescriptor(pg_user_rel);
+ /* Secure a write lock on pg_user so we can be sure that when the dump of
+ * the pg_pwd file is done, there is not another backend doing the same.
+ */
+ RelationSetLockForWrite(pg_user_rel);
scan = heap_beginscan(pg_user_rel, false, false, 0, NULL);
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0, &buffer))) {
@@ -207,9 +214,10 @@ extern void AlterUser(AlterUserStmt *stmt) {
}
}
heap_endscan(scan);
- heap_close(pg_user_rel);
if (!exists) {
+ RelationUnsetLockForWrite(pg_user_rel);
+ heap_close(pg_user_rel);
UserAbortTransactionBlock();
elog(WARN, "alterUser: user \"%s\" does not exist", stmt->user);
return;
@@ -257,6 +265,9 @@ extern void AlterUser(AlterUserStmt *stmt) {
UpdatePgPwdFile(sql);
+ RelationUnsetLockForWrite(pg_user_rel);
+ heap_close(pg_user_rel);
+
if (IsTransactionBlock() && !inblock)
EndTransactionBlock();
}
@@ -265,7 +276,8 @@ extern void AlterUser(AlterUserStmt *stmt) {
extern void RemoveUser(char* user) {
char* pg_user;
- Relation pg_rel;
+ Relation pg_user_rel,
+ pg_rel;
TupleDesc pg_dsc;
HeapScanDesc scan;
HeapTuple tuple;
@@ -295,10 +307,14 @@ extern void RemoveUser(char* user) {
/* Perform a scan of the pg_user relation to find the usesysid of the user to
* be deleted. If it is not found, then return a warning message.
*/
- pg_rel = heap_openr(UserRelationName);
- pg_dsc = RelationGetTupleDescriptor(pg_rel);
+ pg_user_rel = heap_openr(UserRelationName);
+ pg_dsc = RelationGetTupleDescriptor(pg_user_rel);
+ /* Secure a write lock on pg_user so we can be sure that when the dump of
+ * the pg_pwd file is done, there is not another backend doing the same.
+ */
+ RelationSetLockForWrite(pg_user_rel);
- scan = heap_beginscan(pg_rel, false, false, 0, NULL);
+ scan = heap_beginscan(pg_user_rel, false, false, 0, NULL);
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0, &buffer))) {
datum = heap_getattr(tuple, buffer, Anum_pg_user_usename, pg_dsc, &n);
@@ -310,9 +326,10 @@ extern void RemoveUser(char* user) {
ReleaseBuffer(buffer);
}
heap_endscan(scan);
- heap_close(pg_rel);
if (usesysid == -1) {
+ RelationUnsetLockForWrite(pg_user_rel);
+ heap_close(pg_user_rel);
UserAbortTransactionBlock();
elog(WARN, "removeUser: user \"%s\" does not exist", user);
return;
@@ -373,6 +390,9 @@ extern void RemoveUser(char* user) {
UpdatePgPwdFile(sql);
+ RelationUnsetLockForWrite(pg_user_rel);
+ heap_close(pg_user_rel);
+
if (IsTransactionBlock() && !inblock)
EndTransactionBlock();
}
diff --git a/src/backend/libpq/be-pqexec.c b/src/backend/libpq/be-pqexec.c
index d0f133f47a4..d895f7a031d 100644
--- a/src/backend/libpq/be-pqexec.c
+++ b/src/backend/libpq/be-pqexec.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/libpq/Attic/be-pqexec.c,v 1.10 1997/12/06 22:56:35 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/libpq/Attic/be-pqexec.c,v 1.11 1997/12/12 16:26:14 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -143,11 +143,11 @@ PQexec(char *query)
be_portalpush(entry);
/* ----------------
- * pg_eval_dest will put the query results in a portal which will
+ * pg_exec_query_dest will put the query results in a portal which will
* end up on the top of the portal stack.
* ----------------
*/
- pg_eval_dest(query, (char **) NULL, (Oid *) NULL, 0, Local);
+ pg_exec_query_dest(query, (char **) NULL, (Oid *) NULL, 0, Local);
/* ----------------
* pop the portal off the portal stack and return the
diff --git a/src/backend/libpq/crypt.c b/src/backend/libpq/crypt.c
index a91ec8b161e..1386ff74acc 100644
--- a/src/backend/libpq/crypt.c
+++ b/src/backend/libpq/crypt.c
@@ -17,6 +17,7 @@
#endif
#include "postgres.h"
+#include "miscadmin.h"
#include "libpq/crypt.h"
#include "utils/nabstime.h"
#include "utils/palloc.h"
@@ -129,7 +130,7 @@ MsgType crypt_salt(const char* user) {
crypt_getloginfo(user, &passwd, &valuntil);
- if (passwd == NULL || *passwd == '\0') {
+ if (passwd == NULL || *passwd == '\0' || !strcmp(passwd, "\\N")) {
if (passwd) pfree((void*)passwd);
if (valuntil) pfree((void*)valuntil);
return STARTUP_UNSALT_MSG;
diff --git a/src/include/catalog/pg_user.h b/src/include/catalog/pg_user.h
index 970ab7973f3..f98e1bb72bd 100644
--- a/src/include/catalog/pg_user.h
+++ b/src/include/catalog/pg_user.h
@@ -7,7 +7,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: pg_user.h,v 1.7 1997/12/09 03:11:25 scrappy Exp $
+ * $Id: pg_user.h,v 1.8 1997/12/12 16:26:36 momjian Exp $
*
* NOTES
* the genbki.sh script reads this file and generates .bki
@@ -65,7 +65,7 @@ typedef FormData_pg_user *Form_pg_user;
* initial contents of pg_user
* ----------------
*/
-DATA(insert OID = 0 ( postgres PGUID t t t t "" 2116994400 ));
+DATA(insert OID = 0 ( postgres PGUID t t t t _null_ 2116994400 ));
BKI_BEGIN
#ifdef ALLOW_PG_GROUP