-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
stdlib/os: add isAdmin #17012
stdlib/os: add isAdmin #17012
Conversation
8abc38e
to
6bda383
Compare
a78191d
to
abb5127
Compare
@timotheecour I don't like printing |
i think this was already addressed by: let isAzure = existsEnv("TF_BUILD") # xxx factor with testament.specs.isAzure
if isAzure: doAssert isAdmin() but in other situations, instead of echo you can use: discard someAPI() # no warning unused for that, or even:
|
Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
af5de4a
to
2d82330
Compare
What would a "classic use case" of this function be? |
See: nim-lang/RFCs#329 (checking symlinks creation on Windows) |
Being root or Administrator shouldn't be conflated with having the ability to do something. It's quite possible to allow users other than the Administrator to create symlinks on Windows. I don't think that this function should be added, precisely because of this misconception. There are relatively few situations where one actually needs to know whether the user is root/administrator. Usually, one should assume that the user has permission to do something, and appropriately handle the cases where permission is denied. |
Thanks, @timotheecour, and @Araq for pointing me at my mistakes and for your patience! I've been busy these days and finally got some time to fix the code. |
While I appreciate the improvements made, I would still like to know: what use-cases does this addition address? Especially given the fact that it can be easily misused. |
Sorry, but this code should go into its own module. Suggestion: |
I'm fine (and in fact in favor) of a separate module (modules are cheap, giant modules like times and os should be broken down and re-export their sub-modules, even if we implement cyclic imports), however:
In the meantime, we can move this to a new module |
DWORD* = int32 | ||
PDWORD* = ptr DWORD | ||
LPINT* = ptr int32 | ||
ULONG_PTR* = uint | ||
PULONG_PTR* = ptr uint | ||
HDC* = Handle | ||
HGLRC* = Handle | ||
BYTE* = cuchar |
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.
ok for now, but we should address nim-lang/RFCs#344 before next release and move it to wintypes
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.
finished review; after comments are addressed we can decide what to do with #17012 (comment) (keep in os, move to std/private/osutils, other)
Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
For example, some installation scripts that write into |
@timotheecour Comments are addressed. |
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.
LGTM.
for #17012 (comment), IMO extensions / admin
isn't warranted, because it's conceivable isAdmin
can be useful for procs in std/os. That said, I'd support splitting std/os
in future work into multiple submodules that would be imported and re-exported by std/os
(can be done transparently); modules are cheap.
* stdlib/os: add isAdmin * uint8 -> cuchar, assert isAdmin on Azure Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> * Update lib/pure/os.nim docs Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> * Address comments on nim-lang#17012 * Raise on errors in nim-lang#17012 * Check the result of FreeSid in nim-lang#17012 * Change case in nim-lang#17012 * Fix memory leak in nim-lang#17012 * Address comments in nim-lang#17012 Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
* stdlib/os: add isAdmin * uint8 -> cuchar, assert isAdmin on Azure Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> * Update lib/pure/os.nim docs Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> * Address comments on nim-lang#17012 * Raise on errors in nim-lang#17012 * Check the result of FreeSid in nim-lang#17012 * Change case in nim-lang#17012 * Fix memory leak in nim-lang#17012 * Address comments in nim-lang#17012 Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
Tested on Windows 10 as a normal user and as an administrator; on Fedora 33 as a normal user and as a root.
(EDIT(timotheecour))
fixes nim-lang/RFCs#329