|
@@ -15,11 +15,18 @@ using namespace AccessAuthorization;
|
|
|
|
|
|
#include "EventCode.h"
|
|
|
#include "md5file.h"
|
|
|
-#include <io.h>
|
|
|
+
|
|
|
#include "fileutil.h"
|
|
|
#include <regex>
|
|
|
#include "RVCComm.h"
|
|
|
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+#include <io.h>
|
|
|
+#else
|
|
|
+#include <unistd.h>
|
|
|
+#include <dirent.h>
|
|
|
+#endif
|
|
|
+
|
|
|
namespace Task
|
|
|
{
|
|
|
struct GetMD5Task : public ITaskSp
|
|
@@ -274,8 +281,8 @@ ErrorCodeEnum CUpgradeMgrEntity::RollbackUpdate(const CSimpleStringA &strVersion
|
|
|
{
|
|
|
Dbg("try rollback to version: [%s]", (const char*)strVersion);
|
|
|
int w1, w2, w3, w4;
|
|
|
- int rc = sscanf(strVersion, "%d.%d.%d.%d", &w1, &w2, &w3, &w4);
|
|
|
- if (rc <4)
|
|
|
+ int ret = sscanf(strVersion, "%d.%d.%d.%d", &w1, &w2, &w3, &w4);
|
|
|
+ if (ret <4)
|
|
|
{
|
|
|
Dbg("version [%s] parse fail", (const char*)strVersion);
|
|
|
rc= Error_Param;
|
|
@@ -512,14 +519,15 @@ ErrorCodeEnum CUpgradeMgrEntity::SM3DataToStr(CSimpleStringA strData, CSimpleStr
|
|
|
//修改成sm3加密
|
|
|
ErrorCodeEnum CUpgradeMgrEntity::MD5Folder(CSimpleStringA strFolderPath,bool isDepDIr)
|
|
|
{
|
|
|
+
|
|
|
if (strFolderPath.IsNullOrEmpty())
|
|
|
{
|
|
|
return Error_Null;
|
|
|
}
|
|
|
Dbg("Start to get file hash list, dir=[%s] ", strFolderPath);
|
|
|
-
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
_finddata_t FileInfo;
|
|
|
- CSimpleStringA strfind = strFolderPath + "\\*";
|
|
|
+ CSimpleStringA strfind = strFolderPath + SPLIT_SLASH_STR+"*";
|
|
|
long Handle = _findfirst(strfind, &FileInfo);
|
|
|
if (-1L == Handle)
|
|
|
{
|
|
@@ -551,20 +559,20 @@ ErrorCodeEnum CUpgradeMgrEntity::MD5Folder(CSimpleStringA strFolderPath,bool isD
|
|
|
}
|
|
|
|
|
|
if(isBlackDir){
|
|
|
- CSimpleStringA dirPath = strFolderPath + "\\" + FileInfo.name;
|
|
|
+ CSimpleStringA dirPath = strFolderPath + SPLIT_SLASH_STR + FileInfo.name;
|
|
|
Dbg("BlackDir Filter don't add to md5 list, dir=[%s]", dirPath.GetData());
|
|
|
continue;//跳过文件夹
|
|
|
}else{
|
|
|
//判断是否是dep文件夹或者是dep文件夹下面的子文件夹
|
|
|
if(strcmp(FileInfo.name, "dep") == 0||isDepDIr){
|
|
|
- newPath = strFolderPath + "\\" + FileInfo.name;
|
|
|
+ newPath = strFolderPath + SPLIT_SLASH_STR + FileInfo.name;
|
|
|
ErrorCodeEnum rc = MD5Folder(newPath,true);
|
|
|
if(Error_Succeed!=rc){
|
|
|
_findclose(Handle);
|
|
|
return rc;
|
|
|
}
|
|
|
}else{
|
|
|
- newPath = strFolderPath + "\\" + FileInfo.name;
|
|
|
+ newPath = strFolderPath + SPLIT_SLASH_STR + FileInfo.name;
|
|
|
ErrorCodeEnum rc = MD5Folder(newPath);
|
|
|
if(Error_Succeed!=rc){
|
|
|
_findclose(Handle);
|
|
@@ -644,7 +652,7 @@ ErrorCodeEnum CUpgradeMgrEntity::MD5Folder(CSimpleStringA strFolderPath,bool isD
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- CSimpleStringA strFilePath = strFolderPath + "\\" + strFindName;
|
|
|
+ CSimpleStringA strFilePath = strFolderPath + SPLIT_SLASH_STR + strFindName;
|
|
|
CSimpleStringA strMD5Val;
|
|
|
//ErrorCodeEnum rErrcode = MD5File(strFilePath, strMD5Val);
|
|
|
//修改为SM3进行哈希
|
|
@@ -663,6 +671,142 @@ ErrorCodeEnum CUpgradeMgrEntity::MD5Folder(CSimpleStringA strFolderPath,bool isD
|
|
|
|
|
|
_findclose(Handle);
|
|
|
return Error_Succeed;
|
|
|
+#else
|
|
|
+ //循环扫描文件算出文件hash值
|
|
|
+ DIR* dir;
|
|
|
+ struct dirent* entry;
|
|
|
+ CSimpleStringA newPath;
|
|
|
+
|
|
|
+ if ((dir = opendir(strFolderPath.GetData())) == NULL)
|
|
|
+ {
|
|
|
+ Dbg("open dir fail:%d", errno);
|
|
|
+ return Error_Unexpect;
|
|
|
+ }
|
|
|
+ while ((entry = readdir(dir)) != NULL)
|
|
|
+ {
|
|
|
+ if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
|
|
+ {//current dir OR parrent dir
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else if (entry->d_type == 4)
|
|
|
+ {//dir
|
|
|
+ CSimpleStringA strFindName = entry->d_name;
|
|
|
+ //整个黑名单文件夹过滤
|
|
|
+ bool isBlackDir = false;
|
|
|
+ list<CSimpleStringA>::iterator itor = m_fsm.m_DirBlacklist.begin();
|
|
|
+ while (itor != m_fsm.m_DirBlacklist.end())
|
|
|
+ {
|
|
|
+ CSimpleStringA dirBlack = *itor;
|
|
|
+ if (strcmp(dirBlack.GetData(), entry->d_name) == 0) {
|
|
|
+ isBlackDir = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ itor++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isBlackDir) {
|
|
|
+ CSimpleStringA dirPath = strFolderPath + SPLIT_SLASH_STR + entry->d_name;
|
|
|
+ Dbg("BlackDir Filter don't add to md5 list, dir=[%s]", dirPath.GetData());
|
|
|
+ continue;//跳过文件夹
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //判断是否是dep文件夹或者是dep文件夹下面的子文件夹
|
|
|
+ if (strcmp(entry->d_name, "dep") == 0 || isDepDIr) {
|
|
|
+ newPath = strFolderPath + SPLIT_SLASH_STR + entry->d_name;
|
|
|
+ ErrorCodeEnum rc = MD5Folder(newPath, true);
|
|
|
+ if (Error_Succeed != rc) {
|
|
|
+ closedir(dir);
|
|
|
+ return rc;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ newPath = strFolderPath + SPLIT_SLASH_STR + entry->d_name;
|
|
|
+ ErrorCodeEnum rc = MD5Folder(newPath);
|
|
|
+ if (Error_Succeed != rc) {
|
|
|
+ closedir(dir);
|
|
|
+ return rc;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (entry->d_type == 8)
|
|
|
+ {//file
|
|
|
+ CSimpleStringA strFindName = entry->d_name;
|
|
|
+ {
|
|
|
+ if (strFindName.IndexOf(".") == -1)
|
|
|
+ {
|
|
|
+ Dbg("%s file name is illegal", strFindName);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //整体黑名单文件过滤
|
|
|
+ bool isBlackFile = false;
|
|
|
+ list<CSimpleStringA>::iterator itor = m_fsm.m_FileBlacklist.begin();
|
|
|
+ while (itor != m_fsm.m_FileBlacklist.end())
|
|
|
+ {
|
|
|
+ CSimpleStringA fileBlack = *itor;
|
|
|
+ if (strFindName.IsEndWith(fileBlack.GetData(), true)) {
|
|
|
+ isBlackFile = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ itor++;
|
|
|
+ }
|
|
|
+ if (isBlackFile) {
|
|
|
+ Dbg("BlackFile Filter don't add to md5 list, file = [%s]", strFindName.GetData());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //对历史遗留的centerSetting错误缓存文件特殊处理,不纳入hash文件列表
|
|
|
+ //对所有集中配置文件都过滤,规则是CenterSetting.*.ini*
|
|
|
+ regex e("CenterSetting[.][^.]*[.]ini.*");
|
|
|
+ if (std::regex_match(strFindName.GetData(), e, regex_constants::match_default)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断是否需要用dep白名单过滤
|
|
|
+ if (isDepDIr) {
|
|
|
+ bool isWhiteFile = false;
|
|
|
+ list<CSimpleStringA>::iterator itor = m_fsm.m_DepWhitelist.begin();
|
|
|
+ while (itor != m_fsm.m_DepWhitelist.end())
|
|
|
+ {
|
|
|
+ CSimpleStringA fileWhite = *itor;
|
|
|
+ if (strFindName.IsEndWith(fileWhite.GetData(), true)) {
|
|
|
+ isWhiteFile = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ itor++;
|
|
|
+ }
|
|
|
+ //不是白名单也不是默认so文件,不需要加入hash计算
|
|
|
+ if (!isWhiteFile && !strFindName.IsEndWith(".so", true)) {
|
|
|
+ Dbg("WhiteFile Filter don't add to md5 list, file = [%s]", strFindName.GetData());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ CSimpleStringA strFilePath = strFolderPath + SPLIT_SLASH_STR + strFindName;
|
|
|
+ CSimpleStringA strMD5Val;
|
|
|
+ //ErrorCodeEnum rErrcode = MD5File(strFilePath, strMD5Val);
|
|
|
+ //修改为SM3进行哈希
|
|
|
+ ErrorCodeEnum rErrcode = SM3FileToStr(strFilePath, strMD5Val, false);
|
|
|
+ if (Error_Succeed != rErrcode)
|
|
|
+ {
|
|
|
+ Dbg("%s获取MD5失败,错误码:%d", strFilePath.GetData(), (int)rErrcode);
|
|
|
+ closedir(dir);
|
|
|
+ return rErrcode;
|
|
|
+ }
|
|
|
+
|
|
|
+ m_FileHashMap[strFilePath] = strMD5Val;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (entry->d_type == 10)
|
|
|
+ {//link file,暂不处理
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ closedir(dir);
|
|
|
+ return Error_Succeed;
|
|
|
+#endif
|
|
|
+
|
|
|
}
|
|
|
ErrorCodeEnum CUpgradeMgrEntity::GetMD5List(CSimpleStringA &strMD5List)
|
|
|
{
|
|
@@ -686,7 +830,7 @@ ErrorCodeEnum CUpgradeMgrEntity::GetMD5List(CSimpleStringA &strMD5List)
|
|
|
CSimpleStringA strRootVerPath;
|
|
|
this->GetFunction()->GetPath("RootVer", strRootVerPath);
|
|
|
Dbg("strRootVerPath %s,curVer:%s", strRootVerPath.GetData(),curVer.GetData());
|
|
|
- CSimpleStringA strCurVerPath = CSimpleStringA::Format("%s\\%s", (const char*)strRootVerPath, (const char*)curVer);
|
|
|
+ CSimpleStringA strCurVerPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strRootVerPath, (const char*)curVer);
|
|
|
|
|
|
if (!ExistsDirA(strCurVerPath))
|
|
|
{
|