提交 cdee51f6 编写于 作者: S slguan

message of account

上级 07e6caa3
......@@ -196,7 +196,7 @@ int tscSendMsgToServer(SSqlObj *pSql) {
}
void tscProcessMsgFromServer(char type, void *pCont, int contLen, void *ahandle, int32_t code) {
tscPrint("response is received, pCont:%p, code:%d", pCont, code);
tscPrint("response:%d is received, pCont:%p, contLen:%d code:%d", type, pCont, contLen, code);
SSqlObj *pSql = (SSqlObj *)ahandle;
if (pSql == NULL || pSql->signature != pSql) {
tscError("%p sql is already released, signature:%p", pSql, pSql->signature);
......@@ -1692,15 +1692,14 @@ int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCreateAcctMsg *pAlterMsg;
char * pMsg, *pStart;
int msgLen = 0;
SSqlCmd *pCmd = &pSql->cmd;
pCmd->payloadLen = sizeof(SCMCreateAcctMsg);
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY;
}
pMsg = doBuildMsgHeader(pSql, &pStart);
pAlterMsg = (SCreateAcctMsg *)pMsg;
SCMCreateAcctMsg *pAlterMsg = (SCMCreateAcctMsg *)pCmd->payload;
SSQLToken *pName = &pInfo->pDCLInfo->user.user;
SSQLToken *pPwd = &pInfo->pDCLInfo->user.passwd;
......@@ -1708,8 +1707,6 @@ int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
strncpy(pAlterMsg->user, pName->z, pName->n);
strncpy(pAlterMsg->pass, pPwd->z, pPwd->n);
pMsg += sizeof(SCreateAcctMsg);
SCreateAcctSQL *pAcctOpt = &pInfo->pDCLInfo->acctOpt;
pAlterMsg->cfg.maxUsers = htonl(pAcctOpt->maxUsers);
......@@ -1735,21 +1732,18 @@ int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
}
msgLen = pMsg - pStart;
pCmd->payloadLen = msgLen;
pCmd->msgType = TSDB_MSG_TYPE_CREATE_ACCT;
return TSDB_CODE_SUCCESS;
}
int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCreateUserMsg *pAlterMsg;
SCMCreateUserMsg *pAlterMsg;
char * pMsg, *pStart;
SSqlCmd *pCmd = &pSql->cmd;
pMsg = doBuildMsgHeader(pSql, &pStart);
pAlterMsg = (SCreateUserMsg *)pMsg;
pAlterMsg = (SCMCreateUserMsg *)pMsg;
SUserInfo *pUser = &pInfo->pDCLInfo->user;
strncpy(pAlterMsg->user, pUser->user.z, pUser->user.n);
......@@ -1764,7 +1758,7 @@ int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
strncpy(pAlterMsg->pass, pUser->passwd.z, pUser->passwd.n);
}
pMsg += sizeof(SCreateUserMsg);
pMsg += sizeof(SCMCreateUserMsg);
pCmd->payloadLen = pMsg - pStart;
if (pUser->type == TSDB_ALTER_USER_PASSWD || pUser->type == TSDB_ALTER_USER_PRIVILEGES) {
......@@ -1877,18 +1871,18 @@ int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SDropUserMsg *pDropMsg;
SCMDropUserMsg *pDropMsg;
char * pMsg, *pStart;
SSqlCmd *pCmd = &pSql->cmd;
pMsg = doBuildMsgHeader(pSql, &pStart);
pDropMsg = (SDropUserMsg *)pMsg;
pDropMsg = (SCMDropUserMsg *)pMsg;
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0);
strcpy(pDropMsg->user, pMeterMetaInfo->name);
pMsg += sizeof(SDropUserMsg);
pMsg += sizeof(SCMDropUserMsg);
pCmd->payloadLen = pMsg - pStart;
pCmd->msgType = TSDB_MSG_TYPE_DROP_USER;
......
......@@ -34,6 +34,7 @@ TAOS *taos_connect_imp(const char *ip, const char *user, const char *pass, const
void (*fp)(void *, TAOS_RES *, int), void *param, void **taos) {
STscObj *pObj;
taos_init();
if (user == NULL) {
......
......@@ -430,6 +430,9 @@ void tscFreeResData(SSqlObj* pSql) {
}
void tscFreeSqlResult(SSqlObj* pSql) {
//TODO not free
return;
tfree(pSql->res.pRsp);
pSql->res.row = 0;
pSql->res.numOfRows = 0;
......
......@@ -33,16 +33,12 @@
#include "dnodeVnodeMgmt.h"
#ifdef CLUSTER
#include "dnodeCluster.h"
#include "httpAdmin.h"
#include "mnodeAccount.h"
#include "mnodeBalance.h"
#include "mnodeCluster.h"
#include "sdbReplica.h"
#include "multilevelStorage.h"
#include "vnodeCluster.h"
#include "vnodeReplica.h"
#include "dnodeGrant.h"
#include "acct.h"
#include "admin.h"
#include "cluster.h"
#include "grant.h"
#include "replica.h"
#include "storage.h"
#endif
static pthread_mutex_t tsDnodeMutex;
......@@ -120,16 +116,7 @@ void dnodeCheckDataDirOpenned(const char *dir) {
void dnodeInitPlugins() {
#ifdef CLUSTER
dnodeClusterInit();
httpAdminInit();
mnodeAccountInit();
mnodeBalanceInit();
mnodeClusterInit();
sdbReplicaInit();
multilevelStorageInit();
vnodeClusterInit();
vnodeReplicaInit();
dnodeGrantInit();
acctInit();
#endif
}
......
......@@ -247,7 +247,7 @@ typedef struct _db_obj {
struct _acctObj;
typedef struct _user_obj {
char user[TSDB_USER_LEN + 1];
char user[TSDB_USER_LEN];
char pass[TSDB_KEY_LEN];
char acct[TSDB_USER_LEN];
int64_t createdTime;
......@@ -275,23 +275,21 @@ typedef struct {
int64_t totalPoints;
int64_t inblound;
int64_t outbound;
TSKEY sKey;
char accessState; // Checked by mgmt heartbeat message
int64_t sKey;
int8_t accessState; // Checked by mgmt heartbeat message
} SAcctInfo;
typedef struct _acctObj {
char user[TSDB_USER_LEN + 1];
char user[TSDB_USER_LEN];
char pass[TSDB_KEY_LEN];
SAcctCfg cfg;
SCMAcctCfg cfg;
int32_t acctId;
int64_t createdTime;
char reserved[15];
char updateEnd[1];
int8_t reserved[15];
int8_t updateEnd[1];
SAcctInfo acctInfo;
SDbObj * pHead;
SUserObj * pUser;
struct _connObj *pConn;
pthread_mutex_t mutex;
} SAcctObj;
......
......@@ -280,10 +280,6 @@ typedef struct {
uint8_t ignoreNotExists;
} SDropDbMsg, SUseDbMsg;
typedef struct {
char user[TSDB_USER_LEN];
} SDropUserMsg, SDropAcctMsg;
typedef struct {
char db[TSDB_DB_NAME_LEN];
} SShowTableMsg;
......@@ -340,21 +336,25 @@ typedef struct {
int64_t maxQueryTime; // In unit of hour
int64_t maxInbound;
int64_t maxOutbound;
char accessState; // Configured only by command
} SAcctCfg;
int8_t accessState; // Configured only by command
} SCMAcctCfg;
typedef struct {
char user[TSDB_USER_LEN];
char pass[TSDB_KEY_LEN];
SAcctCfg cfg;
} SCreateAcctMsg, SAlterAcctMsg;
char user[TSDB_USER_LEN];
char pass[TSDB_KEY_LEN];
SCMAcctCfg cfg;
} SCMCreateAcctMsg, SCMAlterAcctMsg;
typedef struct {
char user[TSDB_USER_LEN];
char pass[TSDB_KEY_LEN];
char privilege;
char flag;
} SCreateUserMsg, SAlterUserMsg;
} SCMDropUserMsg, SCMDropAcctMsg;
typedef struct {
char user[TSDB_USER_LEN];
char pass[TSDB_KEY_LEN];
int8_t privilege;
int8_t flag;
} SCMCreateUserMsg, SCMAlterUserMsg;
typedef struct {
char db[TSDB_TABLE_ID_LEN];
......
......@@ -81,7 +81,15 @@ struct arguments args = {
*/
int main(int argc, char* argv[]) {
/*setlocale(LC_ALL, "en_US.UTF-8"); */
//
void *taos = taos_connect(NULL, "root", "taosdata", NULL, 0);
printf("ok\n");
taos_query(taos, "create account a pass 'b'");
while (1) {
sleep(1000);
}
//
if (!checkVersion()) {
exit(EXIT_FAILURE);
}
......
......@@ -13,9 +13,9 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
ADD_LIBRARY(mnode ${SRC})
TARGET_LINK_LIBRARIES(mnode trpc tutil sdb pthread)
#IF (TD_CLUSTER)
# TARGET_LINK_LIBRARIES(mnode mcluster)
#ENDIF ()
IF (TD_CLUSTER)
TARGET_LINK_LIBRARIES(mnode acct)
ENDIF ()
ENDIF ()
......@@ -28,12 +28,11 @@ int32_t mgmtAddUserIntoAcct(SAcctObj *pAcct, SUserObj *pUser);
int32_t mgmtRemoveUserFromAcct(SAcctObj *pAcct, SUserObj *pUser);
extern int32_t (*mgmtInitAccts)();
extern void (*mgmtCleanUpAccts)();
extern SAcctObj* (*mgmtGetAcct)(char *acctName);
extern int32_t (*mgmtCheckUserLimit)(SAcctObj *pAcct);
extern int32_t (*mgmtCheckDbLimit)(SAcctObj *pAcct);
extern int32_t (*mgmtCheckTableLimit)(SAcctObj *pAcct, SCreateTableMsg *pCreate);
extern void (*mgmtCheckAcct)();
extern void (*mgmtCleanUpAccts)();
extern int32_t (*mgmtGetAcctMeta)(SMeterMeta *pMeta, SShowObj *pShow, void *pConn);
extern int32_t (*mgmtRetrieveAccts)(SShowObj *pShow, char *data, int32_t rows, void *pConn);
......
......@@ -97,18 +97,21 @@ int32_t mgmtRemoveUserFromAcct(SAcctObj *pAcct, SUserObj *pUser) {
}
int32_t mgmtInitAcctsImp() {
SAcctObj *pAcct = &tsAcctObj;
pAcct->acctId = 0;
strcpy(pAcct->user, "root");
return 0;
}
int32_t (*mgmtInitAccts)() = mgmtInitAcctsImp;
SAcctObj *mgmtGetAcctImp(char *acctName) {
static SAcctObj *mgmtGetAcctImp(char *acctName) {
return &tsAcctObj;
}
SAcctObj *(*mgmtGetAcct)(char *acctName) = mgmtGetAcctImp;
int32_t mgmtCheckUserLimitImp(SAcctObj *pAcct) {
static int32_t mgmtCheckUserLimitImp(SAcctObj *pAcct) {
int32_t numOfUsers = sdbGetNumOfRows(tsUserSdb);
if (numOfUsers >= tsMaxUsers) {
mWarn("numOfUsers:%d, exceed tsMaxUsers:%d", numOfUsers, tsMaxUsers);
......@@ -119,7 +122,7 @@ int32_t mgmtCheckUserLimitImp(SAcctObj *pAcct) {
int32_t (*mgmtCheckUserLimit)(SAcctObj *pAcct) = mgmtCheckUserLimitImp;
int32_t mgmtCheckDbLimitImp(SAcctObj *pAcct) {
static int32_t mgmtCheckDbLimitImp(SAcctObj *pAcct) {
int32_t numOfDbs = sdbGetNumOfRows(tsDbSdb);
if (numOfDbs >= tsMaxDbs) {
mWarn("numOfDbs:%d, exceed tsMaxDbs:%d", numOfDbs, tsMaxDbs);
......@@ -130,36 +133,24 @@ int32_t mgmtCheckDbLimitImp(SAcctObj *pAcct) {
int32_t (*mgmtCheckDbLimit)(SAcctObj *pAcct) = mgmtCheckDbLimitImp;
int32_t mgmtCheckTableLimitImp(SAcctObj *pAcct, SCreateTableMsg *pCreate) {
static int32_t mgmtCheckTableLimitImp(SAcctObj *pAcct, SCreateTableMsg *pCreate) {
return 0;
}
int32_t (*mgmtCheckTableLimit)(SAcctObj *pAcct, SCreateTableMsg *pCreate) = mgmtCheckTableLimitImp;
void mgmtCheckAcctImp() {
SAcctObj *pAcct = &tsAcctObj;
pAcct->acctId = 0;
strcpy(pAcct->user, "root");
mgmtCreateUser(pAcct, "root", "taosdata");
mgmtCreateUser(pAcct, "monitor", tsInternalPass);
mgmtCreateUser(pAcct, "_root", tsInternalPass);
}
void (*mgmtCheckAcct)() = mgmtCheckAcctImp;
void mgmtCleanUpAcctsImp() {
static void mgmtCleanUpAcctsImp() {
}
void (*mgmtCleanUpAccts)() = mgmtCleanUpAcctsImp;
int32_t mgmtGetAcctMetaImp(SMeterMeta *pMeta, SShowObj *pShow, void *pConn) {
static int32_t mgmtGetAcctMetaImp(SMeterMeta *pMeta, SShowObj *pShow, void *pConn) {
return TSDB_CODE_OPS_NOT_SUPPORT;
}
int32_t (*mgmtGetAcctMeta)(SMeterMeta *pMeta, SShowObj *pShow, void *pConn) = mgmtGetAcctMetaImp;
int32_t mgmtRetrieveAcctsImp(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
static int32_t mgmtRetrieveAcctsImp(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
return 0;
}
......
......@@ -60,6 +60,8 @@ void mgmtProcessTranRequest(SSchedMsg *sched) {
void *pConn = sched->thandle;
(*mgmtProcessShellMsg[msgType])(pCont, contLen, pConn);
//rpcSendResponse(pConn, 12, NULL, 0);
if (sched->msg) {
free(sched->msg);
}
......@@ -73,7 +75,7 @@ void mgmtAddToTranRequest(int8_t type, void *pCont, int contLen, void *ahandle)
schedMsg.thandle = ahandle;
*(int8_t *) (schedMsg.msg) = type;
*(int32_t *) (schedMsg.msg + sizeof(int8_t)) = contLen;
memcpy(schedMsg.msg, pCont + sizeof(int32_t) + sizeof(int8_t), contLen);
memcpy(schedMsg.msg + sizeof(int32_t) + sizeof(int8_t), pCont, contLen);
taosScheduleTask(tsMgmtTranQhandle, &schedMsg);
}
......@@ -632,7 +634,7 @@ int32_t mgmtProcessKillConnectionMsg(void *pCont, int32_t contLen, void *ahandle
}
int32_t mgmtProcessCreateUserMsg(void *pCont, int32_t contLen, void *ahandle) {
// SCreateUserMsg *pCreate = (SCreateUserMsg *)pMsg;
// SCMCreateUserMsg *pCreate = (SCMCreateUserMsg *)pMsg;
// int32_t code = 0;
//
// if (mgmtCheckRedirectMsg(pConn, TSDB_MSG_TYPE_CREATE_USER_RSP) != 0) {
......@@ -654,7 +656,7 @@ int32_t mgmtProcessCreateUserMsg(void *pCont, int32_t contLen, void *ahandle) {
}
int32_t mgmtProcessAlterUserMsg(void *pCont, int32_t contLen, void *ahandle) {
// SAlterUserMsg *pAlter = (SAlterUserMsg *)pMsg;
// SCMAlterUserMsg *pAlter = (SCMAlterUserMsg *)pMsg;
// int32_t code = 0;
// SUserObj * pUser;
// SUserObj * pOperUser;
......@@ -766,7 +768,7 @@ int32_t mgmtProcessAlterUserMsg(void *pCont, int32_t contLen, void *ahandle) {
}
int32_t mgmtProcessDropUserMsg(void *pCont, int32_t contLen, void *ahandle) {
// SDropUserMsg *pDrop = (SDropUserMsg *)pMsg;
// SCMDropUserMsg *pDrop = (SCMDropUserMsg *)pMsg;
// int32_t code = 0;
// SUserObj * pUser;
// SUserObj * pOperUser;
......@@ -1407,44 +1409,15 @@ int32_t mgmtCheckRedirectMsgImp(void *pConn, int32_t msgType) {
}
int32_t (*mgmtCheckRedirectMsg)(void *pConn, int32_t msgType) = mgmtCheckRedirectMsgImp;
int32_t mgmtProcessAlterAcctMsgImp(void *pCont, int32_t contLen, void *ahandle) {
//return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_ALTER_ACCT_RSP, TSDB_CODE_OPS_NOT_SUPPORT);
return 0;
}
int32_t (*mgmtProcessAlterAcctMsg)(void *pCont, int32_t contLen, void *ahandle) = mgmtProcessAlterAcctMsgImp;
int32_t mgmtProcessCreateDnodeMsgImp(void *pCont, int32_t contLen, void *ahandle) {
//return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_CREATE_DNODE_RSP, TSDB_CODE_OPS_NOT_SUPPORT);
return 0;
}
int32_t (*mgmtProcessCreateDnodeMsg)(void *pCont, int32_t contLen, void *ahandle) = mgmtProcessCreateDnodeMsgImp;
int32_t mgmtProcessCfgMnodeMsgImp(void *pCont, int32_t contLen, void *ahandle) {
//return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_CFG_MNODE_RSP, TSDB_CODE_OPS_NOT_SUPPORT);
return 0;
}
int32_t (*mgmtProcessCfgMnodeMsg)(void *pCont, int32_t contLen, void *ahandle) = mgmtProcessCfgMnodeMsgImp;
int32_t mgmtProcessDropMnodeMsgImp(void *pCont, int32_t contLen, void *ahandle) {
//return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_MNODE_RSP, TSDB_CODE_OPS_NOT_SUPPORT);
static int32_t mgmtProcessUnSupportMsg(void *pCont, int32_t contLen, void *ahandle) {
rpcSendResponse(ahandle, TSDB_CODE_OPS_NOT_SUPPORT, NULL, 0);
return 0;
}
int32_t (*mgmtProcessDropMnodeMsg)(void *pCont, int32_t contLen, void *ahandle) = mgmtProcessDropMnodeMsgImp;
int32_t mgmtProcessDropDnodeMsgImp(void *pCont, int32_t contLen, void *ahandle) {
//return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_DNODE_RSP, TSDB_CODE_OPS_NOT_SUPPORT);
return 0;
}
int32_t (*mgmtProcessDropDnodeMsg)(void *pCont, int32_t contLen, void *ahandle) = mgmtProcessDropDnodeMsgImp;
int32_t mgmtProcessDropAcctMsgImp(void *pCont, int32_t contLen, void *ahandle) {
// return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_DROP_ACCT_RSP, TSDB_CODE_OPS_NOT_SUPPORT);
return 0;
}
int32_t (*mgmtProcessDropAcctMsg)(void *pCont, int32_t contLen, void *ahandle) = mgmtProcessDropAcctMsgImp;
int32_t mgmtProcessCreateAcctMsgImp(void *pCont, int32_t contLen, void *ahandle) {
// return taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_CREATE_ACCT_RSP, TSDB_CODE_OPS_NOT_SUPPORT);
return 0;
}
int32_t (*mgmtProcessCreateAcctMsg)(void *pCont, int32_t contLen, void *ahandle) = mgmtProcessCreateAcctMsgImp;
\ No newline at end of file
int32_t (*mgmtProcessAlterAcctMsg)(void *pCont, int32_t contLen, void *ahandle) = mgmtProcessUnSupportMsg;
int32_t (*mgmtProcessCreateDnodeMsg)(void *pCont, int32_t contLen, void *ahandle) = mgmtProcessUnSupportMsg;
int32_t (*mgmtProcessCfgMnodeMsg)(void *pCont, int32_t contLen, void *ahandle) = mgmtProcessUnSupportMsg;
int32_t (*mgmtProcessDropMnodeMsg)(void *pCont, int32_t contLen, void *ahandle) = mgmtProcessUnSupportMsg;
int32_t (*mgmtProcessDropDnodeMsg)(void *pCont, int32_t contLen, void *ahandle) = mgmtProcessUnSupportMsg;
int32_t (*mgmtProcessDropAcctMsg)(void *pCont, int32_t contLen, void *ahandle) = mgmtProcessUnSupportMsg;
int32_t (*mgmtProcessCreateAcctMsg)(void *pCont, int32_t contLen, void *ahandle) = mgmtProcessUnSupportMsg;
\ No newline at end of file
......@@ -125,8 +125,6 @@ int32_t mgmtStartSystem() {
mError("failed to init dnode balance")
}
mgmtCheckAcct();
taosTmrReset(mgmtDoStatistic, tsStatusInterval * 30000, NULL, tsMgmtTmr, &tsMgmtStatisTimer);
mPrint("TDengine mgmt is initialized successfully");
......
......@@ -78,6 +78,11 @@ int32_t mgmtInitUsers() {
numOfUsers++;
}
pAcct = mgmtGetAcct("root");
mgmtCreateUser(pAcct, "root", "taosdata");
mgmtCreateUser(pAcct, "monitor", tsInternalPass);
mgmtCreateUser(pAcct, "_root", tsInternalPass);
mTrace("user data is initialized");
return 0;
}
......
......@@ -108,9 +108,9 @@ ELSEIF(TD_DARWIN_64)
TARGET_LINK_LIBRARIES(tutil iconv pthread os)
ENDIF()
IF (TD_CLUSTER)
TARGET_LINK_LIBRARIES(tutil mstorage)
ENDIF ()
#IF (TD_CLUSTER)
# TARGET_LINK_LIBRARIES(tutil mstorage)
#ENDIF ()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册