44 *
55 * PostgreSQL object comments utility code.
66 *
7- * Copyright (c) 1999, PostgreSQL Global Development Group
7+ * Copyright (c) 1999-2001 , PostgreSQL Global Development Group
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.29 2001/06/05 19:34:56 tgl Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.30 2001/06/13 21:44:40 tgl Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
2121#include "catalog/pg_database.h"
2222#include "catalog/pg_description.h"
2323#include "catalog/pg_operator.h"
24- #include "catalog/pg_shadow.h"
2524#include "catalog/pg_trigger.h"
2625#include "catalog/pg_type.h"
2726#include "catalog/pg_class.h"
@@ -389,16 +388,11 @@ CommentAttribute(char *relname, char *attrname, char *comment)
389388static void
390389CommentDatabase (char * database , char * comment )
391390{
392-
393391 Relation pg_database ;
394- HeapTuple dbtuple ,
395- usertuple ;
396392 ScanKeyData entry ;
397393 HeapScanDesc scan ;
394+ HeapTuple dbtuple ;
398395 Oid oid ;
399- bool superuser ;
400- int32 dba ;
401- Oid userid ;
402396
403397 /*** First find the tuple in pg_database for the database ***/
404398
@@ -408,33 +402,17 @@ CommentDatabase(char *database, char *comment)
408402 scan = heap_beginscan (pg_database , 0 , SnapshotNow , 1 , & entry );
409403 dbtuple = heap_getnext (scan , 0 );
410404
411- /*** Validate database exists, and fetch the dba id and oid ***/
405+ /*** Validate database exists, and fetch the db oid ***/
412406
413407 if (!HeapTupleIsValid (dbtuple ))
414408 elog (ERROR , "database '%s' does not exist" , database );
415- dba = ((Form_pg_database ) GETSTRUCT (dbtuple ))-> datdba ;
416409 oid = dbtuple -> t_data -> t_oid ;
417410
418- /*** Now, fetch user information ***/
419-
420- userid = GetUserId ();
421- usertuple = SearchSysCache (SHADOWSYSID ,
422- ObjectIdGetDatum (userid ),
423- 0 , 0 , 0 );
424- if (!HeapTupleIsValid (usertuple ))
425- elog (ERROR , "invalid user id %u" , (unsigned ) userid );
426- superuser = ((Form_pg_shadow ) GETSTRUCT (usertuple ))-> usesuper ;
427- ReleaseSysCache (usertuple );
411+ /*** Allow if the user matches the database dba or is a superuser ***/
428412
429- /*** Allow if the userid matches the database dba or is a superuser ***/
430-
431- #ifndef NO_SECURITY
432- if (!(superuser || (userid == dba )))
433- {
413+ if (!(superuser () || is_dbadmin (oid )))
434414 elog (ERROR , "you are not permitted to comment on database '%s'" ,
435415 database );
436- }
437- #endif
438416
439417 /*** Create the comments with the pg_database oid ***/
440418
@@ -444,7 +422,6 @@ CommentDatabase(char *database, char *comment)
444422
445423 heap_endscan (scan );
446424 heap_close (pg_database , AccessShareLock );
447-
448425}
449426
450427/*------------------------------------------------------------------
0 commit comments