diff --git a/Ghidra/Features/BSim/src/main/help/help/topics/BSim/CommandLineReference.html b/Ghidra/Features/BSim/src/main/help/help/topics/BSim/CommandLineReference.html index 8bc1ec1f12..a3de12661f 100644 --- a/Ghidra/Features/BSim/src/main/help/help/topics/BSim/CommandLineReference.html +++ b/Ghidra/Features/BSim/src/main/help/help/topics/BSim/CommandLineReference.html @@ -41,6 +41,7 @@ bsim_ctl start </datadir-path> [--auth|-a pki|password|trust] [--noLocalAuth] [--cafile </cacert-path>] [--dn "<distinguished-name>"] bsim_ctl stop </datadir-path> [--force] + bsim_ctl status </datadir-path> bsim_ctl adduser </datadir-path> <username> [--dn "<distinguished-name>"] bsim_ctl dropuser </datadir-path> <username> bsim_ctl resetpassword <username> @@ -136,6 +137,13 @@ immediately.

+
status
+ +
+

Retrieves the status of a PostgreSQL server (running/down). The path to the + actively used data directory must be provided.

+
+
adduser
diff --git a/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java b/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java index 72934bad63..71c22d0119 100644 --- a/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java +++ b/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java @@ -52,6 +52,7 @@ public class BSimControlLaunchable implements GhidraLaunchable { // bsim_ctl commands public final static String COMMAND_START = "start"; public final static String COMMAND_STOP = "stop"; + public final static String COMMAND_STATUS = "status"; public final static String COMMAND_RESET_PASSWORD = "resetpassword"; public final static String COMMAND_CHANGE_PRIVILEGE = "changeprivilege"; public final static String COMMAND_ADDUSER = "adduser"; @@ -91,6 +92,7 @@ public class BSimControlLaunchable implements GhidraLaunchable { Set.of(AUTH_OPTION, DN_OPTION, NO_LOCAL_AUTH_OPTION, CAFILE_OPTION); private static final Set STOP_OPTIONS = Set.of(FORCE_OPTION); + private static final Set STATUS_OPTIONS = Set.of(); private static final Set RESET_PASSWORD_OPTIONS = Set.of(); private static final Set CHANGE_PRIVILEGE_OPTIONS = Set.of(); private static final Set ADDUSER_OPTIONS = @@ -104,6 +106,7 @@ public class BSimControlLaunchable implements GhidraLaunchable { static { ALLOWED_OPTION_MAP.put(COMMAND_START, START_OPTIONS); ALLOWED_OPTION_MAP.put(COMMAND_STOP, STOP_OPTIONS); + ALLOWED_OPTION_MAP.put(COMMAND_STATUS, STATUS_OPTIONS); ALLOWED_OPTION_MAP.put(COMMAND_RESET_PASSWORD, RESET_PASSWORD_OPTIONS); ALLOWED_OPTION_MAP.put(COMMAND_CHANGE_PRIVILEGE, CHANGE_PRIVILEGE_OPTIONS); ALLOWED_OPTION_MAP.put(COMMAND_ADDUSER, ADDUSER_OPTIONS); @@ -201,6 +204,9 @@ public class BSimControlLaunchable implements GhidraLaunchable { case COMMAND_STOP: scanDataDirectory(params, slot++); break; + case COMMAND_STATUS: + scanDataDirectory(params, slot++); + break; case COMMAND_ADDUSER: scanDataDirectory(params, slot++); scanUsername(params, slot++); @@ -1060,6 +1066,30 @@ public class BSimControlLaunchable implements GhidraLaunchable { System.out.println("Server shutdown complete"); } + /** + * Retrieve the status of a PostgreSQL server. + * @throws IOException if server status can not be retrieved + * @throws InterruptedException if the status command is interrupted + */ + private void statusCommand() throws IOException, InterruptedException { + discoverPostgresInstall(); + List command = new ArrayList(); + command.add(postgresControl.getAbsolutePath()); + command.add("status"); + command.add("-D"); + command.add(dataDirectory.getAbsolutePath()); + int res = runCommand(null, command, loadLibraryVar, loadLibraryValue); + if (res == 0) { + System.out.println("Server running"); + } + else if (res == 3) { + System.out.println("Server down"); + } + else { + throw new IOException("Error getting postgres server status"); + } + } + /** * Trigger a server running on the local host to rescan its identity file to pickup * any changes to the user mapping @@ -1398,6 +1428,9 @@ public class BSimControlLaunchable implements GhidraLaunchable { case COMMAND_STOP: stopCommand(); break; + case COMMAND_STATUS: + statusCommand(); + break; case COMMAND_ADDUSER: addUserCommand(); break; @@ -1433,6 +1466,7 @@ public class BSimControlLaunchable implements GhidraLaunchable { "USAGE: bsim_ctl [command] required-args... [OPTIONS...}\n\n" + " start [--auth|-a pki|password|trust] [--noLocalAuth] [--cafile \"\"] [--dn \"\"]\n" + " stop [--force]\n" + + " status \n" + " adduser [--dn \"\"]\n" + " dropuser \n" + " changeauth [--auth|-a pki|password|trust] [--noLocalAuth] [--cafile \"\"] [--dn \"\"]\n" +