This is an automated email from the ASF dual-hosted git repository. huor pushed a commit to branch huor_cloud in repository https://gitbox.apache.org/repos/asf/hawq.git
commit 46847b580db05b08d2628e3e90f67342465ea291 Author: wcl14 <[email protected]> AuthorDate: Mon Jul 2 11:45:48 2018 +0800 HAWQ-1685. Fix bug in CheckUserExistOnCloud --- src/backend/commands/user.c | 18 +++++++++--------- src/backend/commands/variable.c | 6 ++++-- src/backend/utils/init/miscinit.c | 3 ++- src/include/commands/user.h | 2 +- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c index 7252918..5896af8 100644 --- a/src/backend/commands/user.c +++ b/src/backend/commands/user.c @@ -1065,8 +1065,8 @@ AlterRole(AlterRoleStmt *stmt) tuple = caql_getnext(pcqCtx); if (!HeapTupleIsValid(tuple) - && !CheckUserExistOnCloud(pcqCtx, pg_authid_rel, stmt->role, &tuple, - true)) + && !CheckUserExistOnCloud(&pcqCtx, &cqc, pg_authid_rel, stmt->role, + &tuple, true)) { releaseResourceContextWithErrorReport(resourceid); ereport(ERROR, @@ -3365,8 +3365,9 @@ CheckUserExistOnCloudSimple(char *rolename, Oid *roleid) return true; } -bool CheckUserExistOnCloud(cqContext *pcqCtx, Relation pg_authid_rel, - char *rolename, HeapTuple *tuple, bool forUpdate) +bool CheckUserExistOnCloud(cqContext **pcqCtx, cqContext *cqc, + Relation pg_authid_rel, char *rolename, HeapTuple *tuple, + bool forUpdate) { if (!pg_cloud_auth) return false; @@ -3384,28 +3385,27 @@ bool CheckUserExistOnCloud(cqContext *pcqCtx, Relation pg_authid_rel, } return false; } - caql_endscan(pcqCtx); + caql_endscan(*pcqCtx); if (pg_authid_rel) { heap_close(pg_authid_rel, NoLock); } Oid roleid = CreateNoPrivligeRole(rolename); - cqContext cqc; if (forUpdate) { pg_authid_rel = heap_open(AuthIdRelationId, RowExclusiveLock); - pcqCtx = caql_beginscan(caql_addrel(cqclr(&cqc), pg_authid_rel), + *pcqCtx = caql_beginscan(caql_addrel(cqclr(cqc), pg_authid_rel), cql("SELECT * FROM pg_authid " " WHERE oid = :1 " " FOR UPDATE ", ObjectIdGetDatum(roleid))); } else { - pcqCtx = caql_beginscan( + *pcqCtx = caql_beginscan( NULL, cql("SELECT * FROM pg_authid " " WHERE oid = :1 ", ObjectIdGetDatum(roleid))); } - *tuple = caql_getnext(pcqCtx); + *tuple = caql_getnext(*pcqCtx); return true; } diff --git a/src/backend/commands/variable.c b/src/backend/commands/variable.c index 6c801ee..d9643e1 100644 --- a/src/backend/commands/variable.c +++ b/src/backend/commands/variable.c @@ -777,7 +777,8 @@ assign_session_authorization(const char *value, bool doit, GucSource source) roleTup = caql_getnext(pcqCtx); if (!HeapTupleIsValid(roleTup) - && !CheckUserExistOnCloud(pcqCtx, NULL, value, &roleTup, false)) + && !CheckUserExistOnCloud(&pcqCtx, NULL, NULL, value, &roleTup, + false)) { if (source >= PGC_S_INTERACTIVE) ereport(ERROR, @@ -923,7 +924,8 @@ assign_role(const char *value, bool doit, GucSource source) roleTup = caql_getnext(pcqCtx); if (!HeapTupleIsValid(roleTup) - && !CheckUserExistOnCloud(pcqCtx, NULL, value, &roleTup, false)) + && !CheckUserExistOnCloud(&pcqCtx, NULL, NULL, value, &roleTup, + false)) { if (source >= PGC_S_INTERACTIVE) ereport(ERROR, diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index c5384f9..1987c7f 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -445,7 +445,8 @@ InitializeSessionUserId(const char *rolename) roleTup = caql_getnext(pcqCtx); if (!HeapTupleIsValid(roleTup) - && !CheckUserExistOnCloud(pcqCtx, NULL, rolename, &roleTup, false)) + && !CheckUserExistOnCloud(&pcqCtx, NULL, NULL, rolename, &roleTup, + false)) ereport(FATAL, (errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION), errmsg("role \"%s\" does not exist", rolename), errOmitLocation(true), errSendAlert(false))); diff --git a/src/include/commands/user.h b/src/include/commands/user.h index c71b6a7..b4f5320 100644 --- a/src/include/commands/user.h +++ b/src/include/commands/user.h @@ -24,6 +24,6 @@ extern void RenameRole(const char *oldname, const char *newname); extern void DropOwnedObjects(DropOwnedStmt *stmt); extern void ReassignOwnedObjects(ReassignOwnedStmt *stmt); extern bool CheckUserExistOnCloudSimple(char *rolename, Oid *roleid); -extern bool CheckUserExistOnCloud(cqContext *pcqCtx, Relation pg_authid_rel, char *rolename, HeapTuple *tuple, bool forUpdate); +extern bool CheckUserExistOnCloud(cqContext **pcqCtx, cqContext *cqc, Relation pg_authid_rel, char *rolename, HeapTuple *tuple, bool forUpdate); #endif /* USER_H */
