From 8c416a5e4e3c990cb5c9c4c642a611eae1c21331 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 10 Dec 2021 17:28:09 +0800 Subject: [PATCH] [td-10564] refactor and add test cases. --- include/common/taosmsg.h | 8 +-- include/util/tdef.h | 2 +- include/util/tutil.h | 14 +++- source/client/inc/clientInt.h | 4 +- source/client/src/client.c | 4 +- source/client/src/clientImpl.c | 8 +-- source/client/src/clientmain.c | 4 ++ source/client/src/tscEnv.c | 76 +++++++++++----------- source/client/test/clientTests.cpp | 1 + source/dnode/mgmt/impl/src/dndTransport.c | 12 ++-- source/dnode/mgmt/impl/test/sut/deploy.cpp | 2 +- source/dnode/mnode/impl/inc/mndDef.h | 2 +- source/dnode/mnode/impl/src/mndUser.c | 6 +- source/libs/sync/src/sync.c | 2 +- source/libs/transport/src/rpcMain.c | 18 ++--- source/os/src/osString.c | 6 +- src/inc/tcq.h | 4 +- 17 files changed, 95 insertions(+), 78 deletions(-) diff --git a/include/common/taosmsg.h b/include/common/taosmsg.h index 2769f8bc7a..ca250ab169 100644 --- a/include/common/taosmsg.h +++ b/include/common/taosmsg.h @@ -379,7 +379,7 @@ typedef struct { typedef struct { char user[TSDB_USER_LEN]; - char pass[TSDB_KEY_LEN]; + char pass[TSDB_PASSWORD_LEN]; int32_t maxUsers; int32_t maxDbs; int32_t maxTimeSeries; @@ -394,7 +394,7 @@ typedef struct { typedef struct { char user[TSDB_USER_LEN]; - char pass[TSDB_KEY_LEN]; + char pass[TSDB_PASSWORD_LEN]; } SCreateUserMsg, SAlterUserMsg; typedef struct { @@ -912,8 +912,8 @@ typedef struct { char user[TSDB_USER_LEN]; char spi; char encrypt; - char secret[TSDB_KEY_LEN]; - char ckey[TSDB_KEY_LEN]; + char secret[TSDB_PASSWORD_LEN]; + char ckey[TSDB_PASSWORD_LEN]; } SAuthMsg, SAuthRsp; typedef struct { diff --git a/include/util/tdef.h b/include/util/tdef.h index d227888582..5be7df2c14 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -188,7 +188,7 @@ do { \ #define TSDB_MAX_TAG_CONDITIONS 1024 #define TSDB_AUTH_LEN 16 -#define TSDB_KEY_LEN 64 +#define TSDB_PASSWORD_LEN 64 #define TSDB_VERSION_LEN 12 #define TSDB_LABEL_LEN 8 diff --git a/include/util/tutil.h b/include/util/tutil.h index 573dee9339..189cc2b728 100644 --- a/include/util/tutil.h +++ b/include/util/tutil.h @@ -51,7 +51,19 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *tar MD5Init(&context); MD5Update(&context, inBuf, (unsigned int)inLen); MD5Final(&context); - memcpy(target, context.digest, TSDB_KEY_LEN); + memcpy(target, context.digest, tListLen(context.digest)); +} + +static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *target) { + MD5_CTX context; + MD5Init(&context); + MD5Update(&context, inBuf, (unsigned int)len); + + MD5Final(&context); + sprintf(target, "%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x", context.digest[0], context.digest[1], context.digest[2], + context.digest[3], context.digest[4], context.digest[5], context.digest[6], context.digest[7], + context.digest[8], context.digest[9], context.digest[10], context.digest[11], context.digest[12], + context.digest[13], context.digest[14], context.digest[15]); } #ifdef __cplusplus diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 4fed198ab6..fb405e50c2 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -71,7 +71,7 @@ typedef struct SAppInfo { typedef struct STscObj { char user[TSDB_USER_LEN]; - char pass[TSDB_KEY_LEN]; + char pass[TSDB_PASSWORD_LEN]; char acctId[TSDB_ACCT_ID_LEN]; char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; uint32_t connId; @@ -117,7 +117,7 @@ void destroyRequest(void* p); TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, const char *auth, const char *db, uint16_t port); void taos_init_imp(void); -int taos_options_imp(TSDB_OPTION option, const char *pStr); +int taos_options_imp(TSDB_OPTION option, const char *str); #ifdef __cplusplus } diff --git a/source/client/src/client.c b/source/client/src/client.c index 8aef77e9e7..a99c7c44bc 100644 --- a/source/client/src/client.c +++ b/source/client/src/client.c @@ -53,11 +53,11 @@ TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, c char ipStr[TSDB_EP_LEN] = {0}; char dbStr[TSDB_DB_NAME_LEN] = {0}; char userStr[TSDB_USER_LEN] = {0}; - char passStr[TSDB_KEY_LEN] = {0}; + char passStr[TSDB_PASSWORD_LEN] = {0}; strncpy(ipStr, ip, MIN(TSDB_EP_LEN - 1, ipLen)); strncpy(userStr, user, MIN(TSDB_USER_LEN - 1, userLen)); - strncpy(passStr, pass, MIN(TSDB_KEY_LEN - 1, passLen)); + strncpy(passStr, pass, MIN(TSDB_PASSWORD_LEN - 1, passLen)); strncpy(dbStr, db, MIN(TSDB_DB_NAME_LEN - 1, dbLen)); return taos_connect(ipStr, userStr, passStr, dbStr, port); } diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index e7940e27b0..89ca302099 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -26,7 +26,7 @@ static bool validateUserName(const char* user) { } static bool validatePassword(const char* passwd) { - return stringLengthCheck(passwd, TSDB_KEY_LEN - 1); + return stringLengthCheck(passwd, TSDB_PASSWORD_LEN - 1); } static bool validateDbName(const char* db) { @@ -52,14 +52,14 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, strdequote(tmp); } - char secretEncrypt[32] = {0}; + char secretEncrypt[64] = {0}; if (auth == NULL) { if (!validatePassword(pass)) { terrno = TSDB_CODE_TSC_INVALID_PASS_LENGTH; return NULL; } - taosEncryptPass((uint8_t *)pass, strlen(pass), secretEncrypt); + taosEncryptPass_c((uint8_t *)pass, strlen(pass), secretEncrypt); } else { tstrncpy(secretEncrypt, auth, tListLen(secretEncrypt)); } @@ -79,7 +79,7 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, } } - return taosConnectImpl(ip, user, auth, db, port, NULL, NULL); + return taosConnectImpl(ip, user, &secretEncrypt[0], db, port, NULL, NULL); } int initEpSetFromCfg(const char *firstEp, const char *secondEp, SRpcCorEpSet *pEpSet) { diff --git a/source/client/src/clientmain.c b/source/client/src/clientmain.c index 7dac304c58..ce3ef41f18 100644 --- a/source/client/src/clientmain.c +++ b/source/client/src/clientmain.c @@ -74,6 +74,10 @@ void taos_cleanup(void) { } void taos_close(TAOS* taos) { + if (taos == NULL) { + return; + } + } diff --git a/source/client/src/tscEnv.c b/source/client/src/tscEnv.c index 0d667b0d19..13ae76ea40 100644 --- a/source/client/src/tscEnv.c +++ b/source/client/src/tscEnv.c @@ -70,6 +70,22 @@ static void deregisterRequest(SRequestObj* pRequest) { taosReleaseRef(tscConnRef, pTscObj->id); } +static void tscInitLogFile() { + taosReadGlobalLogCfg(); + if (mkdir(tsLogDir, 0755) != 0 && errno != EEXIST) { + printf("failed to create log dir:%s\n", tsLogDir); + } + + const char *defaultLogFileNamePrefix = "taoslog"; + const int32_t maxLogFileNum = 10; + + char temp[128] = {0}; + sprintf(temp, "%s/%s", tsLogDir, defaultLogFileNamePrefix); + if (taosInitLog(temp, tsNumOfLogLines, maxLogFileNum) < 0) { + printf("failed to open log file in directory:%s\n", tsLogDir); + } +} + void tscFreeRpcObj(void *param) { #if 0 assert(param); @@ -200,22 +216,6 @@ void destroyRequest(void* p) { deregisterRequest(pRequest); } -static void tscInitLogFile() { - taosReadGlobalLogCfg(); - if (mkdir(tsLogDir, 0755) != 0 && errno != EEXIST) { - printf("failed to create log dir:%s\n", tsLogDir); - } - - const char *defaultLogFileNamePrefix = "taoslog"; - const int32_t maxLogFileNum = 10; - - char temp[128] = {0}; - sprintf(temp, "%s/%s", tsLogDir, defaultLogFileNamePrefix); - if (taosInitLog(temp, tsNumOfLogLines, maxLogFileNum) < 0) { - printf("failed to open log file in directory:%s\n", tsLogDir); - } -} - void taos_init_imp(void) { // In the APIs of other program language, taos_cleanup is not available yet. // So, to make sure taos_cleanup will be invoked to clean up the allocated resource to suppress the valgrind warning. @@ -268,7 +268,7 @@ void taos_init_imp(void) { tscDebug("client is initialized successfully"); } -int taos_options_imp(TSDB_OPTION option, const char *pStr) { +int taos_options_imp(TSDB_OPTION option, const char *str) { SGlobalCfg *cfg = NULL; switch (option) { @@ -277,11 +277,11 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) { assert(cfg != NULL); if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { - tstrncpy(configDir, pStr, TSDB_FILENAME_LEN); + tstrncpy(configDir, str, TSDB_FILENAME_LEN); cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; - tscInfo("set config file directory:%s", pStr); + tscInfo("set config file directory:%s", str); } else { - tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, pStr, tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr); + tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, str, tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr); } break; @@ -290,13 +290,13 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) { assert(cfg != NULL); if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { - tsShellActivityTimer = atoi(pStr); + tsShellActivityTimer = atoi(str); if (tsShellActivityTimer < 1) tsShellActivityTimer = 1; if (tsShellActivityTimer > 3600) tsShellActivityTimer = 3600; cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; tscInfo("set shellActivityTimer:%d", tsShellActivityTimer); } else { - tscWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, pStr, tsCfgStatusStr[cfg->cfgStatus], *(int32_t *)cfg->ptr); + tscWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, str, tsCfgStatusStr[cfg->cfgStatus], *(int32_t *)cfg->ptr); } break; @@ -304,9 +304,9 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) { cfg = taosGetConfigOption("locale"); assert(cfg != NULL); - size_t len = strlen(pStr); + size_t len = strlen(str); if (len == 0 || len > TSDB_LOCALE_LEN) { - tscInfo("Invalid locale:%s, use default", pStr); + tscInfo("Invalid locale:%s, use default", str); return -1; } @@ -327,14 +327,14 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) { } // set the user specified locale - char *locale = setlocale(LC_CTYPE, pStr); + char *locale = setlocale(LC_CTYPE, str); if (locale != NULL) { // failed to set the user specified locale tscInfo("locale set, prev locale:%s, new locale:%s", tsLocale, locale); cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; } else { // set the user specified locale failed, use default LC_CTYPE as current locale locale = setlocale(LC_CTYPE, tsLocale); - tscInfo("failed to set locale:%s, current locale:%s", pStr, tsLocale); + tscInfo("failed to set locale:%s, current locale:%s", str, tsLocale); } tstrncpy(tsLocale, locale, TSDB_LOCALE_LEN); @@ -364,7 +364,7 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) { tscInfo("charset remains:%s", tsCharset); } } else { - tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, pStr, tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr); + tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, str, tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr); } break; } @@ -374,27 +374,27 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) { cfg = taosGetConfigOption("charset"); assert(cfg != NULL); - size_t len = strlen(pStr); + size_t len = strlen(str); if (len == 0 || len > TSDB_LOCALE_LEN) { - tscInfo("failed to set charset:%s", pStr); + tscInfo("failed to set charset:%s", str); return -1; } if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { - if (taosValidateEncodec(pStr)) { + if (taosValidateEncodec(str)) { if (strlen(tsCharset) == 0) { - tscInfo("charset is set:%s", pStr); + tscInfo("charset is set:%s", str); } else { - tscInfo("charset changed from %s to %s", tsCharset, pStr); + tscInfo("charset changed from %s to %s", tsCharset, str); } - tstrncpy(tsCharset, pStr, TSDB_LOCALE_LEN); + tstrncpy(tsCharset, str, TSDB_LOCALE_LEN); cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; } else { - tscInfo("charset:%s not valid", pStr); + tscInfo("charset:%s not valid", str); } } else { - tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, pStr, tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr); + tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, str, tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr); } break; @@ -405,12 +405,12 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) { assert(cfg != NULL); if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { - tstrncpy(tsTimezone, pStr, TSDB_TIMEZONE_LEN); + tstrncpy(tsTimezone, str, TSDB_TIMEZONE_LEN); tsSetTimeZone(); cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; - tscDebug("timezone set:%s, input:%s by taos_options", tsTimezone, pStr); + tscDebug("timezone set:%s, input:%s by taos_options", tsTimezone, str); } else { - tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, pStr, tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr); + tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, str, tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr); } break; diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 4f848a0750..a828d2e079 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -34,4 +34,5 @@ int main(int argc, char** argv) { TEST(testCase, driverInit_Test) { taos_init(); + TAOS* pTaos = taos_connect("ubuntu", "root", "taosdata", NULL, 0); } \ No newline at end of file diff --git a/source/dnode/mgmt/impl/src/dndTransport.c b/source/dnode/mgmt/impl/src/dndTransport.c index 98a0b8e308..07bbe6c0f6 100644 --- a/source/dnode/mgmt/impl/src/dndTransport.c +++ b/source/dnode/mgmt/impl/src/dndTransport.c @@ -240,18 +240,18 @@ static void dndSendMsgToMnodeRecv(SDnode *pDnode, SRpcMsg *pRpcMsg, SRpcMsg *pRp static int32_t dndAuthInternalMsg(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) { if (strcmp(user, INTERNAL_USER) == 0) { // A simple temporary implementation - char pass[32] = {0}; + char pass[TSDB_PASSWORD_LEN] = {0}; taosEncryptPass((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass); - memcpy(secret, pass, TSDB_KEY_LEN); + memcpy(secret, pass, TSDB_PASSWORD_LEN); *spi = 0; *encrypt = 0; *ckey = 0; return 0; } else if (strcmp(user, TSDB_NETTEST_USER) == 0) { // A simple temporary implementation - char pass[32] = {0}; + char pass[TSDB_PASSWORD_LEN] = {0}; taosEncryptPass((uint8_t *)(TSDB_NETTEST_USER), strlen(TSDB_NETTEST_USER), pass); - memcpy(secret, pass, TSDB_KEY_LEN); + memcpy(secret, pass, TSDB_PASSWORD_LEN); *spi = 0; *encrypt = 0; *ckey = 0; @@ -293,8 +293,8 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char dError("user:%s, failed to get user auth from other mnodes since %s", user, terrstr()); } else { SAuthRsp *pRsp = rpcRsp.pCont; - memcpy(secret, pRsp->secret, TSDB_KEY_LEN); - memcpy(ckey, pRsp->ckey, TSDB_KEY_LEN); + memcpy(secret, pRsp->secret, TSDB_PASSWORD_LEN); + memcpy(ckey, pRsp->ckey, TSDB_PASSWORD_LEN); *spi = pRsp->spi; *encrypt = pRsp->encrypt; dDebug("user:%s, success to get user auth from other mnodes", user); diff --git a/source/dnode/mgmt/impl/test/sut/deploy.cpp b/source/dnode/mgmt/impl/test/sut/deploy.cpp index c484ea122d..8a84733fa3 100644 --- a/source/dnode/mgmt/impl/test/sut/deploy.cpp +++ b/source/dnode/mgmt/impl/test/sut/deploy.cpp @@ -107,7 +107,7 @@ SClient* createClient(const char* user, const char* pass, const char* fqdn, uint SClient* pClient = (SClient*)calloc(1, sizeof(SClient)); ASSERT(pClient); - char secretEncrypt[32] = {0}; + char secretEncrypt[TSDB_PASSWORD_LEN] = {0}; taosEncryptPass((uint8_t*)pass, strlen(pass), secretEncrypt); SRpcInit rpcInit; diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 9e4f922540..7da92c84bb 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -181,7 +181,7 @@ typedef struct SAcctObj { typedef struct SUserObj { char user[TSDB_USER_LEN]; - char pass[TSDB_KEY_LEN]; + char pass[TSDB_PASSWORD_LEN]; char acct[TSDB_USER_LEN]; int64_t createdTime; int64_t updateTime; diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index a3dd255577..c5162d8595 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -92,7 +92,7 @@ static SSdbRaw *mndUserActionEncode(SUserObj *pUser) { int32_t dataPos = 0; SDB_SET_BINARY(pRaw, dataPos, pUser->user, TSDB_USER_LEN) - SDB_SET_BINARY(pRaw, dataPos, pUser->pass, TSDB_KEY_LEN) + SDB_SET_BINARY(pRaw, dataPos, pUser->pass, TSDB_PASSWORD_LEN) SDB_SET_BINARY(pRaw, dataPos, pUser->acct, TSDB_USER_LEN) SDB_SET_INT64(pRaw, dataPos, pUser->createdTime) SDB_SET_INT64(pRaw, dataPos, pUser->updateTime) @@ -120,7 +120,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { int32_t dataPos = 0; SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->user, TSDB_USER_LEN) - SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->pass, TSDB_KEY_LEN) + SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->pass, TSDB_PASSWORD_LEN) SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->acct, TSDB_USER_LEN) SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->createdTime) SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->updateTime) @@ -165,7 +165,7 @@ static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) { static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pSrcUser, SUserObj *pDstUser) { mTrace("user:%s, perform update action", pSrcUser->user); memcpy(pSrcUser->user, pDstUser->user, TSDB_USER_LEN); - memcpy(pSrcUser->pass, pDstUser->pass, TSDB_KEY_LEN); + memcpy(pSrcUser->pass, pDstUser->pass, TSDB_PASSWORD_LEN); memcpy(pSrcUser->acct, pDstUser->acct, TSDB_USER_LEN); pSrcUser->createdTime = pDstUser->createdTime; pSrcUser->updateTime = pDstUser->updateTime; diff --git a/source/libs/sync/src/sync.c b/source/libs/sync/src/sync.c index 06af8ff6c2..e49b1d7983 100644 --- a/source/libs/sync/src/sync.c +++ b/source/libs/sync/src/sync.c @@ -228,7 +228,7 @@ static int syncInitRpcServer(SSyncManager* syncManager, const SSyncCluster* pSyn } static int syncInitRpcClient(SSyncManager* syncManager) { - char secret[TSDB_KEY_LEN] = "secret"; + char secret[TSDB_PASSWORD_LEN] = "secret"; SRpcInit rpcInit; memset(&rpcInit, 0, sizeof(rpcInit)); rpcInit.label = "sync-client"; diff --git a/source/libs/transport/src/rpcMain.c b/source/libs/transport/src/rpcMain.c index e392351366..56d5228c2d 100644 --- a/source/libs/transport/src/rpcMain.c +++ b/source/libs/transport/src/rpcMain.c @@ -51,8 +51,8 @@ typedef struct { char user[TSDB_UNI_LEN]; // meter ID char spi; // security parameter index char encrypt; // encrypt algorithm - char secret[TSDB_KEY_LEN]; // secret for the link - char ckey[TSDB_KEY_LEN]; // ciphering key + char secret[TSDB_PASSWORD_LEN]; // secret for the link + char ckey[TSDB_PASSWORD_LEN]; // ciphering key void (*cfp)(void *parent, SRpcMsg *, SEpSet *); int (*afp)(void *parent, char *user, char *spi, char *encrypt, char *secret, char *ckey); @@ -97,8 +97,8 @@ typedef struct SRpcConn { char user[TSDB_UNI_LEN]; // user ID for the link char spi; // security parameter index char encrypt; // encryption, 0:1 - char secret[TSDB_KEY_LEN]; // secret for the link - char ckey[TSDB_KEY_LEN]; // ciphering key + char secret[TSDB_PASSWORD_LEN]; // secret for the link + char ckey[TSDB_PASSWORD_LEN]; // ciphering key char secured; // if set to 1, no authentication uint16_t localPort; // for UDP only uint32_t linkUid; // connection unique ID assigned by client @@ -698,7 +698,7 @@ static SRpcConn *rpcAllocateClientConn(SRpcInfo *pRpc) { pConn->linkUid = (uint32_t)((int64_t)pConn + taosGetPid() + (int64_t)pConn->tranId); pConn->spi = pRpc->spi; pConn->encrypt = pRpc->encrypt; - if (pConn->spi) memcpy(pConn->secret, pRpc->secret, TSDB_KEY_LEN); + if (pConn->spi) memcpy(pConn->secret, pRpc->secret, TSDB_PASSWORD_LEN); tDebug("%s %p client connection is allocated, uid:0x%x", pRpc->label, pConn, pConn->linkUid); } @@ -1527,9 +1527,9 @@ static int rpcAuthenticateMsg(void *pMsg, int msgLen, void *pAuth, void *pKey) { int ret = -1; MD5Init(&context); - MD5Update(&context, (uint8_t *)pKey, TSDB_KEY_LEN); + MD5Update(&context, (uint8_t *)pKey, TSDB_PASSWORD_LEN); MD5Update(&context, (uint8_t *)pMsg, msgLen); - MD5Update(&context, (uint8_t *)pKey, TSDB_KEY_LEN); + MD5Update(&context, (uint8_t *)pKey, TSDB_PASSWORD_LEN); MD5Final(&context); if (memcmp(context.digest, pAuth, sizeof(context.digest)) == 0) ret = 0; @@ -1541,9 +1541,9 @@ static void rpcBuildAuthHead(void *pMsg, int msgLen, void *pAuth, void *pKey) { MD5_CTX context; MD5Init(&context); - MD5Update(&context, (uint8_t *)pKey, TSDB_KEY_LEN); + MD5Update(&context, (uint8_t *)pKey, TSDB_PASSWORD_LEN); MD5Update(&context, (uint8_t *)pMsg, msgLen); - MD5Update(&context, (uint8_t *)pKey, TSDB_KEY_LEN); + MD5Update(&context, (uint8_t *)pKey, TSDB_PASSWORD_LEN); MD5Final(&context); memcpy(pAuth, context.digest, sizeof(context.digest)); diff --git a/source/os/src/osString.c b/source/os/src/osString.c index 8054dc42be..4d8f0d134f 100644 --- a/source/os/src/osString.c +++ b/source/os/src/osString.c @@ -275,13 +275,13 @@ char *strsep(char **stringp, const char *delim) { } char *getpass(const char *prefix) { - static char passwd[TSDB_KEY_LEN] = {0}; - memset(passwd, 0, TSDB_KEY_LEN); + static char passwd[TSDB_PASSWORD_LEN] = {0}; + memset(passwd, 0, TSDB_PASSWORD_LEN); //printf("%s", prefix); int32_t index = 0; char ch; - while (index < TSDB_KEY_LEN) { + while (index < TSDB_PASSWORD_LEN) { ch = getch(); if (ch == '\n' || ch == '\r') { break; diff --git a/src/inc/tcq.h b/src/inc/tcq.h index 7338cccfee..71efe33011 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_KEY_LEN]; + char pass[TSDB_PASSWORD_LEN]; char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; // size must same with SVnodeObj.db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN] FCqWrite cqWrite; } SCqCfg; @@ -37,7 +37,7 @@ typedef struct { int32_t master; int32_t num; // number of continuous streams char user[TSDB_USER_LEN]; - char pass[TSDB_KEY_LEN]; + char pass[TSDB_PASSWORD_LEN]; char db[TSDB_DB_NAME_LEN]; FCqWrite cqWrite; struct SCqObj *pHead;