未验证 提交 f882b496 编写于 作者: M Minglei Jin 提交者: GitHub

Merge pull request #10342 from taosdata/feature/TS-229-D

[TS-229]<feature>: increased the max length for password
......@@ -330,7 +330,7 @@ typedef struct STscObj {
void * signature;
void * pTimer;
char user[TSDB_USER_LEN];
char pass[TSDB_KEY_LEN];
char pass[TSDB_PASS_LEN];
char acctId[TSDB_ACCT_ID_LEN];
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
char sversion[TSDB_VERSION_LEN];
......
......@@ -366,7 +366,7 @@ static int32_t handlePassword(SSqlCmd* pCmd, SStrToken* pPwd) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
if (pPwd->n >= TSDB_KEY_LEN) {
if (pPwd->n > TSDB_PASS_LEN - 1) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
......
......@@ -1254,6 +1254,17 @@ int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
return TSDB_CODE_SUCCESS;
}
static bool tscIsAlterCommand(char* sqlstr) {
int32_t index = 0;
do {
SStrToken t0 = tStrGetToken(sqlstr, &index, false);
if (t0.type != TK_LP) {
return t0.type == TK_ALTER;
}
} while (1);
}
int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SSqlCmd *pCmd = &pSql->cmd;
pCmd->payloadLen = sizeof(SCreateAcctMsg);
......@@ -1295,7 +1306,12 @@ int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
}
pCmd->msgType = TSDB_MSG_TYPE_CM_CREATE_ACCT;
if (tscIsAlterCommand(pSql->sqlstr)) {
pCmd->msgType = TSDB_MSG_TYPE_CM_ALTER_ACCT;
} else {
pCmd->msgType = TSDB_MSG_TYPE_CM_CREATE_ACCT;
}
return TSDB_CODE_SUCCESS;
}
......
......@@ -49,7 +49,7 @@ static bool validUserName(const char* user) {
}
static bool validPassword(const char* passwd) {
return validImpl(passwd, TSDB_KEY_LEN - 1);
return validImpl(passwd, TSDB_PASS_LEN - 1);
}
static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, const char *auth, const char *db,
......@@ -64,7 +64,7 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa
}
SRpcCorEpSet corMgmtEpSet;
char secretEncrypt[32] = {0};
char secretEncrypt[TSDB_PASS_LEN] = {0};
int secretEncryptLen = 0;
if (auth == NULL) {
if (!validPassword(pass)) {
......@@ -82,6 +82,11 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa
terrno = TSDB_CODE_TSC_INVALID_PASS_LENGTH;
return NULL;
} else {
if (outlen >= TSDB_PASS_LEN) {
terrno = TSDB_CODE_TSC_INVALID_USER_LENGTH;
tscError("failed to connect DB, too long length of authentication: %s", base64);
return NULL;
}
memcpy(secretEncrypt, base64, outlen);
free(base64);
}
......@@ -240,11 +245,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_KEY_LEN] = {0};
char passBuf[TSDB_PASS_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_KEY_LEN - 1, passLen));
strncpy(passBuf, pass, MIN(TSDB_PASS_LEN - 1, passLen));
strncpy(dbBuf, db, MIN(TSDB_DB_NAME_LEN - 1, dbLen));
return taos_connect(ipBuf, userBuf, passBuf, dbBuf, port);
}
......
......@@ -86,7 +86,9 @@ extern const int32_t TYPE_BYTES[16];
#define TSDB_DEFAULT_USER "root"
#define TSDB_DEFAULT_PASS "taosdata"
#define SHELL_MAX_PASSWORD_LEN 20
#define TSDB_PASS_LEN 129
#define SHELL_MAX_PASSWORD_LEN TSDB_PASS_LEN
#define TSDB_TRUE 1
#define TSDB_FALSE 0
#define TSDB_OK 0
......
......@@ -372,7 +372,7 @@ typedef struct {
typedef struct {
int8_t extend;
char user[TSDB_USER_LEN];
char pass[TSDB_KEY_LEN];
char pass[TSDB_PASS_LEN];
SAcctCfg cfg;
} SCreateAcctMsg, SAlterAcctMsg;
......@@ -384,7 +384,7 @@ typedef struct {
typedef struct {
int8_t extend;
char user[TSDB_USER_LEN];
char pass[TSDB_KEY_LEN];
char pass[TSDB_PASS_LEN];
int8_t privilege;
int8_t flag;
} SCreateUserMsg, SAlterUserMsg;
......
......@@ -89,7 +89,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
|| (strncmp(argv[i], "--password", 10) == 0)) {
printf("Enter password: ");
taosSetConsoleEcho(false);
if (scanf("%s", g_password) > 1) {
if (scanf("%128s", g_password) > 1) {
fprintf(stderr, "password read error\n");
}
taosSetConsoleEcho(true);
......
......@@ -186,7 +186,7 @@ static void parse_args(
|| (strncmp(argv[i], "--password", 10) == 0)) {
printf("Enter password: ");
taosSetConsoleEcho(false);
if (scanf("%20s", g_password) > 1) {
if (scanf("%128s", g_password) > 1) {
fprintf(stderr, "password reading error\n");
}
taosSetConsoleEcho(true);
......
......@@ -93,7 +93,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
|| (strncmp(argv[i], "--password", 10) == 0)) {
printf("Enter password: ");
taosSetConsoleEcho(false);
if (scanf("%s", g_password) > 1) {
if (scanf("%128s", g_password) > 1) {
fprintf(stderr, "password read error!\n");
}
taosSetConsoleEcho(true);
......
......@@ -625,11 +625,18 @@ int32_t mnodeRetriveAuth(char *user, char *spi, char *encrypt, char *secret, cha
mError("user:%s, failed to auth user, reason:%s", user, tstrerror(TSDB_CODE_MND_INVALID_USER));
return TSDB_CODE_MND_INVALID_USER;
} else {
if (pUser->superAuth) {
SAcctObj *pAcct = mnodeGetAcct(user);
memcpy(secret, pAcct->pass, TSDB_KEY_LEN);
mnodeDecAcctRef(pAcct);
} else {
memcpy(secret, pUser->pass, TSDB_KEY_LEN);
}
*spi = 1;
*encrypt = 0;
*ckey = 0;
memcpy(secret, pUser->pass, TSDB_KEY_LEN);
mnodeDecUserRef(pUser);
mDebug("user:%s, auth info is returned", user);
return TSDB_CODE_SUCCESS;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册