BOOL needToClean;
PSID pSid1, pSid2;
ULONG i;
- LONG rc;
- BOOL ret;
+ BOOL bRet;
+ DWORD LastErr;
+ DWORD Ret = ERROR_SUCCESS;
+
+ /* save the last error code */
+ LastErr = GetLastError();
*NewAcl = NULL;
if (OldAcl)
{
if (!GetAclInformation(OldAcl, &SizeInformation, sizeof(ACL_SIZE_INFORMATION), AclSizeInformation))
- return GetLastError();
+ {
+ Ret = GetLastError();
+ goto Cleanup;
+ }
+
pKeepAce = (BOOL *)LocalAlloc(LMEM_FIXED, SizeInformation.AceCount);
if (!pKeepAce)
- return ERROR_NOT_ENOUGH_MEMORY;
+ {
+ Ret = ERROR_NOT_ENOUGH_MEMORY;
+ goto Cleanup;
+ }
+
memset(pKeepAce, TRUE, SizeInformation.AceCount);
}
else
if (!pKeepAce[i])
continue;
if (!GetAce(OldAcl, i, (PVOID*)&pAce))
- goto cleanup;
+ {
+ Ret = GetLastError();
+ goto Cleanup;
+ }
+
pSid2 = AccpGetAceSid(pAce);
if (RtlEqualSid(pSid1, pSid2))
{
pNew = (PACL)LocalAlloc(LMEM_FIXED, SizeInformation.AclBytesInUse);
if (!pNew)
{
- rc = ERROR_NOT_ENOUGH_MEMORY;
- goto done;
+ Ret = ERROR_NOT_ENOUGH_MEMORY;
+ goto Cleanup;
}
if (!InitializeAcl(pNew, SizeInformation.AclBytesInUse, ACL_REVISION))
- goto cleanup;
+ {
+ Ret = GetLastError();
+ goto Cleanup;
+ }
/* Fill it */
/* 1a) New audit entries (SET_AUDIT_SUCCESS, SET_AUDIT_FAILURE) */
{
/* FIXME: take care of pListOfExplicitEntries[i].grfInheritance */
pSid1 = GetTrusteeSid(&pListOfExplicitEntries[i].Trustee, &needToClean);
- ret = AddAccessDeniedAce(pNew, ACL_REVISION, pListOfExplicitEntries[i].grfAccessPermissions, pSid1);
+ bRet = AddAccessDeniedAce(pNew, ACL_REVISION, pListOfExplicitEntries[i].grfAccessPermissions, pSid1);
if (needToClean) LocalFree((HLOCAL)pSid1);
- if (!ret)
- goto cleanup;
+ if (!bRet)
+ {
+ Ret = GetLastError();
+ goto Cleanup;
+ }
}
}
{
/* FIXME: take care of pListOfExplicitEntries[i].grfInheritance */
pSid1 = GetTrusteeSid(&pListOfExplicitEntries[i].Trustee, &needToClean);
- ret = AddAccessAllowedAce(pNew, ACL_REVISION, pListOfExplicitEntries[i].grfAccessPermissions, pSid1);
+ bRet = AddAccessAllowedAce(pNew, ACL_REVISION, pListOfExplicitEntries[i].grfAccessPermissions, pSid1);
if (needToClean) LocalFree((HLOCAL)pSid1);
- if (!ret)
- goto cleanup;
+ if (!bRet)
+ {
+ Ret = GetLastError();
+ goto Cleanup;
+ }
}
}
/* FIXME */
*NewAcl = pNew;
- rc = ERROR_SUCCESS;
- goto done;
-
-cleanup:
- rc = GetLastError();
-done:
+Cleanup:
if (pKeepAce)
LocalFree((HLOCAL)pKeepAce);
- DPRINT("Returning %d\n", rc);
- return rc;
+
+ /* restore the last error code */
+ SetLastError(LastErr);
+
+ return Ret;
}