From 381d378b588d077c92872ede3f33e18928cdd033 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Sat, 23 Jul 2022 19:38:41 +0800 Subject: [PATCH] fix: grant check for create table --- include/common/tgrant.h | 1 + source/common/src/tgrant.c | 23 +++++++++++++++++++++++ source/dnode/mnode/impl/src/mndFunc.c | 4 ++++ source/dnode/mnode/impl/src/mndGrant.c | 1 - source/dnode/vnode/src/vnd/vnodeSvr.c | 12 ++++++++++++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 source/common/src/tgrant.c diff --git a/include/common/tgrant.h b/include/common/tgrant.h index ad23c661b1..09c6e5378e 100644 --- a/include/common/tgrant.h +++ b/include/common/tgrant.h @@ -21,6 +21,7 @@ extern "C" { #endif #include "os.h" +#include "taoserror.h" typedef enum { TSDB_GRANT_ALL, diff --git a/source/common/src/tgrant.c b/source/common/src/tgrant.c new file mode 100644 index 0000000000..74a59fd580 --- /dev/null +++ b/source/common/src/tgrant.c @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "tgrant.h" + +#ifndef _GRANT + +int32_t grantCheck(EGrantType grant) { return TSDB_CODE_SUCCESS; } + +#endif \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index b626c1fb04..e6f4b48524 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -190,6 +190,10 @@ static int32_t mndCreateFunc(SMnode *pMnode, SRpcMsg *pReq, SCreateFuncReq *pCre int32_t code = -1; STrans *pTrans = NULL; + if ((terrno = grantCheck(TSDB_GRANT_USER)) < 0) { + return code; + } + SFuncObj func = {0}; memcpy(func.name, pCreate->name, TSDB_FUNC_NAME_LEN); func.createdTime = taosGetTimestampMs(); diff --git a/source/dnode/mnode/impl/src/mndGrant.c b/source/dnode/mnode/impl/src/mndGrant.c index 1148fd740b..a608a1e40f 100644 --- a/source/dnode/mnode/impl/src/mndGrant.c +++ b/source/dnode/mnode/impl/src/mndGrant.c @@ -128,7 +128,6 @@ int32_t mndInitGrant(SMnode *pMnode) { void mndCleanupGrant() {} void grantParseParameter() { mError("can't parsed parameter k"); } -int32_t grantCheck(EGrantType grant) { return TSDB_CODE_SUCCESS; } void grantReset(SMnode *pMnode, EGrantType grant, uint64_t value) {} void grantAdd(EGrantType grant, uint64_t value) {} void grantRestore(EGrantType grant, uint64_t value) {} diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 5463f42f6a..9d06fbffdd 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -477,6 +477,11 @@ static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t version, void *pR for (int32_t iReq = 0; iReq < req.nReqs; iReq++) { pCreateReq = req.pReqs + iReq; + if ((terrno = grantCheck(TSDB_GRANT_TIMESERIES)) < 0) { + rcode = -1; + goto _exit; + } + // validate hash sprintf(tbName, "%s.%s", pVnode->config.dbname, pCreateReq->name); if (vnodeValidateTableHash(pVnode, tbName) < 0) { @@ -821,6 +826,13 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq goto _exit; } + if ((terrno = grantCheck(TSDB_GRANT_TIMESERIES)) < 0) { + pRsp->code = terrno; + tDecoderClear(&decoder); + taosArrayDestroy(createTbReq.ctb.tagName); + goto _exit; + } + if (metaCreateTable(pVnode->pMeta, version, &createTbReq) < 0) { if (terrno != TSDB_CODE_TDB_TABLE_ALREADY_EXIST) { submitBlkRsp.code = terrno; -- GitLab