refact<cluster>: adjust auth code
This commit is contained in:
parent
495e417ce6
commit
b086dcafac
|
@ -74,26 +74,12 @@ void mndStop(SMnode *pMnode);
|
||||||
* @brief Get mnode monitor info.
|
* @brief Get mnode monitor info.
|
||||||
*
|
*
|
||||||
* @param pMnode The mnode object.
|
* @param pMnode The mnode object.
|
||||||
* @param pClusterInfo
|
* @param pCluster
|
||||||
* @param pVgroupInfo
|
* @param pVgroup
|
||||||
* @param pGrantInfo
|
* @param pGrant
|
||||||
* @return int32_t 0 for success, -1 for failure.
|
* @return int32_t 0 for success, -1 for failure.
|
||||||
*/
|
*/
|
||||||
int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo,
|
int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pCluster, SMonVgroupInfo *pVgroup, SMonGrantInfo *pGrant);
|
||||||
SMonGrantInfo *pGrantInfo);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get user authentication info.
|
|
||||||
*
|
|
||||||
* @param pMnode The mnode object.
|
|
||||||
* @param user
|
|
||||||
* @param spi
|
|
||||||
* @param encrypt
|
|
||||||
* @param secret
|
|
||||||
* @param ckey
|
|
||||||
* @return int32_t 0 for success, -1 for failure.
|
|
||||||
*/
|
|
||||||
int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Process the read, write, sync request.
|
* @brief Process the read, write, sync request.
|
||||||
|
@ -105,7 +91,6 @@ int32_t mndProcessMsg(SNodeMsg *pMsg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Generate machine code
|
* @brief Generate machine code
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
void mndGenerateMachineCode();
|
void mndGenerateMachineCode();
|
||||||
|
|
||||||
|
|
|
@ -26,22 +26,22 @@ int32_t mndInitAuth(SMnode *pMnode) {
|
||||||
|
|
||||||
void mndCleanupAuth(SMnode *pMnode) {}
|
void mndCleanupAuth(SMnode *pMnode) {}
|
||||||
|
|
||||||
int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
static int32_t mndRetriveAuth(SMnode *pMnode, SAuthRsp *pRsp) {
|
||||||
SUserObj *pUser = mndAcquireUser(pMnode, user);
|
SUserObj *pUser = mndAcquireUser(pMnode, pRsp->user);
|
||||||
if (pUser == NULL) {
|
if (pUser == NULL) {
|
||||||
*secret = 0;
|
*pRsp->secret = 0;
|
||||||
mError("user:%s, failed to auth user since %s", user, terrstr());
|
mError("user:%s, failed to auth user since %s", pRsp->user, terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*spi = 1;
|
pRsp->spi = 1;
|
||||||
*encrypt = 0;
|
pRsp->encrypt = 0;
|
||||||
*ckey = 0;
|
*pRsp->ckey = 0;
|
||||||
|
|
||||||
memcpy(secret, pUser->pass, TSDB_PASSWORD_LEN);
|
memcpy(pRsp->secret, pUser->pass, TSDB_PASSWORD_LEN);
|
||||||
mndReleaseUser(pMnode, pUser);
|
mndReleaseUser(pMnode, pUser);
|
||||||
|
|
||||||
mDebug("user:%s, auth info is returned", user);
|
mDebug("user:%s, auth info is returned", pRsp->user);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,14 +55,19 @@ static int32_t mndProcessAuthReq(SNodeMsg *pReq) {
|
||||||
SAuthReq authRsp = {0};
|
SAuthReq authRsp = {0};
|
||||||
memcpy(authRsp.user, authReq.user, TSDB_USER_LEN);
|
memcpy(authRsp.user, authReq.user, TSDB_USER_LEN);
|
||||||
|
|
||||||
int32_t code =
|
int32_t code = mndRetriveAuth(pReq->pNode, &authRsp);
|
||||||
mndRetriveAuth(pReq->pNode, authRsp.user, &authRsp.spi, &authRsp.encrypt, authRsp.secret, authRsp.ckey);
|
|
||||||
mTrace("user:%s, auth req received, spi:%d encrypt:%d ruser:%s", pReq->user, authRsp.spi, authRsp.encrypt,
|
mTrace("user:%s, auth req received, spi:%d encrypt:%d ruser:%s", pReq->user, authRsp.spi, authRsp.encrypt,
|
||||||
authRsp.user);
|
authRsp.user);
|
||||||
|
|
||||||
int32_t contLen = tSerializeSAuthReq(NULL, 0, &authRsp);
|
int32_t contLen = tSerializeSAuthReq(NULL, 0, &authRsp);
|
||||||
void *pRsp = rpcMallocCont(contLen);
|
void *pRsp = rpcMallocCont(contLen);
|
||||||
|
if (pRsp == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
tSerializeSAuthReq(pRsp, contLen, &authRsp);
|
tSerializeSAuthReq(pRsp, contLen, &authRsp);
|
||||||
|
|
||||||
pReq->pRsp = pRsp;
|
pReq->pRsp = pRsp;
|
||||||
pReq->rspLen = contLen;
|
pReq->rspLen = contLen;
|
||||||
return code;
|
return code;
|
||||||
|
@ -95,11 +100,11 @@ int32_t mndCheckAlterUserAuth(SUserObj *pOperUser, SUserObj *pUser, SDbObj *pDb,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pAlter->alterType == TSDB_ALTER_USER_CLEAR_WRITE_DB || pAlter->alterType == TSDB_ALTER_USER_CLEAR_READ_DB) {
|
if (pAlter->alterType == TSDB_ALTER_USER_CLEAR_WRITE_DB || pAlter->alterType == TSDB_ALTER_USER_CLEAR_READ_DB) {
|
||||||
if (pOperUser->superUser) {
|
if (pOperUser->superUser) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (pAlter->alterType == TSDB_ALTER_USER_ADD_READ_DB || pAlter->alterType == TSDB_ALTER_USER_REMOVE_READ_DB ||
|
if (pAlter->alterType == TSDB_ALTER_USER_ADD_READ_DB || pAlter->alterType == TSDB_ALTER_USER_REMOVE_READ_DB ||
|
||||||
pAlter->alterType == TSDB_ALTER_USER_ADD_WRITE_DB || pAlter->alterType == TSDB_ALTER_USER_REMOVE_WRITE_DB) {
|
pAlter->alterType == TSDB_ALTER_USER_ADD_WRITE_DB || pAlter->alterType == TSDB_ALTER_USER_REMOVE_WRITE_DB) {
|
||||||
|
@ -176,4 +181,4 @@ int32_t mndCheckReadAuth(SUserObj *pOperUser, SDbObj *pDb) {
|
||||||
|
|
||||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue