BOOL kull_m_rpc_bkrp_generic(LPCWSTR NetworkAddr, const GUID * pGuid, PVOID DataIn, DWORD dwDataIn, PVOID *pDataOut, DWORD *pdwDataOut) { BOOL status = FALSE; RPC_BINDING_HANDLE hBinding; NET_API_STATUS netStatus; PBYTE out = NULL; *pDataOut = NULL; *pdwDataOut = 0; if(kull_m_rpc_bkrp_createBinding(NetworkAddr, &hBinding)) { RpcTryExcept { netStatus = BackuprKey(hBinding, (GUID *) pGuid, (PBYTE) DataIn, dwDataIn, &out, pdwDataOut, 0); if(status = (netStatus == 0)) { if(*pDataOut = LocalAlloc(LPTR, *pdwDataOut)) RtlCopyMemory(*pDataOut, out, *pdwDataOut); MIDL_user_free(out); } else PRINT_ERROR(L"BackuprKey: 0x%08x (%u)\n", netStatus, netStatus); } RpcExcept(RPC_EXCEPTION) PRINT_ERROR(L"RPC Exception: 0x%08x (%u)\n", RpcExceptionCode(), RpcExceptionCode()); RpcEndExcept kull_m_rpc_deleteBinding(&hBinding); }
BOOL kull_m_rpc_drsr_getDCBind(RPC_BINDING_HANDLE *hBinding, GUID *NtdsDsaObjectGuid, DRS_HANDLE *hDrs) { BOOL status = FALSE; ULONG drsStatus; DRS_EXTENSIONS_INT DrsExtensionsInt;// = {0}; DRS_EXTENSIONS *pDrsExtensionsOutput = NULL; DrsExtensionsInt.cb = sizeof(DRS_EXTENSIONS_INT) - sizeof(DWORD); DrsExtensionsInt.dwFlags = DRS_EXT_GETCHGREPLY_V6 | DRS_EXT_STRONG_ENCRYPTION; RpcTryExcept { drsStatus = IDL_DRSBind(*hBinding, NtdsDsaObjectGuid, (DRS_EXTENSIONS *) &DrsExtensionsInt, &pDrsExtensionsOutput, hDrs); // to free ? if(drsStatus == 0) { if(pDrsExtensionsOutput) { if(((DRS_EXTENSIONS_INT *) pDrsExtensionsOutput)->dwFlags & (DRS_EXT_GETCHGREQ_V8 | DRS_EXT_STRONG_ENCRYPTION)) status = TRUE; else PRINT_ERROR(L"Incorrect DRS Extensions Output (%08x)\n", ((DRS_EXTENSIONS_INT *) pDrsExtensionsOutput)->dwFlags); MIDL_user_free(pDrsExtensionsOutput); } else PRINT_ERROR(L"No DRS Extensions Output\n"); if(!status) IDL_DRSUnbind(hDrs); } else PRINT_ERROR(L"IDL_DRSBind: %u\n", drsStatus); } RpcExcept(DRS_EXCEPTION) PRINT_ERROR(L"RPC Exception 0x%08x (%u)\n", RpcExceptionCode(), RpcExceptionCode()); RpcEndExcept return status; }
BOOL kull_m_rpc_Generic_Decode(PVOID data, DWORD size, PVOID pObject, PGENERIC_RPC_DECODE fDecode) { BOOL status = FALSE; RPC_STATUS rpcStatus; PVOID buffer; KULL_M_RPC_FCNSTRUCT UserState ; handle_t pHandle; if(buffer = UserState.addr = LocalAlloc(LPTR, size)) { UserState.size = size; RtlCopyMemory(UserState.addr, data, size); // avoid data alteration rpcStatus = MesDecodeIncrementalHandleCreate(&UserState, ReadFcn, &pHandle); if(NT_SUCCESS(rpcStatus)) { rpcStatus = MesIncrementalHandleReset(pHandle, NULL, NULL, NULL, NULL, MES_DECODE); if(NT_SUCCESS(rpcStatus)) { RpcTryExcept { fDecode(pHandle, pObject); status = TRUE; } RpcExcept(EXCEPTION_EXECUTE_HANDLER) PRINT_ERROR(L"RPC Exception: 0x%08x (%u)\n", RpcExceptionCode(), RpcExceptionCode()); RpcEndExcept } else PRINT_ERROR(L"MesIncrementalHandleReset: %08x\n", rpcStatus); MesHandleFree(pHandle); }
void doRpcCall() { char buff[1024]; RpcTryExcept { while (1) { printf("Please input a string param for RPC call:\n"); gets(buff); if ( strcmp(buff, "exit") == 0 || strcmp(buff, "quit") == 0 ) { ShutDown(); break; } else { HelloProc( (unsigned char *)buff ); printf("RPC call <HelloProc> succeed!\n"); } } } RpcExcept(1) { /* unsigned long ulCode = RpcExceptionCode(); printf("RPC exception occured! code: %ld\n", ulCode); */ } RpcEndExcept }
BOOL kull_m_rpc_bkrp_generic(RPC_BINDING_HANDLE *hBinding, const GUID * pGuid, PVOID DataIn, DWORD dwDataIn, PVOID *pDataOut, DWORD *pdwDataOut) { BOOL status = FALSE; NET_API_STATUS netStatus; *pDataOut = NULL; *pdwDataOut = 0; RpcTryExcept { netStatus = BackuprKey(*hBinding, (GUID *) pGuid, (PBYTE) DataIn, dwDataIn, (PBYTE *) pDataOut, pdwDataOut, 0); if(!(status = (netStatus == 0))) wprintf(L"[ERROR] BackuprKey: 0x%08x (%u)\n", netStatus, netStatus); } RpcExcept(RPC_EXCEPTION) wprintf(L"[ERROR] RPC Exception: 0x%08x (%u)\n", RpcExceptionCode(), RpcExceptionCode()); RpcEndExcept return status; }
BOOL kull_m_rpc_drsr_CrackName(DRS_HANDLE hDrs, DS_NAME_FORMAT NameFormat, LPCWSTR Name, DS_NAME_FORMAT FormatWanted, LPWSTR *CrackedName, LPWSTR *CrackedDomain) { BOOL status = FALSE; DRS_MSG_CRACKREQ nameCrackReq = {0}; DWORD nameCrackOutVersion = 0, drsStatus; DRS_MSG_CRACKREPLY nameCrackRep = {0}; nameCrackReq.V1.formatOffered = NameFormat; nameCrackReq.V1.formatDesired = FormatWanted; nameCrackReq.V1.cNames = 1; nameCrackReq.V1.rpNames = (LPWSTR *) &Name; RpcTryExcept { drsStatus = IDL_DRSCrackNames(hDrs, 1, &nameCrackReq, &nameCrackOutVersion, &nameCrackRep); if(drsStatus == 0) { if(nameCrackOutVersion == 1) { if(nameCrackRep.V1.pResult->cItems == 1) { drsStatus = nameCrackRep.V1.pResult->rItems[0].status; if(status = (drsStatus == DS_NAME_NO_ERROR)) { kull_m_string_copy(CrackedName, nameCrackRep.V1.pResult->rItems[0].pName); kull_m_string_copy(CrackedDomain, nameCrackRep.V1.pResult->rItems[0].pDomain); } else PRINT_ERROR(L"CrackNames (name status): 0x%08x (%u) - %s\n", drsStatus, drsStatus, (drsStatus < ARRAYSIZE(KULL_M_RPC_DRSR_CrackNames_Error)) ? KULL_M_RPC_DRSR_CrackNames_Error[drsStatus] : L"?"); } else PRINT_ERROR(L"CrackNames: no item!\n"); } else PRINT_ERROR(L"CrackNames: bad version (%u)\n", nameCrackOutVersion); kull_m_rpc_drsr_free_DRS_MSG_CRACKREPLY_data(nameCrackOutVersion, &nameCrackRep); } else PRINT_ERROR(L"CrackNames: 0x%08x (%u)\n", drsStatus, drsStatus); } RpcExcept(DRS_EXCEPTION) PRINT_ERROR(L"RPC Exception 0x%08x (%u)\n", RpcExceptionCode(), RpcExceptionCode()); RpcEndExcept return status; }
DWORD WINAPI ClientPingThread (LPVOID lp) { for (;;) { Sleep (csecAFSADMSVR_CLIENT_PING * 1000L); // server adds race allowance asc_Enter(); for (size_t ii = 0; ii < l.cdwClients; ++ii) { UINT_PTR idClient; if ((idClient = l.adwClients[ ii ]) == 0) continue; asc_Leave(); RpcTryExcept { ULONG status; if (!AfsAdmSvr_Ping (idClient, &status)) { if (status == ERROR_INVALID_HANDLE) // we've been disconnected! StopPingThread (idClient); } } RpcExcept(1) ; RpcEndExcept asc_Enter(); } asc_Leave(); } l.hPingThread = NULL; return 0; }
void RemoteKeyboard::OnClickSyncBtn(TNotifyUI & msg, bool & handled) { auto const &items = g_LessionMappingTable; DuiLib::CControlUI *ctrl; if (msg.pSender->GetName() == _T("sync_ok")) { pugi::xml_document xmldoc; pugi::xml_node root = xmldoc.append_child(PUGIXML_TEXT("lesson")); for (int i = 0; i < _countof(items); ++i) { pugi::xml_attribute attr = root.append_attribute(items[i].attr); if (ctrl = m_PaintManager.FindControl(items[i].name)) attr = ctrl->GetText(); } std::wostringstream oss; root.print(oss, L"", pugi::format_raw); auto _ExecuteExtendCmdWrap = [this](const std::wstring &buf) -> boolean { boolean ret = false; RpcTryExcept ret = rkbc_ExecuteExtendCmd(m_hwBinding, kExtendType_LessionInfo, reinterpret_cast<const byte *>(buf.data()), (buf.size() + 1) * sizeof(wchar_t)); RpcExcept(1) ret = false; RpcEndExcept return ret; }; if (_ExecuteExtendCmdWrap(oss.str())) { m_lession_info = oss.str(); boost::crc_32_type result; result.process_bytes(reinterpret_cast<const byte *>(m_lession_info.data()), (m_lession_info.size() + 1) * sizeof(wchar_t)); m_lession_info_checksum = result.checksum(); } }
BOOL kull_m_rpc_drsr_getDomainAndUserInfos(RPC_BINDING_HANDLE *hBinding, LPCWSTR ServerName, LPCWSTR Domain, GUID *DomainGUID, LPCWSTR User, LPCWSTR Guid, GUID *UserGuid) { BOOL DomainGUIDfound = FALSE, ObjectGUIDfound = FALSE; DWORD i; ULONG drsStatus; DRS_HANDLE hDrs = NULL; DRS_EXTENSIONS_INT DrsExtensionsInt = {0}; DRS_EXTENSIONS *pDrsExtensionsOutput = NULL; DRS_MSG_DCINFOREQ dcInfoReq = {0}; DWORD dcOutVersion = 0; DRS_MSG_DCINFOREPLY dcInfoRep = {0}; LPWSTR sGuid; UNICODE_STRING uGuid; RpcTryExcept { DrsExtensionsInt.cb = sizeof(DRS_EXTENSIONS_INT) - sizeof(DWORD); drsStatus = IDL_DRSBind(*hBinding, &DRSUAPI_DS_BIND_GUID_Standard, (DRS_EXTENSIONS *) &DrsExtensionsInt, &pDrsExtensionsOutput, &hDrs); if(drsStatus == 0) { dcInfoReq.V1.InfoLevel = 2; dcInfoReq.V1.Domain = (LPWSTR) Domain; drsStatus = IDL_DRSDomainControllerInfo(hDrs, 1, &dcInfoReq, &dcOutVersion, &dcInfoRep); if(drsStatus == 0) { if(dcOutVersion == 2) { for(i = 0; i < dcInfoRep.V2.cItems; i++) { if(!DomainGUIDfound && ((_wcsicmp(ServerName, dcInfoRep.V2.rItems[i].DnsHostName) == 0) || (_wcsicmp(ServerName, dcInfoRep.V2.rItems[i].NetbiosName) == 0))) { DomainGUIDfound = TRUE; *DomainGUID = dcInfoRep.V2.rItems[i].NtdsDsaObjectGuid; } } if(!DomainGUIDfound) PRINT_ERROR(L"DomainControllerInfo: DC \'%s\' not found\n", ServerName); } else PRINT_ERROR(L"DomainControllerInfo: bad version (%u)\n", dcOutVersion); kull_m_rpc_drsr_free_DRS_MSG_DCINFOREPLY_data(dcOutVersion, &dcInfoRep); } else PRINT_ERROR(L"DomainControllerInfo: 0x%08x (%u)\n", drsStatus, drsStatus); if(Guid) { RtlInitUnicodeString(&uGuid, Guid); ObjectGUIDfound = NT_SUCCESS(RtlGUIDFromString(&uGuid, UserGuid)); } else if(User) { if(kull_m_rpc_drsr_CrackName(hDrs, wcschr(User, L'\\') ? DS_NT4_ACCOUNT_NAME : wcschr(User, L'=') ? DS_FQDN_1779_NAME : wcschr(User, L'@') ? DS_USER_PRINCIPAL_NAME : DS_NT4_ACCOUNT_NAME_SANS_DOMAIN, User, DS_UNIQUE_ID_NAME, &sGuid, NULL)) { RtlInitUnicodeString(&uGuid, sGuid); ObjectGUIDfound = NT_SUCCESS(RtlGUIDFromString(&uGuid, UserGuid)); } } drsStatus = IDL_DRSUnbind(&hDrs); MIDL_user_free(pDrsExtensionsOutput); } } RpcExcept(DRS_EXCEPTION) PRINT_ERROR(L"RPC Exception 0x%08x (%u)\n", RpcExceptionCode(), RpcExceptionCode()); RpcEndExcept return (DomainGUIDfound && (ObjectGUIDfound || !(Guid || User))); }
LRESULT RemoteKeyboard::OnUpdateStatus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandle) { static bool _last_enabled = true; bool _enable = (wParam != 0); unsigned int _check_value = (unsigned int)(lParam); TCHAR name[32]; if (_last_enabled != _enable) { _last_enabled = _enable; for (int i = 1;; ++i) { _stprintf_s(name, sizeof(name) / sizeof(TCHAR), _T("rkbc_%02d"), i); if (!EnableControl(name, _last_enabled)) break; } } if (_last_enabled) { unsigned int _recode_status = _check_value & 0x3; unsigned int _ch_status = (_check_value >> 2) & 0xf; unsigned int _director_status = (_check_value >> 6) & 0x3; for (int i = 1; i < 14; ++i) { _stprintf_s(name, sizeof(name) / sizeof(TCHAR), _T("rkbc_%02d"), i); if (i < 4) { EnableControl(name, _recode_status != i); } else if (i < 12) { EnableControl(name, _ch_status != i - 3); } else { EnableControl(name, _director_status != i - 11); } } } auto _GetExtendInfoWrap = [this](byte* &pBuf, long &nSize) -> boolean { boolean ret = false; RpcTryExcept ret = rkbc_GetExtendInfo(m_hwBinding, kExtendType_LessionInfo, __int64(m_lession_info_checksum), &pBuf, &nSize); RpcExcept(1) ret = false; RpcEndExcept return ret; }; /* 如果同步排课界面不处于显示状态,则不刷新 */ if (!m_PaintManager.FindControl(_T("sync_panel"))->IsVisible()) return 0; byte *pBuf = 0; long nSize = 0; if (_enable && _GetExtendInfoWrap(pBuf, nSize) && pBuf) { auto const &items = g_LessionMappingTable; pugi::xml_document doc; if (doc.load(LPCTSTR(pBuf))) { pugi::xml_node elem = doc.child(_T("lesson")); if (elem) { for (int i = 0; i < _countof(items); ++i) { DuiLib::CControlUI *ctrl; if (ctrl = m_PaintManager.FindControl(items[i].name)) ctrl->SetText(elem.attribute(items[i].attr).as_string()); } m_lession_info = LPCTSTR(pBuf); boost::crc_32_type result; result.process_bytes(reinterpret_cast<const byte *>(m_lession_info.data()), (m_lession_info.size() + 1) * sizeof(wchar_t)); m_lession_info_checksum = result.checksum(); } } midl_user_free(pBuf); } return LRESULT(); }