提交 8c416a5e 编写于 作者: H Haojun Liao

[td-10564] refactor and add test cases.

上级 bf97ce3d
...@@ -379,7 +379,7 @@ typedef struct { ...@@ -379,7 +379,7 @@ typedef struct {
typedef struct { typedef struct {
char user[TSDB_USER_LEN]; char user[TSDB_USER_LEN];
char pass[TSDB_KEY_LEN]; char pass[TSDB_PASSWORD_LEN];
int32_t maxUsers; int32_t maxUsers;
int32_t maxDbs; int32_t maxDbs;
int32_t maxTimeSeries; int32_t maxTimeSeries;
...@@ -394,7 +394,7 @@ typedef struct { ...@@ -394,7 +394,7 @@ typedef struct {
typedef struct { typedef struct {
char user[TSDB_USER_LEN]; char user[TSDB_USER_LEN];
char pass[TSDB_KEY_LEN]; char pass[TSDB_PASSWORD_LEN];
} SCreateUserMsg, SAlterUserMsg; } SCreateUserMsg, SAlterUserMsg;
typedef struct { typedef struct {
...@@ -912,8 +912,8 @@ typedef struct { ...@@ -912,8 +912,8 @@ typedef struct {
char user[TSDB_USER_LEN]; char user[TSDB_USER_LEN];
char spi; char spi;
char encrypt; char encrypt;
char secret[TSDB_KEY_LEN]; char secret[TSDB_PASSWORD_LEN];
char ckey[TSDB_KEY_LEN]; char ckey[TSDB_PASSWORD_LEN];
} SAuthMsg, SAuthRsp; } SAuthMsg, SAuthRsp;
typedef struct { typedef struct {
......
...@@ -188,7 +188,7 @@ do { \ ...@@ -188,7 +188,7 @@ do { \
#define TSDB_MAX_TAG_CONDITIONS 1024 #define TSDB_MAX_TAG_CONDITIONS 1024
#define TSDB_AUTH_LEN 16 #define TSDB_AUTH_LEN 16
#define TSDB_KEY_LEN 64 #define TSDB_PASSWORD_LEN 64
#define TSDB_VERSION_LEN 12 #define TSDB_VERSION_LEN 12
#define TSDB_LABEL_LEN 8 #define TSDB_LABEL_LEN 8
......
...@@ -51,7 +51,19 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *tar ...@@ -51,7 +51,19 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *tar
MD5Init(&context); MD5Init(&context);
MD5Update(&context, inBuf, (unsigned int)inLen); MD5Update(&context, inBuf, (unsigned int)inLen);
MD5Final(&context); 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 #ifdef __cplusplus
......
...@@ -71,7 +71,7 @@ typedef struct SAppInfo { ...@@ -71,7 +71,7 @@ typedef struct SAppInfo {
typedef struct STscObj { typedef struct STscObj {
char user[TSDB_USER_LEN]; char user[TSDB_USER_LEN];
char pass[TSDB_KEY_LEN]; char pass[TSDB_PASSWORD_LEN];
char acctId[TSDB_ACCT_ID_LEN]; char acctId[TSDB_ACCT_ID_LEN];
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
uint32_t connId; uint32_t connId;
...@@ -117,7 +117,7 @@ void destroyRequest(void* p); ...@@ -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); 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); 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 #ifdef __cplusplus
} }
......
...@@ -53,11 +53,11 @@ TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, 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 ipStr[TSDB_EP_LEN] = {0};
char dbStr[TSDB_DB_NAME_LEN] = {0}; char dbStr[TSDB_DB_NAME_LEN] = {0};
char userStr[TSDB_USER_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(ipStr, ip, MIN(TSDB_EP_LEN - 1, ipLen));
strncpy(userStr, user, MIN(TSDB_USER_LEN - 1, userLen)); 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)); strncpy(dbStr, db, MIN(TSDB_DB_NAME_LEN - 1, dbLen));
return taos_connect(ipStr, userStr, passStr, dbStr, port); return taos_connect(ipStr, userStr, passStr, dbStr, port);
} }
......
...@@ -26,7 +26,7 @@ static bool validateUserName(const char* user) { ...@@ -26,7 +26,7 @@ static bool validateUserName(const char* user) {
} }
static bool validatePassword(const char* passwd) { 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) { static bool validateDbName(const char* db) {
...@@ -52,14 +52,14 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, ...@@ -52,14 +52,14 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass,
strdequote(tmp); strdequote(tmp);
} }
char secretEncrypt[32] = {0}; char secretEncrypt[64] = {0};
if (auth == NULL) { if (auth == NULL) {
if (!validatePassword(pass)) { if (!validatePassword(pass)) {
terrno = TSDB_CODE_TSC_INVALID_PASS_LENGTH; terrno = TSDB_CODE_TSC_INVALID_PASS_LENGTH;
return NULL; return NULL;
} }
taosEncryptPass((uint8_t *)pass, strlen(pass), secretEncrypt); taosEncryptPass_c((uint8_t *)pass, strlen(pass), secretEncrypt);
} else { } else {
tstrncpy(secretEncrypt, auth, tListLen(secretEncrypt)); tstrncpy(secretEncrypt, auth, tListLen(secretEncrypt));
} }
...@@ -79,7 +79,7 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, ...@@ -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) { int initEpSetFromCfg(const char *firstEp, const char *secondEp, SRpcCorEpSet *pEpSet) {
......
...@@ -74,6 +74,10 @@ void taos_cleanup(void) { ...@@ -74,6 +74,10 @@ void taos_cleanup(void) {
} }
void taos_close(TAOS* taos) { void taos_close(TAOS* taos) {
if (taos == NULL) {
return;
}
} }
......
...@@ -70,6 +70,22 @@ static void deregisterRequest(SRequestObj* pRequest) { ...@@ -70,6 +70,22 @@ static void deregisterRequest(SRequestObj* pRequest) {
taosReleaseRef(tscConnRef, pTscObj->id); 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) { void tscFreeRpcObj(void *param) {
#if 0 #if 0
assert(param); assert(param);
...@@ -200,22 +216,6 @@ void destroyRequest(void* p) { ...@@ -200,22 +216,6 @@ void destroyRequest(void* p) {
deregisterRequest(pRequest); 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) { void taos_init_imp(void) {
// In the APIs of other program language, taos_cleanup is not available yet. // 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. // 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) { ...@@ -268,7 +268,7 @@ void taos_init_imp(void) {
tscDebug("client is initialized successfully"); 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; SGlobalCfg *cfg = NULL;
switch (option) { switch (option) {
...@@ -277,11 +277,11 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) { ...@@ -277,11 +277,11 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) {
assert(cfg != NULL); assert(cfg != NULL);
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { 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; cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
tscInfo("set config file directory:%s", pStr); tscInfo("set config file directory:%s", str);
} else { } 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; break;
...@@ -290,13 +290,13 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) { ...@@ -290,13 +290,13 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) {
assert(cfg != NULL); assert(cfg != NULL);
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) {
tsShellActivityTimer = atoi(pStr); tsShellActivityTimer = atoi(str);
if (tsShellActivityTimer < 1) tsShellActivityTimer = 1; if (tsShellActivityTimer < 1) tsShellActivityTimer = 1;
if (tsShellActivityTimer > 3600) tsShellActivityTimer = 3600; if (tsShellActivityTimer > 3600) tsShellActivityTimer = 3600;
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
tscInfo("set shellActivityTimer:%d", tsShellActivityTimer); tscInfo("set shellActivityTimer:%d", tsShellActivityTimer);
} else { } 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; break;
...@@ -304,9 +304,9 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) { ...@@ -304,9 +304,9 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) {
cfg = taosGetConfigOption("locale"); cfg = taosGetConfigOption("locale");
assert(cfg != NULL); assert(cfg != NULL);
size_t len = strlen(pStr); size_t len = strlen(str);
if (len == 0 || len > TSDB_LOCALE_LEN) { if (len == 0 || len > TSDB_LOCALE_LEN) {
tscInfo("Invalid locale:%s, use default", pStr); tscInfo("Invalid locale:%s, use default", str);
return -1; return -1;
} }
...@@ -327,14 +327,14 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) { ...@@ -327,14 +327,14 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) {
} }
// set the user specified locale // 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 if (locale != NULL) { // failed to set the user specified locale
tscInfo("locale set, prev locale:%s, new locale:%s", tsLocale, locale); tscInfo("locale set, prev locale:%s, new locale:%s", tsLocale, locale);
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
} else { // set the user specified locale failed, use default LC_CTYPE as current locale } else { // set the user specified locale failed, use default LC_CTYPE as current locale
locale = setlocale(LC_CTYPE, tsLocale); 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); tstrncpy(tsLocale, locale, TSDB_LOCALE_LEN);
...@@ -364,7 +364,7 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) { ...@@ -364,7 +364,7 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) {
tscInfo("charset remains:%s", tsCharset); tscInfo("charset remains:%s", tsCharset);
} }
} else { } 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; break;
} }
...@@ -374,27 +374,27 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) { ...@@ -374,27 +374,27 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) {
cfg = taosGetConfigOption("charset"); cfg = taosGetConfigOption("charset");
assert(cfg != NULL); assert(cfg != NULL);
size_t len = strlen(pStr); size_t len = strlen(str);
if (len == 0 || len > TSDB_LOCALE_LEN) { if (len == 0 || len > TSDB_LOCALE_LEN) {
tscInfo("failed to set charset:%s", pStr); tscInfo("failed to set charset:%s", str);
return -1; return -1;
} }
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) {
if (taosValidateEncodec(pStr)) { if (taosValidateEncodec(str)) {
if (strlen(tsCharset) == 0) { if (strlen(tsCharset) == 0) {
tscInfo("charset is set:%s", pStr); tscInfo("charset is set:%s", str);
} else { } 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; cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
} else { } else {
tscInfo("charset:%s not valid", pStr); tscInfo("charset:%s not valid", str);
} }
} else { } 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; break;
...@@ -405,12 +405,12 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) { ...@@ -405,12 +405,12 @@ int taos_options_imp(TSDB_OPTION option, const char *pStr) {
assert(cfg != NULL); assert(cfg != NULL);
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) {
tstrncpy(tsTimezone, pStr, TSDB_TIMEZONE_LEN); tstrncpy(tsTimezone, str, TSDB_TIMEZONE_LEN);
tsSetTimeZone(); tsSetTimeZone();
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; 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 { } 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; break;
......
...@@ -34,4 +34,5 @@ int main(int argc, char** argv) { ...@@ -34,4 +34,5 @@ int main(int argc, char** argv) {
TEST(testCase, driverInit_Test) { TEST(testCase, driverInit_Test) {
taos_init(); taos_init();
TAOS* pTaos = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
} }
\ No newline at end of file
...@@ -240,18 +240,18 @@ static void dndSendMsgToMnodeRecv(SDnode *pDnode, SRpcMsg *pRpcMsg, SRpcMsg *pRp ...@@ -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) { static int32_t dndAuthInternalMsg(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) {
if (strcmp(user, INTERNAL_USER) == 0) { if (strcmp(user, INTERNAL_USER) == 0) {
// A simple temporary implementation // A simple temporary implementation
char pass[32] = {0}; char pass[TSDB_PASSWORD_LEN] = {0};
taosEncryptPass((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass); taosEncryptPass((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass);
memcpy(secret, pass, TSDB_KEY_LEN); memcpy(secret, pass, TSDB_PASSWORD_LEN);
*spi = 0; *spi = 0;
*encrypt = 0; *encrypt = 0;
*ckey = 0; *ckey = 0;
return 0; return 0;
} else if (strcmp(user, TSDB_NETTEST_USER) == 0) { } else if (strcmp(user, TSDB_NETTEST_USER) == 0) {
// A simple temporary implementation // 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); 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; *spi = 0;
*encrypt = 0; *encrypt = 0;
*ckey = 0; *ckey = 0;
...@@ -293,8 +293,8 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char ...@@ -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()); dError("user:%s, failed to get user auth from other mnodes since %s", user, terrstr());
} else { } else {
SAuthRsp *pRsp = rpcRsp.pCont; SAuthRsp *pRsp = rpcRsp.pCont;
memcpy(secret, pRsp->secret, TSDB_KEY_LEN); memcpy(secret, pRsp->secret, TSDB_PASSWORD_LEN);
memcpy(ckey, pRsp->ckey, TSDB_KEY_LEN); memcpy(ckey, pRsp->ckey, TSDB_PASSWORD_LEN);
*spi = pRsp->spi; *spi = pRsp->spi;
*encrypt = pRsp->encrypt; *encrypt = pRsp->encrypt;
dDebug("user:%s, success to get user auth from other mnodes", user); dDebug("user:%s, success to get user auth from other mnodes", user);
......
...@@ -107,7 +107,7 @@ SClient* createClient(const char* user, const char* pass, const char* fqdn, uint ...@@ -107,7 +107,7 @@ SClient* createClient(const char* user, const char* pass, const char* fqdn, uint
SClient* pClient = (SClient*)calloc(1, sizeof(SClient)); SClient* pClient = (SClient*)calloc(1, sizeof(SClient));
ASSERT(pClient); ASSERT(pClient);
char secretEncrypt[32] = {0}; char secretEncrypt[TSDB_PASSWORD_LEN] = {0};
taosEncryptPass((uint8_t*)pass, strlen(pass), secretEncrypt); taosEncryptPass((uint8_t*)pass, strlen(pass), secretEncrypt);
SRpcInit rpcInit; SRpcInit rpcInit;
......
...@@ -181,7 +181,7 @@ typedef struct SAcctObj { ...@@ -181,7 +181,7 @@ typedef struct SAcctObj {
typedef struct SUserObj { typedef struct SUserObj {
char user[TSDB_USER_LEN]; char user[TSDB_USER_LEN];
char pass[TSDB_KEY_LEN]; char pass[TSDB_PASSWORD_LEN];
char acct[TSDB_USER_LEN]; char acct[TSDB_USER_LEN];
int64_t createdTime; int64_t createdTime;
int64_t updateTime; int64_t updateTime;
......
...@@ -92,7 +92,7 @@ static SSdbRaw *mndUserActionEncode(SUserObj *pUser) { ...@@ -92,7 +92,7 @@ static SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
int32_t dataPos = 0; int32_t dataPos = 0;
SDB_SET_BINARY(pRaw, dataPos, pUser->user, TSDB_USER_LEN) 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_BINARY(pRaw, dataPos, pUser->acct, TSDB_USER_LEN)
SDB_SET_INT64(pRaw, dataPos, pUser->createdTime) SDB_SET_INT64(pRaw, dataPos, pUser->createdTime)
SDB_SET_INT64(pRaw, dataPos, pUser->updateTime) SDB_SET_INT64(pRaw, dataPos, pUser->updateTime)
...@@ -120,7 +120,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { ...@@ -120,7 +120,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
int32_t dataPos = 0; int32_t dataPos = 0;
SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->user, TSDB_USER_LEN) 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_BINARY(pRaw, pRow, dataPos, pUser->acct, TSDB_USER_LEN)
SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->createdTime) SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->createdTime)
SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->updateTime) SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->updateTime)
...@@ -165,7 +165,7 @@ static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) { ...@@ -165,7 +165,7 @@ static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pSrcUser, SUserObj *pDstUser) { static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pSrcUser, SUserObj *pDstUser) {
mTrace("user:%s, perform update action", pSrcUser->user); mTrace("user:%s, perform update action", pSrcUser->user);
memcpy(pSrcUser->user, pDstUser->user, TSDB_USER_LEN); 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); memcpy(pSrcUser->acct, pDstUser->acct, TSDB_USER_LEN);
pSrcUser->createdTime = pDstUser->createdTime; pSrcUser->createdTime = pDstUser->createdTime;
pSrcUser->updateTime = pDstUser->updateTime; pSrcUser->updateTime = pDstUser->updateTime;
......
...@@ -228,7 +228,7 @@ static int syncInitRpcServer(SSyncManager* syncManager, const SSyncCluster* pSyn ...@@ -228,7 +228,7 @@ static int syncInitRpcServer(SSyncManager* syncManager, const SSyncCluster* pSyn
} }
static int syncInitRpcClient(SSyncManager* syncManager) { static int syncInitRpcClient(SSyncManager* syncManager) {
char secret[TSDB_KEY_LEN] = "secret"; char secret[TSDB_PASSWORD_LEN] = "secret";
SRpcInit rpcInit; SRpcInit rpcInit;
memset(&rpcInit, 0, sizeof(rpcInit)); memset(&rpcInit, 0, sizeof(rpcInit));
rpcInit.label = "sync-client"; rpcInit.label = "sync-client";
......
...@@ -51,8 +51,8 @@ typedef struct { ...@@ -51,8 +51,8 @@ typedef struct {
char user[TSDB_UNI_LEN]; // meter ID char user[TSDB_UNI_LEN]; // meter ID
char spi; // security parameter index char spi; // security parameter index
char encrypt; // encrypt algorithm char encrypt; // encrypt algorithm
char secret[TSDB_KEY_LEN]; // secret for the link char secret[TSDB_PASSWORD_LEN]; // secret for the link
char ckey[TSDB_KEY_LEN]; // ciphering key char ckey[TSDB_PASSWORD_LEN]; // ciphering key
void (*cfp)(void *parent, SRpcMsg *, SEpSet *); void (*cfp)(void *parent, SRpcMsg *, SEpSet *);
int (*afp)(void *parent, char *user, char *spi, char *encrypt, char *secret, char *ckey); int (*afp)(void *parent, char *user, char *spi, char *encrypt, char *secret, char *ckey);
...@@ -97,8 +97,8 @@ typedef struct SRpcConn { ...@@ -97,8 +97,8 @@ typedef struct SRpcConn {
char user[TSDB_UNI_LEN]; // user ID for the link char user[TSDB_UNI_LEN]; // user ID for the link
char spi; // security parameter index char spi; // security parameter index
char encrypt; // encryption, 0:1 char encrypt; // encryption, 0:1
char secret[TSDB_KEY_LEN]; // secret for the link char secret[TSDB_PASSWORD_LEN]; // secret for the link
char ckey[TSDB_KEY_LEN]; // ciphering key char ckey[TSDB_PASSWORD_LEN]; // ciphering key
char secured; // if set to 1, no authentication char secured; // if set to 1, no authentication
uint16_t localPort; // for UDP only uint16_t localPort; // for UDP only
uint32_t linkUid; // connection unique ID assigned by client uint32_t linkUid; // connection unique ID assigned by client
...@@ -698,7 +698,7 @@ static SRpcConn *rpcAllocateClientConn(SRpcInfo *pRpc) { ...@@ -698,7 +698,7 @@ static SRpcConn *rpcAllocateClientConn(SRpcInfo *pRpc) {
pConn->linkUid = (uint32_t)((int64_t)pConn + taosGetPid() + (int64_t)pConn->tranId); pConn->linkUid = (uint32_t)((int64_t)pConn + taosGetPid() + (int64_t)pConn->tranId);
pConn->spi = pRpc->spi; pConn->spi = pRpc->spi;
pConn->encrypt = pRpc->encrypt; 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); 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) { ...@@ -1527,9 +1527,9 @@ static int rpcAuthenticateMsg(void *pMsg, int msgLen, void *pAuth, void *pKey) {
int ret = -1; int ret = -1;
MD5Init(&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 *)pMsg, msgLen);
MD5Update(&context, (uint8_t *)pKey, TSDB_KEY_LEN); MD5Update(&context, (uint8_t *)pKey, TSDB_PASSWORD_LEN);
MD5Final(&context); MD5Final(&context);
if (memcmp(context.digest, pAuth, sizeof(context.digest)) == 0) ret = 0; 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) { ...@@ -1541,9 +1541,9 @@ static void rpcBuildAuthHead(void *pMsg, int msgLen, void *pAuth, void *pKey) {
MD5_CTX context; MD5_CTX context;
MD5Init(&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 *)pMsg, msgLen);
MD5Update(&context, (uint8_t *)pKey, TSDB_KEY_LEN); MD5Update(&context, (uint8_t *)pKey, TSDB_PASSWORD_LEN);
MD5Final(&context); MD5Final(&context);
memcpy(pAuth, context.digest, sizeof(context.digest)); memcpy(pAuth, context.digest, sizeof(context.digest));
......
...@@ -275,13 +275,13 @@ char *strsep(char **stringp, const char *delim) { ...@@ -275,13 +275,13 @@ char *strsep(char **stringp, const char *delim) {
} }
char *getpass(const char *prefix) { char *getpass(const char *prefix) {
static char passwd[TSDB_KEY_LEN] = {0}; static char passwd[TSDB_PASSWORD_LEN] = {0};
memset(passwd, 0, TSDB_KEY_LEN); memset(passwd, 0, TSDB_PASSWORD_LEN);
//printf("%s", prefix); //printf("%s", prefix);
int32_t index = 0; int32_t index = 0;
char ch; char ch;
while (index < TSDB_KEY_LEN) { while (index < TSDB_PASSWORD_LEN) {
ch = getch(); ch = getch();
if (ch == '\n' || ch == '\r') { if (ch == '\n' || ch == '\r') {
break; break;
......
...@@ -26,7 +26,7 @@ typedef int32_t (*FCqWrite)(int32_t vgId, void *pHead, int32_t qtype, void *pMsg ...@@ -26,7 +26,7 @@ typedef int32_t (*FCqWrite)(int32_t vgId, void *pHead, int32_t qtype, void *pMsg
typedef struct { typedef struct {
int32_t vgId; int32_t vgId;
char user[TSDB_USER_LEN]; 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] 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; FCqWrite cqWrite;
} SCqCfg; } SCqCfg;
...@@ -37,7 +37,7 @@ typedef struct { ...@@ -37,7 +37,7 @@ typedef struct {
int32_t master; int32_t master;
int32_t num; // number of continuous streams int32_t num; // number of continuous streams
char user[TSDB_USER_LEN]; char user[TSDB_USER_LEN];
char pass[TSDB_KEY_LEN]; char pass[TSDB_PASSWORD_LEN];
char db[TSDB_DB_NAME_LEN]; char db[TSDB_DB_NAME_LEN];
FCqWrite cqWrite; FCqWrite cqWrite;
struct SCqObj *pHead; struct SCqObj *pHead;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册