未验证 提交 a4263fd6 编写于 作者: S slguan 提交者: GitHub

Merge pull request #1689 from taosdata/feature/alter

Modify the user code and pass the test case
...@@ -42,6 +42,7 @@ void * tscTmr; ...@@ -42,6 +42,7 @@ void * tscTmr;
void * tscQhandle; void * tscQhandle;
void * tscCheckDiskUsageTmr; void * tscCheckDiskUsageTmr;
int tsInsertHeadSize; int tsInsertHeadSize;
char tsLastUser[TSDB_USER_LEN + 1];
int tscNumOfThreads; int tscNumOfThreads;
...@@ -81,6 +82,13 @@ int32_t tscInitRpc(const char *user, const char *secret) { ...@@ -81,6 +82,13 @@ int32_t tscInitRpc(const char *user, const char *secret) {
} }
} }
// not stop service, switch users
if (strcmp(tsLastUser, user) != 0 && pTscMgmtConn != NULL) {
tscTrace("switch user from %s to %s", user, tsLastUser);
rpcClose(pTscMgmtConn);
pTscMgmtConn = NULL;
}
if (pTscMgmtConn == NULL) { if (pTscMgmtConn == NULL) {
memset(&rpcInit, 0, sizeof(rpcInit)); memset(&rpcInit, 0, sizeof(rpcInit));
rpcInit.localIp = tsLocalIp; rpcInit.localIp = tsLocalIp;
...@@ -94,6 +102,7 @@ int32_t tscInitRpc(const char *user, const char *secret) { ...@@ -94,6 +102,7 @@ int32_t tscInitRpc(const char *user, const char *secret) {
rpcInit.user = (char*)user; rpcInit.user = (char*)user;
rpcInit.ckey = "key"; rpcInit.ckey = "key";
rpcInit.secret = secretEncrypt; rpcInit.secret = secretEncrypt;
strcpy(tsLastUser, user);
pTscMgmtConn = rpcOpen(&rpcInit); pTscMgmtConn = rpcOpen(&rpcInit);
if (pTscMgmtConn == NULL) { if (pTscMgmtConn == NULL) {
......
...@@ -75,14 +75,19 @@ TAOS_DEFINE_ERROR(TSDB_CODE_NOT_CONFIGURED, 0, 27, "not configured") ...@@ -75,14 +75,19 @@ TAOS_DEFINE_ERROR(TSDB_CODE_NOT_CONFIGURED, 0, 27, "not configured")
TAOS_DEFINE_ERROR(TSDB_CODE_NODE_OFFLINE, 0, 28, "node offline") TAOS_DEFINE_ERROR(TSDB_CODE_NODE_OFFLINE, 0, 28, "node offline")
TAOS_DEFINE_ERROR(TSDB_CODE_NETWORK_UNAVAIL, 0, 29, "network unavailable") TAOS_DEFINE_ERROR(TSDB_CODE_NETWORK_UNAVAIL, 0, 29, "network unavailable")
// db & user // db
TAOS_DEFINE_ERROR(TSDB_CODE_DB_NOT_SELECTED, 0, 100, "db not selected") TAOS_DEFINE_ERROR(TSDB_CODE_DB_NOT_SELECTED, 0, 100, "db not selected")
TAOS_DEFINE_ERROR(TSDB_CODE_DB_ALREADY_EXIST, 0, 101, "database aleady exist") TAOS_DEFINE_ERROR(TSDB_CODE_DB_ALREADY_EXIST, 0, 101, "database aleady exist")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_DB, 0, 102, "invalid database") TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_DB, 0, 102, "invalid database")
TAOS_DEFINE_ERROR(TSDB_CODE_MONITOR_DB_FORBIDDEN, 0, 103, "monitor db forbidden") TAOS_DEFINE_ERROR(TSDB_CODE_MONITOR_DB_FORBIDDEN, 0, 103, "monitor db forbidden")
TAOS_DEFINE_ERROR(TSDB_CODE_USER_ALREADY_EXIST, 0, 104, "user already exist")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_USER, 0, 105, "invalid user") // user
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_PASS, 0, 106, "invalid password") TAOS_DEFINE_ERROR(TSDB_CODE_USER_ALREADY_EXIST, 0, 150, "user already exist")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_USER, 0, 151, "invalid user")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_PASS, 0, 152, "invalid password")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_USER_FORMAT, 0, 153, "invalid user format")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_PASS_FORMAT, 0, 154, "invalid password format")
TAOS_DEFINE_ERROR(TSDB_CODE_NO_USER_FROM_CONN, 0, 155, "can not get user from conn")
// table // table
TAOS_DEFINE_ERROR(TSDB_CODE_TABLE_ALREADY_EXIST, 0, 200, "table already exist") TAOS_DEFINE_ERROR(TSDB_CODE_TABLE_ALREADY_EXIST, 0, 200, "table already exist")
......
...@@ -24,6 +24,7 @@ extern "C" { ...@@ -24,6 +24,7 @@ extern "C" {
int32_t mgmtInitUsers(); int32_t mgmtInitUsers();
void mgmtCleanUpUsers(); void mgmtCleanUpUsers();
SUserObj *mgmtGetUser(char *name); SUserObj *mgmtGetUser(char *name);
void * mgmtGetNextUser(void *pNode, SUserObj **pUser);
void mgmtIncUserRef(SUserObj *pUser); void mgmtIncUserRef(SUserObj *pUser);
void mgmtDecUserRef(SUserObj *pUser); void mgmtDecUserRef(SUserObj *pUser);
SUserObj *mgmtGetUserFromConn(void *pConn, bool *usePublicIp); SUserObj *mgmtGetUserFromConn(void *pConn, bool *usePublicIp);
......
...@@ -336,7 +336,7 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) { ...@@ -336,7 +336,7 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) {
if (pStatus->dnodeId == 0) { if (pStatus->dnodeId == 0) {
mTrace("dnode:%d, first access, privateIp:%s, name:%s", pDnode->dnodeId, taosIpStr(pDnode->privateIp), pDnode->dnodeName); mTrace("dnode:%d, first access, privateIp:%s, name:%s", pDnode->dnodeId, taosIpStr(pDnode->privateIp), pDnode->dnodeName);
} else { } else {
mTrace("dnode:%d, status received, access times %d", pDnode->dnodeId, pDnode->lastAccess); //mTrace("dnode:%d, status received, access times %d", pDnode->dnodeId, pDnode->lastAccess);
} }
int32_t openVnodes = htons(pStatus->openVnodes); int32_t openVnodes = htons(pStatus->openVnodes);
......
...@@ -19,23 +19,23 @@ ...@@ -19,23 +19,23 @@
#include "ttime.h" #include "ttime.h"
#include "tutil.h" #include "tutil.h"
#include "tglobal.h" #include "tglobal.h"
#include "tgrant.h"
#include "dnode.h" #include "dnode.h"
#include "mgmtDef.h" #include "mgmtDef.h"
#include "mgmtLog.h" #include "mgmtLog.h"
#include "mgmtAcct.h" #include "mgmtAcct.h"
#include "tgrant.h"
#include "mgmtMnode.h" #include "mgmtMnode.h"
#include "mgmtSdb.h" #include "mgmtSdb.h"
#include "mgmtShell.h" #include "mgmtShell.h"
#include "mgmtUser.h" #include "mgmtUser.h"
void * tsUserSdb = NULL; static void * tsUserSdb = NULL;
static int32_t tsUserUpdateSize = 0; static int32_t tsUserUpdateSize = 0;
static int32_t mgmtGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mgmtGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void *pConn); static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void *pConn);
static void mgmtProcessCreateUserMsg(SQueuedMsg *pMsg); static void mgmtProcessCreateUserMsg(SQueuedMsg *pMsg);
static void mgmtProcessAlterUserMsg(SQueuedMsg *pMsg); static void mgmtProcessAlterUserMsg(SQueuedMsg *pMsg);
static void mgmtProcessDropUserMsg(SQueuedMsg *pMsg); static void mgmtProcessDropUserMsg(SQueuedMsg *pMsg);
static int32_t mgmtUserActionDestroy(SSdbOper *pOper) { static int32_t mgmtUserActionDestroy(SSdbOper *pOper) {
tfree(pOper->pObj); tfree(pOper->pObj);
...@@ -48,8 +48,8 @@ static int32_t mgmtUserActionInsert(SSdbOper *pOper) { ...@@ -48,8 +48,8 @@ static int32_t mgmtUserActionInsert(SSdbOper *pOper) {
if (pAcct != NULL) { if (pAcct != NULL) {
mgmtAddUserToAcct(pAcct, pUser); mgmtAddUserToAcct(pAcct, pUser);
} mgmtDecAcctRef(pAcct);
else { } else {
mError("user:%s, acct:%s info not exist in sdb", pUser->user, pUser->acct); mError("user:%s, acct:%s info not exist in sdb", pUser->user, pUser->acct);
return TSDB_CODE_INVALID_ACCT; return TSDB_CODE_INVALID_ACCT;
} }
...@@ -86,7 +86,7 @@ static int32_t mgmtUserActionEncode(SSdbOper *pOper) { ...@@ -86,7 +86,7 @@ static int32_t mgmtUserActionEncode(SSdbOper *pOper) {
} }
static int32_t mgmtUserActionDecode(SSdbOper *pOper) { static int32_t mgmtUserActionDecode(SSdbOper *pOper) {
SUserObj *pUser = (SUserObj *) calloc(1, sizeof(SUserObj)); SUserObj *pUser = (SUserObj *)calloc(1, sizeof(SUserObj));
if (pUser == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (pUser == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY;
memcpy(pUser, pOper->rowData, tsUserUpdateSize); memcpy(pUser, pOper->rowData, tsUserUpdateSize);
...@@ -103,7 +103,7 @@ static int32_t mgmtUserActionRestored() { ...@@ -103,7 +103,7 @@ static int32_t mgmtUserActionRestored() {
mgmtDecAcctRef(pAcct); mgmtDecAcctRef(pAcct);
} }
return 0; return TSDB_CODE_SUCCESS;
} }
int32_t mgmtInitUsers() { int32_t mgmtInitUsers() {
...@@ -128,7 +128,7 @@ int32_t mgmtInitUsers() { ...@@ -128,7 +128,7 @@ int32_t mgmtInitUsers() {
tsUserSdb = sdbOpenTable(&tableDesc); tsUserSdb = sdbOpenTable(&tableDesc);
if (tsUserSdb == NULL) { if (tsUserSdb == NULL) {
mError("failed to init user data"); mError("table:%s, failed to create hash", tableDesc.tableName);
return -1; return -1;
} }
...@@ -138,7 +138,7 @@ int32_t mgmtInitUsers() { ...@@ -138,7 +138,7 @@ int32_t mgmtInitUsers() {
mgmtAddShellShowMetaHandle(TSDB_MGMT_TABLE_USER, mgmtGetUserMeta); mgmtAddShellShowMetaHandle(TSDB_MGMT_TABLE_USER, mgmtGetUserMeta);
mgmtAddShellShowRetrieveHandle(TSDB_MGMT_TABLE_USER, mgmtRetrieveUsers); mgmtAddShellShowRetrieveHandle(TSDB_MGMT_TABLE_USER, mgmtRetrieveUsers);
mTrace("table:users table is created"); mTrace("table:%s, hash is created", tableDesc.tableName);
return 0; return 0;
} }
...@@ -150,6 +150,10 @@ SUserObj *mgmtGetUser(char *name) { ...@@ -150,6 +150,10 @@ SUserObj *mgmtGetUser(char *name) {
return (SUserObj *)sdbGetRow(tsUserSdb, name); return (SUserObj *)sdbGetRow(tsUserSdb, name);
} }
void *mgmtGetNextUser(void *pNode, SUserObj **pUser) {
return sdbFetchRow(tsUserSdb, pNode, (void **)pUser);
}
void mgmtIncUserRef(SUserObj *pUser) { void mgmtIncUserRef(SUserObj *pUser) {
return sdbIncRef(tsUserSdb, pUser); return sdbIncRef(tsUserSdb, pUser);
} }
...@@ -176,17 +180,21 @@ static int32_t mgmtUpdateUser(SUserObj *pUser) { ...@@ -176,17 +180,21 @@ static int32_t mgmtUpdateUser(SUserObj *pUser) {
int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) { int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) {
int32_t code = acctCheck(pAcct, ACCT_GRANT_USER); int32_t code = acctCheck(pAcct, ACCT_GRANT_USER);
if (code != 0) { if (code != TSDB_CODE_SUCCESS) {
return code; return code;
} }
if (name[0] == 0 || pass[0] == 0) { if (name[0] == 0) {
return TSDB_CODE_INVALID_MSG_CONTENT; return TSDB_CODE_INVALID_USER_FORMAT;
}
if (pass[0] == 0) {
return TSDB_CODE_INVALID_PASS_FORMAT;
} }
SUserObj *pUser = mgmtGetUser(name); SUserObj *pUser = mgmtGetUser(name);
if (pUser != NULL) { if (pUser != NULL) {
mTrace("user:%s is already there", name); mTrace("user:%s, is already there", name);
mgmtDecUserRef(pUser); mgmtDecUserRef(pUser);
return TSDB_CODE_USER_ALREADY_EXIST; return TSDB_CODE_USER_ALREADY_EXIST;
} }
...@@ -241,10 +249,10 @@ static int32_t mgmtDropUser(SUserObj *pUser) { ...@@ -241,10 +249,10 @@ static int32_t mgmtDropUser(SUserObj *pUser) {
static int32_t mgmtGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mgmtGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
SUserObj *pUser = mgmtGetUserFromConn(pConn, NULL); SUserObj *pUser = mgmtGetUserFromConn(pConn, NULL);
if (pUser == NULL) { if (pUser == NULL) {
return TSDB_CODE_INVALID_USER; return TSDB_CODE_NO_USER_FROM_CONN;
} }
int32_t cols = 0; int32_t cols = 0;
SSchema *pSchema = pMeta->schema; SSchema *pSchema = pMeta->schema;
pShow->bytes[cols] = TSDB_USER_LEN; pShow->bytes[cols] = TSDB_USER_LEN;
...@@ -314,6 +322,7 @@ static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void ...@@ -314,6 +322,7 @@ static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void
numOfRows++; numOfRows++;
mgmtDecUserRef(pUser); mgmtDecUserRef(pUser);
} }
pShow->numOfReads += numOfRows; pShow->numOfReads += numOfRows;
return numOfRows; return numOfRows;
} }
...@@ -325,20 +334,21 @@ SUserObj *mgmtGetUserFromConn(void *pConn, bool *usePublicIp) { ...@@ -325,20 +334,21 @@ SUserObj *mgmtGetUserFromConn(void *pConn, bool *usePublicIp) {
*usePublicIp = (connInfo.serverIp == tsPublicIpInt); *usePublicIp = (connInfo.serverIp == tsPublicIpInt);
} }
return mgmtGetUser(connInfo.user); return mgmtGetUser(connInfo.user);
} else {
mError("can not get user from conn:%p", pConn);
return NULL;
} }
return NULL;
} }
static void mgmtProcessCreateUserMsg(SQueuedMsg *pMsg) { static void mgmtProcessCreateUserMsg(SQueuedMsg *pMsg) {
int32_t code; int32_t code;
SUserObj *pUser = pMsg->pUser; SUserObj *pOperUser = pMsg->pUser;
if (pUser->superAuth) { if (pOperUser->superAuth) {
SCMCreateUserMsg *pCreate = pMsg->pCont; SCMCreateUserMsg *pCreate = pMsg->pCont;
code = mgmtCreateUser(pUser->pAcct, pCreate->user, pCreate->pass); code = mgmtCreateUser(pOperUser->pAcct, pCreate->user, pCreate->pass);
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
mLPrint("user:%s is created by %s", pCreate->user, pUser->user); mLPrint("user:%s, is created by %s", pCreate->user, pOperUser->user);
} }
} else { } else {
code = TSDB_CODE_NO_RIGHTS; code = TSDB_CODE_NO_RIGHTS;
...@@ -384,7 +394,7 @@ static void mgmtProcessAlterUserMsg(SQueuedMsg *pMsg) { ...@@ -384,7 +394,7 @@ static void mgmtProcessAlterUserMsg(SQueuedMsg *pMsg) {
memset(pUser->pass, 0, sizeof(pUser->pass)); memset(pUser->pass, 0, sizeof(pUser->pass));
taosEncryptPass((uint8_t*)pAlter->pass, strlen(pAlter->pass), pUser->pass); taosEncryptPass((uint8_t*)pAlter->pass, strlen(pAlter->pass), pUser->pass);
code = mgmtUpdateUser(pUser); code = mgmtUpdateUser(pUser);
mLPrint("user:%s password is altered by %s, result:%d", pUser->user, pOperUser->user, tstrerror(code)); mLPrint("user:%s, password is altered by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code));
} else { } else {
code = TSDB_CODE_NO_RIGHTS; code = TSDB_CODE_NO_RIGHTS;
} }
...@@ -426,7 +436,7 @@ static void mgmtProcessAlterUserMsg(SQueuedMsg *pMsg) { ...@@ -426,7 +436,7 @@ static void mgmtProcessAlterUserMsg(SQueuedMsg *pMsg) {
} }
code = mgmtUpdateUser(pUser); code = mgmtUpdateUser(pUser);
mLPrint("user:%s privilege is altered by %s, result:%d", pUser->user, pOperUser->user, tstrerror(code)); mLPrint("user:%s, privilege is altered by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code));
} else { } else {
code = TSDB_CODE_NO_RIGHTS; code = TSDB_CODE_NO_RIGHTS;
} }
...@@ -447,7 +457,7 @@ static void mgmtProcessDropUserMsg(SQueuedMsg *pMsg) { ...@@ -447,7 +457,7 @@ static void mgmtProcessDropUserMsg(SQueuedMsg *pMsg) {
SUserObj *pUser = mgmtGetUser(pDrop->user); SUserObj *pUser = mgmtGetUser(pDrop->user);
if (pUser == NULL) { if (pUser == NULL) {
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_INVALID_USER); mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_INVALID_USER);
return ; return;
} }
if (strcmp(pUser->user, "monitor") == 0 || strcmp(pUser->user, pUser->acct) == 0 || if (strcmp(pUser->user, "monitor") == 0 || strcmp(pUser->user, pUser->acct) == 0 ||
...@@ -475,7 +485,7 @@ static void mgmtProcessDropUserMsg(SQueuedMsg *pMsg) { ...@@ -475,7 +485,7 @@ static void mgmtProcessDropUserMsg(SQueuedMsg *pMsg) {
if (hasRight) { if (hasRight) {
code = mgmtDropUser(pUser); code = mgmtDropUser(pUser);
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
mLPrint("user:%s is dropped by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code)); mLPrint("user:%s, is dropped by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code));
} }
} else { } else {
code = TSDB_CODE_NO_RIGHTS; code = TSDB_CODE_NO_RIGHTS;
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
run general/db/testSuite.sim run general/db/testSuite.sim
run general/insert/testSuite.sim run general/insert/testSuite.sim
run general/table/testSuite.sim run general/table/testSuite.sim
run general/user/testSuite.sim run general/user/basicSuite.sim
################################## ##################################
...@@ -66,6 +66,4 @@ print $data10 $data11 $data22 ...@@ -66,6 +66,4 @@ print $data10 $data11 $data22
print $data20 $data11 $data22 print $data20 $data11 $data22
print $data30 $data31 $data32 print $data30 $data31 $data32
system sh/exec.sh -n dnode1 -s stop
\ No newline at end of file
run general/user/basic1.sim
\ No newline at end of file
run general/user/basic1.sim run general/user/basic1.sim
\ No newline at end of file run general/user/pass_alter.sim
run general/user/pass_len.sim
run general/user/user_create.sim
run general/user/user_len.sim
#run general/user/monitor.sim
\ No newline at end of file
...@@ -4,8 +4,6 @@ system sh/ip.sh -i 1 -s up ...@@ -4,8 +4,6 @@ system sh/ip.sh -i 1 -s up
system sh/deploy.sh -n dnode1 -m 192.168.0.1 -i 192.168.0.1 system sh/deploy.sh -n dnode1 -m 192.168.0.1 -i 192.168.0.1
system sh/cfg.sh -n dnode1 -c clog -v 0 system sh/cfg.sh -n dnode1 -c clog -v 0
system sh/exec.sh -n dnode1 -s start system sh/exec.sh -n dnode1 -s start
sleep 3000
sql connect sql connect
print =============== step1 print =============== step1
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册