61353ac496
This patch detects whether or not the server is currently executing as a privileged user and spits out a warning. The warning serves as a sort-of PSA for newer server admins who don't understand the risks of running as root. We've seen plenty of bad/malicious plugins hit markets, and there's been a few close-calls with exploits in the past. Hopefully this helps mitigate some potential damage to servers, even if it is just a warning. Co-authored-by: Noah van der Aa <ndvdaa@gmail.com>
24 lines
737 B
Java
24 lines
737 B
Java
package io.papermc.paper.util;
|
|
|
|
import com.sun.security.auth.module.NTSystem;
|
|
import com.sun.security.auth.module.UnixSystem;
|
|
import java.util.Set;
|
|
import org.apache.commons.lang.SystemUtils;
|
|
|
|
public class ServerEnvironment {
|
|
private static final boolean RUNNING_AS_ROOT_OR_ADMIN;
|
|
private static final String WINDOWS_HIGH_INTEGRITY_LEVEL = "S-1-16-12288";
|
|
|
|
static {
|
|
if (SystemUtils.IS_OS_WINDOWS) {
|
|
RUNNING_AS_ROOT_OR_ADMIN = Set.of(new NTSystem().getGroupIDs()).contains(WINDOWS_HIGH_INTEGRITY_LEVEL);
|
|
} else {
|
|
RUNNING_AS_ROOT_OR_ADMIN = new UnixSystem().getUid() == 0;
|
|
}
|
|
}
|
|
|
|
public static boolean userIsRootOrAdmin() {
|
|
return RUNNING_AS_ROOT_OR_ADMIN;
|
|
}
|
|
}
|