Эх сурвалжийг харах

#IQRV #comment [BugFix] 修复获取磁盘信息与初始化实体不一致的缺陷

gifur 4 жил өмнө
parent
commit
1daf2f822e

+ 4 - 2
Module/mod_accessauth/CMakeLists.txt

@@ -11,10 +11,12 @@ if(WIN32)
 	AccessAuthFSM.cpp
 	mod_AccessAuth.cpp
 	WMIDeviceQuery.cpp
+	comm.h
 	comm.cpp
 	)
 else()
 	set(${MODULE_PREFIX}_SRCS
+	comm.h
 	comm.cpp
 	AccessAuthConn.cpp
 	AccessAuthFSM.cpp
@@ -24,7 +26,7 @@ endif(WIN32)
 
 message(STATUS "module=${${MODULE_PREFIX}_SRCS}")
 
-set(MOD_VERSION_STRING "1.0.0-dev1")
+set(MOD_VERSION_STRING "1.0.0-dev2")
 add_module_libraries(${MODULE_PREFIX} ${MODULE_NAME} ${MOD_VERSION_STRING})
 
 target_include_directories(${MODULE_NAME} PRIVATE
@@ -46,7 +48,7 @@ target_link_directories(${MODULE_NAME} PRIVATE
 
 # 添加实体需要依赖的其他共享库(包括系统库)
 set(${MODULE_PREFIX}_LIBS ${MODULE_BASE_ALL_LIBS})#${CONAN_PKG_LIBS_BOOST} RVCCrypt NewRVCCrypt
-target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
+target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS} libpublicFun)
 
 
 

+ 3 - 0
Module/mod_accessauth/ChangeLog

@@ -1,3 +1,6 @@
 
+## 1.0.0-dev2
+* [BugFix] 修复获取磁盘信息与初始化实体不一致的缺陷(廖桂发,2021年6月4日)
+
 ## V1.0.0-dev1
 * 首次适配跨平台稳定版本(雷志明,2020年12月14日)

+ 44 - 21
Module/mod_accessauth/comm.cpp

@@ -1,5 +1,11 @@
 #include "comm.h"
 #include <cstdarg>
+#ifndef _WIN32
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <linux/hdreg.h>
+#include <sys/fcntl.h>
+#endif //NOT _WIN32
 #define MAX_PATH_SIZE 256
 void GetNewForm(const char* form, char* newForm) {
 	int indexNum = 0;
@@ -448,27 +454,44 @@ char* Str2Hex(const char* src, int srcLen)
 		ifs.close();
 	}
 
-	bool get_disk_serial_by_system(std::vector<string>& serial_no,const string save_path)
-	{
-		if (save_path.size() + strlen("/.lshw_result.txt") > MAX_PATH_SIZE) return false;
-		char lshw_result[MAX_PATH_SIZE] = { 0 };
-		strcpy(lshw_result, save_path.c_str());
-		strcat(lshw_result, "/.lshw_result.txt");
-
-		char command[512] = { 0 };
-		snprintf(command, sizeof(command), "lshw -class disk | grep serial > %s", lshw_result);
-
-		if (0 == system(command))
-		{
-			get_disk_serial(lshw_result, "serial:", serial_no);
-		}
-		else {
-			return false;
-		}
-		unlink(lshw_result);
-
-		return(true);
-	}
+    bool isSpace(char x) { return x == ' '; }
+	bool get_disk_serial_by_system(std::vector<string>& serial_no, int& errCode, const string save_path)
+    {
+        //if (save_path.size() + strlen("/.lshw_result.txt") > MAX_PATH_SIZE) return false;
+        //char lshw_result[MAX_PATH_SIZE] = { 0 };
+        //strcpy(lshw_result, save_path.c_str());
+        //strcat(lshw_result, "/.lshw_result.txt");
+
+        //char command[512] = { 0 };
+        //snprintf(command, sizeof(command), "lshw -class disk | grep serial > %s", lshw_result);
+
+        //if (0 == system(command))
+        //{
+        //	get_disk_serial(lshw_result, "serial:", serial_no);
+        //}
+        //else {
+        //	return false;
+        //}
+        errCode = 0;
+        struct hd_driveid id;
+        int fd = open("/dev/hda", O_RDONLY | O_NONBLOCK);
+        if (fd < 0) {
+            fd = open("/dev/sda", O_RDONLY | O_NONBLOCK);
+            if (fd < 0) {
+                perror("read failed:");
+                errCode = errno;
+                return false;
+            }
+        }
+        if (!ioctl(fd, HDIO_GET_IDENTITY, &id)) {
+            string xx((const char*)(id.serial_no));
+            xx.erase(remove_if(xx.begin(), xx.end(), isSpace), xx.end());
+            serial_no.push_back(xx);
+        }
+        //unlink(lshw_result);
+
+        return(true);
+    }
 
 #include <unistd.h>
 	bool file_is_exist(string filePath) {

+ 2 - 1
Module/mod_accessauth/comm.h

@@ -9,6 +9,7 @@
 #include <cmath>
 #include<iostream>
 #include <fstream>
+#include <algorithm>
 
 using namespace std;
 
@@ -58,7 +59,7 @@ int getIPFromLinux(char* ip);
 bool get_cpu_id_by_asm(std::string & cpu_id);
 bool get_cpu_id_by_system(std::string& cpu_id, const string save_path = RUNTIME_PATH);
 bool get_board_serial_by_system(std::string& board_serial, const string save_path = RUNTIME_PATH);
-bool get_disk_serial_by_system(std::vector<string>& serial_no, const string save_path = RUNTIME_PATH);
+bool get_disk_serial_by_system(std::vector<string>& serial_no, int& errCode, const string save_path = RUNTIME_PATH);
 bool file_is_exist(string filePath);
 bool dir_is_exist(string dirPath);
 int file_create(string filePath);

+ 7 - 6
Module/mod_accessauth/mod_AccessAuth.cpp

@@ -853,10 +853,11 @@ bool CAccessAuthEntity::GetTerminalFingerPrint(BYTE *pBuf, int &nBufLen)
 	Dbg("baseboard sn: %s", strTmp.c_str());
 	strRet += strTmp.c_str();
 	vector<string> disk;
-
-	if (!get_disk_serial_by_system(disk, runInfoPath.GetData()))
+    int errCode = 0;
+    if (!get_disk_serial_by_system(disk, errCode, runInfoPath.GetData()))
 #endif // RVC_OS_WIN
 	{
+		Dbg("get_disk_serial_by_system errCode:%d", errCode);
 		strErrMsg = CSimpleStringA::Format("查询磁盘序列号失败, 请重启机器并重新初始化");
 		SetAuthErrMsg((const char*)strErrMsg);
 		spFunction->SetSysVar("AuthErrMsg", (const char*)strErrMsg, false);
@@ -952,10 +953,10 @@ void CAccessAuthEntity::SetAuthErrMsg(const char* pszErrMsg)
 
 void CAccessAuthEntity::WarnAuthErrMsg(DWORD dwSrvCode, DWORD dwSysCode, const std::string& strErrMsg, bool setSysVar)
 {
-	const std::string errStr = SP::Utility::GBK2UTF8(strErrMsg);
-	if (setSysVar) {
-		GetFunction()->SetSysVar("AuthErrMsg", errStr.c_str(), false);
-	}
+    const std::string errStr = SP::Utility::GBK2UTF8(strErrMsg);
+    if (setSysVar) {
+        GetFunction()->SetSysVar("AuthErrMsg", errStr.c_str(), false);
+    }
     LogWarn(Severity_Middle, Error_Unexpect, dwSysCode,
             GetOutPutStr("%s%08X%s%s", "GetErrMsg", dwSrvCode, "AuthErrMsg", errStr.c_str()).c_str());
 }