Skip to content

Commit

Permalink
Do Not Decorate Local System Account
Browse files Browse the repository at this point in the history
- Do not decorate local system account in get_passwd() since it is not a domain account.
  • Loading branch information
NoMoreFood committed Feb 16, 2020
1 parent ee11c8e commit 64d4c84
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions contrib/win32/win32compat/pwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,11 @@ get_passwd(const wchar_t * user_utf16, PSID sid)
goto cleanup;
}

/* If standard local user name, just use name without decoration */
if ((_wcsicmp(domain_name, computer_name) == 0) && (_wcsicmp(computer_name, user_name) != 0))
/* if standard local user name or system account, just use name without decoration */
const SID_IDENTIFIER_AUTHORITY nt_authority = SECURITY_NT_AUTHORITY;
if ((_wcsicmp(domain_name, computer_name) == 0) && (_wcsicmp(computer_name, user_name) != 0) ||
memcmp(&nt_authority, GetSidIdentifierAuthority((PSID) binary_sid), sizeof(SID_IDENTIFIER_AUTHORITY)) == 0 && (
((SID*)binary_sid)->SubAuthority[0] == SECURITY_LOCAL_SYSTEM_RID))
wcscpy_s(user_resolved, ARRAYSIZE(user_resolved), user_name);

/* put any other format in sam compatible format */
Expand Down

2 comments on commit 64d4c84

@bkatyl
Copy link

@bkatyl bkatyl commented on 64d4c84 Feb 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NoMoreFood I used this code to get AuthorizedKeysCommand/AuthorizedPrincipalsCommand working as system. Since you mentioned in PowerShell/Win32-OpenSSH#1546 (comment) that you didn't want to dive to deep given the project hasn't been very active recently.

Would you be ok if I submitted this as a PR and credited you and this commit as the source. I'm happy to have pursue it even given the overall project activity since the 2 PR's will fix this behavior and allow us to run AuthorizedKeysCommand/AuthorizedPrincipalsCommand as system.

@NoMoreFood
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkatyl Yes, fine by me.

Please sign in to comment.