diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2000-09-06 14:15:31 +0000 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2000-09-06 14:15:31 +0000 |
commit | 6dc249610a87aa8b9dcc8baf4e64d2e14d02f548 (patch) | |
tree | 6ca1b864625ecf91a2887c8031a9fa91b5f9c5c5 /src/backend/commands/dbcommands.c | |
parent | daf1e3a7026e367d630be3ac34ac0a9e7cf1340f (diff) | |
download | postgresql-6dc249610a87aa8b9dcc8baf4e64d2e14d02f548.tar.gz postgresql-6dc249610a87aa8b9dcc8baf4e64d2e14d02f548.zip |
Code cleanup of user name and user id handling in the backend. The current
user is now defined in terms of the user id, the user name is only computed
upon request (for display purposes). This is kind of the opposite of the
previous state, which would maintain the user name and compute the user id
for permission checks.
Besides perhaps saving a few cycles (integer vs string), this now creates a
single point of attack for changing the user id during a connection, for
purposes of "setuid" functions, etc.
Diffstat (limited to 'src/backend/commands/dbcommands.c')
-rw-r--r-- | src/backend/commands/dbcommands.c | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 1c2df9c5eb8..f320979af99 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.59 2000/08/03 16:34:01 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.60 2000/09/06 14:15:16 petere Exp $ * *------------------------------------------------------------------------- */ @@ -37,7 +37,7 @@ /* non-export function prototypes */ static bool - get_user_info(const char *name, int4 *use_sysid, bool *use_super, bool *use_createdb); + get_user_info(Oid use_sysid, bool *use_super, bool *use_createdb); static bool get_db_info(const char *name, char *dbpath, Oid *dbIdP, int4 *ownerIdP); @@ -54,7 +54,6 @@ createdb(const char *dbname, const char *dbpath, int encoding) char buf[2 * MAXPGPATH + 100]; char *loc; char locbuf[512]; - int4 user_id; int ret; bool use_super, use_createdb; @@ -64,7 +63,7 @@ createdb(const char *dbname, const char *dbpath, int encoding) Datum new_record[Natts_pg_database]; char new_record_nulls[Natts_pg_database] = {' ', ' ', ' ', ' '}; - if (!get_user_info(GetPgUserName(), &user_id, &use_super, &use_createdb)) + if (!get_user_info(GetUserId(), &use_super, &use_createdb)) elog(ERROR, "current user name is invalid"); if (!use_createdb && !use_super) @@ -100,7 +99,7 @@ createdb(const char *dbname, const char *dbpath, int encoding) /* Form tuple */ new_record[Anum_pg_database_datname - 1] = DirectFunctionCall1(namein, CStringGetDatum(dbname)); - new_record[Anum_pg_database_datdba - 1] = Int32GetDatum(user_id); + new_record[Anum_pg_database_datdba - 1] = Int32GetDatum(GetUserId()); new_record[Anum_pg_database_encoding - 1] = Int32GetDatum(encoding); new_record[Anum_pg_database_datpath - 1] = DirectFunctionCall1(textin, CStringGetDatum(locbuf)); @@ -174,8 +173,7 @@ createdb(const char *dbname, const char *dbpath, int encoding) void dropdb(const char *dbname) { - int4 user_id, - db_owner; + int4 db_owner; bool use_super; Oid db_id; char *path, @@ -197,13 +195,13 @@ dropdb(const char *dbname) if (IsTransactionBlock()) elog(ERROR, "DROP DATABASE: May not be called in a transaction block"); - if (!get_user_info(GetPgUserName(), &user_id, &use_super, NULL)) + if (!get_user_info(GetUserId(), &use_super, NULL)) elog(ERROR, "Current user name is invalid"); if (!get_db_info(dbname, dbpath, &db_id, &db_owner)) elog(ERROR, "DROP DATABASE: Database \"%s\" does not exist", dbname); - if (user_id != db_owner && !use_super) + if (GetUserId() != db_owner && !use_super) elog(ERROR, "DROP DATABASE: Permission denied"); path = ExpandDatabasePath(dbpath); @@ -374,20 +372,17 @@ get_db_info(const char *name, char *dbpath, Oid *dbIdP, int4 *ownerIdP) static bool -get_user_info(const char *name, int4 *use_sysid, bool *use_super, bool *use_createdb) +get_user_info(Oid use_sysid, bool *use_super, bool *use_createdb) { HeapTuple utup; - AssertArg(name); - utup = SearchSysCacheTuple(SHADOWNAME, - PointerGetDatum(name), + utup = SearchSysCacheTuple(SHADOWSYSID, + ObjectIdGetDatum(use_sysid), 0, 0, 0); if (!HeapTupleIsValid(utup)) return false; - if (use_sysid) - *use_sysid = ((Form_pg_shadow) GETSTRUCT(utup))->usesysid; if (use_super) *use_super = ((Form_pg_shadow) GETSTRUCT(utup))->usesuper; if (use_createdb) |