Files
rust-discovery/crates/agent-windows/native/clock_endpoints.c
2026-11-14 02:39:39 +01:00

50 lines
2.0 KiB
C

/* Read-only local endpoint discovery for precisely the MS-W32T interface.
* No status invocation, no endpoint names/annotations leave this boundary.
*/
#define _WIN32_WINNT 0x0a00
#include <windows.h>
#include <rpc.h>
#include <stdint.h>
#include <string.h>
typedef struct {
uint32_t result, scanned, named_pipe, alpc, other, truncated;
} RmmClockEndpoints;
uint32_t rmm_clock_endpoints(RmmClockEndpoints *out) {
RPC_IF_ID interface_id = {0};
RPC_EP_INQ_HANDLE inquiry = NULL;
RPC_STATUS result;
memset(out, 0, sizeof(*out));
result = UuidFromStringW((RPC_WSTR)L"8fb6d884-2388-11d0-8c35-00c04fda2795", &interface_id.Uuid);
if (result) return out->result = result;
interface_id.VersMajor = 4; interface_id.VersMinor = 1;
result = RpcMgmtEpEltInqBegin(NULL, RPC_C_EP_MATCH_BY_IF, &interface_id,
RPC_C_VERS_EXACT, NULL, &inquiry);
if (result) return out->result = result;
for (unsigned i = 0; i < 16; ++i) {
RPC_BINDING_HANDLE binding = NULL;
RPC_IF_ID actual = {0};
UUID object = {0};
RPC_WSTR annotation = NULL, text = NULL, protocol = NULL;
result = RpcMgmtEpEltInqNextW(inquiry, &actual, &binding, &object, &annotation);
if (annotation) RpcStringFreeW(&annotation);
if (result == RPC_X_NO_MORE_ENTRIES) { result = 0; break; }
if (result) break;
++out->scanned;
result = RpcBindingToStringBindingW(binding, &text);
if (!result) result = RpcStringBindingParseW(text, NULL, &protocol, NULL, NULL, NULL);
if (!result) {
if (!wcscmp((wchar_t *)protocol, L"ncalrpc")) ++out->alpc;
else if (!wcscmp((wchar_t *)protocol, L"ncacn_np")) ++out->named_pipe;
else ++out->other;
}
if (protocol) RpcStringFreeW(&protocol);
if (text) RpcStringFreeW(&text);
RpcBindingFree(&binding);
if (result) break;
if (i == 15) out->truncated = 1;
}
RpcMgmtEpEltInqDone(&inquiry);
return out->result = result;
}