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

taosdata / TDengine / #3798

31 Mar 2025 10:39AM UTC coverage: 9.424% (-20.9%) from 30.372%
#3798

push

travis-ci

happyguoxy
test:add test cases

21549 of 307601 branches covered (7.01%)

Branch coverage included in aggregate %.

36084 of 303967 relevant lines covered (11.87%)

58620.7 hits per line

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

60.79
/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,
834✔
38
                               bool isView, bool effective, SUserAuthInfo* pAuth) {
39
  if (effective) {
834!
40
    snprintf(pAuth->user, sizeof(pAuth->user), "%s", pCxt->pEffectiveUser ? pCxt->pEffectiveUser : "");
×
41
  } else {
42
    snprintf(pAuth->user, sizeof(pAuth->user), "%s", pCxt->pUser);
834✔
43
  }
44

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

56
static int32_t checkAuthImpl(SAuthCxt* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type, SNode** pCond,
3,340✔
57
                             bool isView, bool effective) {
58
  SParseContext* pParseCxt = pCxt->pParseCxt;
3,340✔
59
  if (pParseCxt->isSuperUser) {
3,340✔
60
    return TSDB_CODE_SUCCESS;
2,506✔
61
  }
62

63
  AUTH_RES_TYPE auth_res_type = isView ? AUTH_RES_VIEW : AUTH_RES_BASIC;
834✔
64
  SUserAuthInfo authInfo = {0};
834✔
65
  int32_t       code = setUserAuthInfo(pCxt->pParseCxt, pDbName, pTabName, type, isView, effective, &authInfo);
834✔
66
  if (TSDB_CODE_SUCCESS != code) return code;
834!
67
  SUserAuthRes authRes = {0};
834✔
68
  if (NULL != pCxt->pMetaCache) {
834!
69
    code = getUserAuthFromCache(pCxt->pMetaCache, &authInfo, &authRes);
834✔
70
#ifdef TD_ENTERPRISE
71
    if (isView && TSDB_CODE_PAR_INTERNAL_ERROR == code) {
834!
72
      authInfo.isView = false;
×
73
      code = getUserAuthFromCache(pCxt->pMetaCache, &authInfo, &authRes);
×
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) {
834!
84
    *pCond = authRes.pCond[auth_res_type];
74✔
85
  }
86
  return TSDB_CODE_SUCCESS == code ? (authRes.pass[auth_res_type] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED)
834✔
87
                                   : code;
834!
88
}
89

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

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

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

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

108
static EDealRes authSubquery(SAuthCxt* pCxt, SNode* pStmt) {
18✔
109
  return TSDB_CODE_SUCCESS == authQuery(pCxt, pStmt) ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
18!
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) {
54✔
134
  if (QUERY_NODE_COLUMN == nodeType(pNode)) {
54✔
135
    SColumnNode*     pCol = (SColumnNode*)pNode;
18✔
136
    SAuthRewriteCxt* pCxt = (SAuthRewriteCxt*)pContext;
18✔
137
    tstrncpy(pCol->tableName, pCxt->pTarget->tableName, TSDB_TABLE_NAME_LEN);
18✔
138
    tstrncpy(pCol->tableAlias, pCxt->pTarget->tableAlias, TSDB_TABLE_NAME_LEN);
18✔
139
  }
140

141
  return DEAL_RES_CONTINUE;
54✔
142
}
143

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

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

154
  if (NULL == *pWhere) {
18!
155
    *pWhere = pTagCondCopy;
18✔
156
    return TSDB_CODE_SUCCESS;
18✔
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,474✔
168
  SSelectAuthCxt* pCxt = pContext;
1,474✔
169
  SAuthCxt*       pAuthCxt = pCxt->pAuthCxt;
1,474✔
170
  bool            isView = false;
1,474✔
171
  if (QUERY_NODE_REAL_TABLE == nodeType(pNode)) {
1,474✔
172
    SNode*      pTagCond = NULL;
267✔
173
    STableNode* pTable = (STableNode*)pNode;
267✔
174
#ifdef TD_ENTERPRISE
175
    SName name = {0};
267✔
176
    toName(pAuthCxt->pParseCxt->acctId, pTable->dbName, pTable->tableName, &name);
267✔
177
    STableMeta* pTableMeta = NULL;
267✔
178
    toName(pAuthCxt->pParseCxt->acctId, pTable->dbName, pTable->tableName, &name);
267✔
179
    int32_t code = getTargetMetaImpl(
267✔
180
        pAuthCxt->pParseCxt, pAuthCxt->pMetaCache, &name, &pTableMeta, true);
181
    if (TSDB_CODE_SUCCESS == code && TSDB_VIEW_TABLE == pTableMeta->tableType) {
267!
182
      isView = true;
×
183
    }
184
    taosMemoryFree(pTableMeta);
267!
185
#endif
186
    if (!isView) {
267!
187
      pAuthCxt->errCode = checkAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, &pTagCond);
267✔
188
      if (TSDB_CODE_SUCCESS != pAuthCxt->errCode && NULL != pAuthCxt->pParseCxt->pEffectiveUser) {
267!
189
        pAuthCxt->errCode = checkEffectiveAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, NULL);
×
190
      }
191
      if (TSDB_CODE_SUCCESS == pAuthCxt->errCode && NULL != pTagCond) {
267✔
192
        pAuthCxt->errCode = rewriteAppendStableTagCond(&pCxt->pSelect->pWhere, pTagCond, pTable);
18✔
193
      }
194
    } else {
195
      pAuthCxt->errCode = checkViewAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, NULL);
×
196
      if (TSDB_CODE_SUCCESS != pAuthCxt->errCode && NULL != pAuthCxt->pParseCxt->pEffectiveUser) {
×
197
        pAuthCxt->errCode = checkViewEffectiveAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, NULL);
×
198
      }
199
    }
200
    return TSDB_CODE_SUCCESS == pAuthCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
267✔
201
  } else if (QUERY_NODE_TEMP_TABLE == nodeType(pNode)) {
1,207✔
202
    return authSubquery(pAuthCxt, ((STempTableNode*)pNode)->pSubquery);
18✔
203
  }
204
  return DEAL_RES_CONTINUE;
1,189✔
205
}
206

207
static int32_t authSelect(SAuthCxt* pCxt, SSelectStmt* pSelect) {
300✔
208
  SSelectAuthCxt cxt = {.pAuthCxt = pCxt, .pSelect = pSelect};
300✔
209
  nodesWalkSelectStmt(pSelect, SQL_CLAUSE_FROM, authSelectImpl, &cxt);
300✔
210
  return pCxt->errCode;
300✔
211
}
212

213
static int32_t authSetOperator(SAuthCxt* pCxt, SSetOperator* pSetOper) {
×
214
  int32_t code = authQuery(pCxt, pSetOper->pLeft);
×
215
  if (TSDB_CODE_SUCCESS == code) {
×
216
    code = authQuery(pCxt, pSetOper->pRight);
×
217
  }
218
  return code;
×
219
}
220

221
static int32_t authDropUser(SAuthCxt* pCxt, SDropUserStmt* pStmt) {
×
222
  if (!pCxt->pParseCxt->isSuperUser || 0 == strcmp(pStmt->userName, TSDB_DEFAULT_USER)) {
×
223
    return TSDB_CODE_PAR_PERMISSION_DENIED;
×
224
  }
225
  return TSDB_CODE_SUCCESS;
×
226
}
227

228
static int32_t authDelete(SAuthCxt* pCxt, SDeleteStmt* pDelete) {
×
229
  SNode*      pTagCond = NULL;
×
230
  STableNode* pTable = (STableNode*)pDelete->pFromTable;
×
231
  int32_t     code = checkAuth(pCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_WRITE, &pTagCond);
×
232
  if (TSDB_CODE_SUCCESS == code && NULL != pTagCond) {
×
233
    code = rewriteAppendStableTagCond(&pDelete->pWhere, pTagCond, pTable);
×
234
  }
235
  return code;
×
236
}
237

238
static int32_t authInsert(SAuthCxt* pCxt, SInsertStmt* pInsert) {
×
239
  SNode*      pTagCond = NULL;
×
240
  STableNode* pTable = (STableNode*)pInsert->pTable;
×
241
  // todo check tag condition for subtable
242
  int32_t code = checkAuth(pCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_WRITE, &pTagCond);
×
243
  if (TSDB_CODE_SUCCESS == code) {
×
244
    code = authQuery(pCxt, pInsert->pQuery);
×
245
  }
246
  return code;
×
247
}
248

249
static int32_t authShowTables(SAuthCxt* pCxt, SShowStmt* pStmt) {
57✔
250
  return checkAuth(pCxt, ((SValueNode*)pStmt->pDbName)->literal, NULL, AUTH_TYPE_READ_OR_WRITE, NULL);
57✔
251
}
252

253
static int32_t authShowVtables(SAuthCxt* pCxt, SShowStmt* pStmt) {
54✔
254
  return authShowTables(pCxt, pStmt);
54✔
255
}
256

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

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

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

272
  return TSDB_CODE_SUCCESS;
×
273
}
274

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

281
static int32_t authCreateVTable(SAuthCxt* pCxt, SCreateVTableStmt* pStmt) {
172✔
282
  PAR_ERR_RET(checkAuth(pCxt, pStmt->dbName, NULL, AUTH_TYPE_WRITE, NULL));
172✔
283
  SNode  *pCol = NULL;
156✔
284
  FOREACH(pCol, pStmt->pCols) {
1,871!
285
    SColumnDefNode *pColDef = (SColumnDefNode*)pCol;
1,727✔
286
    if (NULL == pColDef) {
1,727!
287
      PAR_ERR_RET(TSDB_CODE_PAR_INVALID_COLUMN);
×
288
    }
289
    SColumnOptions *pOptions = (SColumnOptions*)pColDef->pOptions;
1,727✔
290
    if (pOptions && pOptions->hasRef) {
1,727!
291
      PAR_ERR_RET(checkAuth(pCxt, pOptions->refDb, pOptions->refTable, AUTH_TYPE_READ, NULL));
893✔
292
    }
293
  }
294
  return TSDB_CODE_SUCCESS;
144✔
295
}
296

297
static int32_t authCreateVSubTable(SAuthCxt* pCxt, SCreateVSubTableStmt* pStmt) {
138✔
298
  int32_t   code = TSDB_CODE_SUCCESS;
138✔
299
  SNode     *pNode = NULL;
138✔
300
  SNodeList* pTmpList = pStmt->pSpecificColRefs ? pStmt->pSpecificColRefs : pStmt->pColRefs;
138✔
301
  PAR_ERR_RET(checkAuth(pCxt, pStmt->dbName, NULL, AUTH_TYPE_WRITE, NULL));
138✔
302
  if (NULL == pTmpList) {
122✔
303
    // no column reference
304
    return TSDB_CODE_SUCCESS;
5✔
305
  }
306

307
  FOREACH(pNode, pTmpList) {
752!
308
    SColumnRefNode *pColRef = (SColumnRefNode*)pNode;
647✔
309
    if (NULL == pColRef) {
647!
310
      PAR_ERR_RET(TSDB_CODE_PAR_INVALID_COLUMN);
×
311
    }
312
    PAR_ERR_RET(checkAuth(pCxt, pColRef->refDbName, pColRef->refTableName, AUTH_TYPE_READ, NULL));
647✔
313
  }
314
  return code;
105✔
315
}
316

317
static int32_t authCreateMultiTable(SAuthCxt* pCxt, SCreateMultiTablesStmt* pStmt) {
274✔
318
  int32_t code = TSDB_CODE_SUCCESS;
274✔
319
  SNode*  pNode = NULL;
274✔
320
  FOREACH(pNode, pStmt->pSubTables) {
551!
321
    if (pNode->type == QUERY_NODE_CREATE_SUBTABLE_CLAUSE) {
277!
322
      SCreateSubTableClause* pClause = (SCreateSubTableClause*)pNode;
277✔
323
      code = checkAuth(pCxt, pClause->dbName, NULL, AUTH_TYPE_WRITE, NULL);
277✔
324
      if (TSDB_CODE_SUCCESS != code) {
277!
325
        break;
×
326
      }
327
    } else {
328
      SCreateSubTableFromFileClause* pClause = (SCreateSubTableFromFileClause*)pNode;
×
329
      code = checkAuth(pCxt, pClause->useDbName, NULL, AUTH_TYPE_WRITE, NULL);
×
330
      if (TSDB_CODE_SUCCESS != code) {
×
331
        break;
×
332
      }
333
    }
334
  }
335
  return code;
274✔
336
}
337

338
static int32_t authDropTable(SAuthCxt* pCxt, SDropTableStmt* pStmt) {
6✔
339
  int32_t code = TSDB_CODE_SUCCESS;
6✔
340
  if (pStmt->withOpt && !pCxt->pParseCxt->isSuperUser) {
6!
341
    return TSDB_CODE_PAR_PERMISSION_DENIED;
×
342
  }
343
  SNode* pNode = NULL;
6✔
344
  FOREACH(pNode, pStmt->pTables) {
12!
345
    SDropTableClause* pClause = (SDropTableClause*)pNode;
6✔
346
    code = checkAuth(pCxt, pClause->dbName, pClause->tableName, AUTH_TYPE_WRITE, NULL);
6✔
347
    if (TSDB_CODE_SUCCESS != code) {
6!
348
      break;
×
349
    }
350
  }
351
  return code;
6✔
352
}
353

354
static int32_t authDropStable(SAuthCxt* pCxt, SDropSuperTableStmt* pStmt) {
1✔
355
  if (pStmt->withOpt && !pCxt->pParseCxt->isSuperUser) {
1!
356
    return TSDB_CODE_PAR_PERMISSION_DENIED;
×
357
  }
358
  return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_WRITE, NULL);
1✔
359
}
360

361
static int32_t authDropVtable(SAuthCxt* pCxt, SDropVirtualTableStmt* pStmt) {
50✔
362
  if (pStmt->withOpt && !pCxt->pParseCxt->isSuperUser) {
50!
363
    return TSDB_CODE_PAR_PERMISSION_DENIED;
×
364
  }
365
  return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_WRITE, NULL);
50✔
366
}
367

368
static int32_t authAlterTable(SAuthCxt* pCxt, SAlterTableStmt* pStmt) {
2✔
369
  SNode* pTagCond = NULL;
2✔
370
  // todo check tag condition for subtable
371
  return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_WRITE, NULL);
2✔
372
}
373

374
static int32_t authAlterVTable(SAuthCxt* pCxt, SAlterTableStmt* pStmt) {
395✔
375
  PAR_ERR_RET(checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_WRITE, NULL));
395✔
376
  if (pStmt->alterType == TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COLUMN_REF ||
331✔
377
      pStmt->alterType == TSDB_ALTER_TABLE_ALTER_COLUMN_REF) {
290✔
378
    PAR_ERR_RET(checkAuth(pCxt, pStmt->dbName, pStmt->refTableName, AUTH_TYPE_READ, NULL));
124✔
379
  }
380
  PAR_RET(TSDB_CODE_SUCCESS);
307!
381
}
382

383
static int32_t authCreateView(SAuthCxt* pCxt, SCreateViewStmt* pStmt) {
×
384
#ifndef TD_ENTERPRISE
385
  return TSDB_CODE_OPS_NOT_SUPPORT;
386
#endif
387
  return checkAuth(pCxt, pStmt->dbName, NULL, AUTH_TYPE_WRITE, NULL);
×
388
}
389

390
static int32_t authDropView(SAuthCxt* pCxt, SDropViewStmt* pStmt) {
×
391
#ifndef TD_ENTERPRISE
392
  return TSDB_CODE_OPS_NOT_SUPPORT;
393
#endif
394
  return checkViewAuth(pCxt, pStmt->dbName, pStmt->viewName, AUTH_TYPE_ALTER, NULL);
×
395
}
396

397
static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt) {
2,970✔
398
  switch (nodeType(pStmt)) {
2,970!
399
    case QUERY_NODE_SET_OPERATOR:
×
400
      return authSetOperator(pCxt, (SSetOperator*)pStmt);
×
401
    case QUERY_NODE_SELECT_STMT:
300✔
402
      return authSelect(pCxt, (SSelectStmt*)pStmt);
300✔
403
    case QUERY_NODE_DROP_USER_STMT:
×
404
      return authDropUser(pCxt, (SDropUserStmt*)pStmt);
×
405
    case QUERY_NODE_DELETE_STMT:
×
406
      return authDelete(pCxt, (SDeleteStmt*)pStmt);
×
407
    case QUERY_NODE_INSERT_STMT:
×
408
      return authInsert(pCxt, (SInsertStmt*)pStmt);
×
409
    case QUERY_NODE_CREATE_TABLE_STMT:
309✔
410
      return authCreateTable(pCxt, (SCreateTableStmt*)pStmt);
309✔
411
    case QUERY_NODE_CREATE_VIRTUAL_TABLE_STMT:
172✔
412
      return authCreateVTable(pCxt, (SCreateVTableStmt*)pStmt);
172✔
413
    case QUERY_NODE_CREATE_VIRTUAL_SUBTABLE_STMT:
138✔
414
      return authCreateVSubTable(pCxt, (SCreateVSubTableStmt*)pStmt);
138✔
415
    case QUERY_NODE_CREATE_MULTI_TABLES_STMT:
274✔
416
      return authCreateMultiTable(pCxt, (SCreateMultiTablesStmt*)pStmt);
274✔
417
    case QUERY_NODE_DROP_TABLE_STMT:
6✔
418
      return authDropTable(pCxt, (SDropTableStmt*)pStmt);
6✔
419
    case QUERY_NODE_DROP_SUPER_TABLE_STMT:
1✔
420
      return authDropStable(pCxt, (SDropSuperTableStmt*)pStmt);
1✔
421
    case QUERY_NODE_DROP_VIRTUAL_TABLE_STMT:
50✔
422
      return authDropVtable(pCxt, (SDropVirtualTableStmt*)pStmt);
50✔
423
    case QUERY_NODE_ALTER_TABLE_STMT:
2✔
424
    case QUERY_NODE_ALTER_SUPER_TABLE_STMT:
425
      return authAlterTable(pCxt, (SAlterTableStmt*)pStmt);
2✔
426
    case QUERY_NODE_ALTER_VIRTUAL_TABLE_STMT:
395✔
427
      return authAlterVTable(pCxt, (SAlterTableStmt*)pStmt);
395✔
428
    case QUERY_NODE_SHOW_DNODES_STMT:
×
429
    case QUERY_NODE_SHOW_MNODES_STMT:
430
    case QUERY_NODE_SHOW_MODULES_STMT:
431
    case QUERY_NODE_SHOW_QNODES_STMT:
432
    case QUERY_NODE_SHOW_SNODES_STMT:
433
    case QUERY_NODE_SHOW_BNODES_STMT:
434
    case QUERY_NODE_SHOW_CLUSTER_STMT:
435
    case QUERY_NODE_SHOW_LICENCES_STMT:
436
    case QUERY_NODE_SHOW_VGROUPS_STMT:
437
    case QUERY_NODE_SHOW_DB_ALIVE_STMT:
438
    case QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT:
439
    case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
440
    case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
441
    case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT:
442
    case QUERY_NODE_SHOW_VNODES_STMT:
443
    case QUERY_NODE_SHOW_SCORES_STMT:
444
    case QUERY_NODE_SHOW_USERS_STMT:
445
    case QUERY_NODE_SHOW_USERS_FULL_STMT:
446
    case QUERY_NODE_SHOW_USER_PRIVILEGES_STMT:
447
    case QUERY_NODE_SHOW_GRANTS_FULL_STMT:
448
    case QUERY_NODE_SHOW_GRANTS_LOGS_STMT:
449
    case QUERY_NODE_SHOW_CLUSTER_MACHINES_STMT:
450
    case QUERY_NODE_SHOW_ARBGROUPS_STMT:
451
    case QUERY_NODE_SHOW_ENCRYPTIONS_STMT:
452
    case QUERY_NODE_SHOW_USAGE_STMT:
453
      return !pCxt->pParseCxt->enableSysInfo ? TSDB_CODE_PAR_PERMISSION_DENIED : TSDB_CODE_SUCCESS;
×
454
    case QUERY_NODE_SHOW_ANODES_STMT:
×
455
    case QUERY_NODE_SHOW_ANODES_FULL_STMT:
456
      return TSDB_CODE_SUCCESS;
×
457
    case QUERY_NODE_SHOW_TABLES_STMT:
3✔
458
    case QUERY_NODE_SHOW_STABLES_STMT:
459
      return authShowTables(pCxt, (SShowStmt*)pStmt);
3✔
460
    case QUERY_NODE_SHOW_VTABLES_STMT:
54✔
461
      return authShowVtables(pCxt, (SShowStmt*)pStmt);
54✔
462
    case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
2✔
463
    case QUERY_NODE_SHOW_CREATE_VTABLE_STMT:
464
    case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
465
      return authShowCreateTable(pCxt, (SShowCreateTableStmt*)pStmt);
2✔
466
      //    case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
467
      //      return authShowCreateView(pCxt, (SShowCreateViewStmt*)pStmt);
468
    case QUERY_NODE_CREATE_VIEW_STMT:
×
469
      return authCreateView(pCxt, (SCreateViewStmt*)pStmt);
×
470
    case QUERY_NODE_DROP_VIEW_STMT:
×
471
      return authDropView(pCxt, (SDropViewStmt*)pStmt);
×
472
    default:
1,264✔
473
      break;
1,264✔
474
  }
475

476
  return TSDB_CODE_SUCCESS;
1,264✔
477
}
478

479
int32_t authenticate(SParseContext* pParseCxt, SQuery* pQuery, SParseMetaCache* pMetaCache) {
2,952✔
480
  SAuthCxt cxt = {.pParseCxt = pParseCxt, .pMetaCache = pMetaCache, .errCode = TSDB_CODE_SUCCESS};
2,952✔
481
  return authQuery(&cxt, pQuery->pRoot);
2,952✔
482
}
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