Skip to content

Commit

Permalink
[DEV] Added isRoot check if process is started with su command
Browse files Browse the repository at this point in the history
  • Loading branch information
manneohlund committed Oct 2, 2017
1 parent 6ad683b commit aba16f7
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions library/src/main/java/ashell/ShellFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@

public class ShellFactory {

private boolean isRoot = false;
private AShell shell;

private ShellFactory(AShell shell) {
public ShellFactory(AShell shell, boolean isRoot) {
this.shell = shell;
this.isRoot = isRoot;
}

public AShell getShell() {
return shell;
}

public boolean isRoot() {
return isRoot;
}

@SuppressWarnings("unchecked") // Single-interface proxy creation guarded by parameter safety.
public <T> T create(final Class<T> shellModel) {
//Utils.validateServiceInterface(service);
Expand Down Expand Up @@ -97,12 +103,13 @@ public ShellFactory build() throws IOException {
}

public ShellFactory build(boolean runAsSuperuser) throws IOException {

boolean isRoot = false;
if (processBuilder == null) {
processBuilder = ProcessUtils.getDefaultProcessBuilder("sh");
if (runAsSuperuser) {
try {
processBuilder = ProcessUtils.getDefaultProcessBuilder("su");
isRoot = true;
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -134,7 +141,7 @@ public ShellFactory build(boolean runAsSuperuser) throws IOException {

shell.start();

return new ShellFactory(shell);
return new ShellFactory(shell, isRoot);
}
}
}

0 comments on commit aba16f7

Please sign in to comment.