From cba224d4a002efd32524f578bd42e834e07fdcc6 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 12 Jan 2021 12:06:24 +0800 Subject: [PATCH] [TD-2720]: change the password length by using another macro definition. --- src/client/inc/tsclient.h | 4 ++-- src/client/src/tscSQLParser.c | 4 ++-- src/client/src/tscSql.c | 8 ++++---- src/cq/src/cqMain.c | 2 +- src/inc/taosdef.h | 18 ++++-------------- src/inc/taosmsg.h | 12 ++++++------ src/inc/tcq.h | 2 +- src/mnode/inc/mnodeDef.h | 4 ++-- src/mnode/src/mnodeVgroup.c | 2 +- src/plugins/http/inc/httpInt.h | 4 ++-- src/plugins/http/src/httpAuth.c | 8 ++++---- src/plugins/http/src/httpGcHandle.c | 4 ++-- src/plugins/http/src/httpRestHandle.c | 4 ++-- src/plugins/http/src/httpTgHandle.c | 2 +- src/vnode/inc/vnodeInt.h | 2 +- 15 files changed, 35 insertions(+), 45 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index a3a086ce77..f611bdfd31 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -300,8 +300,8 @@ typedef struct STscObj { void * pTimer; char user[TSDB_USER_LEN]; char pass[TSDB_KEY_LEN]; - char acctId[TSDB_ACCT_LEN]; - char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN]; + char acctId[TSDB_ACCT_ID_LEN]; + char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; char sversion[TSDB_VERSION_LEN]; char writeAuth : 1; char superAuth : 1; diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index a08482f570..3d9a467f40 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -221,7 +221,7 @@ static int32_t handlePassword(SSqlCmd* pCmd, SStrToken* pPwd) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); } - if (pPwd->n >= TSDB_PASSWORD_LEN) { + if (pPwd->n >= TSDB_KEY_LEN) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); } @@ -1242,7 +1242,7 @@ int32_t setObjFullName(char* fullName, const char* account, SStrToken* pDB, SStr /* db name is not specified, the tableName dose not include db name */ if (pDB != NULL) { - if (pDB->n >= TSDB_ACCT_LEN + TSDB_DB_NAME_LEN || pDB->n == 0) { + if (pDB->n >= TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN || pDB->n == 0) { return TSDB_CODE_TSC_INVALID_SQL; } diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index da86b4cb19..b809c4a5e5 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -47,7 +47,7 @@ static bool validUserName(const char* user) { } static bool validPassword(const char* passwd) { - return validImpl(passwd, TSDB_PASSWORD_LEN - 1); + return validImpl(passwd, TSDB_KEY_LEN - 1); } static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, const char *auth, const char *db, @@ -238,11 +238,11 @@ TAOS *taos_connect_c(const char *ip, uint8_t ipLen, const char *user, uint8_t us uint8_t passLen, const char *db, uint8_t dbLen, uint16_t port) { char ipBuf[TSDB_EP_LEN] = {0}; char userBuf[TSDB_USER_LEN] = {0}; - char passBuf[TSDB_PASSWORD_LEN] = {0}; + char passBuf[TSDB_KEY_LEN] = {0}; char dbBuf[TSDB_DB_NAME_LEN] = {0}; strncpy(ipBuf, ip, MIN(TSDB_EP_LEN - 1, ipLen)); strncpy(userBuf, user, MIN(TSDB_USER_LEN - 1, userLen)); - strncpy(passBuf, pass, MIN(TSDB_PASSWORD_LEN - 1, passLen)); + strncpy(passBuf, pass, MIN(TSDB_KEY_LEN - 1, passLen)); strncpy(dbBuf, db, MIN(TSDB_DB_NAME_LEN - 1, dbLen)); return taos_connect(ipBuf, userBuf, passBuf, dbBuf, port); } @@ -978,7 +978,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t return code; } - if (++pCmd->count > TSDB_MULTI_METERMETA_MAX_NUM) { + if (++pCmd->count > TSDB_MULTI_TABLEMETA_MAX_NUM) { code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; sprintf(pCmd->payload, "tables over the max number"); return code; diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index a0df8247b7..0fe5ea78d4 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -43,7 +43,7 @@ typedef struct { int32_t master; int32_t num; // number of continuous streams char user[TSDB_USER_LEN]; - char pass[TSDB_PASSWORD_LEN]; + char pass[TSDB_KEY_LEN]; char db[TSDB_DB_NAME_LEN]; FCqWrite cqWrite; struct SCqObj *pHead; diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index 9a52cb3bee..c11d404aeb 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -256,10 +256,8 @@ int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bo #define TSDB_USER_LEN TSDB_UNI_LEN // ACCOUNT is a 32 bit positive integer -// this is the length of its string representation -// including the terminator zero -#define TSDB_ACCT_LEN 11 -#define TSDB_PASSWORD_LEN TSDB_UNI_LEN +// this is the length of its string representation, including the terminator zero +#define TSDB_ACCT_ID_LEN 11 #define TSDB_MAX_COLUMNS 1024 #define TSDB_MIN_COLUMNS 2 //PRIMARY COLUMN(timestamp) + other columns @@ -267,7 +265,7 @@ int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bo #define TSDB_NODE_NAME_LEN 64 #define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string #define TSDB_DB_NAME_LEN 33 -#define TSDB_TABLE_FNAME_LEN (TSDB_ACCT_LEN + TSDB_DB_NAME_LEN + TSDB_TABLE_NAME_LEN) +#define TSDB_TABLE_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN + TSDB_TABLE_NAME_LEN) #define TSDB_COL_NAME_LEN 65 #define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64 #define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE @@ -293,11 +291,6 @@ int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bo #define TSDB_EP_LEN (TSDB_FQDN_LEN+6) #define TSDB_IPv4ADDR_LEN 16 #define TSDB_FILENAME_LEN 128 -#define TSDB_METER_VNODE_BITS 20 -#define TSDB_METER_SID_MASK 0xFFFFF -#define TSDB_SHELL_VNODE_BITS 24 -#define TSDB_SHELL_SID_MASK 0xFF -#define TSDB_HTTP_TOKEN_LEN 20 #define TSDB_SHOW_SQL_LEN 512 #define TSDB_SLOW_QUERY_SQL_LEN 512 @@ -311,9 +304,6 @@ int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bo #define TSDB_MQTT_TOPIC_LEN 64 #define TSDB_MQTT_CLIENT_ID_LEN 32 -#define TSDB_METER_STATE_OFFLINE 0 -#define TSDB_METER_STATE_ONLLINE 1 - #define TSDB_DEFAULT_PKT_SIZE 65480 //same as RPC_MAX_UDP_SIZE #define TSDB_PAYLOAD_SIZE TSDB_DEFAULT_PKT_SIZE @@ -333,7 +323,7 @@ int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bo #define TSDB_TBNAME_COLUMN_INDEX (-1) #define TSDB_UD_COLUMN_INDEX (-100) -#define TSDB_MULTI_METERMETA_MAX_NUM 100000 // maximum batch size allowed to load metermeta +#define TSDB_MULTI_TABLEMETA_MAX_NUM 100000 // maximum batch size allowed to load table meta #define TSDB_MIN_CACHE_BLOCK_SIZE 1 #define TSDB_MAX_CACHE_BLOCK_SIZE 128 // 128MB for each vnode diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 2dee6dc3bb..905867fbc7 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -268,7 +268,7 @@ typedef struct { typedef struct { int32_t len; // one create table message char tableId[TSDB_TABLE_FNAME_LEN]; - char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN]; + char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; int8_t igExists; int8_t getMeta; int16_t numOfTags; @@ -290,7 +290,7 @@ typedef struct { typedef struct { char tableId[TSDB_TABLE_FNAME_LEN]; - char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN]; + char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; int16_t type; /* operation type */ int16_t numOfCols; /* number of schema */ int32_t tagValLen; @@ -322,7 +322,7 @@ typedef struct { } SConnectMsg; typedef struct { - char acctId[TSDB_ACCT_LEN]; + char acctId[TSDB_ACCT_ID_LEN]; char serverVersion[TSDB_VERSION_LEN]; char clusterId[TSDB_CLUSTER_ID_LEN]; int8_t writeAuth; @@ -534,7 +534,7 @@ typedef struct { } SVnodeLoad; typedef struct { - char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN]; + char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; int32_t cacheBlockSize; //MB int32_t totalBlocks; int32_t maxTables; @@ -682,7 +682,7 @@ typedef struct { } SVnodeDesc; typedef struct { - char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN]; + char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; SVnodeCfg cfg; SVnodeDesc nodes[TSDB_MAX_REPLICA]; } SCreateVnodeMsg, SAlterVnodeMsg; @@ -761,7 +761,7 @@ typedef struct { */ typedef struct { int8_t type; - char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN]; + char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; uint16_t payloadLen; char payload[]; } SShowMsg; diff --git a/src/inc/tcq.h b/src/inc/tcq.h index ad123d4080..1941649d0a 100644 --- a/src/inc/tcq.h +++ b/src/inc/tcq.h @@ -26,7 +26,7 @@ typedef int32_t (*FCqWrite)(int32_t vgId, void *pHead, int32_t qtype, void *pMsg typedef struct { int32_t vgId; char user[TSDB_USER_LEN]; - char pass[TSDB_PASSWORD_LEN]; + char pass[TSDB_KEY_LEN]; char db[TSDB_DB_NAME_LEN]; FCqWrite cqWrite; } SCqCfg; diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h index a07607e615..47d485d97c 100644 --- a/src/mnode/inc/mnodeDef.h +++ b/src/mnode/inc/mnodeDef.h @@ -138,7 +138,7 @@ typedef struct SVgObj { int64_t createdTime; int32_t lbDnodeId; int32_t lbTime; - char dbName[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN]; + char dbName[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; int8_t inUse; int8_t accessState; int8_t status; @@ -179,7 +179,7 @@ typedef struct { } SDbCfg; typedef struct SDbObj { - char name[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN]; + char name[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; int8_t reserved0[4]; char acct[TSDB_USER_LEN]; int64_t createdTime; diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index 827be0687d..881ef95fca 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -565,7 +565,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg) { SDbObj *pDb = pMsg->pDb; SVgObj *pVgroup = (SVgObj *)calloc(1, sizeof(SVgObj)); - tstrncpy(pVgroup->dbName, pDb->name, TSDB_ACCT_LEN + TSDB_DB_NAME_LEN); + tstrncpy(pVgroup->dbName, pDb->name, TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN); pVgroup->numOfVnodes = pDb->cfg.replications; pVgroup->createdTime = taosGetTimestampMs(); pVgroup->accessState = TSDB_VN_ALL_ACCCESS; diff --git a/src/plugins/http/inc/httpInt.h b/src/plugins/http/inc/httpInt.h index ebdfabf310..ac182b707b 100644 --- a/src/plugins/http/inc/httpInt.h +++ b/src/plugins/http/inc/httpInt.h @@ -39,7 +39,7 @@ #define HTTP_GC_TARGET_SIZE 512 #define HTTP_WRITE_RETRY_TIMES 500 #define HTTP_WRITE_WAIT_TIME_MS 5 -#define HTTP_SESSION_ID_LEN (TSDB_USER_LEN + TSDB_PASSWORD_LEN) +#define HTTP_SESSION_ID_LEN (TSDB_USER_LEN + TSDB_KEY_LEN) typedef enum HttpReqType { HTTP_REQTYPE_OTHERS = 0, @@ -147,7 +147,7 @@ typedef struct HttpContext { uint8_t parsed; char ipstr[22]; char user[TSDB_USER_LEN]; // parsed from auth token or login message - char pass[TSDB_PASSWORD_LEN]; + char pass[TSDB_KEY_LEN]; TAOS * taos; void * ppContext; HttpSession *session; diff --git a/src/plugins/http/src/httpAuth.c b/src/plugins/http/src/httpAuth.c index 8beef7c042..56da8a7089 100644 --- a/src/plugins/http/src/httpAuth.c +++ b/src/plugins/http/src/httpAuth.c @@ -51,7 +51,7 @@ int32_t httpParseBasicAuthToken(HttpContext *pContext, char *token, int32_t len) char *password = user + 1; int32_t pass_len = (int32_t)((base64 + outlen) - password); - if (pass_len < 1 || pass_len >= TSDB_PASSWORD_LEN) { + if (pass_len < 1 || pass_len >= TSDB_KEY_LEN) { httpError("context:%p, fd:%d, basic token:%s parse password error", pContext, pContext->fd, token); free(base64); return -1; @@ -73,7 +73,7 @@ int32_t httpParseTaosdAuthToken(HttpContext *pContext, char *token, int32_t len) if (base64) free(base64); return 01; } - if (outlen != (TSDB_USER_LEN + TSDB_PASSWORD_LEN)) { + if (outlen != (TSDB_USER_LEN + TSDB_KEY_LEN)) { httpError("context:%p, fd:%d, taosd token:%s length error", pContext, pContext->fd, token); free(base64); return -1; @@ -103,8 +103,8 @@ int32_t httpGenTaosdAuthToken(HttpContext *pContext, char *token, int32_t maxLen size = sizeof(pContext->pass); tstrncpy(buffer + sizeof(pContext->user), pContext->pass, size); - char *encrypt = taosDesEncode(KEY_DES_4, buffer, TSDB_USER_LEN + TSDB_PASSWORD_LEN); - char *base64 = base64_encode((const unsigned char *)encrypt, TSDB_USER_LEN + TSDB_PASSWORD_LEN); + char *encrypt = taosDesEncode(KEY_DES_4, buffer, TSDB_USER_LEN + TSDB_KEY_LEN); + char *base64 = base64_encode((const unsigned char *)encrypt, TSDB_USER_LEN + TSDB_KEY_LEN); size_t len = strlen(base64); tstrncpy(token, base64, len + 1); diff --git a/src/plugins/http/src/httpGcHandle.c b/src/plugins/http/src/httpGcHandle.c index 5d4cb0c680..c21799e736 100644 --- a/src/plugins/http/src/httpGcHandle.c +++ b/src/plugins/http/src/httpGcHandle.c @@ -59,11 +59,11 @@ bool gcGetUserFromUrl(HttpContext* pContext) { bool gcGetPassFromUrl(HttpContext* pContext) { HttpParser* pParser = pContext->parser; - if (pParser->path[GC_PASS_URL_POS].pos >= TSDB_PASSWORD_LEN || pParser->path[GC_PASS_URL_POS].pos <= 0) { + if (pParser->path[GC_PASS_URL_POS].pos >= TSDB_KEY_LEN || pParser->path[GC_PASS_URL_POS].pos <= 0) { return false; } - tstrncpy(pContext->pass, pParser->path[GC_PASS_URL_POS].str, TSDB_PASSWORD_LEN); + tstrncpy(pContext->pass, pParser->path[GC_PASS_URL_POS].str, TSDB_KEY_LEN); return true; } diff --git a/src/plugins/http/src/httpRestHandle.c b/src/plugins/http/src/httpRestHandle.c index 0a28c431ef..66f1db1a54 100644 --- a/src/plugins/http/src/httpRestHandle.c +++ b/src/plugins/http/src/httpRestHandle.c @@ -72,11 +72,11 @@ bool restGetUserFromUrl(HttpContext* pContext) { bool restGetPassFromUrl(HttpContext* pContext) { HttpParser* pParser = pContext->parser; - if (pParser->path[REST_PASS_URL_POS].pos >= TSDB_PASSWORD_LEN || pParser->path[REST_PASS_URL_POS].pos <= 0) { + if (pParser->path[REST_PASS_URL_POS].pos >= TSDB_KEY_LEN || pParser->path[REST_PASS_URL_POS].pos <= 0) { return false; } - tstrncpy(pContext->pass, pParser->path[REST_PASS_URL_POS].str, TSDB_PASSWORD_LEN); + tstrncpy(pContext->pass, pParser->path[REST_PASS_URL_POS].str, TSDB_KEY_LEN); return true; } diff --git a/src/plugins/http/src/httpTgHandle.c b/src/plugins/http/src/httpTgHandle.c index e2b57b87bb..0a3ef539e3 100644 --- a/src/plugins/http/src/httpTgHandle.c +++ b/src/plugins/http/src/httpTgHandle.c @@ -324,7 +324,7 @@ bool tgGetUserFromUrl(HttpContext *pContext) { bool tgGetPassFromUrl(HttpContext *pContext) { HttpParser *pParser = pContext->parser; - if (pParser->path[TG_PASS_URL_POS].pos >= TSDB_PASSWORD_LEN || pParser->path[TG_PASS_URL_POS].pos <= 0) { + if (pParser->path[TG_PASS_URL_POS].pos >= TSDB_KEY_LEN || pParser->path[TG_PASS_URL_POS].pos <= 0) { return false; } diff --git a/src/vnode/inc/vnodeInt.h b/src/vnode/inc/vnodeInt.h index 7adeda590a..3ec77bbc12 100644 --- a/src/vnode/inc/vnodeInt.h +++ b/src/vnode/inc/vnodeInt.h @@ -67,7 +67,7 @@ typedef struct { void * qMgmt; char * rootDir; tsem_t sem; - char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN]; + char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; pthread_mutex_t statusMutex; } SVnodeObj; -- GitLab