Index: src/backend/libpq/auth.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/libpq/auth.c,v retrieving revision 1.82 diff -c -r1.82 auth.c *** src/backend/libpq/auth.c 20 Jun 2002 20:29:28 -0000 1.82 --- src/backend/libpq/auth.c 1 Aug 2002 05:13:35 -0000 *************** *** 117,123 **** version, PG_KRB4_VERSION); return STATUS_ERROR; } ! if (strncmp(port->user, auth_data.pname, SM_USER) != 0) { elog(LOG, "pg_krb4_recvauth: name \"%s\" != \"%s\"", port->user, auth_data.pname); --- 117,123 ---- version, PG_KRB4_VERSION); return STATUS_ERROR; } ! if (strncmp(port->user, auth_data.pname, SM_DATABASE_USER) != 0) { elog(LOG, "pg_krb4_recvauth: name \"%s\" != \"%s\"", port->user, auth_data.pname); *************** *** 290,296 **** } kusername = pg_an_to_ln(kusername); ! if (strncmp(port->user, kusername, SM_USER)) { elog(LOG, "pg_krb5_recvauth: user name \"%s\" != krb5 name \"%s\"", port->user, kusername); --- 290,296 ---- } kusername = pg_an_to_ln(kusername); ! if (strncmp(port->user, kusername, SM_DATABASE_USER)) { elog(LOG, "pg_krb5_recvauth: user name \"%s\" != krb5 name \"%s\"", port->user, kusername); Index: src/backend/postmaster/postmaster.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v retrieving revision 1.281 diff -c -r1.281 postmaster.c *** src/backend/postmaster/postmaster.c 13 Jul 2002 01:02:14 -0000 1.281 --- src/backend/postmaster/postmaster.c 1 Aug 2002 05:13:37 -0000 *************** *** 192,197 **** --- 192,199 ---- bool HostnameLookup; /* for ps display */ bool ShowPortNumber; bool Log_connections = false; + bool Db_user_namespace = false; + /* Startup/shutdown state */ static pid_t StartupPID = 0, *************** *** 1156,1161 **** --- 1158,1173 ---- /* Check a user name was given. */ if (port->user[0] == '\0') elog(FATAL, "no PostgreSQL user name specified in startup packet"); + + /* Prefix database name for per-db user namespace */ + /* XXX look up super-user name from postmaster */ + if (Db_user_namespace && strcmp(port->user, "postgres")) + { + char hold_user[SM_DATABASE_USER]; + snprintf(hold_user, SM_DATABASE_USER, "%s.%s", port->database, + port->user); + strcpy(port->user, hold_user); + } /* * If we're going to reject the connection due to database state, say Index: src/backend/utils/misc/guc.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v retrieving revision 1.76 diff -c -r1.76 guc.c *** src/backend/utils/misc/guc.c 30 Jul 2002 16:20:03 -0000 1.76 --- src/backend/utils/misc/guc.c 1 Aug 2002 05:13:40 -0000 *************** *** 481,486 **** --- 481,490 ---- { "transform_null_equals", PGC_USERSET }, &Transform_null_equals, false, NULL, NULL }, + { + { "db_user_namespace", PGC_SIGHUP }, &Db_user_namespace, + false, NULL, NULL + }, { { NULL, 0 }, NULL, false, NULL, NULL Index: src/backend/utils/misc/postgresql.conf.sample =================================================================== RCS file: /cvsroot/pgsql/src/backend/utils/misc/postgresql.conf.sample,v retrieving revision 1.42 diff -c -r1.42 postgresql.conf.sample *** src/backend/utils/misc/postgresql.conf.sample 30 Jul 2002 04:24:54 -0000 1.42 --- src/backend/utils/misc/postgresql.conf.sample 1 Aug 2002 05:13:40 -0000 *************** *** 112,118 **** # # Message display # - #server_min_messages = notice # Values, in order of decreasing detail: # debug5, debug4, debug3, debug2, debug1, # info, notice, warning, error, log, fatal, --- 112,117 ---- *************** *** 200,202 **** --- 199,202 ---- #sql_inheritance = true #transform_null_equals = false #statement_timeout = 0 # 0 is disabled + #db_user_namespace = false Index: src/include/libpq/libpq-be.h =================================================================== RCS file: /cvsroot/pgsql/src/include/libpq/libpq-be.h,v retrieving revision 1.32 diff -c -r1.32 libpq-be.h *** src/include/libpq/libpq-be.h 20 Jun 2002 20:29:49 -0000 1.32 --- src/include/libpq/libpq-be.h 1 Aug 2002 05:13:40 -0000 *************** *** 59,65 **** ProtocolVersion proto; char database[SM_DATABASE + 1]; ! char user[SM_USER + 1]; char options[SM_OPTIONS + 1]; char tty[SM_TTY + 1]; char auth_arg[MAX_AUTH_ARG]; --- 59,65 ---- ProtocolVersion proto; char database[SM_DATABASE + 1]; ! char user[SM_DATABASE_USER + 1]; char options[SM_OPTIONS + 1]; char tty[SM_TTY + 1]; char auth_arg[MAX_AUTH_ARG]; *************** *** 72,78 **** SSL *ssl; X509 *peer; char peer_dn[128 + 1]; ! char peer_cn[SM_USER + 1]; unsigned long count; #endif } Port; --- 72,78 ---- SSL *ssl; X509 *peer; char peer_dn[128 + 1]; ! char peer_cn[SM_DATABASE_USER + 1]; unsigned long count; #endif } Port; Index: src/include/libpq/pqcomm.h =================================================================== RCS file: /cvsroot/pgsql/src/include/libpq/pqcomm.h,v retrieving revision 1.64 diff -c -r1.64 pqcomm.h *** src/include/libpq/pqcomm.h 20 Jun 2002 20:29:49 -0000 1.64 --- src/include/libpq/pqcomm.h 1 Aug 2002 05:13:40 -0000 *************** *** 114,119 **** --- 114,121 ---- #define SM_DATABASE 64 /* SM_USER should be the same size as the others. bjm 2002-06-02 */ #define SM_USER 32 + /* We prepend database name if db_user_namespace true. */ + #define SM_DATABASE_USER (SM_DATABASE+SM_USER) #define SM_OPTIONS 64 #define SM_UNUSED 64 #define SM_TTY 64 *************** *** 124,135 **** --- 126,139 ---- { ProtocolVersion protoVersion; /* Protocol version */ char database[SM_DATABASE]; /* Database name */ + /* Db_user_namespace prepends dbname */ char user[SM_USER]; /* User name */ char options[SM_OPTIONS]; /* Optional additional args */ char unused[SM_UNUSED]; /* Unused */ char tty[SM_TTY]; /* Tty for debug output */ } StartupPacket; + extern bool Db_user_namespace; /* These are the authentication requests sent by the backend. */