Skip to content

Commit 4c793c4

Browse files
committed
fix(windows): accept the owner Windows actually stamps on what we create
An elevated install created its own staging file and then refused it: error: failed to stage install candidate: activation transaction I/O failed: owner-not-current-user We compared the object's owner against TokenUser. Windows stamps newly created objects with TokenOwner, and for a member of the Administrators group that defaults to BUILTIN\Administrators ("System objects: Default owner for objects created by members of the Administrators group" — default on Server, common on hardened clients). So on any elevated account the check rejected a file written seconds earlier by the same process. Reported by @spam0115 (DeusData#1580); @gotspatel hit the same wall from the other side (DeusData#1582) — a fresh install whose MCP server exits during initialize, from `C:\Users\Administrator`. The fix reads TokenOwner and accepts that SID too. This is stricter-or-equal, never looser: TokenOwner is the ONE SID this process stamps on its own creations, so the check still refuses anything a different account owns. It does NOT accept "whatever an administrator owns" — that would be the loose version, and the neighbouring activation_windows_owner_is_trusted already covers the pre-existing-directory case where a broader rule is appropriate. On a non-elevated account TokenOwner == TokenUser and nothing changes at all. Windows-only code, so it is unverifiable on the macOS host: this needs the Windows leg to compile and exercise, which is the next step before merge. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 0c64de9 commit 4c793c4

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

‎src/cli/activation_transaction.c‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,52 @@ static bool activation_windows_owner_is_trusted(HANDLE handle) {
453453
return trusted;
454454
}
455455

456+
/* The SID Windows will stamp as OWNER on objects this process creates.
457+
*
458+
* That is TokenOwner, NOT TokenUser, and the two differ exactly when it matters:
459+
* for a member of the Administrators group the default owner is
460+
* BUILTIN\Administrators (the "System objects: Default owner for objects
461+
* created by members of the Administrators group" policy, default on Server and
462+
* common on hardened clients). So an elevated install created its staging file,
463+
* then refused it as "owner-not-current-user" — we rejected a file we had just
464+
* written ourselves (#1580), and the daemon path failed the same way, exiting
465+
* before it could say anything (#1582).
466+
*
467+
* Reading TokenOwner is STRICTER-or-equal, never looser: it is the one SID this
468+
* process stamps. On a non-elevated account TokenOwner == TokenUser and nothing
469+
* changes. It does not accept "anything an administrator owns" — only the exact
470+
* SID our own creations carry. */
471+
static bool activation_windows_token_owner(void **information_out, PSID *sid_out) {
472+
*information_out = NULL;
473+
*sid_out = NULL;
474+
HANDLE token = NULL;
475+
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) {
476+
return false;
477+
}
478+
DWORD needed = 0;
479+
(void)GetTokenInformation(token, TokenOwner, NULL, 0, &needed);
480+
if (needed == 0 || GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
481+
(void)CloseHandle(token);
482+
return false;
483+
}
484+
void *information = calloc(1, needed);
485+
bool ok =
486+
information && GetTokenInformation(token, TokenOwner, information, needed, &needed) != 0;
487+
(void)CloseHandle(token);
488+
if (!ok) {
489+
free(information);
490+
return false;
491+
}
492+
PSID sid = ((TOKEN_OWNER *)information)->Owner;
493+
if (!sid || !IsValidSid(sid)) {
494+
free(information);
495+
return false;
496+
}
497+
*information_out = information;
498+
*sid_out = sid;
499+
return true;
500+
}
501+
456502
static bool activation_windows_owner_is_current(HANDLE handle) {
457503
void *information = NULL;
458504
PSID user_sid = NULL;
@@ -464,6 +510,17 @@ static bool activation_windows_owner_is_current(HANDLE handle) {
464510
DWORD result = GetSecurityInfo(handle, SE_FILE_OBJECT, OWNER_SECURITY_INFORMATION, &owner, NULL,
465511
NULL, NULL, &descriptor);
466512
bool same = result == ERROR_SUCCESS && owner && IsValidSid(owner) && EqualSid(owner, user_sid);
513+
/* Not our user SID — but Windows may legitimately have stamped our token's
514+
* OWNER instead (Administrators, for an elevated account). Accept that and
515+
* only that; see activation_windows_token_owner. */
516+
if (!same && result == ERROR_SUCCESS && owner && IsValidSid(owner)) {
517+
void *owner_information = NULL;
518+
PSID token_owner = NULL;
519+
if (activation_windows_token_owner(&owner_information, &token_owner)) {
520+
same = EqualSid(owner, token_owner) != 0;
521+
free(owner_information);
522+
}
523+
}
467524
if (!same) {
468525
activation_note_refusal("owner-not-current-user", result);
469526
}

0 commit comments

Comments
 (0)