From 6dc249610a87aa8b9dcc8baf4e64d2e14d02f548 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 6 Sep 2000 14:15:31 +0000 Subject: 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. --- src/backend/utils/init/postinit.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/backend/utils/init/postinit.c') diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index f63590cdb98..a9e083557e0 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -8,19 +8,19 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.64 2000/08/06 04:39:10 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.65 2000/09/06 14:15:22 petere Exp $ * * *------------------------------------------------------------------------- */ +#include "postgres.h" + #include #include #include #include #include -#include "postgres.h" - #include "access/heapam.h" #include "catalog/catname.h" #include "catalog/pg_database.h" @@ -223,7 +223,7 @@ int lockingOff = 0; /* backend -L switch */ /* */ void -InitPostgres(const char *dbname) +InitPostgres(const char *dbname, const char *username) { bool bootstrap = IsBootstrapProcessingMode(); @@ -366,16 +366,19 @@ InitPostgres(const char *dbname) /* replace faked-up relcache entries with the real info */ RelationCacheInitializePhase2(); + if (lockingOff) + LockDisable(true); + /* * Set ourselves to the proper user id and figure out our postgres - * user id. If we ever add security so that we check for valid - * postgres users, we might do it here. + * user id. */ - setuid(geteuid()); - SetUserId(); + if (bootstrap) + SetUserId(geteuid()); + else + SetUserIdFromUserName(username); - if (lockingOff) - LockDisable(true); + setuid(geteuid()); /* * Unless we are bootstrapping, double-check that InitMyDatabaseInfo() -- cgit v1.2.3