Minor correction to NtAdjustPrivilegesToken to keep it from returning
total junk.
Modified: trunk/reactos/ntoskrnl/se/token.c
_____
Modified: trunk/reactos/ntoskrnl/se/token.c
--- trunk/reactos/ntoskrnl/se/token.c 2005-03-20 00:53:24 UTC (rev
14208)
+++ trunk/reactos/ntoskrnl/se/token.c 2005-03-20 01:58:54 UTC (rev
14209)
@@ -1632,7 +1632,7 @@
{
// PLUID_AND_ATTRIBUTES Privileges;
KPROCESSOR_MODE PreviousMode;
-// ULONG PrivilegeCount;
+ ULONG PrivilegeCount;
PTOKEN Token;
// ULONG Length;
ULONG i;
@@ -1690,6 +1690,12 @@
&c);
#endif
+ PrivilegeCount = (BufferLength - FIELD_OFFSET(TOKEN_PRIVILEGES,
Privileges)) /
+ sizeof(LUID_AND_ATTRIBUTES);
+
+ if (PreviousState != NULL)
+ PreviousState->PrivilegeCount = 0;
+
k = 0;
if (DisableAllPrivileges == TRUE)
{
@@ -1700,11 +1706,22 @@
DPRINT ("Attributes differ\n");
/* Save current privilege */
- if (PreviousState != NULL && k <
PreviousState->PrivilegeCount)
+ if (PreviousState != NULL)
{
- PreviousState->Privileges[k].Luid =
Token->Privileges[i].Luid;
- PreviousState->Privileges[k].Attributes =
Token->Privileges[i].Attributes;
- k++;
+ if (k < PrivilegeCount)
+ {
+ PreviousState->PrivilegeCount++;
+ PreviousState->Privileges[k].Luid =
Token->Privileges[i].Luid;
+ PreviousState->Privileges[k].Attributes =
Token->Privileges[i].Attributes;
+ }
+ else
+ {
+ /* FIXME: Should revert all the changes,
calculate how
+ * much space would be needed, set ResultLength
+ * accordingly and fail.
+ */
+ }
+ k++;
}
/* Update current privlege */
@@ -1734,11 +1751,22 @@
NewState->Privileges[j].Attributes);
/* Save current privilege */
- if (PreviousState != NULL && k <
PreviousState->PrivilegeCount)
+ if (PreviousState != NULL)
{
- PreviousState->Privileges[k].Luid =
Token->Privileges[i].Luid;
- PreviousState->Privileges[k].Attributes =
Token->Privileges[i].Attributes;
- k++;
+ if (k < PrivilegeCount)
+ {
+ PreviousState->PrivilegeCount++;
+ PreviousState->Privileges[k].Luid =
Token->Privileges[i].Luid;
+ PreviousState->Privileges[k].Attributes =
Token->Privileges[i].Attributes;
+ }
+ else
+ {
+ /* FIXME: Should revert all the changes,
calculate how
+ * much space would be needed, set
ResultLength
+ * accordingly and fail.
+ */
+ }
+ k++;
}
/* Update current privlege */