Merge pull request #26005 from taosdata/enh/TS-3737-3.0

enh: support createdb permission for user
This commit is contained in:
Hongze Cheng 2024-06-11 15:46:00 +08:00 committed by GitHub
commit d321fbbc87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 6050 additions and 7244 deletions

View File

@ -190,6 +190,7 @@ typedef enum _mgmt_table {
#define TSDB_ALTER_USER_DEL_PRIVILEGES 0x6 #define TSDB_ALTER_USER_DEL_PRIVILEGES 0x6
#define TSDB_ALTER_USER_ADD_WHITE_LIST 0x7 #define TSDB_ALTER_USER_ADD_WHITE_LIST 0x7
#define TSDB_ALTER_USER_DROP_WHITE_LIST 0x8 #define TSDB_ALTER_USER_DROP_WHITE_LIST 0x8
#define TSDB_ALTER_USER_CREATEDB 0x9
#define TSDB_KILL_MSG_LEN 30 #define TSDB_KILL_MSG_LEN 30
@ -1049,6 +1050,13 @@ typedef struct {
int8_t sysInfo; int8_t sysInfo;
int8_t enable; int8_t enable;
int8_t isView; int8_t isView;
union {
int8_t flag;
struct {
int8_t createdb : 1;
int8_t reserve : 7;
};
};
char user[TSDB_USER_LEN]; char user[TSDB_USER_LEN];
char pass[TSDB_USET_PASSWORD_LEN]; char pass[TSDB_USET_PASSWORD_LEN];
char objname[TSDB_DB_FNAME_LEN]; // db or topic char objname[TSDB_DB_FNAME_LEN]; // db or topic

View File

@ -289,7 +289,6 @@ int32_t tdGetBitmapValType(const void *pBitmap, int16_t colIdx, TDRowValT *pValT
*/ */
static FORCE_INLINE void tdSRowInit(SRowBuilder *pBuilder, int16_t sver) { static FORCE_INLINE void tdSRowInit(SRowBuilder *pBuilder, int16_t sver) {
pBuilder->rowType = pBuilder->rowType;
pBuilder->sver = sver; pBuilder->sver = sver;
} }
int32_t tdSRowSetInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t nBoundCols, int32_t flen); int32_t tdSRowSetInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t nBoundCols, int32_t flen);

View File

@ -54,343 +54,344 @@
#define TK_ENABLE 36 #define TK_ENABLE 36
#define TK_NK_INTEGER 37 #define TK_NK_INTEGER 37
#define TK_SYSINFO 38 #define TK_SYSINFO 38
#define TK_ADD 39 #define TK_CREATEDB 39
#define TK_DROP 40 #define TK_ADD 40
#define TK_GRANT 41 #define TK_DROP 41
#define TK_ON 42 #define TK_GRANT 42
#define TK_TO 43 #define TK_ON 43
#define TK_REVOKE 44 #define TK_TO 44
#define TK_FROM 45 #define TK_REVOKE 45
#define TK_SUBSCRIBE 46 #define TK_FROM 46
#define TK_READ 47 #define TK_SUBSCRIBE 47
#define TK_WRITE 48 #define TK_READ 48
#define TK_NK_DOT 49 #define TK_WRITE 49
#define TK_WITH 50 #define TK_NK_DOT 50
#define TK_ENCRYPT_KEY 51 #define TK_WITH 51
#define TK_DNODE 52 #define TK_ENCRYPT_KEY 52
#define TK_PORT 53 #define TK_DNODE 53
#define TK_DNODES 54 #define TK_PORT 54
#define TK_RESTORE 55 #define TK_DNODES 55
#define TK_NK_IPTOKEN 56 #define TK_RESTORE 56
#define TK_FORCE 57 #define TK_NK_IPTOKEN 57
#define TK_UNSAFE 58 #define TK_FORCE 58
#define TK_CLUSTER 59 #define TK_UNSAFE 59
#define TK_LOCAL 60 #define TK_CLUSTER 60
#define TK_QNODE 61 #define TK_LOCAL 61
#define TK_BNODE 62 #define TK_QNODE 62
#define TK_SNODE 63 #define TK_BNODE 63
#define TK_MNODE 64 #define TK_SNODE 64
#define TK_VNODE 65 #define TK_MNODE 65
#define TK_DATABASE 66 #define TK_VNODE 66
#define TK_USE 67 #define TK_DATABASE 67
#define TK_FLUSH 68 #define TK_USE 68
#define TK_TRIM 69 #define TK_FLUSH 69
#define TK_S3MIGRATE 70 #define TK_TRIM 70
#define TK_COMPACT 71 #define TK_S3MIGRATE 71
#define TK_IF 72 #define TK_COMPACT 72
#define TK_NOT 73 #define TK_IF 73
#define TK_EXISTS 74 #define TK_NOT 74
#define TK_BUFFER 75 #define TK_EXISTS 75
#define TK_CACHEMODEL 76 #define TK_BUFFER 76
#define TK_CACHESIZE 77 #define TK_CACHEMODEL 77
#define TK_COMP 78 #define TK_CACHESIZE 78
#define TK_DURATION 79 #define TK_COMP 79
#define TK_NK_VARIABLE 80 #define TK_DURATION 80
#define TK_MAXROWS 81 #define TK_NK_VARIABLE 81
#define TK_MINROWS 82 #define TK_MAXROWS 82
#define TK_KEEP 83 #define TK_MINROWS 83
#define TK_PAGES 84 #define TK_KEEP 84
#define TK_PAGESIZE 85 #define TK_PAGES 85
#define TK_TSDB_PAGESIZE 86 #define TK_PAGESIZE 86
#define TK_PRECISION 87 #define TK_TSDB_PAGESIZE 87
#define TK_REPLICA 88 #define TK_PRECISION 88
#define TK_VGROUPS 89 #define TK_REPLICA 89
#define TK_SINGLE_STABLE 90 #define TK_VGROUPS 90
#define TK_RETENTIONS 91 #define TK_SINGLE_STABLE 91
#define TK_SCHEMALESS 92 #define TK_RETENTIONS 92
#define TK_WAL_LEVEL 93 #define TK_SCHEMALESS 93
#define TK_WAL_FSYNC_PERIOD 94 #define TK_WAL_LEVEL 94
#define TK_WAL_RETENTION_PERIOD 95 #define TK_WAL_FSYNC_PERIOD 95
#define TK_WAL_RETENTION_SIZE 96 #define TK_WAL_RETENTION_PERIOD 96
#define TK_WAL_ROLL_PERIOD 97 #define TK_WAL_RETENTION_SIZE 97
#define TK_WAL_SEGMENT_SIZE 98 #define TK_WAL_ROLL_PERIOD 98
#define TK_STT_TRIGGER 99 #define TK_WAL_SEGMENT_SIZE 99
#define TK_TABLE_PREFIX 100 #define TK_STT_TRIGGER 100
#define TK_TABLE_SUFFIX 101 #define TK_TABLE_PREFIX 101
#define TK_S3_CHUNKSIZE 102 #define TK_TABLE_SUFFIX 102
#define TK_S3_KEEPLOCAL 103 #define TK_S3_CHUNKSIZE 103
#define TK_S3_COMPACT 104 #define TK_S3_KEEPLOCAL 104
#define TK_KEEP_TIME_OFFSET 105 #define TK_S3_COMPACT 105
#define TK_ENCRYPT_ALGORITHM 106 #define TK_KEEP_TIME_OFFSET 106
#define TK_NK_COLON 107 #define TK_ENCRYPT_ALGORITHM 107
#define TK_BWLIMIT 108 #define TK_NK_COLON 108
#define TK_START 109 #define TK_BWLIMIT 109
#define TK_TIMESTAMP 110 #define TK_START 110
#define TK_END 111 #define TK_TIMESTAMP 111
#define TK_TABLE 112 #define TK_END 112
#define TK_NK_LP 113 #define TK_TABLE 113
#define TK_NK_RP 114 #define TK_NK_LP 114
#define TK_STABLE 115 #define TK_NK_RP 115
#define TK_COLUMN 116 #define TK_STABLE 116
#define TK_MODIFY 117 #define TK_COLUMN 117
#define TK_RENAME 118 #define TK_MODIFY 118
#define TK_TAG 119 #define TK_RENAME 119
#define TK_SET 120 #define TK_TAG 120
#define TK_NK_EQ 121 #define TK_SET 121
#define TK_USING 122 #define TK_NK_EQ 122
#define TK_TAGS 123 #define TK_USING 123
#define TK_BOOL 124 #define TK_TAGS 124
#define TK_TINYINT 125 #define TK_BOOL 125
#define TK_SMALLINT 126 #define TK_TINYINT 126
#define TK_INT 127 #define TK_SMALLINT 127
#define TK_INTEGER 128 #define TK_INT 128
#define TK_BIGINT 129 #define TK_INTEGER 129
#define TK_FLOAT 130 #define TK_BIGINT 130
#define TK_DOUBLE 131 #define TK_FLOAT 131
#define TK_BINARY 132 #define TK_DOUBLE 132
#define TK_NCHAR 133 #define TK_BINARY 133
#define TK_UNSIGNED 134 #define TK_NCHAR 134
#define TK_JSON 135 #define TK_UNSIGNED 135
#define TK_VARCHAR 136 #define TK_JSON 136
#define TK_MEDIUMBLOB 137 #define TK_VARCHAR 137
#define TK_BLOB 138 #define TK_MEDIUMBLOB 138
#define TK_VARBINARY 139 #define TK_BLOB 139
#define TK_GEOMETRY 140 #define TK_VARBINARY 140
#define TK_DECIMAL 141 #define TK_GEOMETRY 141
#define TK_COMMENT 142 #define TK_DECIMAL 142
#define TK_MAX_DELAY 143 #define TK_COMMENT 143
#define TK_WATERMARK 144 #define TK_MAX_DELAY 144
#define TK_ROLLUP 145 #define TK_WATERMARK 145
#define TK_TTL 146 #define TK_ROLLUP 146
#define TK_SMA 147 #define TK_TTL 147
#define TK_DELETE_MARK 148 #define TK_SMA 148
#define TK_FIRST 149 #define TK_DELETE_MARK 149
#define TK_LAST 150 #define TK_FIRST 150
#define TK_SHOW 151 #define TK_LAST 151
#define TK_PRIVILEGES 152 #define TK_SHOW 152
#define TK_DATABASES 153 #define TK_PRIVILEGES 153
#define TK_TABLES 154 #define TK_DATABASES 154
#define TK_STABLES 155 #define TK_TABLES 155
#define TK_MNODES 156 #define TK_STABLES 156
#define TK_QNODES 157 #define TK_MNODES 157
#define TK_ARBGROUPS 158 #define TK_QNODES 158
#define TK_FUNCTIONS 159 #define TK_ARBGROUPS 159
#define TK_INDEXES 160 #define TK_FUNCTIONS 160
#define TK_ACCOUNTS 161 #define TK_INDEXES 161
#define TK_APPS 162 #define TK_ACCOUNTS 162
#define TK_CONNECTIONS 163 #define TK_APPS 163
#define TK_LICENCES 164 #define TK_CONNECTIONS 164
#define TK_GRANTS 165 #define TK_LICENCES 165
#define TK_FULL 166 #define TK_GRANTS 166
#define TK_LOGS 167 #define TK_FULL 167
#define TK_MACHINES 168 #define TK_LOGS 168
#define TK_ENCRYPTIONS 169 #define TK_MACHINES 169
#define TK_QUERIES 170 #define TK_ENCRYPTIONS 170
#define TK_SCORES 171 #define TK_QUERIES 171
#define TK_TOPICS 172 #define TK_SCORES 172
#define TK_VARIABLES 173 #define TK_TOPICS 173
#define TK_BNODES 174 #define TK_VARIABLES 174
#define TK_SNODES 175 #define TK_BNODES 175
#define TK_TRANSACTIONS 176 #define TK_SNODES 176
#define TK_DISTRIBUTED 177 #define TK_TRANSACTIONS 177
#define TK_CONSUMERS 178 #define TK_DISTRIBUTED 178
#define TK_SUBSCRIPTIONS 179 #define TK_CONSUMERS 179
#define TK_VNODES 180 #define TK_SUBSCRIPTIONS 180
#define TK_ALIVE 181 #define TK_VNODES 181
#define TK_VIEWS 182 #define TK_ALIVE 182
#define TK_VIEW 183 #define TK_VIEWS 183
#define TK_COMPACTS 184 #define TK_VIEW 184
#define TK_NORMAL 185 #define TK_COMPACTS 185
#define TK_CHILD 186 #define TK_NORMAL 186
#define TK_LIKE 187 #define TK_CHILD 187
#define TK_TBNAME 188 #define TK_LIKE 188
#define TK_QTAGS 189 #define TK_TBNAME 189
#define TK_AS 190 #define TK_QTAGS 190
#define TK_SYSTEM 191 #define TK_AS 191
#define TK_TSMA 192 #define TK_SYSTEM 192
#define TK_INTERVAL 193 #define TK_TSMA 193
#define TK_RECURSIVE 194 #define TK_INTERVAL 194
#define TK_TSMAS 195 #define TK_RECURSIVE 195
#define TK_FUNCTION 196 #define TK_TSMAS 196
#define TK_INDEX 197 #define TK_FUNCTION 197
#define TK_COUNT 198 #define TK_INDEX 198
#define TK_LAST_ROW 199 #define TK_COUNT 199
#define TK_META 200 #define TK_LAST_ROW 200
#define TK_ONLY 201 #define TK_META 201
#define TK_TOPIC 202 #define TK_ONLY 202
#define TK_CONSUMER 203 #define TK_TOPIC 203
#define TK_GROUP 204 #define TK_CONSUMER 204
#define TK_DESC 205 #define TK_GROUP 205
#define TK_DESCRIBE 206 #define TK_DESC 206
#define TK_RESET 207 #define TK_DESCRIBE 207
#define TK_QUERY 208 #define TK_RESET 208
#define TK_CACHE 209 #define TK_QUERY 209
#define TK_EXPLAIN 210 #define TK_CACHE 210
#define TK_ANALYZE 211 #define TK_EXPLAIN 211
#define TK_VERBOSE 212 #define TK_ANALYZE 212
#define TK_NK_BOOL 213 #define TK_VERBOSE 213
#define TK_RATIO 214 #define TK_NK_BOOL 214
#define TK_NK_FLOAT 215 #define TK_RATIO 215
#define TK_OUTPUTTYPE 216 #define TK_NK_FLOAT 216
#define TK_AGGREGATE 217 #define TK_OUTPUTTYPE 217
#define TK_BUFSIZE 218 #define TK_AGGREGATE 218
#define TK_LANGUAGE 219 #define TK_BUFSIZE 219
#define TK_REPLACE 220 #define TK_LANGUAGE 220
#define TK_STREAM 221 #define TK_REPLACE 221
#define TK_INTO 222 #define TK_STREAM 222
#define TK_PAUSE 223 #define TK_INTO 223
#define TK_RESUME 224 #define TK_PAUSE 224
#define TK_PRIMARY 225 #define TK_RESUME 225
#define TK_KEY 226 #define TK_PRIMARY 226
#define TK_TRIGGER 227 #define TK_KEY 227
#define TK_AT_ONCE 228 #define TK_TRIGGER 228
#define TK_WINDOW_CLOSE 229 #define TK_AT_ONCE 229
#define TK_IGNORE 230 #define TK_WINDOW_CLOSE 230
#define TK_EXPIRED 231 #define TK_IGNORE 231
#define TK_FILL_HISTORY 232 #define TK_EXPIRED 232
#define TK_UPDATE 233 #define TK_FILL_HISTORY 233
#define TK_SUBTABLE 234 #define TK_UPDATE 234
#define TK_UNTREATED 235 #define TK_SUBTABLE 235
#define TK_KILL 236 #define TK_UNTREATED 236
#define TK_CONNECTION 237 #define TK_KILL 237
#define TK_TRANSACTION 238 #define TK_CONNECTION 238
#define TK_BALANCE 239 #define TK_TRANSACTION 239
#define TK_VGROUP 240 #define TK_BALANCE 240
#define TK_LEADER 241 #define TK_VGROUP 241
#define TK_MERGE 242 #define TK_LEADER 242
#define TK_REDISTRIBUTE 243 #define TK_MERGE 243
#define TK_SPLIT 244 #define TK_REDISTRIBUTE 244
#define TK_DELETE 245 #define TK_SPLIT 245
#define TK_INSERT 246 #define TK_DELETE 246
#define TK_NK_BIN 247 #define TK_INSERT 247
#define TK_NK_HEX 248 #define TK_NK_BIN 248
#define TK_NULL 249 #define TK_NK_HEX 249
#define TK_NK_QUESTION 250 #define TK_NULL 250
#define TK_NK_ALIAS 251 #define TK_NK_QUESTION 251
#define TK_NK_ARROW 252 #define TK_NK_ALIAS 252
#define TK_ROWTS 253 #define TK_NK_ARROW 253
#define TK_QSTART 254 #define TK_ROWTS 254
#define TK_QEND 255 #define TK_QSTART 255
#define TK_QDURATION 256 #define TK_QEND 256
#define TK_WSTART 257 #define TK_QDURATION 257
#define TK_WEND 258 #define TK_WSTART 258
#define TK_WDURATION 259 #define TK_WEND 259
#define TK_IROWTS 260 #define TK_WDURATION 260
#define TK_ISFILLED 261 #define TK_IROWTS 261
#define TK_CAST 262 #define TK_ISFILLED 262
#define TK_NOW 263 #define TK_CAST 263
#define TK_TODAY 264 #define TK_NOW 264
#define TK_TIMEZONE 265 #define TK_TODAY 265
#define TK_CLIENT_VERSION 266 #define TK_TIMEZONE 266
#define TK_SERVER_VERSION 267 #define TK_CLIENT_VERSION 267
#define TK_SERVER_STATUS 268 #define TK_SERVER_VERSION 268
#define TK_CURRENT_USER 269 #define TK_SERVER_STATUS 269
#define TK_CASE 270 #define TK_CURRENT_USER 270
#define TK_WHEN 271 #define TK_CASE 271
#define TK_THEN 272 #define TK_WHEN 272
#define TK_ELSE 273 #define TK_THEN 273
#define TK_BETWEEN 274 #define TK_ELSE 274
#define TK_IS 275 #define TK_BETWEEN 275
#define TK_NK_LT 276 #define TK_IS 276
#define TK_NK_GT 277 #define TK_NK_LT 277
#define TK_NK_LE 278 #define TK_NK_GT 278
#define TK_NK_GE 279 #define TK_NK_LE 279
#define TK_NK_NE 280 #define TK_NK_GE 280
#define TK_MATCH 281 #define TK_NK_NE 281
#define TK_NMATCH 282 #define TK_MATCH 282
#define TK_CONTAINS 283 #define TK_NMATCH 283
#define TK_IN 284 #define TK_CONTAINS 284
#define TK_JOIN 285 #define TK_IN 285
#define TK_INNER 286 #define TK_JOIN 286
#define TK_LEFT 287 #define TK_INNER 287
#define TK_RIGHT 288 #define TK_LEFT 288
#define TK_OUTER 289 #define TK_RIGHT 289
#define TK_SEMI 290 #define TK_OUTER 290
#define TK_ANTI 291 #define TK_SEMI 291
#define TK_ASOF 292 #define TK_ANTI 292
#define TK_WINDOW 293 #define TK_ASOF 293
#define TK_WINDOW_OFFSET 294 #define TK_WINDOW 294
#define TK_JLIMIT 295 #define TK_WINDOW_OFFSET 295
#define TK_SELECT 296 #define TK_JLIMIT 296
#define TK_NK_HINT 297 #define TK_SELECT 297
#define TK_DISTINCT 298 #define TK_NK_HINT 298
#define TK_WHERE 299 #define TK_DISTINCT 299
#define TK_PARTITION 300 #define TK_WHERE 300
#define TK_BY 301 #define TK_PARTITION 301
#define TK_SESSION 302 #define TK_BY 302
#define TK_STATE_WINDOW 303 #define TK_SESSION 303
#define TK_EVENT_WINDOW 304 #define TK_STATE_WINDOW 304
#define TK_COUNT_WINDOW 305 #define TK_EVENT_WINDOW 305
#define TK_SLIDING 306 #define TK_COUNT_WINDOW 306
#define TK_FILL 307 #define TK_SLIDING 307
#define TK_VALUE 308 #define TK_FILL 308
#define TK_VALUE_F 309 #define TK_VALUE 309
#define TK_NONE 310 #define TK_VALUE_F 310
#define TK_PREV 311 #define TK_NONE 311
#define TK_NULL_F 312 #define TK_PREV 312
#define TK_LINEAR 313 #define TK_NULL_F 313
#define TK_NEXT 314 #define TK_LINEAR 314
#define TK_HAVING 315 #define TK_NEXT 315
#define TK_RANGE 316 #define TK_HAVING 316
#define TK_EVERY 317 #define TK_RANGE 317
#define TK_ORDER 318 #define TK_EVERY 318
#define TK_SLIMIT 319 #define TK_ORDER 319
#define TK_SOFFSET 320 #define TK_SLIMIT 320
#define TK_LIMIT 321 #define TK_SOFFSET 321
#define TK_OFFSET 322 #define TK_LIMIT 322
#define TK_ASC 323 #define TK_OFFSET 323
#define TK_NULLS 324 #define TK_ASC 324
#define TK_ABORT 325 #define TK_NULLS 325
#define TK_AFTER 326 #define TK_ABORT 326
#define TK_ATTACH 327 #define TK_AFTER 327
#define TK_BEFORE 328 #define TK_ATTACH 328
#define TK_BEGIN 329 #define TK_BEFORE 329
#define TK_BITAND 330 #define TK_BEGIN 330
#define TK_BITNOT 331 #define TK_BITAND 331
#define TK_BITOR 332 #define TK_BITNOT 332
#define TK_BLOCKS 333 #define TK_BITOR 333
#define TK_CHANGE 334 #define TK_BLOCKS 334
#define TK_COMMA 335 #define TK_CHANGE 335
#define TK_CONCAT 336 #define TK_COMMA 336
#define TK_CONFLICT 337 #define TK_CONCAT 337
#define TK_COPY 338 #define TK_CONFLICT 338
#define TK_DEFERRED 339 #define TK_COPY 339
#define TK_DELIMITERS 340 #define TK_DEFERRED 340
#define TK_DETACH 341 #define TK_DELIMITERS 341
#define TK_DIVIDE 342 #define TK_DETACH 342
#define TK_DOT 343 #define TK_DIVIDE 343
#define TK_EACH 344 #define TK_DOT 344
#define TK_FAIL 345 #define TK_EACH 345
#define TK_FILE 346 #define TK_FAIL 346
#define TK_FOR 347 #define TK_FILE 347
#define TK_GLOB 348 #define TK_FOR 348
#define TK_ID 349 #define TK_GLOB 349
#define TK_IMMEDIATE 350 #define TK_ID 350
#define TK_IMPORT 351 #define TK_IMMEDIATE 351
#define TK_INITIALLY 352 #define TK_IMPORT 352
#define TK_INSTEAD 353 #define TK_INITIALLY 353
#define TK_ISNULL 354 #define TK_INSTEAD 354
#define TK_MODULES 355 #define TK_ISNULL 355
#define TK_NK_BITNOT 356 #define TK_MODULES 356
#define TK_NK_SEMI 357 #define TK_NK_BITNOT 357
#define TK_NOTNULL 358 #define TK_NK_SEMI 358
#define TK_OF 359 #define TK_NOTNULL 359
#define TK_PLUS 360 #define TK_OF 360
#define TK_PRIVILEGE 361 #define TK_PLUS 361
#define TK_RAISE 362 #define TK_PRIVILEGE 362
#define TK_RESTRICT 363 #define TK_RAISE 363
#define TK_ROW 364 #define TK_RESTRICT 364
#define TK_STAR 365 #define TK_ROW 365
#define TK_STATEMENT 366 #define TK_STAR 366
#define TK_STRICT 367 #define TK_STATEMENT 367
#define TK_STRING 368 #define TK_STRICT 368
#define TK_TIMES 369 #define TK_STRING 369
#define TK_VALUES 370 #define TK_TIMES 370
#define TK_VARIABLE 371 #define TK_VALUES 371
#define TK_WAL 372 #define TK_VARIABLE 372
#define TK_ENCODE 373 #define TK_WAL 373
#define TK_COMPRESS 374 #define TK_ENCODE 374
#define TK_LEVEL 375 #define TK_COMPRESS 375
#define TK_LEVEL 376
#define TK_NK_SPACE 600 #define TK_NK_SPACE 600
#define TK_NK_COMMENT 601 #define TK_NK_COMMENT 601

View File

@ -271,6 +271,7 @@ typedef struct SAlterUserStmt {
char password[TSDB_USET_PASSWORD_LEN]; char password[TSDB_USET_PASSWORD_LEN];
int8_t enable; int8_t enable;
int8_t sysinfo; int8_t sysinfo;
int8_t createdb;
int32_t numIpRanges; int32_t numIpRanges;
SIpV4Range* pIpRanges; SIpV4Range* pIpRanges;

View File

@ -334,6 +334,7 @@ void *createRequest(uint64_t connId, int32_t type, int64_t reqid) {
} }
SSyncQueryParam *interParam = taosMemoryCalloc(1, sizeof(SSyncQueryParam)); SSyncQueryParam *interParam = taosMemoryCalloc(1, sizeof(SSyncQueryParam));
if (interParam == NULL) { if (interParam == NULL) {
releaseTscObj(connId);
doDestroyRequest(pRequest); doDestroyRequest(pRequest);
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL; return NULL;

View File

@ -264,6 +264,7 @@ static const SSysDbTableSchema userUsersSchema[] = {
{.name = "super", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT, .sysInfo = true}, {.name = "super", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT, .sysInfo = true},
{.name = "enable", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT, .sysInfo = true}, {.name = "enable", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT, .sysInfo = true},
{.name = "sysinfo", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT, .sysInfo = true}, {.name = "sysinfo", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT, .sysInfo = true},
{.name = "createdb", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT, .sysInfo = true},
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = true}, {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = true},
{.name = "allowed_host", .bytes = TSDB_PRIVILEDGE_HOST_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, {.name = "allowed_host", .bytes = TSDB_PRIVILEDGE_HOST_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
}; };

View File

@ -1810,6 +1810,7 @@ int32_t tSerializeSAlterUserReq(void *buf, int32_t bufLen, SAlterUserReq *pReq)
} }
if (tEncodeI64(&encoder, pReq->privileges) < 0) return -1; if (tEncodeI64(&encoder, pReq->privileges) < 0) return -1;
ENCODESQL(); ENCODESQL();
if (tEncodeI8(&encoder, pReq->flag) < 0) return -1;
tEndEncode(&encoder); tEndEncode(&encoder);
int32_t tlen = encoder.pos; int32_t tlen = encoder.pos;
@ -1849,6 +1850,9 @@ int32_t tDeserializeSAlterUserReq(void *buf, int32_t bufLen, SAlterUserReq *pReq
} }
if (tDecodeI64(&decoder, &pReq->privileges) < 0) return -1; if (tDecodeI64(&decoder, &pReq->privileges) < 0) return -1;
DECODESQL(); DECODESQL();
if (!tDecodeIsEnd(&decoder)) {
if (tDecodeI8(&decoder, &pReq->flag) < 0) return -1;
}
tEndDecode(&decoder); tEndDecode(&decoder);
tDecoderClear(&decoder); tDecoderClear(&decoder);

View File

@ -77,6 +77,7 @@ typedef enum {
MND_OPER_CREATE_VIEW, MND_OPER_CREATE_VIEW,
MND_OPER_DROP_VIEW, MND_OPER_DROP_VIEW,
MND_OPER_CONFIG_CLUSTER, MND_OPER_CONFIG_CLUSTER,
MND_OPER_BALANCE_VGROUP_LEADER,
} EOperType; } EOperType;
typedef enum { typedef enum {
@ -330,7 +331,13 @@ typedef struct {
int8_t superUser; int8_t superUser;
int8_t sysInfo; int8_t sysInfo;
int8_t enable; int8_t enable;
int8_t reserve; union {
int8_t flag;
struct {
int8_t createdb : 1;
int8_t reserve : 7;
};
};
int32_t acctId; int32_t acctId;
int32_t authVersion; int32_t authVersion;
int32_t passVersion; int32_t passVersion;

View File

@ -874,9 +874,6 @@ static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) {
} }
#endif #endif
mInfo("db:%s, start to create, vgroups:%d", createReq.db, createReq.numOfVgroups); mInfo("db:%s, start to create, vgroups:%d", createReq.db, createReq.numOfVgroups);
if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_DB, NULL) != 0) {
goto _OVER;
}
pDb = mndAcquireDb(pMnode, createReq.db); pDb = mndAcquireDb(pMnode, createReq.db);
if (pDb != NULL) { if (pDb != NULL) {
@ -901,6 +898,10 @@ static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) {
} }
} }
if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_DB, NULL) != 0) {
goto _OVER;
}
if ((terrno = grantCheck(TSDB_GRANT_DB)) != 0) { if ((terrno = grantCheck(TSDB_GRANT_DB)) != 0) {
code = terrno; code = terrno;
goto _OVER; goto _OVER;

View File

@ -648,6 +648,7 @@ static int32_t mndCreateDefaultUser(SMnode *pMnode, char *acct, char *user, char
userObj.pIpWhiteList = createDefaultIpWhiteList(); userObj.pIpWhiteList = createDefaultIpWhiteList();
if (strcmp(user, TSDB_DEFAULT_USER) == 0) { if (strcmp(user, TSDB_DEFAULT_USER) == 0) {
userObj.superUser = 1; userObj.superUser = 1;
userObj.createdb = 1;
} }
SSdbRaw *pRaw = mndUserActionEncode(&userObj); SSdbRaw *pRaw = mndUserActionEncode(&userObj);
@ -817,7 +818,7 @@ SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
SDB_SET_INT8(pRaw, dataPos, pUser->superUser, _OVER) SDB_SET_INT8(pRaw, dataPos, pUser->superUser, _OVER)
SDB_SET_INT8(pRaw, dataPos, pUser->sysInfo, _OVER) SDB_SET_INT8(pRaw, dataPos, pUser->sysInfo, _OVER)
SDB_SET_INT8(pRaw, dataPos, pUser->enable, _OVER) SDB_SET_INT8(pRaw, dataPos, pUser->enable, _OVER)
SDB_SET_INT8(pRaw, dataPos, pUser->reserve, _OVER) SDB_SET_INT8(pRaw, dataPos, pUser->flag, _OVER)
SDB_SET_INT32(pRaw, dataPos, pUser->authVersion, _OVER) SDB_SET_INT32(pRaw, dataPos, pUser->authVersion, _OVER)
SDB_SET_INT32(pRaw, dataPos, pUser->passVersion, _OVER) SDB_SET_INT32(pRaw, dataPos, pUser->passVersion, _OVER)
SDB_SET_INT32(pRaw, dataPos, numOfReadDbs, _OVER) SDB_SET_INT32(pRaw, dataPos, numOfReadDbs, _OVER)
@ -1001,7 +1002,8 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT8(pRaw, dataPos, &pUser->superUser, _OVER) SDB_GET_INT8(pRaw, dataPos, &pUser->superUser, _OVER)
SDB_GET_INT8(pRaw, dataPos, &pUser->sysInfo, _OVER) SDB_GET_INT8(pRaw, dataPos, &pUser->sysInfo, _OVER)
SDB_GET_INT8(pRaw, dataPos, &pUser->enable, _OVER) SDB_GET_INT8(pRaw, dataPos, &pUser->enable, _OVER)
SDB_GET_INT8(pRaw, dataPos, &pUser->reserve, _OVER) SDB_GET_INT8(pRaw, dataPos, &pUser->flag, _OVER)
if (pUser->superUser) pUser->createdb = 1;
SDB_GET_INT32(pRaw, dataPos, &pUser->authVersion, _OVER) SDB_GET_INT32(pRaw, dataPos, &pUser->authVersion, _OVER)
if (sver >= 4) { if (sver >= 4) {
SDB_GET_INT32(pRaw, dataPos, &pUser->passVersion, _OVER) SDB_GET_INT32(pRaw, dataPos, &pUser->passVersion, _OVER)
@ -1395,6 +1397,7 @@ static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOld, SUserObj *pNew) {
pOld->passVersion = pNew->passVersion; pOld->passVersion = pNew->passVersion;
pOld->sysInfo = pNew->sysInfo; pOld->sysInfo = pNew->sysInfo;
pOld->enable = pNew->enable; pOld->enable = pNew->enable;
pOld->flag = pNew->flag;
memcpy(pOld->pass, pNew->pass, TSDB_PASSWORD_LEN); memcpy(pOld->pass, pNew->pass, TSDB_PASSWORD_LEN);
TSWAP(pOld->readDbs, pNew->readDbs); TSWAP(pOld->readDbs, pNew->readDbs);
TSWAP(pOld->writeDbs, pNew->writeDbs); TSWAP(pOld->writeDbs, pNew->writeDbs);
@ -1445,6 +1448,7 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, SCreateUserReq *pCreate
userObj.superUser = 0; // pCreate->superUser; userObj.superUser = 0; // pCreate->superUser;
userObj.sysInfo = pCreate->sysInfo; userObj.sysInfo = pCreate->sysInfo;
userObj.enable = pCreate->enable; userObj.enable = pCreate->enable;
userObj.createdb = 0;
if (pCreate->numIpRanges == 0) { if (pCreate->numIpRanges == 0) {
userObj.pIpWhiteList = createDefaultIpWhiteList(); userObj.pIpWhiteList = createDefaultIpWhiteList();
@ -1790,6 +1794,9 @@ static char *mndUserAuditTypeStr(int32_t type) {
if (type == TSDB_ALTER_USER_SYSINFO) { if (type == TSDB_ALTER_USER_SYSINFO) {
return "userSysInfo"; return "userSysInfo";
} }
if (type == TSDB_ALTER_USER_CREATEDB) {
return "userCreateDB";
}
return "error"; return "error";
} }
@ -2009,6 +2016,10 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
newUser.sysInfo = alterReq.sysInfo; newUser.sysInfo = alterReq.sysInfo;
} }
if(alterReq.alterType == TSDB_ALTER_USER_CREATEDB) {
newUser.createdb = alterReq.createdb;
}
if (ALTER_USER_ADD_PRIVS(alterReq.alterType) || ALTER_USER_DEL_PRIVS(alterReq.alterType)) { if (ALTER_USER_ADD_PRIVS(alterReq.alterType) || ALTER_USER_DEL_PRIVS(alterReq.alterType)) {
if (0 != mndProcessAlterUserPrivilegesReq(&alterReq, pMnode, &newUser)) goto _OVER; if (0 != mndProcessAlterUserPrivilegesReq(&alterReq, pMnode, &newUser)) goto _OVER;
} }
@ -2110,14 +2121,15 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
if(alterReq.alterType == TSDB_ALTER_USER_PASSWD){ if(alterReq.alterType == TSDB_ALTER_USER_PASSWD){
char detail[1000] = {0}; char detail[1000] = {0};
sprintf(detail, "alterType:%s, enable:%d, superUser:%d, sysInfo:%d, tabName:%s, password:xxx", sprintf(detail, "alterType:%s, enable:%d, superUser:%d, sysInfo:%d, createdb:%d, tabName:%s, password:xxx",
mndUserAuditTypeStr(alterReq.alterType), alterReq.enable, alterReq.superUser, alterReq.sysInfo, mndUserAuditTypeStr(alterReq.alterType), alterReq.enable, alterReq.superUser, alterReq.sysInfo,
alterReq.tabName); alterReq.createdb ? 1 : 0, alterReq.tabName);
auditRecord(pReq, pMnode->clusterId, "alterUser", "", alterReq.user, detail, strlen(detail)); auditRecord(pReq, pMnode->clusterId, "alterUser", "", alterReq.user, detail, strlen(detail));
} }
else if(alterReq.alterType == TSDB_ALTER_USER_SUPERUSER || else if(alterReq.alterType == TSDB_ALTER_USER_SUPERUSER ||
alterReq.alterType == TSDB_ALTER_USER_ENABLE || alterReq.alterType == TSDB_ALTER_USER_ENABLE ||
alterReq.alterType == TSDB_ALTER_USER_SYSINFO){ alterReq.alterType == TSDB_ALTER_USER_SYSINFO ||
alterReq.alterType == TSDB_ALTER_USER_CREATEDB){
auditRecord(pReq, pMnode->clusterId, "alterUser", "", alterReq.user, alterReq.sql, alterReq.sqlLen); auditRecord(pReq, pMnode->clusterId, "alterUser", "", alterReq.user, alterReq.sql, alterReq.sqlLen);
} }
else if(ALTER_USER_ADD_READ_DB_PRIV(alterReq.alterType, alterReq.privileges, alterReq.tabName)|| else if(ALTER_USER_ADD_READ_DB_PRIV(alterReq.alterType, alterReq.privileges, alterReq.tabName)||
@ -2290,6 +2302,7 @@ static int32_t mndRetrieveUsers(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
int32_t numOfRows = 0; int32_t numOfRows = 0;
SUserObj *pUser = NULL; SUserObj *pUser = NULL;
int32_t cols = 0; int32_t cols = 0;
int8_t flag = 0;
char *pWrite; char *pWrite;
while (numOfRows < rows) { while (numOfRows < rows) {
@ -2314,6 +2327,11 @@ static int32_t mndRetrieveUsers(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
pColInfo = taosArrayGet(pBlock->pDataBlock, cols); pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
colDataSetVal(pColInfo, numOfRows, (const char *)&pUser->sysInfo, false); colDataSetVal(pColInfo, numOfRows, (const char *)&pUser->sysInfo, false);
cols++;
flag = pUser->createdb ? 1 : 0;
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
colDataSetVal(pColInfo, numOfRows, (const char *)&flag, false);
cols++; cols++;
pColInfo = taosArrayGet(pBlock->pDataBlock, cols); pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
colDataSetVal(pColInfo, numOfRows, (const char *)&pUser->createdTime, false); colDataSetVal(pColInfo, numOfRows, (const char *)&pUser->createdTime, false);

View File

@ -6168,6 +6168,7 @@ static const char* jkAlterUserStmtAlterType = "AlterType";
static const char* jkAlterUserStmtPassword = "Password"; static const char* jkAlterUserStmtPassword = "Password";
static const char* jkAlterUserStmtEnable = "Enable"; static const char* jkAlterUserStmtEnable = "Enable";
static const char* jkAlterUserStmtSysinfo = "Sysinfo"; static const char* jkAlterUserStmtSysinfo = "Sysinfo";
static const char* jkAlterUserStmtCreatedb = "Createdb";
static int32_t alterUserStmtToJson(const void* pObj, SJson* pJson) { static int32_t alterUserStmtToJson(const void* pObj, SJson* pJson) {
const SAlterUserStmt* pNode = (const SAlterUserStmt*)pObj; const SAlterUserStmt* pNode = (const SAlterUserStmt*)pObj;
@ -6185,6 +6186,9 @@ static int32_t alterUserStmtToJson(const void* pObj, SJson* pJson) {
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddIntegerToObject(pJson, jkAlterUserStmtSysinfo, pNode->sysinfo); code = tjsonAddIntegerToObject(pJson, jkAlterUserStmtSysinfo, pNode->sysinfo);
} }
if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddIntegerToObject(pJson, jkAlterUserStmtCreatedb, pNode->createdb);
}
return code; return code;
} }
@ -6205,6 +6209,9 @@ static int32_t jsonToAlterUserStmt(const SJson* pJson, void* pObj) {
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonGetTinyIntValue(pJson, jkAlterUserStmtSysinfo, &pNode->sysinfo); code = tjsonGetTinyIntValue(pJson, jkAlterUserStmtSysinfo, &pNode->sysinfo);
} }
if (TSDB_CODE_SUCCESS == code) {
code = tjsonGetTinyIntValue(pJson, jkAlterUserStmtCreatedb, &pNode->createdb);
}
return code; return code;
} }

View File

@ -104,6 +104,7 @@ cmd ::= CREATE USER user_name(A) PASS NK_STRING(B) sysinfo_opt(C)
cmd ::= ALTER USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PASSWD, &B); } cmd ::= ALTER USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PASSWD, &B); }
cmd ::= ALTER USER user_name(A) ENABLE NK_INTEGER(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_ENABLE, &B); } cmd ::= ALTER USER user_name(A) ENABLE NK_INTEGER(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_ENABLE, &B); }
cmd ::= ALTER USER user_name(A) SYSINFO NK_INTEGER(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_SYSINFO, &B); } cmd ::= ALTER USER user_name(A) SYSINFO NK_INTEGER(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_SYSINFO, &B); }
cmd ::= ALTER USER user_name(A) CREATEDB NK_INTEGER(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_CREATEDB, &B); }
cmd ::= ALTER USER user_name(A) ADD white_list(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_ADD_WHITE_LIST, B); } cmd ::= ALTER USER user_name(A) ADD white_list(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_ADD_WHITE_LIST, B); }
cmd ::= ALTER USER user_name(A) DROP white_list(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_DROP_WHITE_LIST, B); } cmd ::= ALTER USER user_name(A) DROP white_list(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_DROP_WHITE_LIST, B); }
cmd ::= DROP USER user_name(A). { pCxt->pRootNode = createDropUserStmt(pCxt, &A); } cmd ::= DROP USER user_name(A). { pCxt->pRootNode = createDropUserStmt(pCxt, &A); }

View File

@ -2294,6 +2294,11 @@ SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t al
pStmt->sysinfo = taosStr2Int8(pVal->z, NULL, 10); pStmt->sysinfo = taosStr2Int8(pVal->z, NULL, 10);
break; break;
} }
case TSDB_ALTER_USER_CREATEDB: {
SToken* pVal = pAlterInfo;
pStmt->createdb = taosStr2Int8(pVal->z, NULL, 10);
break;
}
case TSDB_ALTER_USER_ADD_WHITE_LIST: case TSDB_ALTER_USER_ADD_WHITE_LIST:
case TSDB_ALTER_USER_DROP_WHITE_LIST: { case TSDB_ALTER_USER_DROP_WHITE_LIST: {
SNodeList* pIpRangesNodeList = pAlterInfo; SNodeList* pIpRangesNodeList = pAlterInfo;

View File

@ -77,6 +77,7 @@ static SKeyword keywordTable[] = {
{"COUNT", TK_COUNT}, {"COUNT", TK_COUNT},
{"COUNT_WINDOW", TK_COUNT_WINDOW}, {"COUNT_WINDOW", TK_COUNT_WINDOW},
{"CREATE", TK_CREATE}, {"CREATE", TK_CREATE},
{"CREATEDB", TK_CREATEDB},
{"CURRENT_USER", TK_CURRENT_USER}, {"CURRENT_USER", TK_CURRENT_USER},
{"DATABASE", TK_DATABASE}, {"DATABASE", TK_DATABASE},
{"DATABASES", TK_DATABASES}, {"DATABASES", TK_DATABASES},

View File

@ -6581,8 +6581,8 @@ static int32_t checkRangeOption(STranslateContext* pCxt, int32_t code, const cha
int64_t maxVal) { int64_t maxVal) {
if (val >= 0 && (val < minVal || val > maxVal)) { if (val >= 0 && (val < minVal || val > maxVal)) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, code, return generateSyntaxErrMsgExt(&pCxt->msgBuf, code,
"Invalid option %s: %" PRId64 " valid range: [%" PRId64 ", %" PRId64 "]", pName, val, "Invalid option %s: %" PRId64 ", valid range: [%" PRId64 ", %" PRId64 "]", pName,
minVal, maxVal); val, minVal, maxVal);
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -8456,7 +8456,11 @@ static int32_t translateUseDatabase(STranslateContext* pCxt, SUseDatabaseStmt* p
} }
static int32_t translateCreateUser(STranslateContext* pCxt, SCreateUserStmt* pStmt) { static int32_t translateCreateUser(STranslateContext* pCxt, SCreateUserStmt* pStmt) {
int32_t code = 0;
SCreateUserReq createReq = {0}; SCreateUserReq createReq = {0};
if ((code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "sysinfo", pStmt->sysinfo, 0, 1))) {
return code;
}
strcpy(createReq.user, pStmt->userName); strcpy(createReq.user, pStmt->userName);
createReq.createType = 0; createReq.createType = 0;
createReq.superUser = 0; createReq.superUser = 0;
@ -8469,18 +8473,39 @@ static int32_t translateCreateUser(STranslateContext* pCxt, SCreateUserStmt* pSt
createReq.pIpRanges = taosMemoryMalloc(createReq.numIpRanges * sizeof(SIpV4Range)); createReq.pIpRanges = taosMemoryMalloc(createReq.numIpRanges * sizeof(SIpV4Range));
memcpy(createReq.pIpRanges, pStmt->pIpRanges, sizeof(SIpV4Range) * createReq.numIpRanges); memcpy(createReq.pIpRanges, pStmt->pIpRanges, sizeof(SIpV4Range) * createReq.numIpRanges);
} }
int32_t code = buildCmdMsg(pCxt, TDMT_MND_CREATE_USER, (FSerializeFunc)tSerializeSCreateUserReq, &createReq); code = buildCmdMsg(pCxt, TDMT_MND_CREATE_USER, (FSerializeFunc)tSerializeSCreateUserReq, &createReq);
tFreeSCreateUserReq(&createReq); tFreeSCreateUserReq(&createReq);
return code; return code;
} }
static int32_t checkAlterUser(STranslateContext* pCxt, SAlterUserStmt* pStmt) {
int32_t code = 0;
switch (pStmt->alterType) {
case TSDB_ALTER_USER_ENABLE:
code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "enable", pStmt->enable, 0, 1);
break;
case TSDB_ALTER_USER_SYSINFO:
code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "sysinfo", pStmt->sysinfo, 0, 1);
break;
case TSDB_ALTER_USER_CREATEDB:
code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "createdb", pStmt->createdb, 0, 1);
break;
}
return code;
}
static int32_t translateAlterUser(STranslateContext* pCxt, SAlterUserStmt* pStmt) { static int32_t translateAlterUser(STranslateContext* pCxt, SAlterUserStmt* pStmt) {
int32_t code = 0;
SAlterUserReq alterReq = {0}; SAlterUserReq alterReq = {0};
if ((code = checkAlterUser(pCxt, pStmt))) {
return code;
}
strcpy(alterReq.user, pStmt->userName); strcpy(alterReq.user, pStmt->userName);
alterReq.alterType = pStmt->alterType; alterReq.alterType = pStmt->alterType;
alterReq.superUser = 0; alterReq.superUser = 0;
alterReq.enable = pStmt->enable; alterReq.enable = pStmt->enable;
alterReq.sysInfo = pStmt->sysinfo; alterReq.sysInfo = pStmt->sysinfo;
alterReq.createdb = pStmt->createdb ? 1 : 0;
snprintf(alterReq.pass, sizeof(alterReq.pass), "%s", pStmt->password); snprintf(alterReq.pass, sizeof(alterReq.pass), "%s", pStmt->password);
if (NULL != pCxt->pParseCxt->db) { if (NULL != pCxt->pParseCxt->db) {
snprintf(alterReq.objname, sizeof(alterReq.objname), "%s", pCxt->pParseCxt->db); snprintf(alterReq.objname, sizeof(alterReq.objname), "%s", pCxt->pParseCxt->db);
@ -8491,7 +8516,7 @@ static int32_t translateAlterUser(STranslateContext* pCxt, SAlterUserStmt* pStmt
alterReq.pIpRanges = taosMemoryMalloc(alterReq.numIpRanges * sizeof(SIpV4Range)); alterReq.pIpRanges = taosMemoryMalloc(alterReq.numIpRanges * sizeof(SIpV4Range));
memcpy(alterReq.pIpRanges, pStmt->pIpRanges, sizeof(SIpV4Range) * alterReq.numIpRanges); memcpy(alterReq.pIpRanges, pStmt->pIpRanges, sizeof(SIpV4Range) * alterReq.numIpRanges);
} }
int32_t code = buildCmdMsg(pCxt, TDMT_MND_ALTER_USER, (FSerializeFunc)tSerializeSAlterUserReq, &alterReq); code = buildCmdMsg(pCxt, TDMT_MND_ALTER_USER, (FSerializeFunc)tSerializeSAlterUserReq, &alterReq);
tFreeSAlterUserReq(&alterReq); tFreeSAlterUserReq(&alterReq);
return code; return code;
} }

File diff suppressed because it is too large Load Diff

View File

@ -14,6 +14,9 @@ endi
if $data(root)[3] != 1 then if $data(root)[3] != 1 then
return -1 return -1
endi endi
if $data(root)[4] != 1 then
return -1
endi
sql alter user root pass 'taosdata' sql alter user root pass 'taosdata'
@ -21,6 +24,8 @@ sql_error ALTER USER root SYSINFO 0
sql_error ALTER USER root SYSINFO 1 sql_error ALTER USER root SYSINFO 1
sql_error ALTER USER root enable 0 sql_error ALTER USER root enable 0
sql_error ALTER USER root enable 1 sql_error ALTER USER root enable 1
sql_error ALTER USER root createdb 0
sql_error ALTER USER root createdb 1
#sql_error create database db vgroups 1; #sql_error create database db vgroups 1;
sql_error GRANT read ON db.* to root; sql_error GRANT read ON db.* to root;
@ -53,6 +58,9 @@ endi
if $data(u1)[3] != 0 then if $data(u1)[3] != 0 then
return -1 return -1
endi endi
if $data(u1)[4] != 0 then
return -1
endi
sql CREATE USER u2 PASS 'taosdata' SYSINFO 1; sql CREATE USER u2 PASS 'taosdata' SYSINFO 1;
sql select * from information_schema.ins_users sql select * from information_schema.ins_users
@ -68,6 +76,9 @@ endi
if $data(u2)[3] != 1 then if $data(u2)[3] != 1 then
return -1 return -1
endi endi
if $data(u2)[4] != 0 then
return -1
endi
print =============== step2: sysinfo alter print =============== step2: sysinfo alter
sql ALTER USER u1 SYSINFO 1 sql ALTER USER u1 SYSINFO 1
@ -81,6 +92,9 @@ endi
if $data(u1)[3] != 1 then if $data(u1)[3] != 1 then
return -1 return -1
endi endi
if $data(u1)[4] != 0 then
return -1
endi
sql ALTER USER u1 SYSINFO 0 sql ALTER USER u1 SYSINFO 0
sql select * from information_schema.ins_users sql select * from information_schema.ins_users
@ -93,6 +107,9 @@ endi
if $data(u1)[3] != 0 then if $data(u1)[3] != 0 then
return -1 return -1
endi endi
if $data(u1)[4] != 0 then
return -1
endi
sql ALTER USER u1 SYSINFO 0 sql ALTER USER u1 SYSINFO 0
sql ALTER USER u1 SYSINFO 0 sql ALTER USER u1 SYSINFO 0
@ -118,6 +135,9 @@ endi
if $data(u2)[3] != 1 then if $data(u2)[3] != 1 then
return -1 return -1
endi endi
if $data(u2)[4] != 0 then
return -1
endi
sql ALTER USER u2 enable 1 sql ALTER USER u2 enable 1
sql select * from information_schema.ins_users sql select * from information_schema.ins_users
@ -130,15 +150,16 @@ endi
if $data(u2)[3] != 1 then if $data(u2)[3] != 1 then
return -1 return -1
endi endi
if $data(u2)[4] != 0 then
return -1
endi
sql ALTER USER u2 enable 1 sql ALTER USER u2 enable 1
sql ALTER USER u2 enable 1 sql ALTER USER u2 enable 1
print =============== restart taosd
system sh/exec.sh -n dnode1 -s stop
system sh/exec.sh -n dnode1 -s start
print =============== step4: enable privilege print =============== step4: createdb alter
sql ALTER USER u2 createdb 1
sql select * from information_schema.ins_users sql select * from information_schema.ins_users
if $rows != 2 then if $rows != 2 then
return -1 return -1
@ -152,6 +173,58 @@ endi
if $data(u2)[3] != 1 then if $data(u2)[3] != 1 then
return -1 return -1
endi endi
if $data(u2)[4] != 1 then
return -1
endi
sql ALTER USER u2 createdb 0
sql select * from information_schema.ins_users
if $data(u2)[1] != 0 then
return -1
endi
if $data(u2)[2] != 1 then
return -1
endi
if $data(u2)[3] != 1 then
return -1
endi
if $data(u2)[4] != 0 then
return -1
endi
print =============== restart taosd
system sh/exec.sh -n dnode1 -s stop
system sh/exec.sh -n dnode1 -s start
print =============== step5: enable privilege
sql select * from information_schema.ins_users
if $rows != 2 then
return -1
endi
if $data(u2)[1] != 0 then
return -1
endi
if $data(u2)[2] != 1 then
return -1
endi
if $data(u2)[3] != 1 then
return -1
endi
if $data(u2)[4] != 0 then
return -1
endi
sql_error CREATE USER u100 PASS 'taosdata' SYSINFO -1;
sql_error CREATE USER u101 PASS 'taosdata' SYSINFO 2;
sql_error CREATE USER u102 PASS 'taosdata' SYSINFO 20000;
sql_error ALTER USER u1 enable -1
sql_error ALTER USER u1 enable 2
sql_error ALTER USER u1 enable 10000
sql_error ALTER USER u1 sysinfo -1
sql_error ALTER USER u1 sysinfo 2
sql_error ALTER USER u1 sysinfo -20000
sql_error ALTER USER u1 createdb -1
sql_error ALTER USER u1 createdb 3
sql_error ALTER USER u1 createdb 100000
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s stop -x SIGINT

View File

@ -6,6 +6,8 @@ sql connect
print ========================root user create user print ========================root user create user
sql create user u1 pass "taosdata" sql create user u1 pass "taosdata"
sql create user u2 pass "taosdata" sql create user u2 pass "taosdata"
sql alter user u1 createdb 1
sql alter user u2 createdb 1
sql create database test sql create database test
sql select * from information_schema.ins_user_privileges where user_name == "root" sql select * from information_schema.ins_user_privileges where user_name == "root"
if $rows != 1 then if $rows != 1 then

View File

@ -67,6 +67,7 @@ sql_error drop snode on dnode 1
sql_error redistribute vgroup 2 dnode 1 dnode 2 sql_error redistribute vgroup 2 dnode 1 dnode 2
sql_error balance vgroup sql_error balance vgroup
sql_error balance vgroup leader
sql_error kill transaction 1 sql_error kill transaction 1
sql_error kill connection 1 sql_error kill connection 1

View File

@ -222,7 +222,7 @@ class TDTestCase:
tdSql.query("select * from information_schema.ins_columns where db_name ='information_schema'") tdSql.query("select * from information_schema.ins_columns where db_name ='information_schema'")
tdLog.info(len(tdSql.queryResult)) tdLog.info(len(tdSql.queryResult))
tdSql.checkEqual(True, len(tdSql.queryResult) in range(260, 261)) tdSql.checkEqual(True, len(tdSql.queryResult) in range(261, 262))
tdSql.query("select * from information_schema.ins_columns where db_name ='performance_schema'") tdSql.query("select * from information_schema.ins_columns where db_name ='performance_schema'")
tdSql.checkEqual(54, len(tdSql.queryResult)) tdSql.checkEqual(54, len(tdSql.queryResult))

View File

@ -134,6 +134,7 @@ class TDTestCase:
tdSql.prepare() tdSql.prepare()
# time.sleep(2) # time.sleep(2)
tdSql.query("create user testpy pass 'testpy'") tdSql.query("create user testpy pass 'testpy'")
tdSql.query("alter user testpy createdb 1")
#hostname = socket.gethostname() #hostname = socket.gethostname()
#tdLog.info ("hostname: %s" % hostname) #tdLog.info ("hostname: %s" % hostname)

View File

@ -87,21 +87,29 @@ class TDconnect:
self.cursor = self._conn.cursor() self.cursor = self._conn.cursor()
return self return self
def error(self, sql): def error(self, sql, expectErrInfo = None):
caller = inspect.getframeinfo(inspect.stack()[1][0])
expectErrNotOccured = True expectErrNotOccured = True
try: try:
self.cursor.execute(sql) self.cursor.execute(sql)
except BaseException: except BaseException as e:
tdLog.info("err:%s" % (e))
expectErrNotOccured = False expectErrNotOccured = False
self.errno = e.errno
error_info = repr(e)
self.error_info = ','.join(error_info[error_info.index('(')+1:-1].split(",")[:-1]).replace("'","")
if expectErrNotOccured: if expectErrNotOccured:
caller = inspect.getframeinfo(inspect.stack()[1][0])
tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{sql}, expect error not occured" ) tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{sql}, expect error not occured" )
else: else:
if expectErrInfo != None:
if expectErrInfo == self.error_info:
self.queryRows = 0 self.queryRows = 0
self.queryCols = 0 self.queryCols = 0
self.queryResult = None self.queryResult = None
tdLog.info(f"sql:{sql}, expect error occured") tdLog.info("sql:%s, expected ErrInfo '%s' occured" % (sql, expectErrInfo))
else:
tdLog.exit("%s(%d) failed: sql:%s, ErrInfo '%s' occured, but not expected ErrInfo '%s'" % (caller.filename, caller.lineno, sql, self.error_info, expectErrInfo))
def query(self, sql, row_tag=None): def query(self, sql, row_tag=None):
# sourcery skip: raise-from-previous-error, raise-specific-error # sourcery skip: raise-from-previous-error, raise-specific-error
@ -504,6 +512,17 @@ class TDTestCase:
else: else:
tdLog.exit("connect successfully, except error not occrued!") tdLog.exit("connect successfully, except error not occrued!")
def test_alter_user(self):
options = ["enable", "sysinfo", "createdb"]
optionErrVals = [-10000, -128, -1, 2, 127, 10000]
for optionErrVal in optionErrVals:
tdSql.error("create user user_alter pass 'taosdata' sysinfo %d" % optionErrVal)
tdSql.execute("create user user_alter pass 'taosdata'")
for option in options:
for optionErrVal in optionErrVals:
tdSql.error("alter user user_alter %s %d" % (option, optionErrVal))
tdSql.execute("drop user user_alter")
def __drop_user(self, user): def __drop_user(self, user):
return f"DROP USER {user}" return f"DROP USER {user}"
@ -647,6 +666,16 @@ class TDTestCase:
user.error(f"drop user {self.__user_list[0]}") user.error(f"drop user {self.__user_list[0]}")
user.error(f"drop user {self.__user_list[1]}") user.error(f"drop user {self.__user_list[1]}")
user.error("drop user root") user.error("drop user root")
# 普通用户默认不可创建 db
user.error("create database ordinary_user_db", expectErrInfo='Insufficient privilege for operation')
tdSql.execute(f'alter user {self.__user_list[0]} createdb 1')
tdSql.execute(f'alter user {self.__user_list[0]} createdb 0')
tdSql.execute(f'alter user {self.__user_list[0]} createdb 1')
tdSql.execute(f'alter user {self.__user_list[0]} createdb 1')
user.query("create database ordinary_user_db")
user.query("drop database ordinary_user_db")
tdSql.execute(f'alter user {self.__user_list[0]} createdb 0')
user.error("create database ordinary_user_db", expectErrInfo='Insufficient privilege for operation')
tdLog.printNoPrefix("==========step5: enable info") tdLog.printNoPrefix("==========step5: enable info")
taos1_conn = taos.connect(user=self.__user_list[1], password=f"new{self.__passwd_list[1]}") taos1_conn = taos.connect(user=self.__user_list[1], password=f"new{self.__passwd_list[1]}")
@ -702,8 +731,12 @@ class TDTestCase:
else: else:
tdLog.info("taos 4 query except error occured, sysinfo == 0, can not show dnode/vgroups") tdLog.info("taos 4 query except error occured, sysinfo == 0, can not show dnode/vgroups")
# alter 用户测试
tdLog.printNoPrefix("==========step7: alter ordinary user")
self.test_alter_user()
# root删除用户测试 # root删除用户测试
tdLog.printNoPrefix("==========step7: super user drop normal user") tdLog.printNoPrefix("==========step8: super user drop normal user")
self.test_drop_user() self.test_drop_user()
tdSql.query("show users") tdSql.query("show users")

View File

@ -80,6 +80,7 @@ class TDTestCase:
def create_user(self, username, password): def create_user(self, username, password):
tdSql.execute(f"create user {username} pass '{password}';") tdSql.execute(f"create user {username} pass '{password}';")
tdSql.execute(f"alter user {username} createdb 1;")
tdLog.debug("Create user {} with password {} successfully".format(username, password)) tdLog.debug("Create user {} with password {} successfully".format(username, password))
def check_permissions(self, username, db_name, permission_dict, view_name=None): def check_permissions(self, username, db_name, permission_dict, view_name=None):