Don't leak admin group SID memory
This commit is contained in:
parent
eafbf90d15
commit
84dbd934bf
1 changed files with 7 additions and 6 deletions
13
main.c
13
main.c
|
|
@ -84,22 +84,23 @@ void usage(FILE *fp)
|
||||||
void require_admin()
|
void require_admin()
|
||||||
{
|
{
|
||||||
SID_IDENTIFIER_AUTHORITY auth = SECURITY_NT_AUTHORITY;
|
SID_IDENTIFIER_AUTHORITY auth = SECURITY_NT_AUTHORITY;
|
||||||
PSID adminGroup = NULL;
|
PSID group = NULL;
|
||||||
BOOL success = AllocateAndInitializeSid(
|
BOOL admin, success = AllocateAndInitializeSid(
|
||||||
&auth, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
|
&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 (success) {
|
||||||
if (CheckTokenMembership(NULL, adminGroup, &success)) {
|
success = CheckTokenMembership(NULL, group, &admin);
|
||||||
if (!success) {
|
FreeSid(group);
|
||||||
|
if (success) {
|
||||||
|
if (!admin) {
|
||||||
fprintf(stderr, "Error: must be run as administrator\n");
|
fprintf(stderr, "Error: must be run as administrator\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FreeSid(adminGroup);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Warning: failed to check administrator privileges\n");
|
fprintf(stderr, "Warning: failed to check administrator privileges\n");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue