|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.122 2004/07/21 22:31:21 tgl Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.123 2004/08/01 20:30:48 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -5115,7 +5115,7 @@ ATExecChangeOwner(Oid relationOid, int32 newOwnerSysId)
|
5115 | 5115 | /* Get its pg_class tuple, too */
|
5116 | 5116 | class_rel = heap_openr(RelationRelationName, RowExclusiveLock);
|
5117 | 5117 |
|
5118 |
| - tuple = SearchSysCacheCopy(RELOID, |
| 5118 | + tuple = SearchSysCache(RELOID, |
5119 | 5119 | ObjectIdGetDatum(relationOid),
|
5120 | 5120 | 0, 0, 0);
|
5121 | 5121 | if (!HeapTupleIsValid(tuple))
|
@@ -5145,21 +5145,47 @@ ATExecChangeOwner(Oid relationOid, int32 newOwnerSysId)
|
5145 | 5145 | */
|
5146 | 5146 | if (tuple_class->relowner != newOwnerSysId)
|
5147 | 5147 | {
|
| 5148 | + Datum repl_val[Natts_pg_class]; |
| 5149 | + char repl_null[Natts_pg_class]; |
| 5150 | + char repl_repl[Natts_pg_class]; |
| 5151 | + Acl *newAcl; |
| 5152 | + Datum aclDatum; |
| 5153 | + bool isNull; |
| 5154 | + HeapTuple newtuple; |
| 5155 | + |
5148 | 5156 | /* Otherwise, check that we are the superuser */
|
5149 | 5157 | if (!superuser())
|
5150 | 5158 | ereport(ERROR,
|
5151 | 5159 | (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
5152 | 5160 | errmsg("must be superuser to change owner")));
|
5153 | 5161 |
|
| 5162 | + memset(repl_null, ' ', sizeof(repl_null)); |
| 5163 | + memset(repl_repl, ' ', sizeof(repl_repl)); |
| 5164 | + |
| 5165 | + repl_repl[Anum_pg_class_relowner - 1] = 'r'; |
| 5166 | + repl_val[Anum_pg_class_relowner - 1] = Int32GetDatum(newOwnerSysId); |
| 5167 | + |
5154 | 5168 | /*
|
5155 |
| - * Okay, this is a valid tuple: change its ownership and write to the |
5156 |
| - * heap. |
| 5169 | + * Determine the modified ACL for the new owner. This is only |
| 5170 | + * necessary when the ACL is non-null. |
5157 | 5171 | */
|
5158 |
| - tuple_class->relowner = newOwnerSysId; |
5159 |
| - simple_heap_update(class_rel, &tuple->t_self, tuple); |
| 5172 | + aclDatum = SysCacheGetAttr(RELOID, tuple, |
| 5173 | + Anum_pg_class_relacl, |
| 5174 | + &isNull); |
| 5175 | + if (!isNull) |
| 5176 | + { |
| 5177 | + newAcl = aclnewowner(DatumGetAclP(aclDatum), |
| 5178 | + tuple_class->relowner, newOwnerSysId); |
| 5179 | + repl_repl[Anum_pg_class_relacl - 1] = 'r'; |
| 5180 | + repl_val[Anum_pg_class_relacl - 1] = PointerGetDatum(newAcl); |
| 5181 | + } |
5160 | 5182 |
|
5161 |
| - /* Keep the catalog indexes up to date */ |
5162 |
| - CatalogUpdateIndexes(class_rel, tuple); |
| 5183 | + newtuple = heap_modifytuple(tuple, class_rel, repl_val, repl_null, repl_repl); |
| 5184 | + |
| 5185 | + simple_heap_update(class_rel, &newtuple->t_self, newtuple); |
| 5186 | + CatalogUpdateIndexes(class_rel, newtuple); |
| 5187 | + |
| 5188 | + heap_freetuple(newtuple); |
5163 | 5189 |
|
5164 | 5190 | /*
|
5165 | 5191 | * If we are operating on a table, also change the ownership of any
|
@@ -5190,7 +5216,7 @@ ATExecChangeOwner(Oid relationOid, int32 newOwnerSysId)
|
5190 | 5216 | }
|
5191 | 5217 | }
|
5192 | 5218 |
|
5193 |
| - heap_freetuple(tuple); |
| 5219 | + ReleaseSysCache(tuple); |
5194 | 5220 | heap_close(class_rel, RowExclusiveLock);
|
5195 | 5221 | relation_close(target_rel, NoLock);
|
5196 | 5222 | }
|
|
0 commit comments