|
9 | 9 | *
|
10 | 10 | *
|
11 | 11 | * IDENTIFICATION
|
12 |
| - * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.133 2004/05/2604:41:10 neilc Exp $ |
| 12 | + * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.134 2004/05/2613:56:45 momjian Exp $ |
13 | 13 | *
|
14 | 14 | *-------------------------------------------------------------------------
|
15 | 15 | */
|
@@ -776,6 +776,52 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
|
776 | 776 | }
|
777 | 777 |
|
778 | 778 |
|
| 779 | +/* |
| 780 | + * ALTER DATABASE name OWNER TO newowner |
| 781 | + */ |
| 782 | +void |
| 783 | +AlterDatabaseOwner(constchar*dbname,constchar*newowner) |
| 784 | +{ |
| 785 | +AclIdnewdatdba; |
| 786 | +HeapTupletuple, |
| 787 | +newtuple; |
| 788 | +Relationrel; |
| 789 | +ScanKeyDatascankey; |
| 790 | +SysScanDescscan; |
| 791 | + |
| 792 | +rel=heap_openr(DatabaseRelationName,RowExclusiveLock); |
| 793 | +ScanKeyInit(&scankey, |
| 794 | +Anum_pg_database_datname, |
| 795 | +BTEqualStrategyNumber,F_NAMEEQ, |
| 796 | +NameGetDatum(dbname)); |
| 797 | +scan=systable_beginscan(rel,DatabaseNameIndex, true, |
| 798 | +SnapshotNow,1,&scankey); |
| 799 | +tuple=systable_getnext(scan); |
| 800 | +if (!HeapTupleIsValid(tuple)) |
| 801 | +ereport(ERROR, |
| 802 | +(errcode(ERRCODE_UNDEFINED_DATABASE), |
| 803 | +errmsg("database \"%s\" does not exist",dbname))); |
| 804 | + |
| 805 | +/* obtain sysid of proposed owner */ |
| 806 | +newdatdba=get_usesysid(newowner);/* will ereport if no such user */ |
| 807 | + |
| 808 | +/* changing owner's database for someone else: must be superuser */ |
| 809 | +/* note that the someone else need not have any permissions */ |
| 810 | +if (!superuser()) |
| 811 | +ereport(ERROR, |
| 812 | +(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), |
| 813 | +errmsg("must be superuser to change owner's database for another user"))); |
| 814 | + |
| 815 | +/* change owner */ |
| 816 | +newtuple=heap_copytuple(tuple); |
| 817 | +((Form_pg_database)GETSTRUCT(newtuple))->datdba=newdatdba; |
| 818 | +simple_heap_update(rel,&tuple->t_self,newtuple); |
| 819 | +CatalogUpdateIndexes(rel,newtuple); |
| 820 | + |
| 821 | +systable_endscan(scan); |
| 822 | +heap_close(rel,NoLock); |
| 823 | +} |
| 824 | + |
779 | 825 |
|
780 | 826 | /*
|
781 | 827 | * Helper functions
|
|