mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-06-01 03:45:04 +08:00
BSim: Add status subcommand to bsim_ctl
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
<CODE class="computeroutput">
|
||||
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.</P>
|
||||
</DD>
|
||||
|
||||
<DT><SPAN class="term"><SPAN class="bold"><STRONG>status</STRONG></SPAN></SPAN></DT>
|
||||
|
||||
<DD>
|
||||
<P>Retrieves the status of a PostgreSQL server (running/down). The path to the
|
||||
actively used data directory must be provided.</P>
|
||||
</DD>
|
||||
|
||||
<DT><SPAN class="term"><SPAN class="bold"><STRONG>adduser</STRONG></SPAN></SPAN></DT>
|
||||
|
||||
<DD>
|
||||
|
||||
+34
@@ -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<String> STOP_OPTIONS =
|
||||
Set.of(FORCE_OPTION);
|
||||
private static final Set<String> STATUS_OPTIONS = Set.of();
|
||||
private static final Set<String> RESET_PASSWORD_OPTIONS = Set.of();
|
||||
private static final Set<String> CHANGE_PRIVILEGE_OPTIONS = Set.of();
|
||||
private static final Set<String> 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<String> command = new ArrayList<String>();
|
||||
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 </datadir-path> [--auth|-a pki|password|trust] [--noLocalAuth] [--cafile \"</cacert-path>\"] [--dn \"<distinguished-name>\"]\n" +
|
||||
" stop </datadir-path> [--force]\n" +
|
||||
" status </datadir-path>\n" +
|
||||
" adduser </datadir-path> <username> [--dn \"<distinguished-name>\"]\n" +
|
||||
" dropuser </datadir-path> <username>\n" +
|
||||
" changeauth </datadir-path> [--auth|-a pki|password|trust] [--noLocalAuth] [--cafile \"</cacert-path>\"] [--dn \"<distinguished-name>\"]\n" +
|
||||
|
||||
Reference in New Issue
Block a user