-
-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use SIDs as UIDs on Windows #930
Use SIDs as UIDs on Windows #930
Conversation
You're absolutely right on this, the ordering is very much a convenience that doesn't really make sense, but in case you're storing them in an array or anything that can be sorted, it's quite useful. In that regard, I think it's fine to have a Otherwise, this PR looks really great and I'm glad you were able to fix the current situation! I wasn't even able to find out how to make processes' users match the user list with the So just a few comments and then I think it's ready for merge. |
Done! |
Okay, so funnily enough the new test fails on FreeBSD... I don't have this OS handy to investigate, but at a glance it looks like the code parses the user list from |
And the Android failures seem to be related to this: rust-lang/rust#103673. But I'm not sure. |
Don't worry about other CIs than windows. If your test allowed to discover new bugs, I'm very happy. :) I'll fix them in a follow-up PR. Otherwise we're almost there. Some suggestions about memory allocations that could be skipped and some naming nitpicking. |
This is great, thanks a lot for working on this! We'll see if we encounter issues with I'll send a patch for the freebsd bug that this PR allowed to uncover in the next days. |
The reason for implementing this is correctness.
Right now, the user list returned by
SystemExt::users
can contain different UIDs than those returned byProcessExt::user_id
. The reason is thatProcessExt::user_id
usesLookupAccountSidW
to convert an SID to a name (which is used as an ID). On the other hand,SystemExt::users
usesNetUserEnum
andLsaEnumerateLogonSessions
/LsaGetLogonSessionData
to harvest usernames. For system accounts (e.g. LocalSystem or NetworkService) these two techniques return different names. For example, for LocalSystem (S-1-5-18
)LookupAccountSidW
returnsSYSTEM
, whileLsaGetLogonSessionData
returns<COMPUTER NAME>$
.The effect is that
SystemExt::get_user_by_id
is effectively broken for these users. Which means that given aUid
from a process owned by such a user it's impossible to get a username out of it, without relying on the implementation detail that theUid
is actually a username.Note that this PR is a breaking change:
Uid
,Gid
, andUser
no longer implementPartialOrd
andOrd
. This is because SIDs have no meaningful ordering.Uid
andGid
are implemented using the samexid!
macro,PartialOrd
andOrd
were removed from both.Uid
on Windows no longer implementsTryFrom<usize>
. This is because an SID cannot be constructed from a single number.Re: #790 — I have added a Windows-only test that for every process for which we can retrieve a UID, we can also find that UID (using
EqualSid
) in the list returned bySystemExt::users
.I tested this both on Windows 10 (22H2) and on Windows 7 SP1, both 64-bit systems.