51 PSID AdministratorsSid;
53 SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY};
54 BOOL IsAdministrators;
57 if (!AllocateAndInitializeSid(&NtAuthority, 2,
58 SECURITY_BUILTIN_DOMAIN_RID,
59 DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0,
60 0, &AdministratorsSid))
62 log_error(
_(
"could not get SID for Administrators group: error code %lu\n"),
67 if (!AllocateAndInitializeSid(&NtAuthority, 2,
68 SECURITY_BUILTIN_DOMAIN_RID,
69 DOMAIN_ALIAS_RID_POWER_USERS, 0, 0, 0, 0, 0,
72 log_error(
_(
"could not get SID for PowerUsers group: error code %lu\n"),
77 if (!CheckTokenMembership(NULL, AdministratorsSid, &IsAdministrators) ||
78 !CheckTokenMembership(NULL, PowerUsersSid, &IsPowerUsers))
80 log_error(
_(
"could not check access token membership: error code %lu\n"),
85 FreeSid(AdministratorsSid);
86 FreeSid(PowerUsersSid);
88 if (IsAdministrators || IsPowerUsers)
122 static int _is_service = -1;
126 SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY};
127 HANDLE stderr_handle;
130 if (_is_service != -1)
134 stderr_handle = GetStdHandle(STD_ERROR_HANDLE);
135 if (stderr_handle != INVALID_HANDLE_VALUE && stderr_handle != NULL)
142 if (!AllocateAndInitializeSid(&NtAuthority, 1,
143 SECURITY_LOCAL_SYSTEM_RID, 0, 0, 0, 0, 0, 0, 0,
146 fprintf(stderr,
"could not get SID for local system account\n");
150 if (!CheckTokenMembership(NULL, LocalSystemSid, &IsMember))
152 fprintf(stderr,
"could not check access token membership: error code %lu\n",
154 FreeSid(LocalSystemSid);
157 FreeSid(LocalSystemSid);
166 if (!AllocateAndInitializeSid(&NtAuthority, 1,
167 SECURITY_SERVICE_RID, 0, 0, 0, 0, 0, 0, 0,
170 fprintf(stderr,
"could not get SID for service group: error code %lu\n",
175 if (!CheckTokenMembership(NULL, ServiceSid, &IsMember))
177 fprintf(stderr,
"could not check access token membership: error code %lu\n",
#define write_stderr(str)
#define pg_attribute_printf(f, a)
static void const char * fmt
int pgwin32_is_service(void)
static void log_error(const char *fmt,...) pg_attribute_printf(1
int pgwin32_is_admin(void)