-
Notifications
You must be signed in to change notification settings - Fork 190
Home directory for non-existent user should not fall back to /var/empty or %ALLUSERSPROFILE% #1072
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
Home directory for non-existent user should not fall back to /var/empty or %ALLUSERSPROFILE% #1072
Conversation
… to /var/empty or %ALLUSERSPROFILE%
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be a bit of bleeding whitespace that this change is introducing. It seems mostly like an extraction of the windows logic into a helper function which is adding a fair amount of contextual change.
internal static func homeDirectoryPath(forUser user: String) -> String? { | ||
#if os(Windows) | ||
guard !user.isEmpty else { | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we return nil
for empty user on non-Windows platforms, too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see that Platform.homeDirectory(forUserName: "")
returns nil
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we have some unit tests that check for this behavior that aren't platform specific so in the end I think the behavior matches, but happy to restructure if you think this should be moved out of the #if
block
} | ||
#else | ||
// First check CFFIXED_USER_HOME if the environment is not considered tainted | ||
if let envVar = Platform.getEnvSecure("CFFIXED_USER_HOME") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed this. The behavior appears consistent with CFCopyHomeDirectoryURLForUser
, but I'm not sure it's correct. 😓 An issue for a different day, perhaps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it did seem a bit weird that CFFIXED_USER_HOME
affects all users and not just the current user, but I agree probably an issue to address separately to minimize the behavioral changes of this patch (this was sort of easily overlooked before but is now very clear since the implementations for current vs. specific user are split)
Somewhat yes. The windows logic was previously if let user {
// Other user specific logic
}
// Current user logic I split this into two separate functions (one where user is non-optional and one where there is no user variable) so you're likely seeing the indentation change of the user-specific logic moving from an |
… to /var/empty or %ALLUSERSPROFILE% (swiftlang#1072)
When porting
FileManager
to swift-foundation, I made the mistake of changing the underlying home directory lookup behavior for non-existent users to fallback to/var/empty
. I also synced this behavior to Windows where it now falls back to%ALLUSERSPROFILE%
and updated unit tests to match this behavior. However, this behavior is incorrect. Falling back to/var/empty
or%ALLUSERSPROFILE%
is an alright choice for the current user, but for an arbitrary other user, we should instead returnnil
as these APIs return optional values. This PR splits the user home directory implementation into two: one for the current user that falls back to/var/empty
/%ALLUSERSPROFILE%
and one for a specific user that returnsnil
on failure.