提交 97c52abc 编写于 作者: T Tom Lane

Repair problems with omitted password and VALID UNTIL

parameters in CREATE USER.
上级 f620241d
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: user.c,v 1.26 1999/03/16 04:25:45 momjian Exp $ * $Id: user.c,v 1.27 1999/04/02 06:16:36 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -94,20 +94,24 @@ UpdatePgPwdFile(char *sql, CommandDest dest) ...@@ -94,20 +94,24 @@ UpdatePgPwdFile(char *sql, CommandDest dest)
void void
DefineUser(CreateUserStmt *stmt, CommandDest dest) DefineUser(CreateUserStmt *stmt, CommandDest dest)
{ {
char *pg_shadow,
char *pg_shadow, sql[SQL_LENGTH];
sql[SQL_LENGTH];
Relation pg_shadow_rel; Relation pg_shadow_rel;
TupleDesc pg_shadow_dsc; TupleDesc pg_shadow_dsc;
HeapScanDesc scan; HeapScanDesc scan;
HeapTuple tuple; HeapTuple tuple;
Datum datum; Datum datum;
bool exists = false, bool exists = false,
n, n,
inblock; inblock,
int max_id = -1; havepassword,
havevaluntil;
if (stmt->password) int max_id = -1;
havepassword = stmt->password && stmt->password[0];
havevaluntil = stmt->validUntil && stmt->validUntil[0];
if (havepassword)
CheckPgUserAclNotNull(); CheckPgUserAclNotNull();
if (!(inblock = IsTransactionBlock())) if (!(inblock = IsTransactionBlock()))
BeginTransactionBlock(); BeginTransactionBlock();
...@@ -163,18 +167,31 @@ DefineUser(CreateUserStmt *stmt, CommandDest dest) ...@@ -163,18 +167,31 @@ DefineUser(CreateUserStmt *stmt, CommandDest dest)
} }
/* /*
* Build the insert statment to be executed. * Build the insert statement to be executed.
*
* XXX Ugly as this code is, it still fails to cope with ' or \
* in any of the provided strings.
*/ */
snprintf(sql, SQL_LENGTH, snprintf(sql, SQL_LENGTH,
"insert into %s(usename,usesysid,usecreatedb,usetrace,usesuper," "insert into %s (usename,usesysid,usecreatedb,usetrace,"
"usecatupd,passwd,valuntil) values('%s',%d%s%s,'%s','%s')", "usesuper,usecatupd,passwd,valuntil) "
ShadowRelationName, "values('%s',%d,'%c','t','%c','t',%s%s%s,%s%s%s)",
stmt->user, max_id + 1, ShadowRelationName,
(stmt->createdb && *stmt->createdb) ? ",'t','t'" : ",'f','t'", stmt->user,
(stmt->createuser && *stmt->createuser) ? ",'t','t'" : ",'f','t'", max_id + 1,
stmt->password ? stmt->password : "''", (stmt->createdb && *stmt->createdb) ? 't' : 'f',
stmt->validUntil ? stmt->validUntil : ""); (stmt->createuser && *stmt->createuser) ? 't' : 'f',
havepassword ? "'" : "",
havepassword ? stmt->password : "NULL",
havepassword ? "'" : "",
havevaluntil ? "'" : "",
havevaluntil ? stmt->validUntil : "NULL",
havevaluntil ? "'" : "");
/*
* XXX If insert fails, say because a bogus valuntil date is given,
* need to catch the resulting error and undo our transaction.
*/
pg_exec_query_dest(sql, dest, false); pg_exec_query_dest(sql, dest, false);
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册