?? cli_user.c
字號:
/********************************************************************/
_U32 CLI_CreatUserLink(_VOID)
{
_U32 i;
/* 增加調試用戶*/
CLI_UserInfoCfg(&(m_sUserTable[0]),
g_csz_CFG_CLI_DBG_USER_NAME, g_csz_CFG_CLI_DBG_USER_PASSWORD,
CT_AL_DEBUG, USER_FOR_CLI, ML_CHS);
/* 增加超級用戶*/
CLI_UserInfoCfg(&(m_sUserTable[1]),
g_csz_CFG_CLI_SUPER_USER_NAME, g_csz_CFG_CLI_SUPER_USER_PASSWORD,
CT_AL_SUPER, USER_FOR_CLI, ML_ENG);
/* 增加普通管理員用戶*/
CLI_UserInfoCfg(&(m_sUserTable[2]),
g_csz_CFG_CLI_ADMIN_USER_NAME, g_csz_CFG_CLI_ADMIN_USER_PASSWORD,
CT_AL_ADMIN, USER_FOR_CLI, ML_ENG);
for (i = 3; i< MAX_USER_NUM; i++)
{
CLI_UserInfoCfg(&m_sUserTable[i],
"", "", 0, USER_NOT_USED, ML_GetDefaultLang());
}
return G_SUCCESS ;
}
/********************************************************************/
/* 函數名稱 :CLI_AddTermUser */
/* 函數功能 :增加一個用戶 */
/* 輸入參數 :_S8 *szUserName 用戶名 */
/* _S8 *szPassword 用戶口令 */
/* _U32 ulLevel 用戶權限 */
/* 輸出參數 :無 */
/* 返回值 :成功、失敗 */
/* 調用函數 : */
/* 被調函數 :該函數只能被命令行調用 */
/********************************************************************/
_U32 CLI_AddTermUser(const _S8 *szUserName, const _S8 *szPassword, _U8 ucLevel, _U8 ucUserType, _U8 ucLan)
{
_U32 i;
PTerm_Data_S pTermStruct;
_U8 ucCurLevel;
if (EOS_StrLen(szUserName) >= USERNAME_LEN
|| EOS_StrLen(szPassword) >= PASSWORD_LEN)
{
MT_ERRLOG(0);
return G_FAILURE;
}
/* 語種ID的合法性檢查 */
if( ucLan >= ML_GetLangNum() )
{
MT_ERRLOG(0);
return G_FAILURE;
}
if((pTermStruct = CLI_GetCurrentTaskData()) == G_NULL)
{
MT_ERRLOG(0);
return G_FAILURE;
}
ucCurLevel = pTermStruct->ucUserLevel;
if (ucCurLevel < ucLevel)
{
IO_Print(CLI_USER_HAS_NO_RIGHT);
return G_FAILURE;
}
for (i = 0; i < MAX_USER_NUM; i++)
{
if (!EOS_StriCmp(m_sUserTable[i].szUserName, szUserName)
&& m_sUserTable[i].ucUserType != USER_NOT_USED)
{
IO_Print(CLI_USER_HAS_EXISTED);
return G_FAILURE;
}
}
/*調試用戶為固定用戶,不能被替換*/
for (i = 1; i < MAX_USER_NUM; i++)
{
if (m_sUserTable[i].ucUserType == USER_NOT_USED)
break;
}
if (i == MAX_USER_NUM)
{
IO_Print(CLI_USER_TABLE_FULL);
return G_FAILURE;
}
CLI_UserInfoCfg(&m_sUserTable[i],
szUserName, szPassword, ucLevel, ucUserType, ucLan);
#if CLI_DBASE_SUPPORT
/* 是否包含RDB模塊 */
if( G_YES == g_ul_INCLUDE_MODULE_CLI_RDB )
{
/* 函數指針是否注冊 */
if( G_NULL == g_pfn_CFG_CLI_RDB_RecordDirectInsert )
{
MT_ERRLOG(0);
return G_FAILURE;
}
if (g_pfn_CFG_CLI_RDB_RecordDirectInsert(m_ulCliUserHandle, m_usUserTable, i, &m_sUserTable[i])!= G_SUCCESS)
{
m_sUserTable[i].ucUserType = USER_NOT_USED;
return G_FAILURE;
}
}
#endif
return G_SUCCESS ;
}
/********************************************************************/
/* 函數名稱 :CLI_DelTermUser */
/* 函數功能 :刪除一個用戶 */
/* 輸入參數 :_S8 *szUserName 刪除的用戶名 */
/* 輸出參數 :無 */
/* 返回值 :成功、失敗 */
/* 調用函數 : */
/* 被調函數 : */
/********************************************************************/
_U32 CLI_DelTermUser(const _S8 *szUserName)
{
_U32 i;
_U8 ucTmp;
PTerm_Data_S pTermStruct;
_U8 ucLevel;
if((pTermStruct = CLI_GetCurrentTaskData()) == G_NULL)
{
MT_ERRLOG(0);
return G_FAILURE;
}
ucLevel = pTermStruct->ucUserLevel;
for (i = 0; i < MAX_USER_NUM; i++)
{
if (!EOS_StriCmp(m_sUserTable[i].szUserName, szUserName)
&& m_sUserTable[i].ucUserType != USER_NOT_USED)
{
if (m_sUserTable[i].ulLevel >= CT_AL_SUPER
|| ucLevel < m_sUserTable[i].ulLevel)
{
IO_Print(CLI_USER_HAS_NO_RIGHT);
return G_FAILURE;
}
else if (m_sUserTable[i].ulTermId != 0)
{
IO_Print(CLI_USER_DEL_ONLINE);
return G_FAILURE;
}
else
break;
}
}
if (i == MAX_USER_NUM)
{
IO_Print(CLI_USER_NOT_EXISTED);
return G_FAILURE;
}
ucTmp = m_sUserTable[i].ucUserType;
m_sUserTable[i].ucUserType = USER_NOT_USED;
#if CLI_DBASE_SUPPORT
/* 是否包含RDB模塊 */
if( G_YES == g_ul_INCLUDE_MODULE_CLI_RDB )
{
/* 函數指針是否注冊 */
if( G_NULL == g_pfn_CFG_CLI_RDB_RecordDirectDelete )
{
MT_ERRLOG(0);
return G_FAILURE;
}
if (g_pfn_CFG_CLI_RDB_RecordDirectDelete( m_ulCliUserHandle, m_usUserTable, i) != G_SUCCESS)
{
m_sUserTable[i].ucUserType = ucTmp;
MT_ERRLOG(0);
return G_FAILURE;
}
}
#endif
return G_SUCCESS;
}
/********************************************************************/
/* 函數名稱 :CLI_LoadTermUser */
/* 函數功能 :從flash中裝載所有的用戶信息到用戶數據表 */
/* 輸入參數 :無 */
/* 輸出參數 :無 */
/* 返回值 :成功、失敗 */
/* 調用函數 : */
/* 被調函數 : */
/********************************************************************/
_U32 CLI_LoadTermUser(_VOID)
{
_U8 ucType;
_U32 i;
/*將用戶數據讀到用戶信息表*/
#if CLI_DBASE_SUPPORT
/* 是否包含RDB模塊 */
if( G_YES == g_ul_INCLUDE_MODULE_CLI_RDB )
{
if (G_SUCCESS != CLI_UserRead())
{
CLI_CreatUserLink();
CLI_UserWrite();
}
}
else
{
CLI_CreatUserLink();
}
#else
CLI_CreatUserLink();
#endif
for (i = 0; i < MAX_USER_NUM; i++)
{
ucType = m_sUserTable[i].ucUserType;
if (ucType > USER_NOT_USED)
{
return G_FAILURE;
}
}
return G_SUCCESS;
}
/********************************************************************/
/* 函數名稱 :CLI_GetUserByName */
/* 函數功能 :取得某一用戶的信息 */
/* 輸入參數 :_S8 *szUserName 用戶名 */
/* 輸出參數 :無 */
/* 返回值 :PTermUserItem: 取得的用戶信息指針 */
/* 調用函數 : */
/* 被調函數 : */
/********************************************************************/
PTermUserItem CLI_GetUserByName(const _S8 *szUserName)
{
_U32 i;
CLI_ASSURE_OR_NULL( szUserName != G_NULL );
for (i = 0; i < MAX_USER_NUM; i++)
{
if (!EOS_StriCmp(m_sUserTable[i].szUserName, szUserName)
&& m_sUserTable[i].ucUserType != USER_NOT_USED)
{
return &m_sUserTable[i];
}
}
return G_NULL ;
}
/********************************************************************/
/* 函數名稱 :CLI_GetPasswordByName */
/* 函數功能 :取得某一用戶的口令 */
/* 輸入參數 :_S8 *szUserName 用戶名 */
/* 輸出參數 :_S8 *szPassword用戶口令 */
/* 返回值 :成功、失敗 */
/* 調用函數 : */
/* 被調函數 : */
/********************************************************************/
_U32 CLI_GetPasswordByName(_S8 *szUserName, _S8 *szPassword)
{
PTermUserItem pTermUserItem ;
CLI_ASSURE_OR_FAIL(( szUserName != G_NULL ) && ( szPassword != G_NULL ));
pTermUserItem = CLI_GetUserByName(szUserName) ;
if (G_NULL == pTermUserItem)
return G_FAILURE ;
EOS_MemCopy(szPassword, pTermUserItem->szPassword, PASSWORD_LEN) ;
return G_SUCCESS ;
}
/********************************************************************/
/* 函數名稱 :CLI_CheckUserPassword */
/* 函數功能 :取得某一用戶的口令 */
/* 輸入參數 :_S8 *szUserName 用戶名 */
/* 輸出參數 :_S8 *szPassword用戶口令 */
/* 返回值 :成功、失敗 */
/* 調用函數 : */
/* 被調函數 : */
/********************************************************************/
_U32 CLI_CheckUserPassword(const _S8 *szUserName, const _S8 *szPassword)
{
PTermUserItem pTermUserItem ;
_S8 szPswd[PASSWORD_LEN];
CLI_ASSURE_OR_FAIL(( szUserName != G_NULL ) && ( szPassword != G_NULL ));
pTermUserItem = CLI_GetUserByName(szUserName) ;
if (G_NULL == pTermUserItem)
return G_FAILURE ;
CLI_Encrypt(szPswd, szPassword, 0);
if (EOS_MemCmp(pTermUserItem->szPassword, szPswd, PASSWORD_LEN))
{
return G_FAILURE;
}
return G_SUCCESS ;
}
/********************************************************************/
/* 函數名稱 :CLI_GetUserLevel */
/* 函數功能 :取得某一用戶的權限 */
/* 輸入參數 :_S8 *szUserName 用戶名 */
/* _U32 *ulLevel用戶權限 */
/* 輸出參數 :_U32 *ulLevel用戶權限 */
/* 返回值 :成功、失敗 */
/* 調用函數 : */
/* 被調函數 : */
/********************************************************************/
_U32 CLI_GetUserLevel(const _S8 *szUserName, _U32 *ulLevel)
{
PTermUserItem pTermUserItem ;
CLI_ASSURE_OR_FAIL(( szUserName != G_NULL ) && ( ulLevel != G_NULL ));
pTermUserItem = CLI_GetUserByName(szUserName) ;
if (G_NULL == pTermUserItem)
return G_FAILURE ;
*ulLevel = pTermUserItem->ulLevel ;
return G_SUCCESS ;
}
/********************************************************************/
/* 函數名稱 :CLI_SetUserName */
/* 函數功能 :設定某一用戶的口令 */
/* 輸入參數 :ulIndex: 用戶數據索引 */
/* _S8 *szUserName 用戶名 */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -