未验证 提交 5abbfe99 编写于 作者: B BaiShaoqi 提交者: GitHub

GPDB_93_MERGE_FIXME: AlterExtProtocolOwner() refactored to AlterObjectOwner_internal() (#6122)

上级 20f4dfd5
......@@ -760,12 +760,6 @@ ExecAlterOwnerStmt_internal(AlterOwnerStmt *stmt)
newowner);
case OBJECT_EXTPROTOCOL:
// GPDB_93_MERGE_FIXME: this probably could be refactored to
// follow the generic case below
return AlterExtProtocolOwner(strVal(linitial(stmt->object)),
newowner);
/* Generic cases */
case OBJECT_AGGREGATE:
case OBJECT_COLLATION:
case OBJECT_CONVERSION:
......@@ -933,6 +927,34 @@ AlterObjectOwner_internal(Relation rel, Oid objectId, Oid new_ownerId)
}
}
/* MPP-14592: untrusted? don't allow ALTER OWNER to non-super user */
if(classId == ExtprotocolRelationId)
{
char *old_name;
bool is_trusted;
datum = heap_getattr(oldtup, Anum_name,
RelationGetDescr(rel), &isnull);
Assert(!isnull);
old_name = NameStr(*(DatumGetName(datum)));
datum = heap_getattr(oldtup, Anum_pg_extprotocol_ptctrusted,
RelationGetDescr(rel), &isnull);
if (isnull)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("internal error: protocol \"%s\" has no trust attribute defined", old_name)));
is_trusted = DatumGetBool(datum);
if(!is_trusted && !superuser_arg(new_ownerId))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("untrusted protocol \"%s\" can't be owned by non superuser", old_name)));
}
/* Build a modified tuple */
nattrs = RelationGetNumberOfAttributes(rel);
values = palloc0(nattrs * sizeof(Datum));
......
......@@ -144,138 +144,3 @@ RemoveExtProtocolById(Oid protOid)
heap_close(rel, NoLock);
}
/*
* Change external protocol owner
*/
Oid
AlterExtProtocolOwner(const char *name, Oid newOwnerId)
{
HeapTuple tup;
Relation rel;
ScanKeyData scankey;
SysScanDesc scan;
Oid ptcId;
Oid ownerId;
AclResult aclresult;
bool isNull;
bool isTrusted;
Datum ownerDatum;
Datum trustedDatum;
/*
* Check the pg_extprotocol relation to be certain the protocol
* is there.
*/
rel = heap_open(ExtprotocolRelationId, RowExclusiveLock);
ScanKeyInit(&scankey,
Anum_pg_extprotocol_ptcname,
BTEqualStrategyNumber, F_NAMEEQ,
CStringGetDatum(name));
scan = systable_beginscan(rel, ExtprotocolPtcnameIndexId, true,
NULL, 1, &scankey);
tup = systable_getnext(scan);
if (!HeapTupleIsValid(tup))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("protocol \"%s\" does not exist",
name)));
ptcId = HeapTupleGetOid(tup);
ownerDatum = heap_getattr(tup,
Anum_pg_extprotocol_ptcowner,
RelationGetDescr(rel),
&isNull);
if (isNull)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("internal error: protocol \"%s\" has no owner defined",
name)));
ownerId = DatumGetObjectId(ownerDatum);
trustedDatum = heap_getattr(tup,
Anum_pg_extprotocol_ptctrusted,
RelationGetDescr(rel),
&isNull);
if (isNull)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("internal error: protocol \"%s\" has no trust attribute defined",
name)));
isTrusted = DatumGetBool(trustedDatum);
if (ownerId != newOwnerId)
{
Acl *newAcl;
Datum values[Natts_pg_extprotocol];
bool nulls[Natts_pg_extprotocol];
bool replaces[Natts_pg_extprotocol];
HeapTuple newtuple;
Datum aclDatum;
/* Superusers can always do it */
if (!superuser())
{
/* Must be owner */
if (!pg_extprotocol_ownercheck(ptcId, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_EXTPROTOCOL,
name);
/* Must be able to become new owner */
check_is_member_of_role(GetUserId(), newOwnerId);
/* New owner must have USAGE privilege on protocol */
aclresult = pg_extprotocol_aclcheck(ptcId, newOwnerId, ACL_USAGE);
if (aclresult != ACLCHECK_OK)
aclcheck_error(aclresult, ACL_KIND_EXTPROTOCOL, name);
}
/* MPP-14592: untrusted? don't allow ALTER OWNER to non-super user */
if(!isTrusted && !superuser_arg(newOwnerId))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("untrusted protocol \"%s\" can't be owned by non superuser",
name)));
MemSet(values, 0, sizeof(values));
MemSet(nulls, false, sizeof(nulls));
MemSet(replaces, false, sizeof(replaces));
replaces[Anum_pg_extprotocol_ptcowner - 1] = true;
values[Anum_pg_extprotocol_ptcowner - 1] = ObjectIdGetDatum(newOwnerId);
aclDatum = heap_getattr(tup,
Anum_pg_extprotocol_ptcacl,
RelationGetDescr(rel),
&isNull);
if (!isNull)
{
newAcl = aclnewowner(DatumGetAclP(aclDatum),
ownerId, newOwnerId);
replaces[Anum_pg_extprotocol_ptcacl - 1] = true;
values[Anum_pg_extprotocol_ptcacl - 1] = PointerGetDatum(newAcl);
}
newtuple = heap_modify_tuple(tup,
RelationGetDescr(rel),
values, nulls, replaces);
simple_heap_update(rel, &newtuple->t_self, newtuple);
CatalogUpdateIndexes(rel, newtuple);
heap_freetuple(newtuple);
/* Update owner dependency reference */
changeDependencyOnOwner(ExtprotocolRelationId, ptcId, newOwnerId);
}
systable_endscan(scan);
heap_close(rel, NoLock);
return ptcId;
}
......@@ -13,7 +13,5 @@
extern void DefineExtProtocol(List *name, List *parameters, bool trusted);
extern void RemoveExtProtocolById(Oid protOid);
extern Oid AlterExtProtocolOwner(const char *name, Oid newOwnerId);
#endif /* EXTPROTOCOLCMDS_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册