-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add isWindowsDeveloperModeActive #343
Comments
@rominf now that nim-lang/Nim#17012 was merged (thanks!) PR welcome for this, and then we need to think what's the proper way to support symlinks for os.copyDir on windows. One possiblity would be: proc copyDir(...):
for ...
when defined(windows):
if isAdmin() or isWindowsDeveloperModeActive():
call copyFile with {`cfSymlinkAsIs`}
else:
call copyFile with {`cfSymlinkIgnore`} Another possibility would be: proc copyDir(...):
for ...
when defined(windows):
call copyFile with `{cfSymlinkAsIs, cfSymlinkIgnoreErrors}`
else:
call copyFile with `{cfSymlinkAsIs}` with some new And yet another would be: proc copyDir(..., onError = onErrorDefault):
for ...
call copyFile with `{cfSymlinkAsIs}, onError(path, kind) which would allow users to pass a callback that would be called on error (with a sane default) |
As I pointed out in the PR regarding isAdmin, this kind of procedure has little value. Furthermore, it promotes the kind of logic that leads to bugs and vulnerabilities. Using the assumption that a user is an administrator, a developer, etc., to assume that some set of functionality can be used, is fundamentally flawed when you are dealing with modern operating systems. This is because such the conditions on which such assumptions are based can change at a moment's notice (TOCTOU). Not only that, but the assumptions aren't even guaranteed to hold true in any time but the present - for example, what happens if the user is a developer, but certain capabilities which are normally enabled have been disabled via group policy? Nobody has given a good purpose yet for these kinds of functions that both outweigh their inherent disadvantages, and can't already be done through basic error handling. |
just because a feature can be misused doesn't mean it's not useful. If we don't provide it, users will re-implement, most likely poorly The OS will still check permissions when priviledges are needed for an OS operation, so the TOCTOU concerns don't apply here unless you're obviously misusing the feature by granting access to some resource just on the basis of isAdmin / isWindowsDeveloperModeActive, which is not what the feature is about. example use cases: fail fastwhen we want a script to only run as root, or only run as non-root; eg, see https://electrictoolbox.com/check-user-root-sudo-before-running/; eg, allows to not do some initial tasks if later tasks would fail because of that improved error messagesgiving relevant context, eg: (After a common failed with a permission error): report whether user was admin or had developper mode enabled relying on
|
Yes and then these are their bugs, not ours. That can be a pretty important thing when you lack infinite resources to develop a project and also when you don't want to sit on millions of lines of code you have to maintain for good. |
What are some common tasks (on Windows, or on both Windows and Linux) where these points apply, and can't be satisfied by a quick test call (such as attempting to create an empty file)?
That is a standard library test, testing low-level, OS-specific functionality. Furthermore, the function
Android and iOS are very, very, very different from desktop operating systems, especially from a permissions standpoint. They do not allow anywhere near the kind of flexibility in changing user permissions and system state, and the significance of being rooted vs non-rooted is a quality that is very unique to those systems. When considering the inclusion of something into the standard library, a number of points have to be considered (roughly, from most to least important):
If something can't pass the above questions, then it might be better to place it in a module. Keep in mind that, once things are added to the standard library, it can be difficult to remove them (and even if they are removed, the identifiers used can't be reclaimed). |
On Windows 10, symlink creation works when the user is an Administrator (see nim-lang/Nim#17012) or if the developer mode is activated (see: https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/). I propose to add the
isWindowsDeveloperModeActive
function to thewinlean
module for handling the latter.The implementation is relatively straightforward; see https://github.com/golang/go/blob/5a8fbb0d2d339fa87a02c0794f5a92c1ce121631/src/os/os_windows_test.go#L1001 for example.
The text was updated successfully, but these errors were encountered: