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

taosdata / TDengine / #4893

20 Dec 2025 01:15PM UTC coverage: 65.57% (-0.001%) from 65.571%
#4893

push

travis-ci

web-flow
feat: support taos_connect_with func (#33952)

* feat: support taos_connect_with

* refactor: enhance connection options and add tests for taos_set_option and taos_connect_with

* fix: handle NULL keys and values in taos_connect_with options

* fix: revert TAOSWS_GIT_TAG to default value "main"

* docs: add TLS configuration options for WebSocket connections in documentation

* docs: modify zh docs and add en docs

* chore: update taos.cfg

* docs: add examples

* docs: add error handling for connection failure in example code

2 of 82 new or added lines in 3 files covered. (2.44%)

1158 existing lines in 109 files now uncovered.

182854 of 278870 relevant lines covered (65.57%)

105213271.06 hits per line

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

87.03
/source/libs/parser/src/parAuthenticator.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
#include "catalog.h"
17
#include "cmdnodes.h"
18
#include "parInt.h"
19

20
typedef struct SAuthCxt {
21
  SParseContext*   pParseCxt;
22
  SParseMetaCache* pMetaCache;
23
  int32_t          errCode;
24
} SAuthCxt;
25

26
typedef struct SSelectAuthCxt {
27
  SAuthCxt*    pAuthCxt;
28
  SSelectStmt* pSelect;
29
} SSelectAuthCxt;
30

31
typedef struct SAuthRewriteCxt {
32
  STableNode* pTarget;
33
} SAuthRewriteCxt;
34

35
static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt);
36

37
static int32_t setUserAuthInfo(SParseContext* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type,
1,052,173✔
38
                               bool isView, bool effective, SUserAuthInfo* pAuth) {
39
  if (effective) {
1,052,173✔
40
    snprintf(pAuth->user, sizeof(pAuth->user), "%s", pCxt->pEffectiveUser ? pCxt->pEffectiveUser : "");
32,629✔
41
  } else {
42
    snprintf(pAuth->user, sizeof(pAuth->user), "%s", pCxt->pUser);
1,019,544✔
43
  }
44

45
  if (NULL == pTabName) {
1,052,173✔
46
    int32_t code = tNameSetDbName(&pAuth->tbName, pCxt->acctId, pDbName, strlen(pDbName));
107,502✔
47
    if (TSDB_CODE_SUCCESS != code) return code;
107,502✔
48
  } else {
49
    toName(pCxt->acctId, pDbName, pTabName, &pAuth->tbName);
944,671✔
50
  }
51
  pAuth->type = type;
1,052,173✔
52
  pAuth->isView = isView;
1,052,173✔
53
  return TSDB_CODE_SUCCESS;
1,052,173✔
54
}
55

56
static int32_t checkAuthImpl(SAuthCxt* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type, SNode** pCond,
171,387,240✔
57
                             bool isView, bool effective) {
58
  SParseContext* pParseCxt = pCxt->pParseCxt;
171,387,240✔
59
  if (pParseCxt->isSuperUser) {
171,387,666✔
60
    return TSDB_CODE_SUCCESS;
170,336,401✔
61
  }
62

63
  AUTH_RES_TYPE auth_res_type = isView ? AUTH_RES_VIEW : AUTH_RES_BASIC;
1,052,173✔
64
  SUserAuthInfo authInfo = {0};
1,052,173✔
65
  int32_t       code = setUserAuthInfo(pCxt->pParseCxt, pDbName, pTabName, type, isView, effective, &authInfo);
1,052,173✔
66
  if (TSDB_CODE_SUCCESS != code) return code;
1,052,173✔
67
  SUserAuthRes authRes = {0};
1,052,173✔
68
  if (NULL != pCxt->pMetaCache) {
1,052,173✔
69
    code = getUserAuthFromCache(pCxt->pMetaCache, &authInfo, &authRes);
1,052,173✔
70
#ifdef TD_ENTERPRISE
71
    if (isView && TSDB_CODE_PAR_INTERNAL_ERROR == code) {
1,052,173✔
72
      authInfo.isView = false;
50,359✔
73
      code = getUserAuthFromCache(pCxt->pMetaCache, &authInfo, &authRes);
50,359✔
74
    }
75
#endif
76
  } else {
77
    SRequestConnInfo conn = {.pTrans = pParseCxt->pTransporter,
×
78
                             .requestId = pParseCxt->requestId,
×
79
                             .requestObjRefId = pParseCxt->requestRid,
×
80
                             .mgmtEps = pParseCxt->mgmtEpSet};
81
    code = catalogChkAuth(pParseCxt->pCatalog, &conn, &authInfo, &authRes);
×
82
  }
83
  if (TSDB_CODE_SUCCESS == code && NULL != pCond) {
1,052,173✔
84
    *pCond = authRes.pCond[auth_res_type];
257,010✔
85
  }
86
  return TSDB_CODE_SUCCESS == code ? (authRes.pass[auth_res_type] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED)
1,052,173✔
87
                                   : code;
2,104,346✔
88
}
89

90
static int32_t checkAuth(SAuthCxt* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type, SNode** pCond) {
170,936,500✔
91
  return checkAuthImpl(pCxt, pDbName, pTabName, type, pCond, false, false);
170,936,500✔
92
}
93

94
static int32_t checkEffectiveAuth(SAuthCxt* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type,
21,277✔
95
                                  SNode** pCond) {
96
  return checkAuthImpl(pCxt, pDbName, pTabName, type, NULL, false, true);
21,277✔
97
}
98

99
static int32_t checkViewAuth(SAuthCxt* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type, SNode** pCond) {
430,094✔
100
  return checkAuthImpl(pCxt, pDbName, pTabName, type, NULL, true, false);
430,094✔
101
}
102

103
static int32_t checkViewEffectiveAuth(SAuthCxt* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type,
11,352✔
104
                                      SNode** pCond) {
105
  return checkAuthImpl(pCxt, pDbName, pTabName, type, NULL, true, true);
11,352✔
106
}
107

108
static EDealRes authSubquery(SAuthCxt* pCxt, SNode* pStmt) {
9,749,423✔
109
  return TSDB_CODE_SUCCESS == authQuery(pCxt, pStmt) ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
9,749,423✔
110
}
111

112
static int32_t mergeStableTagCond(SNode** pWhere, SNode* pTagCond) {
×
113
  SLogicConditionNode* pLogicCond = NULL;
×
114
  int32_t              code = nodesMakeNode(QUERY_NODE_LOGIC_CONDITION, (SNode**)&pLogicCond);
×
115
  if (NULL == pLogicCond) {
×
116
    return code;
×
117
  }
118
  pLogicCond->node.resType.type = TSDB_DATA_TYPE_BOOL;
×
119
  pLogicCond->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes;
×
120
  pLogicCond->condType = LOGIC_COND_TYPE_AND;
×
121
  code = nodesListMakeStrictAppend(&pLogicCond->pParameterList, pTagCond);
×
122
  if (TSDB_CODE_SUCCESS == code) {
×
123
    code = nodesListMakeAppend(&pLogicCond->pParameterList, *pWhere);
×
124
  }
125
  if (TSDB_CODE_SUCCESS == code) {
×
126
    *pWhere = (SNode*)pLogicCond;
×
127
  } else {
128
    nodesDestroyNode((SNode*)pLogicCond);
×
129
  }
130
  return code;
×
131
}
132

133
EDealRes rewriteAuthTable(SNode* pNode, void* pContext) {
40,041✔
134
  if (QUERY_NODE_COLUMN == nodeType(pNode)) {
40,041✔
135
    SColumnNode*     pCol = (SColumnNode*)pNode;
13,347✔
136
    SAuthRewriteCxt* pCxt = (SAuthRewriteCxt*)pContext;
13,347✔
137
    tstrncpy(pCol->tableName, pCxt->pTarget->tableName, TSDB_TABLE_NAME_LEN);
13,347✔
138
    tstrncpy(pCol->tableAlias, pCxt->pTarget->tableAlias, TSDB_TABLE_NAME_LEN);
13,347✔
139
  }
140

141
  return DEAL_RES_CONTINUE;
40,041✔
142
}
143

144
static int32_t rewriteAppendStableTagCond(SNode** pWhere, SNode* pTagCond, STableNode* pTable) {
13,347✔
145
  SNode*  pTagCondCopy = NULL;
13,347✔
146
  int32_t code = nodesCloneNode(pTagCond, &pTagCondCopy);
13,347✔
147
  if (NULL == pTagCondCopy) {
13,347✔
148
    return code;
×
149
  }
150

151
  SAuthRewriteCxt cxt = {.pTarget = pTable};
13,347✔
152
  nodesWalkExpr(pTagCondCopy, rewriteAuthTable, &cxt);
13,347✔
153

154
  if (NULL == *pWhere) {
13,347✔
155
    *pWhere = pTagCondCopy;
13,347✔
156
    return TSDB_CODE_SUCCESS;
13,347✔
157
  }
158

159
  if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pWhere) &&
×
160
      LOGIC_COND_TYPE_AND == ((SLogicConditionNode*)*pWhere)->condType) {
×
161
    return nodesListStrictAppend(((SLogicConditionNode*)*pWhere)->pParameterList, pTagCondCopy);
×
162
  }
163

164
  return mergeStableTagCond(pWhere, pTagCondCopy);
×
165
}
166

167
static EDealRes authSelectImpl(SNode* pNode, void* pContext) {
1,083,687,359✔
168
  SSelectAuthCxt* pCxt = pContext;
1,083,687,359✔
169
  SAuthCxt*       pAuthCxt = pCxt->pAuthCxt;
1,083,687,359✔
170
  bool            isView = false;
1,083,687,616✔
171
  if (QUERY_NODE_REAL_TABLE == nodeType(pNode)) {
1,083,687,616✔
172
    SNode*      pTagCond = NULL;
100,310,099✔
173
    STableNode* pTable = (STableNode*)pNode;
100,310,099✔
174
    if ((pAuthCxt->pParseCxt->enableSysInfo == 0) && IS_INFORMATION_SCHEMA_DB(pTable->dbName) &&
100,310,099✔
175
        (strcmp(pTable->tableName, TSDB_INS_TABLE_VGROUPS) == 0)) {
41,019✔
176
      pAuthCxt->errCode = TSDB_CODE_PAR_PERMISSION_DENIED;
1,452✔
177
      return DEAL_RES_ERROR;
1,452✔
178
    }
179
#ifdef TD_ENTERPRISE
180
    SName name = {0};
100,308,378✔
181
    toName(pAuthCxt->pParseCxt->acctId, pTable->dbName, pTable->tableName, &name);
100,308,877✔
182
    STableMeta* pTableMeta = NULL;
100,308,904✔
183
    toName(pAuthCxt->pParseCxt->acctId, pTable->dbName, pTable->tableName, &name);
100,308,904✔
184
    int32_t code = getTargetMetaImpl(pAuthCxt->pParseCxt, pAuthCxt->pMetaCache, &name, &pTableMeta, true);
100,309,403✔
185
    if (TSDB_CODE_SUCCESS == code && TSDB_VIEW_TABLE == pTableMeta->tableType) {
100,307,453✔
186
      isView = true;
236,591✔
187
    }
188
    taosMemoryFree(pTableMeta);
100,307,669✔
189
#endif
190
    if (!isView) {
100,308,445✔
191
      pAuthCxt->errCode = checkAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, &pTagCond);
100,071,854✔
192
      if (TSDB_CODE_SUCCESS != pAuthCxt->errCode && NULL != pAuthCxt->pParseCxt->pEffectiveUser) {
100,071,860✔
193
        pAuthCxt->errCode = checkEffectiveAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, NULL);
21,277✔
194
      }
195
      if (TSDB_CODE_SUCCESS == pAuthCxt->errCode && NULL != pTagCond) {
100,071,801✔
196
        pAuthCxt->errCode = rewriteAppendStableTagCond(&pCxt->pSelect->pWhere, pTagCond, pTable);
13,347✔
197
      }
198
    } else {
199
      pAuthCxt->errCode = checkViewAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, NULL);
236,591✔
200
      if (TSDB_CODE_SUCCESS != pAuthCxt->errCode && NULL != pAuthCxt->pParseCxt->pEffectiveUser) {
236,591✔
201
        pAuthCxt->errCode = checkViewEffectiveAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, NULL);
11,352✔
202
      }
203
    }
204
    return TSDB_CODE_SUCCESS == pAuthCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
100,309,146✔
205
  } else if (QUERY_NODE_TEMP_TABLE == nodeType(pNode)) {
983,377,851✔
206
    return authSubquery(pAuthCxt, ((STempTableNode*)pNode)->pSubquery);
9,749,154✔
207
  }
208
  return DEAL_RES_CONTINUE;
973,628,644✔
209
}
210

211
static int32_t authSelect(SAuthCxt* pCxt, SSelectStmt* pSelect) {
104,620,123✔
212
  SSelectAuthCxt cxt = {.pAuthCxt = pCxt, .pSelect = pSelect};
104,620,123✔
213
  nodesWalkSelectStmt(pSelect, SQL_CLAUSE_FROM, authSelectImpl, &cxt);
104,620,123✔
214
  return pCxt->errCode;
104,620,405✔
215
}
216

217
static int32_t authSetOperator(SAuthCxt* pCxt, SSetOperator* pSetOper) {
3,235,510✔
218
  int32_t code = authQuery(pCxt, pSetOper->pLeft);
3,235,510✔
219
  if (TSDB_CODE_SUCCESS == code) {
3,235,510✔
220
    code = authQuery(pCxt, pSetOper->pRight);
3,235,510✔
221
  }
222
  return code;
3,235,510✔
223
}
224

225
static int32_t authDropUser(SAuthCxt* pCxt, SDropUserStmt* pStmt) {
65,807✔
226
  if (!pCxt->pParseCxt->isSuperUser || 0 == strcmp(pStmt->userName, TSDB_DEFAULT_USER)) {
65,807✔
227
    return TSDB_CODE_PAR_PERMISSION_DENIED;
1,449✔
228
  }
229
  return TSDB_CODE_SUCCESS;
64,358✔
230
}
231

232
static int32_t authDelete(SAuthCxt* pCxt, SDeleteStmt* pDelete) {
1,841,237✔
233
  SNode*      pTagCond = NULL;
1,841,237✔
234
  STableNode* pTable = (STableNode*)pDelete->pFromTable;
1,841,237✔
235
  int32_t     code = checkAuth(pCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_WRITE, &pTagCond);
1,841,237✔
236
  if (TSDB_CODE_SUCCESS == code && NULL != pTagCond) {
1,841,237✔
237
    code = rewriteAppendStableTagCond(&pDelete->pWhere, pTagCond, pTable);
×
238
  }
239
  return code;
1,841,237✔
240
}
241

242
static int32_t authInsert(SAuthCxt* pCxt, SInsertStmt* pInsert) {
76,986✔
243
  SNode*      pTagCond = NULL;
76,986✔
244
  STableNode* pTable = (STableNode*)pInsert->pTable;
76,986✔
245
  // todo check tag condition for subtable
246
  int32_t code = checkAuth(pCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_WRITE, &pTagCond);
76,986✔
247
  if (TSDB_CODE_SUCCESS == code) {
76,986✔
248
    code = authQuery(pCxt, pInsert->pQuery);
76,986✔
249
  }
250
  return code;
76,986✔
251
}
252

253
static int32_t authShowTables(SAuthCxt* pCxt, SShowStmt* pStmt) {
653,956✔
254
  return checkAuth(pCxt, ((SValueNode*)pStmt->pDbName)->literal, NULL, AUTH_TYPE_READ_OR_WRITE, NULL);
653,956✔
255
}
256

257
static int32_t authShowVtables(SAuthCxt* pCxt, SShowStmt* pStmt) { return authShowTables(pCxt, pStmt); }
61,874✔
258

259
static int32_t authShowUsage(SAuthCxt* pCxt, SShowStmt* pStmt) {
×
260
  return checkAuth(pCxt, ((SValueNode*)pStmt->pDbName)->literal, NULL, AUTH_TYPE_READ_OR_WRITE, NULL);
×
261
}
262

263
static int32_t authShowCreateTable(SAuthCxt* pCxt, SShowCreateTableStmt* pStmt) {
131,406✔
264
  SNode* pTagCond = NULL;
131,406✔
265
  // todo check tag condition for subtable
266
  return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_READ, &pTagCond);
131,406✔
267
}
268

269
static int32_t authShowCreateView(SAuthCxt* pCxt, SShowCreateViewStmt* pStmt) {
×
270
#ifndef TD_ENTERPRISE
271
  return TSDB_CODE_OPS_NOT_SUPPORT;
272
#endif
273

274
  return TSDB_CODE_SUCCESS;
×
275
}
276

277
static int32_t authCreateTable(SAuthCxt* pCxt, SCreateTableStmt* pStmt) {
4,241,582✔
278
  SNode* pTagCond = NULL;
4,241,582✔
279
  // todo check tag condition for subtable
280
  return checkAuth(pCxt, pStmt->dbName, NULL, AUTH_TYPE_WRITE, &pTagCond);
4,241,582✔
281
}
282

283
static int32_t authCreateVTable(SAuthCxt* pCxt, SCreateVTableStmt* pStmt) {
156,933✔
284
  PAR_ERR_RET(checkAuth(pCxt, pStmt->dbName, NULL, AUTH_TYPE_WRITE, NULL));
156,933✔
285
  SNode* pCol = NULL;
146,037✔
286
  FOREACH(pCol, pStmt->pCols) {
1,789,766✔
287
    SColumnDefNode* pColDef = (SColumnDefNode*)pCol;
1,651,901✔
288
    if (NULL == pColDef) {
1,651,901✔
289
      PAR_ERR_RET(TSDB_CODE_PAR_INVALID_COLUMN);
×
290
    }
291
    SColumnOptions* pOptions = (SColumnOptions*)pColDef->pOptions;
1,651,901✔
292
    if (pOptions && pOptions->hasRef) {
1,651,901✔
293
      PAR_ERR_RET(checkAuth(pCxt, pOptions->refDb, pOptions->refTable, AUTH_TYPE_READ, NULL));
888,572✔
294
    }
295
  }
296
  return TSDB_CODE_SUCCESS;
137,865✔
297
}
298

299
static int32_t authCreateVSubTable(SAuthCxt* pCxt, SCreateVSubTableStmt* pStmt) {
287,439✔
300
  int32_t    code = TSDB_CODE_SUCCESS;
287,439✔
301
  SNode*     pNode = NULL;
287,439✔
302
  SNodeList* pTmpList = pStmt->pSpecificColRefs ? pStmt->pSpecificColRefs : pStmt->pColRefs;
287,439✔
303
  PAR_ERR_RET(checkAuth(pCxt, pStmt->dbName, NULL, AUTH_TYPE_WRITE, NULL));
287,439✔
304
  if (NULL == pTmpList) {
276,543✔
305
    // no column reference
306
    return TSDB_CODE_SUCCESS;
9,454✔
307
  }
308

309
  FOREACH(pNode, pTmpList) {
1,948,949✔
310
    SColumnRefNode* pColRef = (SColumnRefNode*)pNode;
1,690,032✔
311
    if (NULL == pColRef) {
1,690,032✔
312
      PAR_ERR_RET(TSDB_CODE_PAR_INVALID_COLUMN);
×
313
    }
314
    PAR_ERR_RET(checkAuth(pCxt, pColRef->refDbName, pColRef->refTableName, AUTH_TYPE_READ, NULL));
1,690,032✔
315
  }
316
  return code;
258,917✔
317
}
318

319
static int32_t authCreateStream(SAuthCxt* pCxt, SCreateStreamStmt* pStmt) {
403,231✔
320
  int32_t   code = TSDB_CODE_SUCCESS;
403,231✔
321

322
  if (IS_SYS_DBNAME(pStmt->streamDbName)) {
403,231✔
323
    return TSDB_CODE_PAR_PERMISSION_DENIED;
×
324
  }
325
  if (IS_SYS_DBNAME(pStmt->targetDbName)) {
403,231✔
326
    return TSDB_CODE_PAR_PERMISSION_DENIED;
60✔
327
  }
328
  if (pStmt->pTrigger) {
403,171✔
329
    SStreamTriggerNode *pTrigger = (SStreamTriggerNode*)pStmt->pTrigger;
403,171✔
330
    STableNode* pTriggerTable = (STableNode*)pTrigger->pTrigerTable;
403,171✔
331
    if (pTriggerTable && IS_SYS_DBNAME(pTriggerTable->dbName)) {
403,171✔
332
      return TSDB_CODE_PAR_PERMISSION_DENIED;
60✔
333
    }
334
  }
335
  return code;
403,111✔
336
}
337

338
static int32_t authCreateMultiTable(SAuthCxt* pCxt, SCreateMultiTablesStmt* pStmt) {
33,065,413✔
339
  int32_t code = TSDB_CODE_SUCCESS;
33,065,413✔
340
  SNode*  pNode = NULL;
33,065,413✔
341
  FOREACH(pNode, pStmt->pSubTables) {
70,646,634✔
342
    if (pNode->type == QUERY_NODE_CREATE_SUBTABLE_CLAUSE) {
37,586,562✔
343
      SCreateSubTableClause* pClause = (SCreateSubTableClause*)pNode;
37,588,315✔
344
      code = checkAuth(pCxt, pClause->dbName, NULL, AUTH_TYPE_WRITE, NULL);
37,588,315✔
345
      if (TSDB_CODE_SUCCESS != code) {
37,581,584✔
346
        break;
363✔
347
      }
348
    } else {
349
      SCreateSubTableFromFileClause* pClause = (SCreateSubTableFromFileClause*)pNode;
×
350
      code = checkAuth(pCxt, pClause->useDbName, NULL, AUTH_TYPE_WRITE, NULL);
×
UNCOV
351
      if (TSDB_CODE_SUCCESS != code) {
×
352
        break;
×
353
      }
354
    }
355
  }
356
  return code;
33,060,522✔
357
}
358

359
static int32_t authDropTable(SAuthCxt* pCxt, SDropTableStmt* pStmt) {
1,704,906✔
360
  int32_t code = TSDB_CODE_SUCCESS;
1,704,906✔
361
  if (pStmt->withOpt && !pCxt->pParseCxt->isSuperUser) {
1,704,906✔
362
    return TSDB_CODE_PAR_PERMISSION_DENIED;
668✔
363
  }
364
  SNode* pNode = NULL;
1,704,238✔
365
  FOREACH(pNode, pStmt->pTables) {
3,692,938✔
366
    SDropTableClause* pClause = (SDropTableClause*)pNode;
1,988,700✔
367
    code = checkAuth(pCxt, pClause->dbName, pClause->tableName, AUTH_TYPE_WRITE, NULL);
1,988,700✔
368
    if (TSDB_CODE_SUCCESS != code) {
1,988,700✔
369
      break;
×
370
    }
371
  }
372
  return code;
1,704,238✔
373
}
374

375
static int32_t authDropStable(SAuthCxt* pCxt, SDropSuperTableStmt* pStmt) {
185,334✔
376
  if (pStmt->withOpt && !pCxt->pParseCxt->isSuperUser) {
185,334✔
377
    return TSDB_CODE_PAR_PERMISSION_DENIED;
334✔
378
  }
379
  return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_WRITE, NULL);
185,000✔
380
}
381

382
static int32_t authDropVtable(SAuthCxt* pCxt, SDropVirtualTableStmt* pStmt) {
76,992✔
383
  if (pStmt->withOpt && !pCxt->pParseCxt->isSuperUser) {
76,992✔
384
    return TSDB_CODE_PAR_PERMISSION_DENIED;
×
385
  }
386
  return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_WRITE, NULL);
76,992✔
387
}
388

389
static int32_t authAlterTable(SAuthCxt* pCxt, SAlterTableStmt* pStmt) {
20,252,453✔
390
  SNode* pTagCond = NULL;
20,252,453✔
391
  // todo check tag condition for subtable
392
  return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_WRITE, NULL);
20,252,453✔
393
}
394

395
static int32_t authAlterVTable(SAuthCxt* pCxt, SAlterTableStmt* pStmt) {
408,765✔
396
  PAR_ERR_RET(checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_WRITE, NULL));
408,765✔
397
  if (pStmt->alterType == TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COLUMN_REF ||
348,837✔
398
      pStmt->alterType == TSDB_ALTER_TABLE_ALTER_COLUMN_REF) {
318,192✔
399
    PAR_ERR_RET(checkAuth(pCxt, pStmt->dbName, pStmt->refTableName, AUTH_TYPE_READ, NULL));
136,176✔
400
  }
401
  PAR_RET(TSDB_CODE_SUCCESS);
327,045✔
402
}
403

404
static int32_t authCreateView(SAuthCxt* pCxt, SCreateViewStmt* pStmt) {
262,585✔
405
#ifndef TD_ENTERPRISE
406
  return TSDB_CODE_OPS_NOT_SUPPORT;
407
#endif
408
  return checkAuth(pCxt, pStmt->dbName, NULL, AUTH_TYPE_WRITE, NULL);
262,585✔
409
}
410

411
static int32_t authDropView(SAuthCxt* pCxt, SDropViewStmt* pStmt) {
193,503✔
412
#ifndef TD_ENTERPRISE
413
  return TSDB_CODE_OPS_NOT_SUPPORT;
414
#endif
415
  return checkViewAuth(pCxt, pStmt->dbName, pStmt->viewName, AUTH_TYPE_ALTER, NULL);
193,503✔
416
}
417

418
static int32_t authCreateRsma(SAuthCxt* pCxt, SCreateRsmaStmt* pStmt) {
118,604✔
419
  return TSDB_CODE_SUCCESS;
118,604✔
420
}
421

422
static int32_t authDropRsma(SAuthCxt* pCxt, SDropRsmaStmt* pStmt) {
2,388✔
423
  return TSDB_CODE_SUCCESS;
2,388✔
424
}
425

426
static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt) {
193,335,755✔
427
  switch (nodeType(pStmt)) {
193,335,755✔
428
    case QUERY_NODE_SET_OPERATOR:
3,235,510✔
429
      return authSetOperator(pCxt, (SSetOperator*)pStmt);
3,235,510✔
430
    case QUERY_NODE_SELECT_STMT:
104,619,624✔
431
      return authSelect(pCxt, (SSelectStmt*)pStmt);
104,619,624✔
432
    case QUERY_NODE_DROP_USER_STMT:
65,807✔
433
      return authDropUser(pCxt, (SDropUserStmt*)pStmt);
65,807✔
434
    case QUERY_NODE_DELETE_STMT:
1,841,237✔
435
      return authDelete(pCxt, (SDeleteStmt*)pStmt);
1,841,237✔
436
    case QUERY_NODE_INSERT_STMT:
76,986✔
437
      return authInsert(pCxt, (SInsertStmt*)pStmt);
76,986✔
438
    case QUERY_NODE_CREATE_TABLE_STMT:
4,241,582✔
439
      return authCreateTable(pCxt, (SCreateTableStmt*)pStmt);
4,241,582✔
440
    case QUERY_NODE_CREATE_VIRTUAL_TABLE_STMT:
156,933✔
441
      return authCreateVTable(pCxt, (SCreateVTableStmt*)pStmt);
156,933✔
442
    case QUERY_NODE_CREATE_VIRTUAL_SUBTABLE_STMT:
287,439✔
443
      return authCreateVSubTable(pCxt, (SCreateVSubTableStmt*)pStmt);
287,439✔
444
    case QUERY_NODE_CREATE_MULTI_TABLES_STMT:
33,060,341✔
445
      return authCreateMultiTable(pCxt, (SCreateMultiTablesStmt*)pStmt);
33,060,341✔
446
    case QUERY_NODE_CREATE_STREAM_STMT:
403,231✔
447
      return authCreateStream(pCxt, (SCreateStreamStmt*)pStmt);
403,231✔
448
    case QUERY_NODE_DROP_TABLE_STMT:
1,704,906✔
449
      return authDropTable(pCxt, (SDropTableStmt*)pStmt);
1,704,906✔
450
    case QUERY_NODE_DROP_SUPER_TABLE_STMT:
185,334✔
451
      return authDropStable(pCxt, (SDropSuperTableStmt*)pStmt);
185,334✔
452
    case QUERY_NODE_DROP_VIRTUAL_TABLE_STMT:
76,992✔
453
      return authDropVtable(pCxt, (SDropVirtualTableStmt*)pStmt);
76,992✔
454
    case QUERY_NODE_ALTER_TABLE_STMT:
20,252,453✔
455
    case QUERY_NODE_ALTER_SUPER_TABLE_STMT:
456
      return authAlterTable(pCxt, (SAlterTableStmt*)pStmt);
20,252,453✔
457
    case QUERY_NODE_ALTER_VIRTUAL_TABLE_STMT:
408,765✔
458
      return authAlterVTable(pCxt, (SAlterTableStmt*)pStmt);
408,765✔
459
    case QUERY_NODE_SHOW_DNODES_STMT:
1,022,037✔
460
    case QUERY_NODE_SHOW_MNODES_STMT:
461
    case QUERY_NODE_SHOW_MODULES_STMT:
462
    case QUERY_NODE_SHOW_QNODES_STMT:
463
    case QUERY_NODE_SHOW_SNODES_STMT:
464
    case QUERY_NODE_SHOW_BACKUP_NODES_STMT:
465
    case QUERY_NODE_SHOW_CLUSTER_STMT:
466
    case QUERY_NODE_SHOW_LICENCES_STMT:
467
    case QUERY_NODE_SHOW_VGROUPS_STMT:
468
    case QUERY_NODE_SHOW_DB_ALIVE_STMT:
469
    // case QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT:
470
    case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
471
    case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
472
    case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT:
473
    case QUERY_NODE_SHOW_VNODES_STMT:
474
    case QUERY_NODE_SHOW_SCORES_STMT:
475
    case QUERY_NODE_SHOW_USERS_STMT:
476
    case QUERY_NODE_SHOW_USERS_FULL_STMT:
477
    case QUERY_NODE_SHOW_USER_PRIVILEGES_STMT:
478
    case QUERY_NODE_SHOW_GRANTS_FULL_STMT:
479
    case QUERY_NODE_SHOW_GRANTS_LOGS_STMT:
480
    case QUERY_NODE_SHOW_CLUSTER_MACHINES_STMT:
481
    case QUERY_NODE_SHOW_ARBGROUPS_STMT:
482
    case QUERY_NODE_SHOW_ENCRYPTIONS_STMT:
483
    case QUERY_NODE_SHOW_MOUNTS_STMT:
484
    case QUERY_NODE_SHOW_ENCRYPT_ALGORITHMS_STMT:
485
      return !pCxt->pParseCxt->enableSysInfo ? TSDB_CODE_PAR_PERMISSION_DENIED : TSDB_CODE_SUCCESS;
1,022,037✔
486
    case QUERY_NODE_SHOW_USAGE_STMT:
1,069✔
487
    case QUERY_NODE_SHOW_ANODES_STMT:
488
    case QUERY_NODE_SHOW_ANODES_FULL_STMT:
489
      return TSDB_CODE_SUCCESS;
1,069✔
490
    case QUERY_NODE_SHOW_TABLES_STMT:
592,082✔
491
    case QUERY_NODE_SHOW_STABLES_STMT:
492
      return authShowTables(pCxt, (SShowStmt*)pStmt);
592,082✔
493
    case QUERY_NODE_SHOW_VTABLES_STMT:
61,874✔
494
      return authShowVtables(pCxt, (SShowStmt*)pStmt);
61,874✔
495
    case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
131,406✔
496
    case QUERY_NODE_SHOW_CREATE_VTABLE_STMT:
497
    case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
498
      return authShowCreateTable(pCxt, (SShowCreateTableStmt*)pStmt);
131,406✔
499
      //    case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
500
      //      return authShowCreateView(pCxt, (SShowCreateViewStmt*)pStmt);
501
    case QUERY_NODE_CREATE_VIEW_STMT:
262,585✔
502
      return authCreateView(pCxt, (SCreateViewStmt*)pStmt);
262,585✔
503
    case QUERY_NODE_DROP_VIEW_STMT:
193,503✔
504
      return authDropView(pCxt, (SDropViewStmt*)pStmt);
193,503✔
505
    case QUERY_NODE_CREATE_RSMA_STMT:
118,604✔
506
      return authCreateRsma(pCxt, (SCreateRsmaStmt*)pStmt);
118,604✔
507
    case QUERY_NODE_DROP_RSMA_STMT:
9,064✔
508
      return authDropRsma(pCxt, (SDropRsmaStmt*)pStmt);
9,064✔
509
    default:
20,327,397✔
510
      break;
20,327,397✔
511
  }
512

513
  return TSDB_CODE_SUCCESS;
20,327,397✔
514
}
515

516
int32_t authenticate(SParseContext* pParseCxt, SQuery* pQuery, SParseMetaCache* pMetaCache) {
177,037,560✔
517
  SAuthCxt cxt = {.pParseCxt = pParseCxt, .pMetaCache = pMetaCache, .errCode = TSDB_CODE_SUCCESS};
177,037,560✔
518
  return authQuery(&cxt, pQuery->pRoot);
177,040,044✔
519
}
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