-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Check if app is run by sudo/admin on Linux #25118
Comments
@maroallegro I do not think there is an API. This is how we do it for tests: You could propose an API, perhaps? This is the process: https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/api-review-process.md |
You will want to decide whether there should be a generic API, or Unix specific, ie., are sudo and the Windows concept of elevated sufficiently common concepts. |
one way would be to check effective rights. (SystemNative_GetEUid) However things may be more complicate with POSIX capabilities. With work for dotnet/corefx#26431 we may have enough plumbing to process groups as well. |
@eerhardt @wfurt are the concepts of Unix sudo and Windows elevation sufficiently analogous that we could have some single boolean property for both? My guess is not because after this boolean concepts quickly diverge. Also is there a reasonable type where such API could go? RuntimeInformation is more about static information about the platform. Environment is a grab bag. |
To check if you are running as
public static bool IsAdministrator =>
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
new WindowsPrincipal(WindowsIdentity.GetCurrent())
.IsInRole(WindowsBuiltInRole.Administrator) :
Mono.Unix.Native.Syscall.geteuid() == 0; |
@maroallegro commented on Mon Jan 29 2018
I am trying to check if .NetCore code is running as sudo/admin on Linux. It works on Windows but throws exception on Linux.
How do I check if app is run by admin/sudo on Ubuntu Linux by using .NET Core2.0 build-in class?
Here is the code I have tried (however i thought that it will not manage admin rights on Linux):
The code works on Windows, but does not work on Linux:
The text was updated successfully, but these errors were encountered: