-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Re-readd root/admin user detection #6703
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
Merged
me4502
merged 6 commits into
PaperMC:master
from
NoahvdAa:feature/re-readd-root-detection
Oct 9, 2021
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Only run id command if needed
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,13 +12,14 @@ Co-authored-by: Noah van der Aa <[email protected]> | |
|
|
||
| diff --git a/src/main/java/io/papermc/paper/util/ServerEnvironment.java b/src/main/java/io/papermc/paper/util/ServerEnvironment.java | ||
| new file mode 100644 | ||
| index 0000000000000000000000000000000000000000..afec67a3c69dcc0cbdc4fb14d9444b4434cb82e9 | ||
| index 0000000000000000000000000000000000000000..9bc2cbf015998b98b6681a427596b151ed1806a0 | ||
| --- /dev/null | ||
| +++ b/src/main/java/io/papermc/paper/util/ServerEnvironment.java | ||
| @@ -0,0 +1,31 @@ | ||
| @@ -0,0 +1,36 @@ | ||
| +package io.papermc.paper.util; | ||
| + | ||
| +import com.sun.security.auth.module.NTSystem; | ||
| +import com.sun.security.auth.module.UnixSystem; | ||
| +import org.apache.commons.lang.SystemUtils; | ||
| + | ||
| +import java.io.IOException; | ||
|
|
@@ -33,11 +34,15 @@ index 0000000000000000000000000000000000000000..afec67a3c69dcc0cbdc4fb14d9444b44 | |
| + if (SystemUtils.IS_OS_WINDOWS) { | ||
| + RUNNING_AS_ROOT_OR_ADMIN = Set.of(new NTSystem().getGroupIDs()).contains(WINDOWS_HIGH_INTEGRITY_LEVEL); | ||
| + } else { | ||
| + boolean isRunningAsRoot; | ||
| + try (final InputStream inputStream = Runtime.getRuntime().exec("id -u").getInputStream()) { | ||
| + isRunningAsRoot = new String(inputStream.readAllBytes()).trim().equals("0"); | ||
| + } catch (IOException ignored) { | ||
| + isRunningAsRoot = false; | ||
| + boolean isRunningAsRoot = false; | ||
| + if (new UnixSystem().getUid() == 0) { | ||
| + // Due to an OpenJDK bug, UnixSystem#getUid incorrectly returns 0 when the user doesn't have a username. | ||
| + // Because of this, we'll have to double-check if the user ID is actually 0 by running the id command. | ||
| + try (final InputStream inputStream = Runtime.getRuntime().exec("id -u").getInputStream()) { | ||
NoahvdAa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| + isRunningAsRoot = new String(inputStream.readAllBytes()).trim().equals("0"); | ||
| + } catch (IOException ignored) { | ||
| + isRunningAsRoot = false; | ||
| + } | ||
| + } | ||
| + RUNNING_AS_ROOT_OR_ADMIN = isRunningAsRoot; | ||
| + } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.