提交 bf6cb839 编写于 作者: S Shengliang Guan

TD-13253 serialize user msg

上级 6693b5fa
......@@ -129,6 +129,14 @@ typedef enum _mgmt_table {
#define TSDB_FILL_NEXT 5
#define TSDB_ALTER_USER_PASSWD 0x1
#define TSDB_ALTER_USER_SUPERUSER 0x2
#define TSDB_ALTER_USER_ADD_READ_DB 0x3
#define TSDB_ALTER_USER_REMOVE_READ_DB 0x4
#define TSDB_ALTER_USER_CLEAR_READ_DB 0x5
#define TSDB_ALTER_USER_ADD_WRITE_DB 0x6
#define TSDB_ALTER_USER_REMOVE_WRITE_DB 0x7
#define TSDB_ALTER_USER_CLEAR_WRITE_DB 0x7
#define TSDB_ALTER_USER_PRIVILEGES 0x2
#define TSDB_KILL_MSG_LEN 30
......@@ -341,16 +349,36 @@ typedef struct {
int64_t maxStorage; // In unit of GB
} SCreateAcctReq, SAlterAcctReq;
int32_t tSerializeSCreateAcctReq(void** buf, SCreateAcctReq* pReq);
void* tDeserializeSCreateAcctReq(void* buf, SCreateAcctReq* pReq);
typedef struct {
char user[TSDB_USER_LEN];
} SDropUserReq, SDropAcctReq;
int32_t tSerializeSDropUserReq(void** buf, SDropUserReq* pReq);
void* tDeserializeSDropUserReq(void* buf, SDropUserReq* pReq);
typedef struct {
int8_t type;
int8_t createType;
int8_t superUser; // denote if it is a super user or not
char user[TSDB_USER_LEN];
char pass[TSDB_PASSWORD_LEN];
int8_t superUser; // denote if it is a super user or not
} SCreateUserReq, SAlterUserReq;
} SCreateUserReq;
int32_t tSerializeSCreateUserReq(void** buf, SCreateUserReq* pReq);
void* tDeserializeSCreateUserReq(void* buf, SCreateUserReq* pReq);
typedef struct {
int8_t alterType;
char user[TSDB_USER_LEN];
char pass[TSDB_PASSWORD_LEN];
char dbname[TSDB_DB_FNAME_LEN];
int8_t superUser;
} SAlterUserReq;
int32_t tSerializeSAlterUserReq(void** buf, SAlterUserReq* pReq);
void* tDeserializeSAlterUserReq(void* buf, SAlterUserReq* pReq);
typedef struct {
int16_t colId; // column id
......@@ -622,7 +650,6 @@ typedef struct {
} SVnodeLoad;
typedef struct {
int32_t mver; // msg version
int32_t sver; // software version
int64_t dver; // dnode table version in sdb
int32_t dnodeId;
......@@ -651,7 +678,6 @@ typedef struct {
} SDnodeEp;
typedef struct {
int32_t mver;
int64_t dver;
SDnodeCfg dnodeCfg;
SArray* pDnodeEps; // Array of SDnodeEp
......@@ -661,7 +687,7 @@ int32_t tSerializeSStatusRsp(void** buf, SStatusRsp* pRsp);
void* tDeserializeSStatusRsp(void* buf, SStatusRsp* pRsp);
typedef struct {
int32_t mver;
int32_t reserve;
} STransReq;
typedef struct {
......
......@@ -199,6 +199,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_MND_INVALID_USER_FORMAT TAOS_DEF_ERROR_CODE(0, 0x0373)
#define TSDB_CODE_MND_INVALID_PASS_FORMAT TAOS_DEF_ERROR_CODE(0, 0x0374)
#define TSDB_CODE_MND_NO_USER_FROM_CONN TAOS_DEF_ERROR_CODE(0, 0x0375)
#define TSDB_CODE_MND_INVALID_ALTER_OPER TAOS_DEF_ERROR_CODE(0, 0x0376)
// mnode-db
#define TSDB_CODE_MND_DB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0380)
......
......@@ -464,7 +464,6 @@ int32_t tSerializeSStatusReq(void **buf, SStatusReq *pReq) {
int32_t tlen = 0;
// status
tlen += taosEncodeFixedI32(buf, pReq->mver);
tlen += taosEncodeFixedI32(buf, pReq->sver);
tlen += taosEncodeFixedI64(buf, pReq->dver);
tlen += taosEncodeFixedI32(buf, pReq->dnodeId);
......@@ -501,7 +500,6 @@ int32_t tSerializeSStatusReq(void **buf, SStatusReq *pReq) {
void *tDeserializeSStatusReq(void *buf, SStatusReq *pReq) {
// status
buf = taosDecodeFixedI32(buf, &pReq->mver);
buf = taosDecodeFixedI32(buf, &pReq->sver);
buf = taosDecodeFixedI64(buf, &pReq->dver);
buf = taosDecodeFixedI32(buf, &pReq->dnodeId);
......@@ -549,8 +547,7 @@ void *tDeserializeSStatusReq(void *buf, SStatusReq *pReq) {
int32_t tSerializeSStatusRsp(void **buf, SStatusRsp *pRsp) {
int32_t tlen = 0;
// status
tlen += taosEncodeFixedI32(buf, pRsp->mver);
// status;
tlen += taosEncodeFixedI64(buf, pRsp->dver);
// dnode cfg
......@@ -573,7 +570,6 @@ int32_t tSerializeSStatusRsp(void **buf, SStatusRsp *pRsp) {
void *tDeserializeSStatusRsp(void *buf, SStatusRsp *pRsp) {
// status
buf = taosDecodeFixedI32(buf, &pRsp->mver);
buf = taosDecodeFixedI64(buf, &pRsp->dver);
// cluster cfg
......@@ -603,3 +599,75 @@ void *tDeserializeSStatusRsp(void *buf, SStatusRsp *pRsp) {
return buf;
}
int32_t tSerializeSCreateAcctReq(void **buf, SCreateAcctReq *pReq) {
int32_t tlen = 0;
tlen += taosEncodeString(buf, pReq->user);
tlen += taosEncodeString(buf, pReq->pass);
tlen += taosEncodeFixedI32(buf, pReq->maxUsers);
tlen += taosEncodeFixedI32(buf, pReq->maxDbs);
tlen += taosEncodeFixedI32(buf, pReq->maxTimeSeries);
tlen += taosEncodeFixedI32(buf, pReq->maxStreams);
tlen += taosEncodeFixedI32(buf, pReq->accessState);
tlen += taosEncodeFixedI64(buf, pReq->maxStorage);
return tlen;
}
void *tDeserializeSCreateAcctReq(void *buf, SCreateAcctReq *pReq) {
buf = taosDecodeStringTo(buf, pReq->user);
buf = taosDecodeStringTo(buf, pReq->pass);
buf = taosDecodeFixedI32(buf, &pReq->maxUsers);
buf = taosDecodeFixedI32(buf, &pReq->maxDbs);
buf = taosDecodeFixedI32(buf, &pReq->maxTimeSeries);
buf = taosDecodeFixedI32(buf, &pReq->maxStreams);
buf = taosDecodeFixedI32(buf, &pReq->accessState);
buf = taosDecodeFixedI64(buf, &pReq->maxStorage);
return buf;
}
int32_t tSerializeSDropUserReq(void **buf, SDropUserReq *pReq) {
int32_t tlen = 0;
tlen += taosEncodeString(buf, pReq->user);
return tlen;
}
void *tDeserializeSDropUserReq(void *buf, SDropUserReq *pReq) {
buf = taosDecodeStringTo(buf, pReq->user);
return buf;
}
int32_t tSerializeSCreateUserReq(void **buf, SCreateUserReq *pReq) {
int32_t tlen = 0;
tlen += taosEncodeFixedI8(buf, pReq->createType);
tlen += taosEncodeFixedI8(buf, pReq->superUser);
tlen += taosEncodeString(buf, pReq->user);
tlen += taosEncodeString(buf, pReq->pass);
return tlen;
}
void *tDeserializeSCreateUserReq(void *buf, SCreateUserReq *pReq) {
buf = taosDecodeFixedI8(buf, &pReq->createType);
buf = taosDecodeFixedI8(buf, &pReq->superUser);
buf = taosDecodeStringTo(buf, pReq->user);
buf = taosDecodeStringTo(buf, pReq->pass);
return buf;
}
int32_t tSerializeSAlterUserReq(void **buf, SAlterUserReq *pReq) {
int32_t tlen = 0;
tlen += taosEncodeFixedI8(buf, pReq->alterType);
tlen += taosEncodeString(buf, pReq->user);
tlen += taosEncodeString(buf, pReq->pass);
tlen += taosEncodeString(buf, pReq->dbname);
tlen += taosEncodeFixedI8(buf, pReq->superUser);
return tlen;
}
void *tDeserializeSAlterUserReq(void *buf, SAlterUserReq *pReq) {
buf = taosDecodeFixedI8(buf, &pReq->alterType);
buf = taosDecodeStringTo(buf, pReq->user);
buf = taosDecodeStringTo(buf, pReq->pass);
buf = taosDecodeStringTo(buf, pReq->dbname);
buf = taosDecodeFixedI8(buf, &pReq->superUser);
return buf;
}
\ No newline at end of file
......@@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE
#include "mndUser.h"
#include "mndDb.h"
#include "mndShow.h"
#include "mndTrans.h"
#include "tkey.h"
......@@ -206,7 +207,7 @@ USER_DECODE_OVER:
static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) {
mTrace("user:%s, perform insert action, row:%p", pUser->user, pUser);
SAcctObj *pAcct = sdbAcquire(pSdb, SDB_ACCT, pUser->acct);
if (pAcct == NULL) {
terrno = TSDB_CODE_MND_ACCT_NOT_EXIST;
......@@ -291,47 +292,50 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass,
}
static int32_t mndProcessCreateUserReq(SMnodeMsg *pReq) {
SMnode *pMnode = pReq->pMnode;
SCreateUserReq *pCreate = pReq->rpcMsg.pCont;
SMnode *pMnode = pReq->pMnode;
int32_t code = -1;
SUserObj *pUser = NULL;
SUserObj *pOperUser = NULL;
SCreateUserReq createReq = {0};
mDebug("user:%s, start to create", pCreate->user);
if (tDeserializeSCreateUserReq(pReq->rpcMsg.pCont, &createReq) == NULL) goto CREATE_USER_OVER;
if (pCreate->user[0] == 0) {
mDebug("user:%s, start to create", createReq.user);
if (createReq.user[0] == 0) {
terrno = TSDB_CODE_MND_INVALID_USER_FORMAT;
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
return -1;
goto CREATE_USER_OVER;
}
if (pCreate->pass[0] == 0) {
if (createReq.pass[0] == 0) {
terrno = TSDB_CODE_MND_INVALID_PASS_FORMAT;
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
return -1;
goto CREATE_USER_OVER;
}
SUserObj *pUser = mndAcquireUser(pMnode, pCreate->user);
pUser = mndAcquireUser(pMnode, createReq.user);
if (pUser != NULL) {
mndReleaseUser(pMnode, pUser);
terrno = TSDB_CODE_MND_USER_ALREADY_EXIST;
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
return -1;
goto CREATE_USER_OVER;
}
SUserObj *pOperUser = mndAcquireUser(pMnode, pReq->user);
pOperUser = mndAcquireUser(pMnode, pReq->user);
if (pOperUser == NULL) {
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
return -1;
goto CREATE_USER_OVER;
}
int32_t code = mndCreateUser(pMnode, pOperUser->acct, pCreate->user, pCreate->pass, pReq);
mndReleaseUser(pMnode, pOperUser);
code = mndCreateUser(pMnode, pOperUser->acct, createReq.user, createReq.pass, pReq);
if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
if (code != 0) {
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
return -1;
CREATE_USER_OVER:
if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
mError("user:%s, failed to create since %s", createReq.user, terrstr());
}
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
mndReleaseUser(pMnode, pUser);
mndReleaseUser(pMnode, pOperUser);
return code;
}
static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SMnodeMsg *pReq) {
......@@ -360,56 +364,131 @@ static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SMn
return 0;
}
static SHashObj *mndDupDbHash(SHashObj *pOld) {
SHashObj *pNew = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, true);
if (pNew == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
char *db = taosHashIterate(pOld, NULL);
while (db != NULL) {
int32_t len = strlen(db) + 1;
if (taosHashPut(pNew, db, len, db, TSDB_DB_FNAME_LEN) != 0) {
taosHashCancelIterate(pOld, db);
terrno = TSDB_CODE_OUT_OF_MEMORY;
taosHashCleanup(pNew);
return NULL;
}
db = taosHashIterate(pOld, db);
}
return pNew;
}
static int32_t mndProcessAlterUserReq(SMnodeMsg *pReq) {
SMnode *pMnode = pReq->pMnode;
SAlterUserReq *pAlter = pReq->rpcMsg.pCont;
SMnode *pMnode = pReq->pMnode;
int32_t code = -1;
SUserObj *pUser = NULL;
SUserObj *pOperUser = NULL;
SAlterUserReq alterReq = {0};
if (tDeserializeSAlterUserReq(pReq->rpcMsg.pCont, &alterReq) == NULL) goto ALTER_USER_OVER;
mDebug("user:%s, start to alter", pAlter->user);
mDebug("user:%s, start to alter", alterReq.user);
if (pAlter->user[0] == 0) {
if (alterReq.user[0] == 0) {
terrno = TSDB_CODE_MND_INVALID_USER_FORMAT;
mError("user:%s, failed to alter since %s", pAlter->user, terrstr());
return -1;
goto ALTER_USER_OVER;
}
if (pAlter->pass[0] == 0) {
if (alterReq.pass[0] == 0) {
terrno = TSDB_CODE_MND_INVALID_PASS_FORMAT;
mError("user:%s, failed to alter since %s", pAlter->user, terrstr());
return -1;
goto ALTER_USER_OVER;
}
SUserObj *pUser = mndAcquireUser(pMnode, pAlter->user);
pUser = mndAcquireUser(pMnode, alterReq.user);
if (pUser == NULL) {
terrno = TSDB_CODE_MND_USER_NOT_EXIST;
mError("user:%s, failed to alter since %s", pAlter->user, terrstr());
return -1;
goto ALTER_USER_OVER;
}
SUserObj *pOperUser = mndAcquireUser(pMnode, pReq->user);
pOperUser = mndAcquireUser(pMnode, pReq->user);
if (pOperUser == NULL) {
mndReleaseUser(pMnode, pUser);
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
mError("user:%s, failed to alter since %s", pAlter->user, terrstr());
return -1;
goto ALTER_USER_OVER;
}
SUserObj newUser = {0};
memcpy(&newUser, pUser, sizeof(SUserObj));
char pass[TSDB_PASSWORD_LEN + 1] = {0};
taosEncryptPass_c((uint8_t *)pAlter->pass, strlen(pAlter->pass), pass);
memcpy(pUser->pass, pass, TSDB_PASSWORD_LEN);
newUser.readDbs = mndDupDbHash(pUser->readDbs);
newUser.writeDbs = mndDupDbHash(pUser->writeDbs);
if (newUser.readDbs == NULL || newUser.writeDbs == NULL) {
goto ALTER_USER_OVER;
}
int32_t len = strlen(alterReq.dbname) + 1;
SDbObj *pDb = mndAcquireDb(pMnode, alterReq.dbname);
mndReleaseDb(pMnode, pDb);
if (alterReq.alterType == TSDB_ALTER_USER_PASSWD) {
char pass[TSDB_PASSWORD_LEN + 1] = {0};
taosEncryptPass_c((uint8_t *)alterReq.pass, strlen(alterReq.pass), pass);
memcpy(pUser->pass, pass, TSDB_PASSWORD_LEN);
} else if (alterReq.alterType == TSDB_ALTER_USER_SUPERUSER) {
newUser.superUser = alterReq.superUser;
} else if (alterReq.alterType == TSDB_ALTER_USER_ADD_READ_DB) {
if (pDb == NULL) {
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
goto ALTER_USER_OVER;
}
if (taosHashPut(newUser.readDbs, alterReq.dbname, len, alterReq.dbname, TSDB_DB_FNAME_LEN) != 0) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto ALTER_USER_OVER;
}
} else if (alterReq.alterType == TSDB_ALTER_USER_REMOVE_READ_DB) {
if (taosHashRemove(newUser.readDbs, alterReq.dbname, len) != 0) {
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
goto ALTER_USER_OVER;
}
} else if (alterReq.alterType == TSDB_ALTER_USER_CLEAR_READ_DB) {
taosHashClear(newUser.readDbs);
} else if (alterReq.alterType == TSDB_ALTER_USER_ADD_WRITE_DB) {
if (pDb == NULL) {
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
goto ALTER_USER_OVER;
}
if (taosHashPut(newUser.writeDbs, alterReq.dbname, len, alterReq.dbname, TSDB_DB_FNAME_LEN) != 0) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto ALTER_USER_OVER;
}
} else if (alterReq.alterType == TSDB_ALTER_USER_REMOVE_WRITE_DB) {
if (taosHashRemove(newUser.writeDbs, alterReq.dbname, len) != 0) {
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
goto ALTER_USER_OVER;
}
} else if (alterReq.alterType == TSDB_ALTER_USER_CLEAR_WRITE_DB) {
taosHashClear(newUser.writeDbs);
} else {
terrno = TSDB_CODE_MND_INVALID_ALTER_OPER;
goto ALTER_USER_OVER;
}
newUser.updateTime = taosGetTimestampMs();
int32_t code = mndUpdateUser(pMnode, pUser, &newUser, pReq);
mndReleaseUser(pMnode, pOperUser);
mndReleaseUser(pMnode, pUser);
code = mndUpdateUser(pMnode, pUser, &newUser, pReq);
if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
if (code != 0) {
mError("user:%s, failed to alter since %s", pAlter->user, terrstr());
return -1;
ALTER_USER_OVER:
if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
mError("user:%s, failed to alter since %s", alterReq.user, terrstr());
}
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
mndReleaseUser(pMnode, pOperUser);
mndReleaseUser(pMnode, pUser);
return code;
}
static int32_t mndDropUser(SMnode *pMnode, SMnodeMsg *pReq, SUserObj *pUser) {
......@@ -439,42 +518,45 @@ static int32_t mndDropUser(SMnode *pMnode, SMnodeMsg *pReq, SUserObj *pUser) {
}
static int32_t mndProcessDropUserReq(SMnodeMsg *pReq) {
SMnode *pMnode = pReq->pMnode;
SDropUserReq *pDrop = pReq->rpcMsg.pCont;
SMnode *pMnode = pReq->pMnode;
int32_t code = -1;
SUserObj *pUser = NULL;
SUserObj *pOperUser = NULL;
SDropUserReq dropReq = {0};
if (tDeserializeSDropUserReq(pReq->rpcMsg.pCont, &dropReq) == NULL) goto DROP_USER_OVER;
mDebug("user:%s, start to drop", pDrop->user);
mDebug("user:%s, start to drop", dropReq.user);
if (pDrop->user[0] == 0) {
if (dropReq.user[0] == 0) {
terrno = TSDB_CODE_MND_INVALID_USER_FORMAT;
mError("user:%s, failed to drop since %s", pDrop->user, terrstr());
return -1;
goto DROP_USER_OVER;
}
SUserObj *pUser = mndAcquireUser(pMnode, pDrop->user);
pUser = mndAcquireUser(pMnode, dropReq.user);
if (pUser == NULL) {
terrno = TSDB_CODE_MND_USER_NOT_EXIST;
mError("user:%s, failed to drop since %s", pDrop->user, terrstr());
return -1;
goto DROP_USER_OVER;
}
SUserObj *pOperUser = mndAcquireUser(pMnode, pReq->user);
pOperUser = mndAcquireUser(pMnode, pReq->user);
if (pOperUser == NULL) {
mndReleaseUser(pMnode, pUser);
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
mError("user:%s, failed to drop since %s", pDrop->user, terrstr());
return -1;
goto DROP_USER_OVER;
}
int32_t code = mndDropUser(pMnode, pReq, pUser);
mndReleaseUser(pMnode, pOperUser);
mndReleaseUser(pMnode, pUser);
code = mndDropUser(pMnode, pReq, pUser);
if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
if (code != 0) {
mError("user:%s, failed to drop since %s", pDrop->user, terrstr());
return -1;
DROP_USER_OVER:
if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
mError("user:%s, failed to drop since %s", dropReq.user, terrstr());
}
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
mndReleaseUser(pMnode, pOperUser);
mndReleaseUser(pMnode, pUser);
return code;
}
static int32_t mndGetUserMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) {
......
......@@ -63,11 +63,14 @@ TestServer MndTestTrans::server2;
TEST_F(MndTestTrans, 01_Create_User_Crash) {
{
int32_t contLen = sizeof(SCreateUserReq);
SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "u1");
strcpy(pReq->pass, "p1");
SCreateUserReq createReq = {0};
strcpy(createReq.user, "u1");
strcpy(createReq.pass, "p1");
int32_t contLen = tSerializeSCreateUserReq(NULL, &createReq);
void* pReq = rpcMallocCont(contLen);
void* pBuf = pReq;
tSerializeSCreateUserReq(&pBuf, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
......
......@@ -45,11 +45,14 @@ TEST_F(MndTestUser, 01_Show_User) {
TEST_F(MndTestUser, 02_Create_User) {
{
int32_t contLen = sizeof(SCreateUserReq);
SCreateUserReq createReq = {0};
strcpy(createReq.user, "");
strcpy(createReq.pass, "p1");
SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "");
strcpy(pReq->pass, "p1");
int32_t contLen = tSerializeSCreateUserReq(NULL, &createReq);
void* pReq = rpcMallocCont(contLen);
void* pBuf = pReq;
tSerializeSCreateUserReq(&pBuf, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
......@@ -57,11 +60,14 @@ TEST_F(MndTestUser, 02_Create_User) {
}
{
int32_t contLen = sizeof(SCreateUserReq);
SCreateUserReq createReq = {0};
strcpy(createReq.user, "u1");
strcpy(createReq.pass, "");
SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "u1");
strcpy(pReq->pass, "");
int32_t contLen = tSerializeSCreateUserReq(NULL, &createReq);
void* pReq = rpcMallocCont(contLen);
void* pBuf = pReq;
tSerializeSCreateUserReq(&pBuf, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
......@@ -69,11 +75,14 @@ TEST_F(MndTestUser, 02_Create_User) {
}
{
int32_t contLen = sizeof(SCreateUserReq);
SCreateUserReq createReq = {0};
strcpy(createReq.user, "root");
strcpy(createReq.pass, "1");
SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "root");
strcpy(pReq->pass, "1");
int32_t contLen = tSerializeSCreateUserReq(NULL, &createReq);
void* pReq = rpcMallocCont(contLen);
void* pBuf = pReq;
tSerializeSCreateUserReq(&pBuf, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
......@@ -81,11 +90,14 @@ TEST_F(MndTestUser, 02_Create_User) {
}
{
int32_t contLen = sizeof(SCreateUserReq);
SCreateUserReq createReq = {0};
strcpy(createReq.user, "u1");
strcpy(createReq.pass, "p1");
SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "u1");
strcpy(pReq->pass, "p1");
int32_t contLen = tSerializeSCreateUserReq(NULL, &createReq);
void* pReq = rpcMallocCont(contLen);
void* pBuf = pReq;
tSerializeSCreateUserReq(&pBuf, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
......@@ -101,11 +113,15 @@ TEST_F(MndTestUser, 02_Create_User) {
TEST_F(MndTestUser, 03_Alter_User) {
{
int32_t contLen = sizeof(SAlterUserReq);
SAlterUserReq alterReq = {0};
alterReq.alterType = TSDB_ALTER_USER_PASSWD;
strcpy(alterReq.user, "");
strcpy(alterReq.pass, "p1");
SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "");
strcpy(pReq->pass, "p1");
int32_t contLen = tSerializeSAlterUserReq(NULL, &alterReq);
void* pReq = rpcMallocCont(contLen);
void* pBuf = pReq;
tSerializeSAlterUserReq(&pBuf, &alterReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
......@@ -113,11 +129,15 @@ TEST_F(MndTestUser, 03_Alter_User) {
}
{
int32_t contLen = sizeof(SAlterUserReq);
SAlterUserReq alterReq = {0};
alterReq.alterType = TSDB_ALTER_USER_PASSWD;
strcpy(alterReq.user, "u1");
strcpy(alterReq.pass, "");
SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "u1");
strcpy(pReq->pass, "");
int32_t contLen = tSerializeSAlterUserReq(NULL, &alterReq);
void* pReq = rpcMallocCont(contLen);
void* pBuf = pReq;
tSerializeSAlterUserReq(&pBuf, &alterReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
......@@ -125,11 +145,15 @@ TEST_F(MndTestUser, 03_Alter_User) {
}
{
int32_t contLen = sizeof(SAlterUserReq);
SAlterUserReq alterReq = {0};
alterReq.alterType = TSDB_ALTER_USER_PASSWD;
strcpy(alterReq.user, "u4");
strcpy(alterReq.pass, "1");
SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "u4");
strcpy(pReq->pass, "1");
int32_t contLen = tSerializeSAlterUserReq(NULL, &alterReq);
void* pReq = rpcMallocCont(contLen);
void* pBuf = pReq;
tSerializeSAlterUserReq(&pBuf, &alterReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
......@@ -137,11 +161,15 @@ TEST_F(MndTestUser, 03_Alter_User) {
}
{
int32_t contLen = sizeof(SAlterUserReq);
SAlterUserReq alterReq = {0};
alterReq.alterType = TSDB_ALTER_USER_PASSWD;
strcpy(alterReq.user, "u1");
strcpy(alterReq.pass, "1");
SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "u1");
strcpy(pReq->pass, "1");
int32_t contLen = tSerializeSAlterUserReq(NULL, &alterReq);
void* pReq = rpcMallocCont(contLen);
void* pBuf = pReq;
tSerializeSAlterUserReq(&pBuf, &alterReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
......@@ -151,10 +179,13 @@ TEST_F(MndTestUser, 03_Alter_User) {
TEST_F(MndTestUser, 04_Drop_User) {
{
int32_t contLen = sizeof(SDropUserReq);
SDropUserReq dropReq = {0};
strcpy(dropReq.user, "");
SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "");
int32_t contLen = tSerializeSDropUserReq(NULL, &dropReq);
void* pReq = rpcMallocCont(contLen);
void* pBuf = pReq;
tSerializeSDropUserReq(&pBuf, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
......@@ -162,10 +193,13 @@ TEST_F(MndTestUser, 04_Drop_User) {
}
{
int32_t contLen = sizeof(SDropUserReq);
SDropUserReq dropReq = {0};
strcpy(dropReq.user, "u4");
SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "u4");
int32_t contLen = tSerializeSDropUserReq(NULL, &dropReq);
void* pReq = rpcMallocCont(contLen);
void* pBuf = pReq;
tSerializeSDropUserReq(&pBuf, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
......@@ -173,10 +207,13 @@ TEST_F(MndTestUser, 04_Drop_User) {
}
{
int32_t contLen = sizeof(SDropUserReq);
SDropUserReq dropReq = {0};
strcpy(dropReq.user, "u1");
SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "u1");
int32_t contLen = tSerializeSDropUserReq(NULL, &dropReq);
void* pReq = rpcMallocCont(contLen);
void* pBuf = pReq;
tSerializeSDropUserReq(&pBuf, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
......@@ -192,11 +229,14 @@ TEST_F(MndTestUser, 04_Drop_User) {
TEST_F(MndTestUser, 05_Create_Drop_Alter_User) {
{
int32_t contLen = sizeof(SCreateUserReq);
SCreateUserReq createReq = {0};
strcpy(createReq.user, "u1");
strcpy(createReq.pass, "p1");
SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "u1");
strcpy(pReq->pass, "p1");
int32_t contLen = tSerializeSCreateUserReq(NULL, &createReq);
void* pReq = rpcMallocCont(contLen);
void* pBuf = pReq;
tSerializeSCreateUserReq(&pBuf, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
......@@ -204,11 +244,14 @@ TEST_F(MndTestUser, 05_Create_Drop_Alter_User) {
}
{
int32_t contLen = sizeof(SCreateUserReq);
SCreateUserReq createReq = {0};
strcpy(createReq.user, "u2");
strcpy(createReq.pass, "p2");
SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "u2");
strcpy(pReq->pass, "p2");
int32_t contLen = tSerializeSCreateUserReq(NULL, &createReq);
void* pReq = rpcMallocCont(contLen);
void* pBuf = pReq;
tSerializeSCreateUserReq(&pBuf, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
......@@ -235,11 +278,15 @@ TEST_F(MndTestUser, 05_Create_Drop_Alter_User) {
CheckBinary("root", TSDB_USER_LEN);
{
int32_t contLen = sizeof(SAlterUserReq);
SAlterUserReq alterReq = {0};
alterReq.alterType = TSDB_ALTER_USER_PASSWD;
strcpy(alterReq.user, "u1");
strcpy(alterReq.pass, "p2");
SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "u1");
strcpy(pReq->pass, "p2");
int32_t contLen = tSerializeSAlterUserReq(NULL, &alterReq);
void* pReq = rpcMallocCont(contLen);
void* pBuf = pReq;
tSerializeSAlterUserReq(&pBuf, &alterReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
......@@ -266,10 +313,13 @@ TEST_F(MndTestUser, 05_Create_Drop_Alter_User) {
CheckBinary("root", TSDB_USER_LEN);
{
int32_t contLen = sizeof(SDropUserReq);
SDropUserReq dropReq = {0};
strcpy(dropReq.user, "u1");
SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "u1");
int32_t contLen = tSerializeSDropUserReq(NULL, &dropReq);
void* pReq = rpcMallocCont(contLen);
void* pBuf = pReq;
tSerializeSDropUserReq(&pBuf, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
......
......@@ -5,9 +5,9 @@
#include "tmsg.h"
SCreateUserReq* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen);
SCreateAcctReq* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen);
SDropUserReq* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen);
char* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen);
char* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen);
char* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen);
SShowReq* buildShowMsg(SShowInfo* pShowInfo, SParseContext* pParseCtx, SMsgBuf* pMsgBuf);
SCreateDbReq* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, SParseContext *pCtx, SMsgBuf* pMsgBuf);
char* buildCreateStbReq(SCreateTableSql* pCreateTableSql, int32_t* len, SParseContext* pParseCtx, SMsgBuf* pMsgBuf);
......
......@@ -2,87 +2,101 @@
#include "astGenerator.h"
#include "parserUtil.h"
SCreateUserReq* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) {
SCreateUserReq* pMsg = (SCreateUserReq*)calloc(1, sizeof(SCreateUserReq));
if (pMsg == NULL) {
// tscError("0x%" PRIx64 " failed to malloc for query msg", id);
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
return NULL;
}
char* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) {
SCreateUserReq createReq = {0};
SUserInfo* pUser = &pInfo->pMiscInfo->user;
strncpy(pMsg->user, pUser->user.z, pUser->user.n);
pMsg->type = pUser->type;
pMsg->superUser = (int8_t)pUser->type;
strncpy(createReq.user, pUser->user.z, pUser->user.n);
createReq.createType = pUser->type;
createReq.superUser = (int8_t)pUser->type;
if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) {
// pMsg->privilege = (char)pCmd->count;
} else {
strncpy(pMsg->pass, pUser->passwd.z, pUser->passwd.n);
strncpy(createReq.pass, pUser->passwd.z, pUser->passwd.n);
}
*outputLen = sizeof(SUserInfo);
return pMsg;
}
SCreateAcctReq* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) {
SCreateAcctReq *pCreateMsg = (SCreateAcctReq *) calloc(1, sizeof(SCreateAcctReq));
if (pCreateMsg == NULL) {
qError("0x%" PRIx64 " failed to malloc for query msg", id);
terrno = TSDB_CODE_QRY_OUT_OF_MEMORY;
int32_t tlen = tSerializeSCreateUserReq(NULL, &createReq);
void* pReq = malloc(tlen);
if (pReq == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
SToken *pName = &pInfo->pMiscInfo->user.user;
SToken *pPwd = &pInfo->pMiscInfo->user.passwd;
void* pBuf = pReq;
tSerializeSCreateUserReq(&pBuf, &createReq);
*outputLen = tlen;
return pReq;
}
char* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) {
SCreateAcctReq createReq = {0};
SToken* pName = &pInfo->pMiscInfo->user.user;
SToken* pPwd = &pInfo->pMiscInfo->user.passwd;
strncpy(pCreateMsg->user, pName->z, pName->n);
strncpy(pCreateMsg->pass, pPwd->z, pPwd->n);
strncpy(createReq.user, pName->z, pName->n);
strncpy(createReq.pass, pPwd->z, pPwd->n);
SCreateAcctInfo *pAcctOpt = &pInfo->pMiscInfo->acctOpt;
SCreateAcctInfo* pAcctOpt = &pInfo->pMiscInfo->acctOpt;
pCreateMsg->maxUsers = htonl(pAcctOpt->maxUsers);
pCreateMsg->maxDbs = htonl(pAcctOpt->maxDbs);
pCreateMsg->maxTimeSeries = htonl(pAcctOpt->maxTimeSeries);
pCreateMsg->maxStreams = htonl(pAcctOpt->maxStreams);
// pCreateMsg->maxPointsPerSecond = htonl(pAcctOpt->maxPointsPerSecond);
pCreateMsg->maxStorage = htobe64(pAcctOpt->maxStorage);
// pCreateMsg->maxQueryTime = htobe64(pAcctOpt->maxQueryTime);
// pCreateMsg->maxConnections = htonl(pAcctOpt->maxConnections);
createReq.maxUsers = htonl(pAcctOpt->maxUsers);
createReq.maxDbs = htonl(pAcctOpt->maxDbs);
createReq.maxTimeSeries = htonl(pAcctOpt->maxTimeSeries);
createReq.maxStreams = htonl(pAcctOpt->maxStreams);
// createReq.maxPointsPerSecond = htonl(pAcctOpt->maxPointsPerSecond);
createReq.maxStorage = htobe64(pAcctOpt->maxStorage);
// createReq.maxQueryTime = htobe64(pAcctOpt->maxQueryTime);
// createReq.maxConnections = htonl(pAcctOpt->maxConnections);
if (pAcctOpt->stat.n == 0) {
pCreateMsg->accessState = -1;
createReq.accessState = -1;
} else {
if (pAcctOpt->stat.z[0] == 'r' && pAcctOpt->stat.n == 1) {
pCreateMsg->accessState = TSDB_VN_READ_ACCCESS;
createReq.accessState = TSDB_VN_READ_ACCCESS;
} else if (pAcctOpt->stat.z[0] == 'w' && pAcctOpt->stat.n == 1) {
pCreateMsg->accessState = TSDB_VN_WRITE_ACCCESS;
createReq.accessState = TSDB_VN_WRITE_ACCCESS;
} else if (strncmp(pAcctOpt->stat.z, "all", 3) == 0 && pAcctOpt->stat.n == 3) {
pCreateMsg->accessState = TSDB_VN_ALL_ACCCESS;
createReq.accessState = TSDB_VN_ALL_ACCCESS;
} else if (strncmp(pAcctOpt->stat.z, "no", 2) == 0 && pAcctOpt->stat.n == 2) {
pCreateMsg->accessState = 0;
createReq.accessState = 0;
}
}
*outputLen = sizeof(SCreateAcctReq);
return pCreateMsg;
int32_t tlen = tSerializeSCreateAcctReq(NULL, &createReq);
void* pReq = malloc(tlen);
if (pReq == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
void* pBuf = pReq;
tSerializeSCreateAcctReq(&pBuf, &createReq);
*outputLen = tlen;
return pReq;
}
SDropUserReq* buildDropUserMsg(SSqlInfo* pInfo, int32_t *msgLen, int64_t id, char* msgBuf, int32_t msgBufLen) {
char* buildDropUserMsg(SSqlInfo* pInfo, int32_t* msgLen, int64_t id, char* msgBuf, int32_t msgBufLen) {
SDropUserReq dropReq = {0};
SToken* pName = taosArrayGet(pInfo->pMiscInfo->a, 0);
if (pName->n >= TSDB_USER_LEN) {
return NULL;
}
SDropUserReq* pMsg = calloc(1, sizeof(SDropUserReq));
if (pMsg == NULL) {
terrno = TSDB_CODE_QRY_OUT_OF_MEMORY;
strncpy(dropReq.user, pName->z, pName->n);
int32_t tlen = tSerializeSDropUserReq(NULL, &dropReq);
void* pReq = malloc(tlen);
if (pReq == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
strncpy(pMsg->user, pName->z, pName->n);
*msgLen = sizeof(SDropUserReq);
return pMsg;
void* pBuf = pReq;
tSerializeSDropUserReq(&pBuf, &dropReq);
*msgLen = tlen;
return pReq;
}
SShowReq* buildShowMsg(SShowInfo* pShowInfo, SParseContext *pCtx, SMsgBuf* pMsgBuf) {
......@@ -268,16 +282,16 @@ char* buildCreateStbReq(SCreateTableSql* pCreateTableSql, int32_t* len, SParseCo
}
int32_t tlen = tSerializeSMCreateStbReq(NULL, &createReq);
void* req = malloc(tlen);
if (req == NULL) {
void* pReq = malloc(tlen);
if (pReq == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
void* buf = req;
tSerializeSMCreateStbReq(&buf, &createReq);
void* pBuf = pReq;
tSerializeSMCreateStbReq(&pBuf, &createReq);
*len = tlen;
return req;
return pReq;
}
char* buildDropStableReq(SSqlInfo* pInfo, int32_t* len, SParseContext* pParseCtx, SMsgBuf* pMsgBuf) {
......@@ -297,16 +311,16 @@ char* buildDropStableReq(SSqlInfo* pInfo, int32_t* len, SParseContext* pParseCtx
dropReq.igNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0;
int32_t tlen = tSerializeSMDropStbReq(NULL, &dropReq);
void* req = malloc(tlen);
if (req == NULL) {
void* pReq = malloc(tlen);
if (pReq == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
void* buf = req;
tSerializeSMDropStbReq(&buf, &dropReq);
void* pBuf = pReq;
tSerializeSMDropStbReq(&pBuf, &dropReq);
*len = tlen;
return req;
return pReq;
}
SCreateDnodeReq *buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf) {
......
......@@ -209,6 +209,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_USERS, "Too many users")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_USER_FORMAT, "Invalid user format")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_PASS_FORMAT, "Invalid password format")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_USER_FROM_CONN, "Can not get user from conn")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ALTER_OPER, "Invalid alter operation")
// mnode-db
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_ALREADY_EXIST, "Database already exists")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册