From 75810bbdbbcd6270e44a2e5d851b8999cfc9f6e2 Mon Sep 17 00:00:00 2001 From: dmchen Date: Thu, 23 Nov 2023 11:26:14 +0000 Subject: [PATCH] audit --- include/common/tmsg.h | 5 ++++- source/common/src/tmsg.c | 18 ++++++++++++++---- source/dnode/mnode/impl/src/mndCompact.c | 20 +++++++++++++------- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 2d8a54df06..79593f4451 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1395,10 +1395,13 @@ int32_t tDeserializeSCompactDbRsp(void* buf, int32_t bufLen, SCompactDbRsp* pRsp typedef struct { int32_t compactId; + int32_t sqlLen; + char* sql; } SKillCompactReq; int32_t tSerializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq); -int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReqp); +int32_t tDeserializeSKillCompactReq(void* buf, int32_t bufLen, SKillCompactReq* pReq); +void tFreeSKillCompactReq(SKillCompactReq *pReq); typedef struct { char name[TSDB_FUNC_NAME_LEN]; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index de7cae40c1..a3e45d7126 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -3466,12 +3466,15 @@ int32_t tDeserializeSCompactDbRsp(void *buf, int32_t bufLen, SCompactDbRsp *pRsp return 0; } -int32_t tSerializeSKillCompactReq(void *buf, int32_t bufLen, SKillCompactReq *pRsp) { +int32_t tSerializeSKillCompactReq(void *buf, int32_t bufLen, SKillCompactReq *pReq) { SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeI32(&encoder, pRsp->compactId) < 0) return -1; + + if (tEncodeI32(&encoder, pReq->compactId) < 0) return -1; + ENCODESQL(); + tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -3479,18 +3482,25 @@ int32_t tSerializeSKillCompactReq(void *buf, int32_t bufLen, SKillCompactReq *pR return tlen; } -int32_t tDeserializeSKillCompactReq(void *buf, int32_t bufLen, SKillCompactReq *pRsp) { +int32_t tDeserializeSKillCompactReq(void *buf, int32_t bufLen, SKillCompactReq *pReq) { SDecoder decoder = {0}; tDecoderInit(&decoder, buf, bufLen); if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeI32(&decoder, &pRsp->compactId) < 0) return -1; + + if (tDecodeI32(&decoder, &pReq->compactId) < 0) return -1; + DECODESQL(); + tEndDecode(&decoder); tDecoderClear(&decoder); return 0; } +void tFreeSKillCompactReq(SKillCompactReq *pReq) { + FREESQL(); +} + int32_t tSerializeSUseDbRspImp(SEncoder *pEncoder, const SUseDbRsp *pRsp) { if (tEncodeCStr(pEncoder, pRsp->db) < 0) return -1; if (tEncodeI64(pEncoder, pRsp->uid) < 0) return -1; diff --git a/source/dnode/mnode/impl/src/mndCompact.c b/source/dnode/mnode/impl/src/mndCompact.c index 571ba90071..e206567572 100644 --- a/source/dnode/mnode/impl/src/mndCompact.c +++ b/source/dnode/mnode/impl/src/mndCompact.c @@ -21,6 +21,8 @@ #include "tmsgcb.h" #include "mndDnode.h" #include "tmisce.h" +#include "audit.h" +#include "mndPrivilege.h" #define MND_COMPACT_VER_NUMBER 1 @@ -421,8 +423,6 @@ static int32_t mndKillCompact(SMnode *pMnode, SRpcMsg *pReq, SCompactObj *pCompa sdbRelease(pMnode->pSdb, pDetail); } - //mndUserRemoveView(pMnode, pTrans, pView->fullname); - if (mndTransPrepare(pMnode, pTrans) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); mndTransDrop(pTrans); @@ -463,12 +463,14 @@ int32_t mndProcessKillCompactReq(SRpcMsg *pReq){ SMnode *pMnode = pReq->info.node; int32_t code = -1; SCompactObj *pCompact = mndAcquireCompact(pMnode, killCompactReq.compactId); + if(pCompact == NULL){ + tFreeSKillCompactReq(&killCompactReq); + return -1; + } - /* - if (0 != mndCheckViewPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_VIEW, killCompactReq.compactId)) { + if (0 != mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_COMPACT_DB)) { goto _OVER; } - */ if (mndKillCompact(pMnode, pReq, pCompact) < 0) { goto _OVER; @@ -476,13 +478,17 @@ int32_t mndProcessKillCompactReq(SRpcMsg *pReq){ code = TSDB_CODE_ACTION_IN_PROGRESS; - //mndLogDropViewAudit(pReq, pMnode, killCompactReq); + char obj[10] = {0}; + sprintf(obj, "%d", pCompact->compactId); + + auditRecord(pReq, pMnode->clusterId, "killCompact", pCompact->dbname, obj, killCompactReq.sql, killCompactReq.sqlLen); _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("failed to kill compact %" PRId32 " since %s", killCompactReq.compactId, terrstr()); } - + + tFreeSKillCompactReq(&killCompactReq); sdbRelease(pMnode->pSdb, pCompact); return code;