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/tcop/postgres.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/tcop/postgres.c')
-rw-r--r-- | src/backend/tcop/postgres.c | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 3369e22825e..373d6831df6 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.174 2000/08/30 20:30:06 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.175 2000/09/06 14:15:21 petere Exp $ * * NOTES * this is the "main" module of the postgres backend and @@ -817,28 +817,27 @@ usage(char *progname) } /* ---------------------------------------------------------------- - * PostgresMain - * postgres main loop - * all backends, interactive or otherwise start here + * PostgresMain + * postgres main loop -- all backends, interactive or otherwise start here * - * argc/argv are the command line arguments to be used. When being forked - * by the postmaster, these are not the original argv array of the process. - * real_argc/real_argv point to the original argv array, which is needed by - * PS_INIT_STATUS on some platforms. + * argc/argv are the command line arguments to be used. When being forked + * by the postmaster, these are not the original argv array of the process. + * real_argc/real_argv point to the original argv array, which is needed by + * `ps' display on some platforms. username is the (possibly authenticated) + * PostgreSQL user name to be used for the session. * ---------------------------------------------------------------- */ int -PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) +PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const char * username) { int flag; - char *DBName = NULL; + const char *DBName = NULL; bool secure = true; int errs = 0; int firstchar; StringInfo parser_input; - char *userName; char *remote_host; unsigned short remote_port; @@ -1244,12 +1243,6 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) pqsignal(SIGTTOU, SIG_DFL); pqsignal(SIGCONT, SIG_DFL); - /* - * Get user name (needed now in case it is the default database name) - * and check command line validity - */ - SetPgUserName(); - userName = GetPgUserName(); if (IsUnderPostmaster) { @@ -1274,9 +1267,9 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) } else if (argc - optind == 1) DBName = argv[optind]; - else if ((DBName = userName) == NULL) + else if ((DBName = username) == NULL) { - fprintf(stderr, "%s: USER undefined and no database specified\n", + fprintf(stderr, "%s: user name undefined and no database specified\n", argv[0]); proc_exit(0); } @@ -1361,20 +1354,20 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) * references to optarg or getenv() from above will be invalid * after this call. Better use strdup or something similar. */ - init_ps_display(real_argc, real_argv, userName, DBName, remote_host); + init_ps_display(real_argc, real_argv, username, DBName, remote_host); set_ps_display("startup"); } if (Log_connections) elog(DEBUG, "connection: host=%s user=%s database=%s", - remote_host, userName, DBName); + remote_host, username, DBName); /* * general initialization */ if (DebugLvl > 1) elog(DEBUG, "InitPostgres"); - InitPostgres(DBName); + InitPostgres(DBName, username); #ifdef MULTIBYTE /* set default client encoding */ @@ -1404,7 +1397,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) if (!IsUnderPostmaster) { puts("\nPOSTGRES backend interactive interface "); - puts("$Revision: 1.174 $ $Date: 2000/08/30 20:30:06 $\n"); + puts("$Revision: 1.175 $ $Date: 2000/09/06 14:15:21 $\n"); } /* |