提交 689e7f0e 编写于 作者: S Shengliang Guan

process get user auth request

上级 fb9b00ef
...@@ -371,15 +371,32 @@ void* tDeserializeSCreateUserReq(void* buf, SCreateUserReq* pReq); ...@@ -371,15 +371,32 @@ void* tDeserializeSCreateUserReq(void* buf, SCreateUserReq* pReq);
typedef struct { typedef struct {
int8_t alterType; int8_t alterType;
int8_t superUser;
char user[TSDB_USER_LEN]; char user[TSDB_USER_LEN];
char pass[TSDB_PASSWORD_LEN]; char pass[TSDB_PASSWORD_LEN];
char dbname[TSDB_DB_FNAME_LEN]; char dbname[TSDB_DB_FNAME_LEN];
int8_t superUser;
} SAlterUserReq; } SAlterUserReq;
int32_t tSerializeSAlterUserReq(void** buf, SAlterUserReq* pReq); int32_t tSerializeSAlterUserReq(void** buf, SAlterUserReq* pReq);
void* tDeserializeSAlterUserReq(void* buf, SAlterUserReq* pReq); void* tDeserializeSAlterUserReq(void* buf, SAlterUserReq* pReq);
typedef struct {
char user[TSDB_USER_LEN];
} SGetUserAuthReq;
int32_t tSerializeSGetUserAuthReq(void** buf, SGetUserAuthReq* pReq);
void* tDeserializeSGetUserAuthReq(void* buf, SGetUserAuthReq* pReq);
typedef struct {
char user[TSDB_USER_LEN];
int8_t superAuth;
SHashObj* readDbs;
SHashObj* writeDbs;
} SGetUserAuthRsp;
int32_t tSerializeSGetUserAuthRsp(void** buf, SGetUserAuthRsp* pReq);
void* tDeserializeSGetUserAuthRsp(void* buf, SGetUserAuthRsp* pReq);
typedef struct { typedef struct {
int16_t colId; // column id int16_t colId; // column id
int16_t colIndex; // column index in colList if it is a normal column or index in tagColList if a tag int16_t colIndex; // column index in colList if it is a normal column or index in tagColList if a tag
......
...@@ -97,6 +97,7 @@ enum { ...@@ -97,6 +97,7 @@ enum {
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_USER, "mnode-create-user", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_CREATE_USER, "mnode-create-user", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_USER, "mnode-alter-user", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_ALTER_USER, "mnode-alter-user", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_DROP_USER, "mnode-drop-user", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_DROP_USER, "mnode-drop-user", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_GET_USER_AUTH, "mnode-get-user-auth", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_DNODE, "mnode-create-dnode", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_CREATE_DNODE, "mnode-create-dnode", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_CONFIG_DNODE, "mnode-config-dnode", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_CONFIG_DNODE, "mnode-config-dnode", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_DNODE, "mnode-alter-dnode", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_ALTER_DNODE, "mnode-alter-dnode", NULL, NULL)
......
...@@ -670,4 +670,72 @@ void *tDeserializeSAlterUserReq(void *buf, SAlterUserReq *pReq) { ...@@ -670,4 +670,72 @@ void *tDeserializeSAlterUserReq(void *buf, SAlterUserReq *pReq) {
buf = taosDecodeStringTo(buf, pReq->dbname); buf = taosDecodeStringTo(buf, pReq->dbname);
buf = taosDecodeFixedI8(buf, &pReq->superUser); buf = taosDecodeFixedI8(buf, &pReq->superUser);
return buf; return buf;
} }
\ No newline at end of file
int32_t tSerializeSGetUserAuthReq(void **buf, SGetUserAuthReq *pReq) {
int32_t tlen = 0;
tlen += taosEncodeString(buf, pReq->user);
return tlen;
}
void *tDeserializeSGetUserAuthReq(void *buf, SGetUserAuthReq *pReq) {
buf = taosDecodeStringTo(buf, pReq->user);
return buf;
}
int32_t tSerializeSGetUserAuthRsp(void **buf, SGetUserAuthRsp *pReq) {
int32_t tlen = 0;
tlen += taosEncodeString(buf, pReq->user);
tlen += taosEncodeFixedI8(buf, pReq->superAuth);
int32_t numOfReadDbs = taosHashGetSize(pReq->readDbs);
int32_t numOfWriteDbs = taosHashGetSize(pReq->writeDbs);
tlen += taosEncodeFixedI32(buf, numOfReadDbs);
tlen += taosEncodeFixedI32(buf, numOfWriteDbs);
char *db = taosHashIterate(pReq->readDbs, NULL);
while (db != NULL) {
tlen += taosEncodeString(buf, db);
db = taosHashIterate(pReq->readDbs, db);
}
db = taosHashIterate(pReq->writeDbs, NULL);
while (db != NULL) {
tlen += taosEncodeString(buf, db);
db = taosHashIterate(pReq->writeDbs, db);
}
return tlen;
}
void *tDeserializeSGetUserAuthRsp(void *buf, SGetUserAuthRsp *pReq) {
buf = taosDecodeStringTo(buf, pReq->user);
buf = taosDecodeFixedI8(buf, &pReq->superAuth);
pReq->readDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false);
pReq->writeDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false);
if (pReq->readDbs == NULL || pReq->writeDbs == NULL) {
return NULL;
}
int32_t numOfReadDbs = 0;
int32_t numOfWriteDbs = 0;
buf = taosDecodeFixedI32(buf, &numOfReadDbs);
buf = taosDecodeFixedI32(buf, &numOfWriteDbs);
for (int32_t i = 0; i < numOfReadDbs; ++i) {
char db[TSDB_DB_FNAME_LEN] = {0};
buf = taosDecodeStringTo(buf, db);
int32_t len = strlen(db) + 1;
taosHashPut(pReq->readDbs, db, len, db, len);
}
for (int32_t i = 0; i < numOfWriteDbs; ++i) {
char db[TSDB_DB_FNAME_LEN] = {0};
buf = taosDecodeStringTo(buf, db);
int32_t len = strlen(db) + 1;
taosHashPut(pReq->writeDbs, db, len, db, len);
}
return buf;
}
...@@ -73,6 +73,7 @@ static void dndInitMsgFp(STransMgmt *pMgmt) { ...@@ -73,6 +73,7 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_USER)] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_USER)] = dndProcessMnodeWriteMsg;
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_ALTER_USER)] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_ALTER_USER)] = dndProcessMnodeWriteMsg;
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_USER)] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_USER)] = dndProcessMnodeWriteMsg;
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = dndProcessMnodeReadMsg;
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_DNODE)] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_DNODE)] = dndProcessMnodeWriteMsg;
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CONFIG_DNODE)] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CONFIG_DNODE)] = dndProcessMnodeWriteMsg;
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_DNODE)] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_DNODE)] = dndProcessMnodeWriteMsg;
......
...@@ -34,6 +34,7 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, SCreateUserReq *pCreat ...@@ -34,6 +34,7 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, SCreateUserReq *pCreat
static int32_t mndProcessCreateUserReq(SMnodeMsg *pReq); static int32_t mndProcessCreateUserReq(SMnodeMsg *pReq);
static int32_t mndProcessAlterUserReq(SMnodeMsg *pReq); static int32_t mndProcessAlterUserReq(SMnodeMsg *pReq);
static int32_t mndProcessDropUserReq(SMnodeMsg *pReq); static int32_t mndProcessDropUserReq(SMnodeMsg *pReq);
static int32_t mndProcessGetUserAuthReq(SMnodeMsg *pReq);
static int32_t mndGetUserMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta); static int32_t mndGetUserMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta);
static int32_t mndRetrieveUsers(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); static int32_t mndRetrieveUsers(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows);
static void mndCancelGetNextUser(SMnode *pMnode, void *pIter); static void mndCancelGetNextUser(SMnode *pMnode, void *pIter);
...@@ -51,6 +52,7 @@ int32_t mndInitUser(SMnode *pMnode) { ...@@ -51,6 +52,7 @@ int32_t mndInitUser(SMnode *pMnode) {
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_USER, mndProcessCreateUserReq); mndSetMsgHandle(pMnode, TDMT_MND_CREATE_USER, mndProcessCreateUserReq);
mndSetMsgHandle(pMnode, TDMT_MND_ALTER_USER, mndProcessAlterUserReq); mndSetMsgHandle(pMnode, TDMT_MND_ALTER_USER, mndProcessAlterUserReq);
mndSetMsgHandle(pMnode, TDMT_MND_DROP_USER, mndProcessDropUserReq); mndSetMsgHandle(pMnode, TDMT_MND_DROP_USER, mndProcessDropUserReq);
mndSetMsgHandle(pMnode, TDMT_MND_GET_USER_AUTH, mndProcessGetUserAuthReq);
mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_USER, mndGetUserMeta); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_USER, mndGetUserMeta);
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_USER, mndRetrieveUsers); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_USER, mndRetrieveUsers);
...@@ -574,6 +576,66 @@ DROP_USER_OVER: ...@@ -574,6 +576,66 @@ DROP_USER_OVER:
return code; return code;
} }
static int32_t mndProcessGetUserAuthReq(SMnodeMsg *pReq) {
SMnode *pMnode = pReq->pMnode;
int32_t code = -1;
SUserObj *pUser = NULL;
SGetUserAuthReq authReq = {0};
SGetUserAuthRsp authRsp = {0};
if (tDeserializeSGetUserAuthReq(pReq->rpcMsg.pCont, &authReq) == NULL) goto GET_AUTH_OVER;
mTrace("user:%s, start to get auth", authReq.user);
pUser = mndAcquireUser(pMnode, authReq.user);
if (pUser == NULL) {
terrno = TSDB_CODE_MND_USER_NOT_EXIST;
goto GET_AUTH_OVER;
}
memcpy(authRsp.user, pUser->user, TSDB_USER_LEN);
authRsp.superAuth = pUser->superUser;
authRsp.readDbs = mndDupDbHash(pUser->readDbs);
authRsp.writeDbs = mndDupDbHash(pUser->writeDbs);
SSdb *pSdb = pMnode->pSdb;
void *pIter = NULL;
while (1) {
SDbObj *pDb = NULL;
pIter = sdbFetch(pSdb, SDB_DB, pIter, (void **)&pDb);
if (pIter == NULL) break;
if (strcmp(pDb->createUser, pUser->user) == 0) {
int32_t len = strlen(pDb->name) + 1;
taosHashPut(authRsp.readDbs, pDb->name, len, pDb->name, len);
taosHashPut(authRsp.writeDbs, pDb->name, len, pDb->name, len);
}
sdbRelease(pSdb, pDb);
}
int32_t contLen = tSerializeSGetUserAuthRsp(NULL, &authRsp);
void *pRsp = rpcMallocCont(contLen);
if (pRsp == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto GET_AUTH_OVER;
}
void *pBuf = pRsp;
tSerializeSGetUserAuthRsp(&pBuf, &authRsp);
pReq->pCont = pRsp;
pReq->contLen = contLen;
code = 0;
GET_AUTH_OVER:
mndReleaseUser(pMnode, pUser);
taosHashCleanup(authRsp.readDbs);
taosHashCleanup(authRsp.writeDbs);
return code;
}
static int32_t mndGetUserMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { static int32_t mndGetUserMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) {
SMnode *pMnode = pReq->pMnode; SMnode *pMnode = pReq->pMnode;
SSdb *pSdb = pMnode->pSdb; SSdb *pSdb = pMnode->pSdb;
...@@ -668,4 +730,4 @@ static int32_t mndRetrieveUsers(SMnodeMsg *pReq, SShowObj *pShow, char *data, in ...@@ -668,4 +730,4 @@ static int32_t mndRetrieveUsers(SMnodeMsg *pReq, SShowObj *pShow, char *data, in
static void mndCancelGetNextUser(SMnode *pMnode, void *pIter) { static void mndCancelGetNextUser(SMnode *pMnode, void *pIter) {
SSdb *pSdb = pMnode->pSdb; SSdb *pSdb = pMnode->pSdb;
sdbCancelFetch(pSdb, pIter); sdbCancelFetch(pSdb, pIter);
} }
\ No newline at end of file
...@@ -398,6 +398,34 @@ TEST_F(MndTestUser, 03_Alter_User) { ...@@ -398,6 +398,34 @@ TEST_F(MndTestUser, 03_Alter_User) {
ASSERT_EQ(pRsp->code, 0); ASSERT_EQ(pRsp->code, 0);
} }
{
SGetUserAuthReq authReq = {0};
strcpy(authReq.user, "u3");
int32_t contLen = tSerializeSGetUserAuthReq(NULL, &authReq);
void* pReq = rpcMallocCont(contLen);
void* pBuf = pReq;
tSerializeSGetUserAuthReq(&pBuf, &authReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_GET_USER_AUTH, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
SGetUserAuthRsp authRsp = {0};
tDeserializeSGetUserAuthRsp(pRsp->pCont, &authRsp);
EXPECT_STREQ(authRsp.user, "u3");
EXPECT_EQ(authRsp.superAuth, 1);
int32_t numOfReadDbs = taosHashGetSize(authRsp.readDbs);
int32_t numOfWriteDbs = taosHashGetSize(authRsp.writeDbs);
EXPECT_EQ(numOfReadDbs, 1);
EXPECT_EQ(numOfWriteDbs, 0);
char* dbname = (char*)taosHashGet(authRsp.readDbs, "1.d2", 5);
EXPECT_STREQ(dbname, "1.d2");
taosHashCleanup(authRsp.readDbs);
taosHashCleanup(authRsp.writeDbs);
}
{ {
SAlterUserReq alterReq = {0}; SAlterUserReq alterReq = {0};
alterReq.alterType = TSDB_ALTER_USER_REMOVE_READ_DB; alterReq.alterType = TSDB_ALTER_USER_REMOVE_READ_DB;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册