MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / win_resolve_local_admin_sid

Function win_resolve_local_admin_sid

src/daemon/ipc.c:4719–4768  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4717static PSID g_local_admin_sid = NULL; /* process-lifetime cache; NULL => no tolerance */
4718
4719static BOOL CALLBACK win_resolve_local_admin_sid(PINIT_ONCE once, PVOID parameter, PVOID *context) {
4720 (void)once;
4721 (void)context;
4722 win_security_t *security = (win_security_t *)parameter;
4723 if (!security || !security->advapi) {
4724 return TRUE; /* ran once; cache stays NULL (fail closed) */
4725 }
4726 HMODULE advapi = security->advapi;
4727 lsa_open_policy_fn lsa_open =
4728 (lsa_open_policy_fn)(void (*)(void))GetProcAddress(advapi, "LsaOpenPolicy");
4729 lsa_query_information_policy_fn lsa_query = (lsa_query_information_policy_fn)(void (*)(
4730 void))GetProcAddress(advapi, "LsaQueryInformationPolicy");
4731 lsa_free_memory_fn lsa_free =
4732 (lsa_free_memory_fn)(void (*)(void))GetProcAddress(advapi, "LsaFreeMemory");
4733 lsa_close_fn lsa_close = (lsa_close_fn)(void (*)(void))GetProcAddress(advapi, "LsaClose");
4734 create_well_known_sid_fn create_sid =
4735 (create_well_known_sid_fn)(void (*)(void))GetProcAddress(advapi, "CreateWellKnownSid");
4736 if (!lsa_open || !lsa_query || !lsa_free || !lsa_close || !create_sid) {
4737 return TRUE;
4738 }
4739 LSA_OBJECT_ATTRIBUTES attributes;
4740 memset(&attributes, 0, sizeof(attributes));
4741 LSA_HANDLE policy = NULL;
4742 /* STATUS_SUCCESS is 0; any other status (including informational positives) is
4743 * treated as failure, keeping the outcome fail-closed. */
4744 if (lsa_open(NULL, &attributes, POLICY_VIEW_LOCAL_INFORMATION, &policy) != 0 || !policy) {
4745 return TRUE;
4746 }
4747 POLICY_ACCOUNT_DOMAIN_INFO *domain = NULL;
4748 if (lsa_query(policy, PolicyAccountDomainInformation, (PVOID *)&domain) == 0 && domain &&
4749 domain->DomainSid && security->is_valid_sid(domain->DomainSid)) {
4750 DWORD needed = 0;
4751 (void)create_sid(WinAccountAdministratorSid, domain->DomainSid, NULL, &needed);
4752 if (needed > 0U) {
4753 PSID resolved = malloc(needed);
4754 if (resolved &&
4755 create_sid(WinAccountAdministratorSid, domain->DomainSid, resolved, &needed) &&
4756 security->is_valid_sid(resolved)) {
4757 g_local_admin_sid = resolved;
4758 } else {
4759 free(resolved);
4760 }
4761 }
4762 }
4763 if (domain) {
4764 (void)lsa_free(domain);
4765 }
4766 (void)lsa_close(policy);
4767 return TRUE;
4768}
4769
4770static PSID win_local_admin_sid(win_security_t *security) {
4771 if (!security || !security->advapi) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected