• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #4905

29 Dec 2025 02:08PM UTC coverage: 65.423% (-0.3%) from 65.734%
#4905

push

travis-ci

web-flow
enh: sign connect request (#34067)

23 of 29 new or added lines in 4 files covered. (79.31%)

11614 existing lines in 186 files now uncovered.

193476 of 295730 relevant lines covered (65.42%)

115752566.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

43.81
/source/dnode/mnode/impl/src/mndEncryptAlgr.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#define MND_ENCRYPT_ALGR_VER_NUMBER 1
17

18
#include "audit.h"
19
#include "mndEncryptAlgr.h"
20
#include "mndMnode.h"
21
#include "mndShow.h"
22
#include "mndSync.h"
23
#include "mndTrans.h"
24
#include "tencrypt.h"
25

26
static void tFreeEncryptAlgrObj(SEncryptAlgrObj *pEncryptAlgr) {}
2,312,928✔
27

28
static int32_t tSerializeSEncryptAlgrObj(void *buf, int32_t bufLen, const SEncryptAlgrObj *pObj) {
8,775,996✔
29
  SEncoder encoder = {0};
8,775,996✔
30
  int32_t  code = 0;
8,775,996✔
31
  int32_t  lino;
32
  int32_t  tlen;
33
  tEncoderInit(&encoder, buf, bufLen);
8,775,996✔
34

35
  TAOS_CHECK_EXIT(tStartEncode(&encoder));
8,775,996✔
36
  TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->id));
17,551,992✔
37
  TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pObj->algorithm_id));
17,551,992✔
38
  TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pObj->name));
17,551,992✔
39
  TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pObj->desc));
17,551,992✔
40
  TAOS_CHECK_EXIT(tEncodeI16(&encoder, pObj->type));
17,551,992✔
41
  TAOS_CHECK_EXIT(tEncodeI8(&encoder, pObj->source));
17,551,992✔
42
  TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pObj->ossl_algr_name));
17,551,992✔
43

44
  tEndEncode(&encoder);
8,775,996✔
45

46
_exit:
8,775,996✔
47
  if (code) {
8,775,996✔
48
    tlen = code;
×
49
  } else {
50
    tlen = encoder.pos;
8,775,996✔
51
  }
52
  tEncoderClear(&encoder);
8,775,996✔
53
  return tlen;
8,775,996✔
54
}
55

56
static int32_t tDeserializeSEncryptAlgrObj(void *buf, int32_t bufLen, SEncryptAlgrObj *pObj) {
2,312,928✔
57
  int32_t  code = 0;
2,312,928✔
58
  int32_t  lino;
59
  SDecoder decoder = {0};
2,312,928✔
60
  tDecoderInit(&decoder, buf, bufLen);
2,312,928✔
61

62
  TAOS_CHECK_EXIT(tStartDecode(&decoder));
2,312,928✔
63
  TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->id));
4,625,856✔
64
  TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pObj->algorithm_id));
2,312,928✔
65
  TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pObj->name));
2,312,928✔
66
  TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pObj->desc));
2,312,928✔
67
  TAOS_CHECK_EXIT(tDecodeI16(&decoder, &pObj->type));
4,625,856✔
68
  TAOS_CHECK_EXIT(tDecodeI8(&decoder, &pObj->source));
4,625,856✔
69
  TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pObj->ossl_algr_name));
2,312,928✔
70

71
  tEndDecode(&decoder);
2,312,928✔
72

73
_exit:
2,312,928✔
74
  tDecoderClear(&decoder);
2,312,928✔
75
  return code;
2,312,928✔
76
}
77

78
static SSdbRaw *mndEncryptAlgrActionEncode(SEncryptAlgrObj *pEncryptAlgr) {
4,387,998✔
79
  int32_t code = 0;
4,387,998✔
80
  int32_t lino = 0;
4,387,998✔
81
  terrno = TSDB_CODE_SUCCESS;
4,387,998✔
82

83
  void    *buf = NULL;
4,387,998✔
84
  SSdbRaw *pRaw = NULL;
4,387,998✔
85

86
  int32_t tlen = tSerializeSEncryptAlgrObj(NULL, 0, pEncryptAlgr);
4,387,998✔
87
  if (tlen < 0) {
4,387,998✔
88
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
89
    goto OVER;
×
90
  }
91

92
  int32_t size = sizeof(int32_t) + tlen;
4,387,998✔
93
  pRaw = sdbAllocRaw(SDB_ENCRYPT_ALGORITHMS, MND_ENCRYPT_ALGR_VER_NUMBER, size);
4,387,998✔
94
  if (pRaw == NULL) {
4,387,998✔
95
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
96
    goto OVER;
×
97
  }
98

99
  buf = taosMemoryMalloc(tlen);
4,387,998✔
100
  if (buf == NULL) {
4,387,998✔
101
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
102
    goto OVER;
×
103
  }
104

105
  tlen = tSerializeSEncryptAlgrObj(buf, tlen, pEncryptAlgr);
4,387,998✔
106
  if (tlen < 0) {
4,387,998✔
107
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
108
    goto OVER;
×
109
  }
110

111
  int32_t dataPos = 0;
4,387,998✔
112
  SDB_SET_INT32(pRaw, dataPos, tlen, OVER);
4,387,998✔
113
  SDB_SET_BINARY(pRaw, dataPos, buf, tlen, OVER);
4,387,998✔
114
  SDB_SET_DATALEN(pRaw, dataPos, OVER);
4,387,998✔
115

116
OVER:
4,387,998✔
117
  taosMemoryFreeClear(buf);
4,387,998✔
118
  if (terrno != TSDB_CODE_SUCCESS) {
4,387,998✔
119
    mError("encrypt_algr:%" PRId32 ", failed to encode to raw:%p since %s", pEncryptAlgr->id, pRaw, terrstr());
×
120
    sdbFreeRaw(pRaw);
×
121
    return NULL;
×
122
  }
123

124
  mTrace("encrypt_algr:%" PRId32 ", encode to raw:%p, row:%p", pEncryptAlgr->id, pRaw, pEncryptAlgr);
4,387,998✔
125
  return pRaw;
4,387,998✔
126
}
127

128
SSdbRow *mndEncryptAlgrActionDecode(SSdbRaw *pRaw) {
2,312,928✔
129
  int32_t      code = 0;
2,312,928✔
130
  int32_t      lino = 0;
2,312,928✔
131
  SSdbRow     *pRow = NULL;
2,312,928✔
132
  SEncryptAlgrObj *pEncryptAlgr = NULL;
2,312,928✔
133
  void        *buf = NULL;
2,312,928✔
134
  terrno = TSDB_CODE_SUCCESS;
2,312,928✔
135

136
  int8_t sver = 0;
2,312,928✔
137
  if (sdbGetRawSoftVer(pRaw, &sver) != 0) {
2,312,928✔
138
    goto OVER;
×
139
  }
140

141
  if (sver != MND_ENCRYPT_ALGR_VER_NUMBER) {
2,312,928✔
142
    terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
×
143
    mError("encrypt_algr read invalid ver, data ver: %d, curr ver: %d", sver, MND_ENCRYPT_ALGR_VER_NUMBER);
×
144
    goto OVER;
×
145
  }
146

147
  pRow = sdbAllocRow(sizeof(SEncryptAlgrObj));
2,312,928✔
148
  if (pRow == NULL) {
2,312,928✔
149
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
150
    goto OVER;
×
151
  }
152

153
  pEncryptAlgr = sdbGetRowObj(pRow);
2,312,928✔
154
  if (pEncryptAlgr == NULL) {
2,312,928✔
155
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
156
    goto OVER;
×
157
  }
158

159
  int32_t tlen;
2,312,088✔
160
  int32_t dataPos = 0;
2,312,928✔
161
  SDB_GET_INT32(pRaw, dataPos, &tlen, OVER);
2,312,928✔
162
  buf = taosMemoryMalloc(tlen + 1);
2,312,928✔
163
  if (buf == NULL) {
2,312,928✔
164
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
165
    goto OVER;
×
166
  }
167
  SDB_GET_BINARY(pRaw, dataPos, buf, tlen, OVER);
2,312,928✔
168

169
  if ((terrno = tDeserializeSEncryptAlgrObj(buf, tlen, pEncryptAlgr)) < 0) {
2,312,928✔
170
    goto OVER;
×
171
  }
172

173
OVER:
2,312,928✔
174
  taosMemoryFreeClear(buf);
2,312,928✔
175
  if (terrno != TSDB_CODE_SUCCESS) {
2,312,928✔
176
    mError("encrypt_algr:%" PRId32 ", failed to decode from raw:%p since %s", pEncryptAlgr->id, pRaw, terrstr());
×
177
    taosMemoryFreeClear(pRow);
×
178
    return NULL;
×
179
  }
180

181
  mTrace("encrypt_algr:%" PRId32 ", decode from raw:%p, row:%p", pEncryptAlgr->id, pRaw, pEncryptAlgr);
2,312,928✔
182
  return pRow;
2,312,928✔
183
}
184

185
int32_t mndEncryptAlgrActionInsert(SSdb *pSdb, SEncryptAlgrObj *pEncryptAlgr) {
2,312,928✔
186
  mTrace("encrypt_algr:%" PRId32 ", perform insert action", pEncryptAlgr->id);
2,312,928✔
187
  return 0;
2,312,928✔
188
}
189

190
int32_t mndEncryptAlgrActionDelete(SSdb *pSdb, SEncryptAlgrObj *pEncryptAlgr) {
2,312,928✔
191
  mTrace("encrypt_algr:%" PRId32 ", perform delete action", pEncryptAlgr->id);
2,312,928✔
192
  tFreeEncryptAlgrObj(pEncryptAlgr);
2,312,928✔
193
  return 0;
2,312,928✔
194
}
195

196
int32_t mndEncryptAlgrActionUpdate(SSdb *pSdb, SEncryptAlgrObj *pOldEncryptAlgr, SEncryptAlgrObj *pNewEncryptAlgr) {
×
197
  mTrace("encrypt_algr:%" PRId32 ", perform update action, old row:%p new row:%p", pOldEncryptAlgr->id, pOldEncryptAlgr,
×
198
         pNewEncryptAlgr);
199

200
  return 0;
×
201
}
202

203
typedef void (*mndSetEncryptAlgrFp)(SEncryptAlgrObj *Obj);
204

205
static void mndSetSM4EncryptAlgr(SEncryptAlgrObj *Obj){
277,256✔
206
  Obj->id = 1;
277,256✔
207
  strncpy(Obj->algorithm_id, "SM4-CBC", TSDB_ENCRYPT_ALGR_NAME_LEN);
277,256✔
208
  strncpy(Obj->name, "SM4", TSDB_ENCRYPT_ALGR_NAME_LEN);
277,256✔
209
  strncpy(Obj->desc, "SM4 symmetric encryption", TSDB_ENCRYPT_ALGR_DESC_LEN);
277,256✔
210
  Obj->type = ENCRYPT_ALGR_TYPE__SYMMETRIC_CIPHERS;
277,256✔
211
  Obj->source = ENCRYPT_ALGR_SOURCE_BUILTIN;
277,256✔
212
  strncpy(Obj->ossl_algr_name, "SM4-CBC:SM4", TSDB_ENCRYPT_ALGR_NAME_LEN);
277,256✔
213
}
277,256✔
214

215
static void mndSetAESEncryptAlgr(SEncryptAlgrObj *Obj){
277,256✔
216
  Obj->id = 2;
277,256✔
217
  strncpy(Obj->algorithm_id, "AES-128-CBC", TSDB_ENCRYPT_ALGR_NAME_LEN);
277,256✔
218
  strncpy(Obj->name, "AES", TSDB_ENCRYPT_ALGR_NAME_LEN);
277,256✔
219
  strncpy(Obj->desc, "AES symmetric encryption", TSDB_ENCRYPT_ALGR_DESC_LEN);
277,256✔
220
  Obj->type = ENCRYPT_ALGR_TYPE__SYMMETRIC_CIPHERS;
277,256✔
221
  Obj->source = ENCRYPT_ALGR_SOURCE_BUILTIN;
277,256✔
222
  strncpy(Obj->ossl_algr_name, "AES-128-CBC", TSDB_ENCRYPT_ALGR_NAME_LEN);
277,256✔
223
}
277,256✔
224

225
static void mndSetSM3EncryptAlgr(SEncryptAlgrObj *Obj) {
277,256✔
226
  Obj->id = 3;
277,256✔
227
  strncpy(Obj->algorithm_id, "SM3", TSDB_ENCRYPT_ALGR_NAME_LEN);
277,256✔
228
  strncpy(Obj->name, "SM3", TSDB_ENCRYPT_ALGR_NAME_LEN);
277,256✔
229
  strncpy(Obj->desc, "SM3 digests", TSDB_ENCRYPT_ALGR_DESC_LEN);
277,256✔
230
  Obj->type = ENCRYPT_ALGR_TYPE__DIGEST;
277,256✔
231
  Obj->source = ENCRYPT_ALGR_SOURCE_BUILTIN;
277,256✔
232
  strncpy(Obj->ossl_algr_name, "SM3", TSDB_ENCRYPT_ALGR_NAME_LEN);
277,256✔
233
}
277,256✔
234

235
static void mndSetSHAEncryptAlgr(SEncryptAlgrObj *Obj) {
277,256✔
236
  Obj->id = 4;
277,256✔
237
  strncpy(Obj->algorithm_id, "SHA-256", TSDB_ENCRYPT_ALGR_NAME_LEN);
277,256✔
238
  strncpy(Obj->name, "SHA-256", TSDB_ENCRYPT_ALGR_NAME_LEN);
277,256✔
239
  strncpy(Obj->desc, "SHA2 digests", TSDB_ENCRYPT_ALGR_DESC_LEN);
277,256✔
240
  Obj->type = ENCRYPT_ALGR_TYPE__DIGEST;
277,256✔
241
  Obj->source = ENCRYPT_ALGR_SOURCE_BUILTIN;
277,256✔
242
  strncpy(Obj->ossl_algr_name, "SHA-256", TSDB_ENCRYPT_ALGR_NAME_LEN);
277,256✔
243
}
277,256✔
244

245
static void mndSetSM2EncryptAlgr(SEncryptAlgrObj *Obj) {
277,256✔
246
  Obj->id = 5;
277,256✔
247
  strncpy(Obj->algorithm_id, "SM2", TSDB_ENCRYPT_ALGR_NAME_LEN);
277,256✔
248
  strncpy(Obj->name, "SM2", TSDB_ENCRYPT_ALGR_NAME_LEN);
277,256✔
249
  strncpy(Obj->desc, "SM2 Asymmetric Cipher", TSDB_ENCRYPT_ALGR_DESC_LEN);
277,256✔
250
  Obj->type = ENCRYPT_ALGR_TYPE__ASYMMETRIC_CIPHERS;
277,256✔
251
  Obj->source = ENCRYPT_ALGR_SOURCE_BUILTIN;
277,256✔
252
}
277,256✔
253

254
static void mndSetRSAEncryptAlgr(SEncryptAlgrObj *Obj) {
277,256✔
255
  Obj->id = 6;
277,256✔
256
  strncpy(Obj->algorithm_id, "RSA", TSDB_ENCRYPT_ALGR_NAME_LEN);
277,256✔
257
  strncpy(Obj->name, "RSA", TSDB_ENCRYPT_ALGR_NAME_LEN);
277,256✔
258
  strncpy(Obj->desc, "RSA Asymmetric Cipher", TSDB_ENCRYPT_ALGR_DESC_LEN);
277,256✔
259
  Obj->type = ENCRYPT_ALGR_TYPE__ASYMMETRIC_CIPHERS;
277,256✔
260
  Obj->source = ENCRYPT_ALGR_SOURCE_BUILTIN;
277,256✔
261
}
277,256✔
262

263
static SSdbRaw * mndCreateEncryptAlgrRaw(STrans *pTrans, SEncryptAlgrObj *Obj) {
1,663,536✔
264
  int32_t code = 0;
1,663,536✔
265

266
  SSdbRaw *pRaw = mndEncryptAlgrActionEncode(Obj);
1,663,536✔
267
  if (pRaw == NULL) {
1,663,536✔
268
    return NULL;
×
269
  }
270
  code = sdbSetRawStatus(pRaw, SDB_STATUS_READY);
1,663,536✔
271
  if (code != 0) {
1,663,536✔
272
    terrno = code;
×
273
    return NULL;
×
274
  }
275

276
  if ((code = mndTransAppendCommitlog(pTrans, pRaw)) != 0) {
1,663,536✔
277
    terrno = code;
×
278
    return NULL;
×
279
  }
280
  return pRaw;
1,663,536✔
281
}
282

283
int32_t mndSendCreateBuiltinReq(SMnode *pMnode) {
277,256✔
284
  int32_t code = 0;
277,256✔
285

286
  SRpcMsg rpcMsg = {.pCont = NULL,
277,256✔
287
                    .contLen = 0,
288
                    .msgType = TDMT_MND_BUILTIN_ENCRYPT_ALGR,
289
                    .info.ahandle = 0,
290
                    .info.notFreeAhandle = 1,
291
                    .info.refId = 0,
292
                    .info.noResp = 0,
293
                    .info.handle = 0};
294
  SEpSet  epSet = {0};
277,256✔
295

296
  mndGetMnodeEpSet(pMnode, &epSet);
277,256✔
297

298
  code = tmsgSendReq(&epSet, &rpcMsg);
277,256✔
299
  if (code != 0) {
277,256✔
300
    mError("failed to send builtin encrypt algr req, since %s", tstrerror(code));
×
301
  }
302
  return code;
277,256✔
303
}
304

305
static int32_t mndCreateBuiltinEncryptAlgr(SMnode *pMnode) {
277,256✔
306
  int32_t code = 0;
277,256✔
307
  STrans *pTrans = NULL;
277,256✔
308

309
  mndSetEncryptAlgrFp setFpArr[] = {mndSetSM4EncryptAlgr
277,256✔
310
#if defined(TD_ENTERPRISE) && defined(LINUX)
311
                                    ,
312
                                    mndSetAESEncryptAlgr,
313
                                    mndSetSM3EncryptAlgr,
314
                                    mndSetSHAEncryptAlgr,
315
                                    mndSetSM2EncryptAlgr,
316
                                    mndSetRSAEncryptAlgr
317
#endif
318
  };
319

320
  int32_t algrNum = sizeof(setFpArr) / sizeof(mndSetEncryptAlgrFp);
277,256✔
321

322
  pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "create-enc-algr");
277,256✔
323
  if (pTrans == NULL) {
277,256✔
324
    mError("failed to create since %s",terrstr());
×
325
    code = terrno;
×
326
    goto _OVER;
×
327
  }
328
  mInfo("trans:%d, used to create default encrypt_algr", pTrans->id);
277,256✔
329

330
  for (int32_t i = 0; i < algrNum; i++) {
1,940,792✔
331
    SEncryptAlgrObj *Obj = taosMemoryMalloc(sizeof(SEncryptAlgrObj));
1,663,536✔
332
    if (Obj == NULL) {
1,663,536✔
333
      goto _OVER;
×
334
    }
335
    memset(Obj, 0, sizeof(SEncryptAlgrObj));
1,663,536✔
336
    setFpArr[i](Obj);
1,663,536✔
337
    SSdbRaw *pRaw = mndCreateEncryptAlgrRaw(pTrans, Obj);
1,663,536✔
338
    taosMemoryFree(Obj);
1,663,536✔
339
    if (pRaw == NULL) {
1,663,536✔
340
      mError("trans:%d, failed to commit redo log since %s", pTrans->id, terrstr());
×
341
      goto _OVER;
×
342
    }
343
  }
344

345
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
277,256✔
346
    mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
×
347
    goto _OVER;
×
348
  }
349

350
  code = 0;
277,256✔
351

352
_OVER:
277,256✔
353
  mndTransDrop(pTrans);
277,256✔
354
  return code;
277,256✔
355
}
356

357
static int32_t mndProcessBuiltinReq(SRpcMsg *pReq) {
277,256✔
358
  SMnode *pMnode = pReq->info.node;
277,256✔
359
  if (!mndIsLeader(pMnode)) {
277,256✔
360
    return TSDB_CODE_SUCCESS;
×
361
  }
362

363
  return mndCreateBuiltinEncryptAlgr(pMnode);
277,256✔
364
}
365

366
static int32_t mndProcessBuiltinRsp(SRpcMsg *pRsp) {
277,256✔
367
  mInfo("builtin rsp");
277,256✔
368
  return 0;
277,256✔
369
}
370

371
static int32_t mndUpgradeBuiltinEncryptAlgr(SMnode *pMnode, int32_t version) {
349,084✔
372
  if (version >= TSDB_MNODE_BUILTIN_DATA_VERSION) return 0;
349,084✔
373

374
  return mndSendCreateBuiltinReq(pMnode);
277,256✔
375
}
376

377
#define SYMCBC "Symmetric Ciphers CBC mode"
378
#define ASYM       "Asymmetric Ciphers"
379
#define DIGEST     "Digests"
380
#define BUILTIN "build-in"
381
#define CUSTOMIZED "customized"
382
static int32_t mndRetrieveEncryptAlgr(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows){
×
383
  SMnode      *pMnode = pMsg->info.node;
×
384
  SSdb        *pSdb = pMnode->pSdb;
×
385
  int32_t      code = 0;
×
386
  int32_t      lino = 0;
×
387
  int32_t      numOfRows = 0;
×
388
  int32_t      cols = 0;
×
389
  SEncryptAlgrObj *pObj = NULL;
×
390

391
  char tmpBuf[1000] = {0};
×
392

393
  while (numOfRows < rows) {
×
394
    pShow->pIter = sdbFetch(pSdb, SDB_ENCRYPT_ALGORITHMS, pShow->pIter, (void **)&pObj);
×
395
    if (pShow->pIter == NULL) break;
×
396

397
    cols = 0;
×
398
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
399
    COL_DATA_SET_VAL_GOTO((const char *)&pObj->id, false, pObj, pShow->pIter, _OVER);
×
400

401
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
402
    tstrncpy(varDataVal(tmpBuf), pObj->algorithm_id, TSDB_ENCRYPT_ALGR_NAME_LEN);
×
403
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
404
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), pObj, &lino, _OVER);
×
405

406
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
407
    tstrncpy(varDataVal(tmpBuf), pObj->name, TSDB_ENCRYPT_ALGR_NAME_LEN);
×
408
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
409
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), pObj, &lino, _OVER);
×
410

411
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
412
    tstrncpy(varDataVal(tmpBuf), pObj->desc, TSDB_ENCRYPT_ALGR_DESC_LEN);
×
413
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
414
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), pObj, &lino, _OVER);
×
415

416
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
417
    if(pObj->type == ENCRYPT_ALGR_TYPE__SYMMETRIC_CIPHERS){
×
418
      tstrncpy(varDataVal(tmpBuf), SYMCBC, strlen(SYMCBC) + 1);
×
419
    } else if (pObj->type == ENCRYPT_ALGR_TYPE__DIGEST) {
×
420
      tstrncpy(varDataVal(tmpBuf), DIGEST, strlen(DIGEST) + 1);
×
421
    } else if (pObj->type == ENCRYPT_ALGR_TYPE__ASYMMETRIC_CIPHERS) {
×
422
      tstrncpy(varDataVal(tmpBuf), ASYM, strlen(ASYM) + 1);
×
423
    }
424
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
425
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), pObj, &lino, _OVER);
×
426

427
    memset(tmpBuf, 0, 1000);
×
428
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
429
    if(pObj->source == ENCRYPT_ALGR_SOURCE_BUILTIN){
×
430
      tstrncpy(varDataVal(tmpBuf), BUILTIN, strlen(BUILTIN) + 1);
×
431
    } else if (pObj->source == ENCRYPT_ALGR_SOURCE_CUSTOMIZED) {
×
432
      tstrncpy(varDataVal(tmpBuf), CUSTOMIZED, strlen(CUSTOMIZED) + 1);
×
433
    }
434
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
435
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), pObj, &lino, _OVER);
×
436

437
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
438
    tstrncpy(varDataVal(tmpBuf), pObj->ossl_algr_name, TSDB_ENCRYPT_ALGR_NAME_LEN);
×
439
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
440
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), pObj, &lino, _OVER);
×
441

442
    sdbRelease(pSdb, pObj);
×
443
    numOfRows++;
×
444
  }
445

446
  pShow->numOfRows += numOfRows;
×
447

448
_OVER:
×
449
  if (code != 0) {
×
450
    mError("failed to retrieve encrypt_algr info at line %d since %s", lino, tstrerror(code));
×
451
    TAOS_RETURN(code);
×
452
  }
453
  return numOfRows;
×
454
}
455

456
static void mndCancelRetrieveEncryptAlgr(SMnode *pMnode, void *pIter) {
×
457
  SSdb *pSdb = pMnode->pSdb;
×
458
  sdbCancelFetchByType(pSdb, pIter, SDB_ENCRYPT_ALGORITHMS);
×
459
}
×
460

461
static int32_t mndProcessCreateEncryptAlgrReq(SRpcMsg *pReq) {
×
UNCOV
462
  SMnode               *pMnode = pReq->info.node;
×
463
  int32_t               code = 0;
×
UNCOV
464
  int32_t               lino = 0;
×
465
  SCreateEncryptAlgrReq createReq = {0};
×
466
  STrans               *pTrans = NULL;
×
467

UNCOV
468
  int64_t tss = taosGetTimestampMs();
×
469

UNCOV
470
  if (tDeserializeSCreateEncryptAlgrReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
×
UNCOV
471
    TAOS_CHECK_GOTO(TSDB_CODE_INVALID_MSG, &lino, _OVER);
×
472
  }
473

474
  mInfo("algr:%s, start to create, ossl_name:%s", createReq.algorithmId, createReq.osslAlgrName);
×
475

476
  // TAOS_CHECK_GOTO(grantCheck(TSDB_GRANT_USER), &lino, _OVER);
477

UNCOV
478
  SEncryptAlgrObj *exist = mndAcquireEncryptAlgrByAId(pMnode, createReq.algorithmId);
×
479
  if (exist != NULL) {
×
480
    mndReleaseEncryptAlgr(pMnode, exist);
×
481
    TAOS_CHECK_GOTO(TSDB_CODE_MNODE_ALGR_EXIST, &lino, _OVER);
×
482
  }
483

484
  SEncryptAlgrObj Obj = {0};
×
485
  int32_t         id = sdbGetMaxId(pMnode->pSdb, SDB_ENCRYPT_ALGORITHMS);
×
486
  if (id < 100) id = 101;
×
487
  Obj.id = id;
×
488
  strncpy(Obj.algorithm_id, createReq.algorithmId, TSDB_ENCRYPT_ALGR_NAME_LEN);
×
489
  strncpy(Obj.name, createReq.name, TSDB_ENCRYPT_ALGR_NAME_LEN);
×
490
  strncpy(Obj.desc, createReq.desc, TSDB_ENCRYPT_ALGR_DESC_LEN);
×
491
  if (strncmp(createReq.type, "Symmetric_Ciphers_CBC_mode", TSDB_ENCRYPT_ALGR_TYPE_LEN) == 0) {
×
UNCOV
492
    Obj.type = ENCRYPT_ALGR_TYPE__SYMMETRIC_CIPHERS;
×
493
  } else if (strncmp(createReq.type, "Digests", TSDB_ENCRYPT_ALGR_TYPE_LEN) == 0) {
×
UNCOV
494
    Obj.type = ENCRYPT_ALGR_TYPE__DIGEST;
×
495
  } else if (strncmp(createReq.type, "Asymmetric_Ciphers", TSDB_ENCRYPT_ALGR_TYPE_LEN) == 0) {
×
496
    Obj.type = ENCRYPT_ALGR_TYPE__ASYMMETRIC_CIPHERS;
×
497
  } else {
498
    TAOS_CHECK_GOTO(TSDB_CODE_MNODE_INVALID_ENCRYPT_ALGR_TYPE, &lino, _OVER);
×
499
  }
500
  Obj.source = ENCRYPT_ALGR_SOURCE_CUSTOMIZED;
×
501
  strncpy(Obj.ossl_algr_name, createReq.osslAlgrName, TSDB_ENCRYPT_ALGR_NAME_LEN);
×
502

UNCOV
503
  pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "create-enc-algr");
×
504
  if (pTrans == NULL) {
×
UNCOV
505
    mError("failed to create since %s", terrstr());
×
506
    code = terrno;
×
507
    goto _OVER;
×
508
  }
509
  mInfo("trans:%d, used to create encrypt_algr", pTrans->id);
×
510

UNCOV
511
  SSdbRaw *pRaw = mndCreateEncryptAlgrRaw(pTrans, &Obj);
×
512
  if (pRaw == NULL) {
×
513
    mError("trans:%d, failed to commit redo log since %s", pTrans->id, terrstr());
×
514
    goto _OVER;
×
515
  }
516

517
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
×
518
    mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
×
519
    goto _OVER;
×
520
  }
521

522
  if (tsAuditLevel >= AUDIT_LEVEL_CLUSTER) {
×
UNCOV
523
    int64_t tse = taosGetTimestampMs();
×
UNCOV
524
    double  duration = (double)(tse - tss);
×
525
    duration = duration / 1000;
×
526
    auditRecord(pReq, pMnode->clusterId, "createEncryptAlgr", "", createReq.algorithmId, createReq.sql,
×
527
                strlen(createReq.sql), duration, 0);
×
528
  }
529

UNCOV
530
  return code;
×
531
_OVER:
×
532
  if (code < 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
×
533
    mError("algr:%s, failed to create at line %d since %s", createReq.algorithmId, lino, tstrerror(code));
×
534
  }
535

536
  tFreeSCreateEncryptAlgrReq(&createReq);
×
537
  mndTransDrop(pTrans);
×
538
  TAOS_RETURN(code);
×
539
}
540

UNCOV
541
static int32_t mndDropEncryptAlgr(SMnode *pMnode, SRpcMsg *pReq, SEncryptAlgrObj *pAlgr) {
×
542
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "drop-encrypt-algr");
×
UNCOV
543
  if (pTrans == NULL) {
×
544
    mError("algr:%s, failed to drop since %s", pAlgr->algorithm_id, terrstr());
×
545
    TAOS_RETURN(terrno);
×
546
  }
547
  mInfo("trans:%d, used to drop algr:%s", pTrans->id, pAlgr->algorithm_id);
×
548

UNCOV
549
  SSdbRaw *pCommitRaw = mndEncryptAlgrActionEncode(pAlgr);
×
550
  if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
×
551
    mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
×
552
    mndTransDrop(pTrans);
×
UNCOV
553
    TAOS_RETURN(terrno);
×
554
  }
555
  if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) < 0) {
×
556
    mndTransDrop(pTrans);
×
557
    TAOS_RETURN(terrno);
×
558
  }
559

UNCOV
560
  if (mndTransPrepare(pMnode, pTrans) != 0) {
×
561
    mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
×
562
    mndTransDrop(pTrans);
×
UNCOV
563
    TAOS_RETURN(terrno);
×
564
  }
565

566
  mndTransDrop(pTrans);
×
567
  TAOS_RETURN(0);
×
568
}
569

570
static int32_t mndProcessDropEncryptAlgrReq(SRpcMsg *pReq) {
×
UNCOV
571
  SMnode             *pMnode = pReq->info.node;
×
572
  int32_t             code = 0;
×
UNCOV
573
  int32_t             lino = 0;
×
574
  SEncryptAlgrObj    *pObj = NULL;
×
UNCOV
575
  SDropEncryptAlgrReq dropReq = {0};
×
576

UNCOV
577
  int64_t tss = taosGetTimestampMs();
×
578

579
  TAOS_CHECK_GOTO(tDeserializeSDropEncryptAlgrReq(pReq->pCont, pReq->contLen, &dropReq), &lino, _OVER);
×
580

UNCOV
581
  mInfo("algr:%s, start to drop", dropReq.algorithmId);
×
582
  // TAOS_CHECK_GOTO(mndCheckOperPrivilege(pMnode, RPC_MSG_USER(pReq), RPC_MSG_TOKEN(pReq), MND_OPER_DROP_USER), &lino, _OVER);
583

584
  if (dropReq.algorithmId[0] == 0) {
×
585
    TAOS_CHECK_GOTO(TSDB_CODE_MND_INVALID_ENCRYPT_ALGR_FORMAT, &lino, _OVER);
×
586
  }
587

588
  pObj = mndAcquireEncryptAlgrByAId(pMnode, dropReq.algorithmId);
×
589
  if (pObj == NULL) {
×
590
    TAOS_CHECK_GOTO(TSDB_CODE_MNODE_ENCRYPT_ALGR_NOT_EXIST, &lino, _OVER);
×
591
  }
592

593
  bool    exist = false;
×
UNCOV
594
  void   *pIter = NULL;
×
595
  SDbObj *pDb = NULL;
×
596
  while (1) {
597
    pIter = sdbFetch(pMnode->pSdb, SDB_DB, pIter, (void **)&pDb);
×
598
    if (pIter == NULL) break;
×
599

UNCOV
600
    if (pDb->cfg.encryptAlgorithm == pObj->id) {
×
UNCOV
601
      exist = true;
×
602
      sdbRelease(pMnode->pSdb, pDb);
×
UNCOV
603
      sdbCancelFetch(pMnode->pSdb, pIter);
×
UNCOV
604
      break;
×
605
    }
606

UNCOV
607
    sdbRelease(pMnode->pSdb, pDb);
×
608
  }
609

610
  if (exist) {
×
UNCOV
611
    TAOS_CHECK_GOTO(TSDB_CODE_MNODE_ENCRYPT_ALGR_IN_USE, &lino, _OVER);
×
612
  }
613

614
  TAOS_CHECK_GOTO(mndDropEncryptAlgr(pMnode, pReq, pObj), &lino, _OVER);
×
615
  if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
×
616

UNCOV
617
  if (tsAuditLevel >= AUDIT_LEVEL_CLUSTER) {
×
UNCOV
618
    int64_t tse = taosGetTimestampMs();
×
UNCOV
619
    double  duration = (double)(tse - tss);
×
620
    duration = duration / 1000;
×
621
    auditRecord(pReq, pMnode->clusterId, "dropEncryptAlgr", "", dropReq.algorithmId, dropReq.sql, dropReq.sqlLen,
×
622
                duration, 0);
623
  }
624

625
_OVER:
×
626
  if (code < 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
×
627
    mError("algr:%s, failed to drop at line %d since %s", dropReq.algorithmId, lino, tstrerror(code));
×
628
  }
629

630
  mndReleaseEncryptAlgr(pMnode, pObj);
×
631
  tFreeSDropEncryptAlgrReq(&dropReq);
×
632
  TAOS_RETURN(code);
×
633
}
634

635
static int32_t mndRetrieveEncryptStatus(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
×
UNCOV
636
  int32_t code = 0;
×
UNCOV
637
  int32_t lino = 0;
×
638
  int32_t numOfRows = 0;
×
639
  int32_t cols = 0;
×
UNCOV
640
  char    tmpBuf[1000] = {0};
×
641

642
  // Only return data if not already retrieved
643
  if (pShow->numOfRows > 0) {
×
644
    return 0;
×
645
  }
646

647
  // Row 1: config encryption status
648
  if (numOfRows < rows) {
×
UNCOV
649
    cols = 0;
×
650
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
651
    tstrncpy(varDataVal(tmpBuf), "config", 32);
×
652
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
653
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
×
654

655
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
656
    tstrncpy(varDataVal(tmpBuf), taosGetEncryptAlgoName(tsCfgAlgorithm), 32);
×
657
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
658
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
×
659

660
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
UNCOV
661
    tstrncpy(varDataVal(tmpBuf), (tsCfgKey[0] != '\0') ? "enabled" : "disabled", 16);
×
UNCOV
662
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
UNCOV
663
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
×
664

665
    numOfRows++;
×
666
  }
667

668
  // Row 2: metadata encryption status
669
  if (numOfRows < rows) {
×
UNCOV
670
    cols = 0;
×
671
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
672
    tstrncpy(varDataVal(tmpBuf), "metadata", 32);
×
673
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
674
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
×
675

676
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
677
    tstrncpy(varDataVal(tmpBuf), taosGetEncryptAlgoName(tsMetaAlgorithm), 32);
×
678
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
679
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
×
680

681
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
UNCOV
682
    tstrncpy(varDataVal(tmpBuf), (tsMetaKey[0] != '\0') ? "enabled" : "disabled", 16);
×
UNCOV
683
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
UNCOV
684
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
×
685

686
    numOfRows++;
×
687
  }
688

689
  // Row 3: data encryption status
690
  if (numOfRows < rows) {
×
UNCOV
691
    cols = 0;
×
692
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
UNCOV
693
    tstrncpy(varDataVal(tmpBuf), "data", 32);
×
694
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
695
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
×
696

UNCOV
697
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
698
    // Data key uses the master algorithm (usually SM4)
699
    tstrncpy(varDataVal(tmpBuf), taosGetEncryptAlgoName(tsEncryptAlgorithmType), 32);
×
700
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
701
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
×
702

703
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
UNCOV
704
    tstrncpy(varDataVal(tmpBuf), (tsDataKey[0] != '\0') ? "enabled" : "disabled", 16);
×
UNCOV
705
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
×
706
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
×
707

UNCOV
708
    numOfRows++;
×
709
  }
710

711
  pShow->numOfRows += numOfRows;
×
UNCOV
712
  return numOfRows;
×
713

UNCOV
714
_OVER:
×
UNCOV
715
  if (code != 0) {
×
UNCOV
716
    mError("failed to retrieve encrypt status at line %d since %s", lino, tstrerror(code));
×
717
  }
UNCOV
718
  return numOfRows;
×
719
}
720

721
int32_t mndInitEncryptAlgr(SMnode *pMnode) {
385,551✔
722
  mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ENCRYPT_ALGR, mndProcessCreateEncryptAlgrReq);
385,551✔
723
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_ENCRYPT_ALGORITHMS, mndRetrieveEncryptAlgr);
385,551✔
724
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_ENCRYPT_STATUS, mndRetrieveEncryptStatus);
385,551✔
725
  mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_ENCRYPT_ALGORITHMS, mndCancelRetrieveEncryptAlgr);
385,551✔
726
  mndSetMsgHandle(pMnode, TDMT_MND_DROP_ENCRYPT_ALGR, mndProcessDropEncryptAlgrReq);
385,551✔
727
  mndSetMsgHandle(pMnode, TDMT_MND_BUILTIN_ENCRYPT_ALGR, mndProcessBuiltinReq);
385,551✔
728
  mndSetMsgHandle(pMnode, TDMT_MND_BUILTIN_ENCRYPT_ALGR_RSP, mndProcessBuiltinRsp);
385,551✔
729

730
  SSdbTable table = {
385,551✔
731
      .sdbType = SDB_ENCRYPT_ALGORITHMS,
732
      .keyType = SDB_KEY_INT32,
733
      .upgradeFp = (SdbUpgradeFp)mndUpgradeBuiltinEncryptAlgr,
734
      .encodeFp = (SdbEncodeFp)mndEncryptAlgrActionEncode,
735
      .decodeFp = (SdbDecodeFp)mndEncryptAlgrActionDecode,
736
      .insertFp = (SdbInsertFp)mndEncryptAlgrActionInsert,
737
      .updateFp = (SdbUpdateFp)mndEncryptAlgrActionUpdate,
738
      .deleteFp = (SdbDeleteFp)mndEncryptAlgrActionDelete,
739
  };
740

741
  return sdbSetTable(pMnode->pSdb, table);
385,551✔
742
}
743

744
void mndCleanupEncryptAlgr(SMnode *pMnode) { mDebug("mnd encrypt algorithms cleanup"); }
385,488✔
745

746
SEncryptAlgrObj *mndAcquireEncryptAlgrById(SMnode *pMnode, int64_t id) {
3,505,063✔
747
  SSdb        *pSdb = pMnode->pSdb;
3,505,063✔
748
  SEncryptAlgrObj *pAlgr = sdbAcquire(pSdb, SDB_ENCRYPT_ALGORITHMS, &id);
3,505,063✔
749
  if (pAlgr == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) {
3,505,063✔
750
    terrno = TSDB_CODE_SUCCESS;
3,505,063✔
751
  }
752
  return pAlgr;
3,505,063✔
753
}
754

755
void mndGetEncryptOsslAlgrNameById(SMnode *pMnode, int64_t id, char* out){
3,505,063✔
756
  SEncryptAlgrObj *obj = mndAcquireEncryptAlgrById(pMnode, id);
3,505,063✔
757
  if(obj != NULL){
3,505,063✔
UNCOV
758
    tstrncpy(out, obj->ossl_algr_name, TSDB_ENCRYPT_ALGR_NAME_LEN);
×
UNCOV
759
    mndReleaseEncryptAlgr(pMnode, obj);
×
760
  }
761
}
3,505,063✔
762

763
SEncryptAlgrObj *mndAcquireEncryptAlgrByAId(SMnode *pMnode, char* algorithm_id) {
2,136✔
764
  SSdb        *pSdb = pMnode->pSdb;
2,136✔
765
  SEncryptAlgrObj *pObj = NULL;
2,136✔
766
  void *pIter = NULL;
2,136✔
767
  while (1) {
768
    pIter = sdbFetch(pSdb, SDB_ENCRYPT_ALGORITHMS, pIter, (void **)&pObj);
6,486✔
769
    if (pIter == NULL) break;
6,486✔
770

771
    if (strncasecmp(pObj->algorithm_id, algorithm_id, TSDB_ENCRYPT_ALGR_NAME_LEN) == 0) {
5,761✔
772
      sdbCancelFetch(pSdb, pIter);
1,411✔
773
      break;
1,411✔
774
    }
775

776
    sdbRelease(pSdb, pObj);
4,350✔
777
  }
778
  return pObj;
2,136✔
779
}
780

UNCOV
781
void mndReleaseEncryptAlgr(SMnode *pMnode, SEncryptAlgrObj *pObj) {
×
UNCOV
782
  SSdb *pSdb = pMnode->pSdb;
×
UNCOV
783
  sdbRelease(pSdb, pObj);
×
UNCOV
784
  pObj = NULL;
×
UNCOV
785
}
×
786

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc