Skip to content

Commit

Permalink
Don't leak admin group SID memory
Browse files Browse the repository at this point in the history
  • Loading branch information
jclehner committed Jan 18, 2017
1 parent eafbf90 commit 84dbd93
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,23 @@ void usage(FILE *fp)
void require_admin()
{
SID_IDENTIFIER_AUTHORITY auth = SECURITY_NT_AUTHORITY;
PSID adminGroup = NULL;
BOOL success = AllocateAndInitializeSid(
PSID group = NULL;
BOOL admin, success = AllocateAndInitializeSid(
&auth, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0, &adminGroup
0, 0, 0, 0, 0, 0, &group
);

if (success) {
if (CheckTokenMembership(NULL, adminGroup, &success)) {
if (!success) {
success = CheckTokenMembership(NULL, group, &admin);
FreeSid(group);
if (success) {
if (!admin) {
fprintf(stderr, "Error: must be run as administrator\n");
exit(1);
} else {
return;
}
}
FreeSid(adminGroup);
}

fprintf(stderr, "Warning: failed to check administrator privileges\n");
Expand Down

0 comments on commit 84dbd93

Please sign in to comment.