| 354 | } |
| 355 | |
| 356 | static bool activation_windows_user(void **information_out, PSID *sid_out) { |
| 357 | *information_out = NULL; |
| 358 | *sid_out = NULL; |
| 359 | HANDLE token = NULL; |
| 360 | if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) { |
| 361 | return false; |
| 362 | } |
| 363 | DWORD needed = 0; |
| 364 | (void)GetTokenInformation(token, TokenUser, NULL, 0, &needed); |
| 365 | if (needed == 0 || GetLastError() != ERROR_INSUFFICIENT_BUFFER) { |
| 366 | (void)CloseHandle(token); |
| 367 | return false; |
| 368 | } |
| 369 | void *information = calloc(1, needed); |
| 370 | bool ok = |
| 371 | information && GetTokenInformation(token, TokenUser, information, needed, &needed) != 0; |
| 372 | (void)CloseHandle(token); |
| 373 | if (!ok) { |
| 374 | free(information); |
| 375 | return false; |
| 376 | } |
| 377 | PSID sid = ((TOKEN_USER *)information)->User.Sid; |
| 378 | if (!sid || !IsValidSid(sid)) { |
| 379 | free(information); |
| 380 | return false; |
| 381 | } |
| 382 | *information_out = information; |
| 383 | *sid_out = sid; |
| 384 | return true; |
| 385 | } |
| 386 | |
| 387 | static bool activation_windows_security_init(activation_windows_security_t *security) { |
| 388 | memset(security, 0, sizeof(*security)); |
no outgoing calls
no test coverage detected