📄 pc_net_prog.cpp
字号:
CHAR *pReBasedRemark;
for(UINT i=0; i<(uiIdx+1); i++) {
if(FAILED(RAPI.MapFloatToFixed(i, (BYTE **)&pReBasedRemark))) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: TRANACT -- SMB_TRANS_API_ShareEnum -- internal error with coalesce()!!"));
ASSERT(FALSE);
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
if(pShareTemp->Remark)
pShareTemp->Remark = (char *)(pReBasedRemark - (CHAR *)pFirstShareInfo);
pShareTemp ++; //advance an entire SHARE_INFO_1!
}
}
//fill out response SMB
//PERFPERF: we dont HAVE to zero this out -- if we cover all fields
// run in profiler to see if its a hot spot
memset(pResponse, 0, sizeof(SMB_COM_TRANSACTION_SERVER_RESPONSE));
pResponse->WordCount = (sizeof(SMB_COM_TRANSACTION_SERVER_RESPONSE) - 3) / sizeof(WORD);
pResponse->TotalParameterCount = RAPI.ParamBytesUsed();
pResponse->TotalDataCount = RAPI.DataBytesUsed();
pResponse->ParameterCount = RAPI.ParamBytesUsed();
pResponse->ParameterOffset = RAPI.ParamOffset((BYTE *)_pRawResponse->pSMBHeader);
pResponse->ParameterDisplacement = 0;
pResponse->DataCount = RAPI.DataBytesUsed();
pResponse->DataOffset = RAPI.DataOffset((BYTE *)_pRawResponse->pSMBHeader);
pResponse->DataDisplacement = 0;
pResponse->SetupCount = 0;
pResponse->ByteCount = RAPI.TotalBytesUsed();
ASSERT(10 == pResponse->WordCount);
//
// Fill out the param headers
pParamHeader->ConverterWord = 0;
pParamHeader->ErrorStatus = 0;
pParamHeader->NumberEntries = uiNumShares;
pParamHeader->TotalEntries = uiNumShares;
//
// Set the number of bytes we used
*puiUsed = RAPI.TotalBytesUsed() + sizeof(SMB_COM_TRANSACTION_SERVER_RESPONSE);
dwRet = 0;
}
Done:
return dwRet;
}
DWORD SMB_TRANS_API_WNetWkstaGetInfo(
SMB_PACKET *pSMB,
SMB_PROCESS_CMD *_pRawRequest,
SMB_PROCESS_CMD *_pRawResponse,
UINT *puiUsed,
StringTokenizer &RequestTokenizer)
{
DWORD dwRet = 0;
CHAR *pAPIParam = NULL;
CHAR *pAPIData = NULL;
WORD wLevel;
WORD wRecvBufferSize;
SMB_USERINFO_11 *pUserInfo = NULL;
WNetWkstaGetInfo_RESPONSE_PARAMS *pResponseParams = NULL;
ActiveConnection *pMyConnection = NULL;
SMB_COM_TRANSACTION_CLIENT_REQUEST *pRequest = (SMB_COM_TRANSACTION_CLIENT_REQUEST *)_pRawRequest->pDataPortion;
SMB_COM_TRANSACTION_SERVER_RESPONSE *pResponse = (SMB_COM_TRANSACTION_SERVER_RESPONSE *)_pRawResponse->pDataPortion;
if(FAILED(RequestTokenizer.GetString(&pAPIParam))) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: SMB_TRANS_API_WNetWkstaGetInfo -- Error fetching apiParams! from params!"));
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
if(FAILED(RequestTokenizer.GetString(&pAPIData))) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: SMB_TRANS_API_WNetWkstaGetInfo -- Error fetching smpParams! from params!"));
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
TRACEMSG(ZONE_SMB, (L"...processing API_WNetWkstaGetInfo"));
//
// Verify the param/data/level to make sure they are what we expected
//BUGBUG: there is a way to say we dont support this level.. we need to do that
if( (0 != strcmp("WrLh", (CHAR *)pAPIParam)) ||
(0 != strcmp("zzzBBzz", (CHAR *)pAPIData)))
{
TRACEMSG(ZONE_ERROR, (L"SMBSRV: TRANACT -- SMB_TRANS_API_WNetWkstaGetInfo -- invalid apiparam for api"));
dwRet = ERROR_CODE(STATUS_NOT_SUPPORTED);
goto Done;
}
//
// Fetch request level information
if(FAILED(RequestTokenizer.GetWORD(&wLevel))) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: TRANACT -- SMB_TRANS_API_WNetWkstaGetInfo -- error getting Level from params on API"));
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
if(FAILED(RequestTokenizer.GetWORD(&wRecvBufferSize))) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: TRANACT -- SMB_TRANS_API_WNetWkstaGetInfo -- error getting Level from params on API"));
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
//
// Make sure we have more space than they do
if(wRecvBufferSize > _pRawResponse->uiDataSize) {
wRecvBufferSize = _pRawResponse->uiDataSize - sizeof(SMB_COM_TRANSACTION_SERVER_RESPONSE);
}
{
RAPIBuilder RAPI((BYTE *)(pResponse+1), wRecvBufferSize, pRequest->MaxParameterCount, pRequest->MaxDataCount);
CHAR *pCName = NULL;
UINT uiCNameLen = 0;
CHAR UserName[MAX_PATH];
//
// Find our connection state
if(!(pMyConnection = SMB_Globals::g_pConnectionManager->FindConnection(pSMB))) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: SMB_TRANS_API_WNetWkstaGetInfo: -- cant find connection 0x%x!", pSMB->ulConnectionID));
ASSERT(FALSE);
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
//
// Convert the username to ASCII
if(0 == WideCharToMultiByte(CP_ACP, 0, pMyConnection->UserName(), -1, UserName, MAX_PATH,NULL,NULL)) {
TRACEMSG(ZONE_ERROR, (L"Conversion of username (%s) failed!!!", pMyConnection->UserName()));
ASSERT(FALSE);
goto Done;
}
//BUGBUG: when we dont have enough memory we need to report back to the client!
if(FAILED(RAPI.ReserveParams(sizeof(WNetWkstaGetInfo_RESPONSE_PARAMS), (BYTE**)&pResponseParams))) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: TRANACT -- SMB_TRANS_API_WNetWkstaGetInfo -- not enough memory in request -- sending back request for more"));
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
//
// We wont be alligned if we dont make a gap
while(0 != ((UINT)RAPI.DataPtr() % sizeof(DWORD)))
RAPI.MakeParamByteGap(1);
//
// Allocate enough memory for the response block
if(FAILED(RAPI.ReserveBlock(sizeof(SMB_USERINFO_11), (BYTE**)&pUserInfo))) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: TRANACT -- SMB_TRANS_API_WNetWkstaGetInfo -- not enough memory in request"));
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
//
// Fill in the response parameters
pResponseParams->ReturnStatus = 0;
pResponseParams->ConverterWord = 0;
pResponseParams->TotalBytes = 1000;
SMB_Globals::GetCName((BYTE **)&pCName, &uiCNameLen);
//
// Fill in the data section
if(FAILED(AddStringToFloat(pCName,&pUserInfo->pComputerName, (CHAR *)pUserInfo, &RAPI))) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: TRANACT -- SMB_TRANS_API_WNetWkstaGetInfo -- error adding computername to floating blob"));
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
if(FAILED(AddStringToFloat(UserName,&pUserInfo->pUserName, (CHAR *)pUserInfo, &RAPI))) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: TRANACT -- SMB_TRANS_API_WNetWkstaGetInfo -- error adding username to floating blob"));
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
if(FAILED(AddStringToFloat(SMB_Globals::g_szWorkGroup,&pUserInfo->pLanGroup, (CHAR *)pUserInfo, &RAPI))) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: TRANACT -- SMB_TRANS_API_WNetWkstaGetInfo -- error adding langroup to floating blob"));
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
CHAR *pTempAlignDomain = NULL; //<for alignment! (reset pointers *AFTER* Coalesce called!)
CHAR *pTempAlignOtherDomain = NULL; //<for alignment!
if(FAILED(AddStringToFloat(NULL,&pTempAlignDomain, (CHAR *)pUserInfo, &RAPI))) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: TRANACT -- SMB_TRANS_API_WNetWkstaGetInfo -- error adding domain to floating blob"));
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
if(FAILED(AddStringToFloat(NULL,&pTempAlignOtherDomain, (CHAR *)pUserInfo, &RAPI))) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: TRANACT -- SMB_TRANS_API_WNetWkstaGetInfo -- error adding other domains to floating blob"));
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
pUserInfo->verMajor = CE_MAJOR_VER;
pUserInfo->verMinor = CE_MINOR_VER;
//
// Coalesce the buffer
if(FAILED(RAPI.Coalesce())) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: TRANACT -- SMB_TRANS_API_WNetWkstaGetInfo -- COULDNT coalesce buffer!"));
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
//
// *MUST* be done AFTER Coalesce since the stack data has been modified
pUserInfo->pDomain = pTempAlignDomain;
pUserInfo->pOtherDomains = pTempAlignOtherDomain;
//
//fill out response SMB
memset(pResponse, 0, sizeof(SMB_COM_TRANSACTION_SERVER_RESPONSE));
//word count is 3 bytes (1=WordCount 2=ByteCount) less than the response
pResponse->WordCount = (sizeof(SMB_COM_TRANSACTION_SERVER_RESPONSE) - 3) / sizeof(WORD);
pResponse->TotalParameterCount = RAPI.ParamBytesUsed();
pResponse->TotalDataCount = RAPI.DataBytesUsed();
pResponse->ParameterCount = RAPI.ParamBytesUsed();
pResponse->ParameterOffset = RAPI.ParamOffset((BYTE *)_pRawResponse->pSMBHeader);
pResponse->ParameterDisplacement = 0;
pResponse->DataCount = RAPI.DataBytesUsed();
pResponse->DataOffset = RAPI.DataOffset((BYTE *)_pRawResponse->pSMBHeader);
pResponse->DataDisplacement = 0;
pResponse->SetupCount = 0;
pResponse->ByteCount = RAPI.TotalBytesUsed();
ASSERT(10 == pResponse->WordCount);
//set the number of bytes we used
*puiUsed = RAPI.TotalBytesUsed() + sizeof(SMB_COM_TRANSACTION_SERVER_RESPONSE);
dwRet = 0;
}
Done:
return dwRet;
}
DWORD SMB_TRANS_API_ServerGetInfo(SMB_PACKET *pSMB, SMB_PROCESS_CMD *_pRawRequest, SMB_PROCESS_CMD *_pRawResponse, UINT *puiUsed, StringTokenizer &RequestTokenizer)
{
DWORD dwRet = 0;
CHAR *pAPIParam = NULL;
CHAR *pAPIData = NULL;
WORD wLevel;
WORD wRecvBufferSize;
ServerGetInfo_RESPONSE_PARAMS *pResponseParams = NULL;
SMB_COM_TRANSACTION_CLIENT_REQUEST *pRequest = (SMB_COM_TRANSACTION_CLIENT_REQUEST *)_pRawRequest->pDataPortion;
SMB_COM_TRANSACTION_SERVER_RESPONSE *pResponse = (SMB_COM_TRANSACTION_SERVER_RESPONSE *)_pRawResponse->pDataPortion;
if(FAILED(RequestTokenizer.GetString(&pAPIParam))) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: SMB_TRANS_API_ServerGetInfo -- Error fetching apiParams! from params!"));
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
if(FAILED(RequestTokenizer.GetString(&pAPIData))) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: SMB_TRANS_API_ServerGetInfo -- Error fetching smpParams! from params!"));
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
TRACEMSG(ZONE_SMB, (L"...processing API_WNetWkstaGetInfo"));
//
// Verify the param/data/level to make sure they are what we expected
if( (0 != strcmp("WrLh", (CHAR *)pAPIParam)) ||
((0 != strcmp("zzzBBzz", (CHAR *)pAPIData)) && (0 != strcmp("B16BBDz", (CHAR *)pAPIData))))
{
TRACEMSG(ZONE_ERROR, (L"SMBSRV: TRANACT -- SMB_TRANS_API_ServerGetInfo -- invalid apiparam for api"));
dwRet = ERROR_CODE(STATUS_NOT_SUPPORTED);
goto Done;
}
//
// Fetch request level information
if(FAILED(RequestTokenizer.GetWORD(&wLevel))) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: TRANACT -- SMB_TRANS_API_ServerGetInfo -- error getting Level from params on API"));
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
if(FAILED(RequestTokenizer.GetWORD(&wRecvBufferSize))) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: TRANACT -- SMB_TRANS_API_ServerGetInfo -- error getting Level from params on API"));
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
//
// Make sure we have more space than they do
if(wRecvBufferSize > _pRawResponse->uiDataSize) {
wRecvBufferSize = _pRawResponse->uiDataSize - sizeof(SMB_COM_TRANSACTION_SERVER_RESPONSE);
}
{
RAPIBuilder RAPI((BYTE *)(pResponse+1), wRecvBufferSize, pRequest->MaxParameterCount, pRequest->MaxDataCount);
CHAR *pCName = NULL;
UINT uiCNameLen = 0;
//
// Get the CName from globals
if(FAILED(SMB_Globals::GetCName((BYTE **)&pCName, &uiCNameLen))) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: TRANACT -- SMB_TRANS_API_ServerGetInfo -- not enough memory in request -- sending back request for more"));
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
//
// Reserve parameter information
if(FAILED(RAPI.ReserveParams(sizeof(ServerGetInfo_RESPONSE_PARAMS), (BYTE**)&pResponseParams))) {
TRACEMSG(ZONE_ERROR, (L"SMBSRV: TRANACT -- SMB_TRANS_API_ServerGetInfo -- not enough memory in request -- sending back request for more"));
dwRet = ERROR_CODE(STATUS_INTERNAL_ERROR);
goto Done;
}
//
// We wont be alligned if we dont make a gap, so make one
while(0 != ((UINT)RAPI.DataPtr() % sizeof(DWORD)))
RAPI.MakeParamByteGap(1);
if(0 == wLevel) {
SMB_SERVER_INFO_0 *pServerInfo = NULL;
UINT uiToWrite = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -