Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3588 corrected duplicate front-end action error on server connect. Minor cleanup of server code.

ghidra166cc2ed90a06
diff --git a/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/Repository.java b/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/Repository.java
index 66b33f68fb..0199e2bc94 100644
--- a/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/Repository.java
+++ b/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/Repository.java
@@ -658,8 +658,8 @@ public class Repository implements FileSystemListener, RepositoryLogger {
synchronized (fileSystem) {
User user = getUser(currentUser);
if (user == null) {
- throw new UserAccessException(
- "User " + currentUser + " was not found in the user access list.");
+ throw new UserAccessException("User " + currentUser + " was not found in the '" +
+ name + "' repository access list.");
}
if (!user.isAdmin()) {
throw new UserAccessException(
@@ -679,8 +679,8 @@ public class Repository implements FileSystemListener, RepositoryLogger {
synchronized (fileSystem) {
User user = getUser(currentUser);
if (user == null) {
- throw new UserAccessException(
- "User " + currentUser + " was not found in the user access list.");
+ throw new UserAccessException("User " + currentUser + " was not found in the '" +
+ name + "' repository access list.");
}
if (user.isReadOnly()) {
throw new UserAccessException(
@@ -700,8 +700,8 @@ public class Repository implements FileSystemListener, RepositoryLogger {
synchronized (fileSystem) {
User user = getUser(currentUser);
if (user == null) {
- throw new UserAccessException(
- "User " + currentUser + " was not found in the user access list.");
+ throw new UserAccessException("User " + currentUser + " was not found in the '" +
+ name + "' repository access list.");
}
return user;
}
diff --git a/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/RepositoryManager.java b/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/RepositoryManager.java
index 0bd2b4c821..2ac8c60f55 100644
--- a/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/RepositoryManager.java
+++ b/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/RepositoryManager.java
@@ -52,11 +52,16 @@ public class RepositoryManager {
* @param rootDir directory where repositories will be created; this
* path contains a list of users that can access the repositories
* being managed.
- * @throws IOException
+ * @param enableLocalPasswords if true user passwords will be maintained
+ * within local 'users' file
+ * @param defaultPasswordExpirationDays password expiration in days when
+ * local passwords are enabled
+ * @param anonymousAccessAllowed if true server permits anonymous access
+ * to repositories.
+ * @throws IOException if IO error occurs
*/
- public RepositoryManager(File rootDir, boolean supportLocalPasswords,
- boolean requireExplicitPasswordReset, int defaultPasswordExpirationDays,
- boolean anonymousAccessAllowed) throws IOException {
+ public RepositoryManager(File rootDir, boolean enableLocalPasswords,
+ int defaultPasswordExpirationDays, boolean anonymousAccessAllowed) throws IOException {
rootDirFile = rootDir;
log.info("Instantiating Repository Manager for " + rootDirFile.getAbsolutePath());
if (!rootDirFile.isDirectory()) {
@@ -66,8 +71,7 @@ public class RepositoryManager {
throw new IOException(rootDirFile + " can not be written to");
}
this.anonymousAccessAllowed = anonymousAccessAllowed;
- this.userMgr = new UserManager(this, supportLocalPasswords, requireExplicitPasswordReset,
- defaultPasswordExpirationDays);
+ this.userMgr = new UserManager(this, enableLocalPasswords, defaultPasswordExpirationDays);
repositoryMap = new HashMap<>();
initialize();
}
diff --git a/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/UserManager.java b/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/UserManager.java
index fefa4c0b5d..937b6b6fd2 100644
--- a/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/UserManager.java
+++ b/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/UserManager.java
@@ -59,9 +59,8 @@ public class UserManager {
private final File userFile;
private final File sshDir;
- private boolean enableLocalPasswords = false;
+ private boolean enableLocalPasswords;
private long defaultPasswordExpirationMS;
- private boolean requireExplicitPasswordReset = true;
private PrintWriter dnLogOut;
@@ -71,14 +70,17 @@ public class UserManager {
private boolean userListUpdateInProgress = false;
/**
- * Constructor.
- * @param repositoryRoot root server directory
+ * Construct server user manager
+ * @param repositoryMgr repository manager (used for queued command processing)
+ * @param enableLocalPasswords if true user passwords will be maintained
+ * within local 'users' file
+ * @param defaultPasswordExpirationDays password expiration in days when
+ * local passwords are enabled
*/
UserManager(RepositoryManager repositoryMgr, boolean enableLocalPasswords,
- boolean requireExplicitPasswordReset, int defaultPasswordExpirationDays) {
+ int defaultPasswordExpirationDays) {
this.repositoryMgr = repositoryMgr;
this.enableLocalPasswords = enableLocalPasswords;
- this.requireExplicitPasswordReset = requireExplicitPasswordReset;
if (defaultPasswordExpirationDays < 0) {
defaultPasswordExpirationDays = DEFAULT_PASSWORD_TIMEOUT_DAYS;
}
@@ -163,7 +165,7 @@ public class UserManager {
* @param passwordHash MD5 hash of initial password or null if explicit password reset required
* @param dn X500 distinguished name for user (may be null)
* @throws DuplicateNameException if username already exists
- * @throws IOException
+ * @throws IOException if IO error occurs
*/
private synchronized void addUser(String username, char[] passwordHash, X500Principal x500User)
throws DuplicateNameException, IOException {
@@ -190,11 +192,10 @@ public class UserManager {
* Add a user.
* @param username user name/SID
* @throws DuplicateNameException if username already exists
- * @throws IOException
+ * @throws IOException if IO error occurs
*/
public void addUser(String username) throws DuplicateNameException, IOException {
- char[] passwordHash = requireExplicitPasswordReset ? null : getDefaultPasswordHash();
- addUser(username, passwordHash, null);
+ addUser(username, null);
}
/**
@@ -202,11 +203,11 @@ public class UserManager {
* @param username user name/SID
* @param x500User X500 distinguished name for user (may be null)
* @throws DuplicateNameException if username already exists
- * @throws IOException
+ * @throws IOException if IO error occurs
*/
public void addUser(String username, X500Principal x500User)
throws DuplicateNameException, IOException {
- char[] passwordHash = requireExplicitPasswordReset ? null : getDefaultPasswordHash();
+ char[] passwordHash = enableLocalPasswords ? getDefaultPasswordHash() : null;
addUser(username, passwordHash, x500User);
}
diff --git a/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/remote/GhidraServer.java b/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/remote/GhidraServer.java
index 70ce0db134..06b917c1ae 100644
--- a/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/remote/GhidraServer.java
+++ b/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/remote/GhidraServer.java
@@ -158,11 +158,9 @@ public class GhidraServer extends UnicastRemoteObject implements GhidraServerHan
}
boolean supportLocalPasswords = false;
- boolean requireExplicitPasswordReset = true;
switch (authMode) {
case PASSWORD_FILE_LOGIN:
supportLocalPasswords = true;
- requireExplicitPasswordReset = false;
authModule = new PasswordFileAuthenticationModule(allowUserToSpecifyName);
break;
case PKI_LOGIN:
@@ -199,8 +197,8 @@ public class GhidraServer extends UnicastRemoteObject implements GhidraServerHan
sshAuthModule = new SSHAuthenticationModule(allowUserToSpecifyName);
}
- mgr = new RepositoryManager(rootDir, supportLocalPasswords, requireExplicitPasswordReset,
- defaultPasswordExpirationDays, allowAnonymousAccess);
+ mgr = new RepositoryManager(rootDir, supportLocalPasswords, defaultPasswordExpirationDays,
+ allowAnonymousAccess);
GhidraServer.server = this;
@@ -533,7 +531,7 @@ public class GhidraServer extends UnicastRemoteObject implements GhidraServerHan
// Network name resolution disabled by default
InetNameLookup.setLookupEnabled(false);
-
+
// Initialize application
try {
ApplicationLayout layout = new GhidraServerApplicationLayout();
diff --git a/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/client/ClientUtil.java b/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/client/ClientUtil.java
index 3896db1727..ded0c8b9d2 100644
--- a/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/client/ClientUtil.java
+++ b/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/client/ClientUtil.java
@@ -33,6 +33,7 @@ import ghidra.framework.remote.security.SSHKeyManager;
import ghidra.net.*;
import ghidra.util.*;
import ghidra.util.exception.AssertException;
+import ghidra.util.exception.UserAccessException;
import ghidra.util.task.TaskLauncher;
/**
@@ -209,6 +210,10 @@ public class ClientUtil {
Msg.debug(ClientUtil.class, "Server not connected (" + operation + ")");
promptForReconnect(repository, operation, mustRetry, parent);
}
+ else if (exc instanceof UserAccessException) {
+ Msg.showError(ClientUtil.class, parent, title,
+ "Access denied: " + repository + "\n" + exc.getMessage());
+ }
else if ((exc instanceof ServerException) || (exc instanceof ServerError)) {
Msg.showError(ClientUtil.class, parent, title,
"Exception occurred on the Ghidra Server.", exc.getCause());
diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/ProjectActionManager.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/ProjectActionManager.java
index 07eb35f01b..a9b2108bda 100644
--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/ProjectActionManager.java
+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/ProjectActionManager.java
@@ -375,43 +375,42 @@ class ProjectActionManager {
buildCloseViewsActions();
boolean hasActiveProject = activeProject != null;
- enableActions(hasActiveProject);
-
- if (hasActiveProject) {
- RepositoryAdapter repository = activeProject.getRepository();
- if (repository != null) {
- if (isUserAdmin(repository)) {
- tool.addAction(editAccessAction);
- editAccessAction.setEnabled(true);
- }
- else if (!isAnonymousUserOrNotConnected(repository)) {
- tool.addAction(viewAccessAction);
- viewAccessAction.setEnabled(true);
- }
-
- if (repository.isConnected() && repository.getServer().canSetPassword()) {
- tool.addAction(setPasswordAction);
- setPasswordAction.setEnabled(true);
- }
- }
- }
+ enableActions(activeProject != null);
}
/**
* Notification that the connection state has changed;
- * enable or disable the edit Project access action.
+ * @param repository shared project repository adapter
*/
void connectionStateChanged(RepositoryAdapter repository) {
+
+ // Action removal is done each time to avoid possibility
+ // of adding actions twice. Action manipulated here are
+ // not intended to appear in menu when not available.
+
+ setPasswordAction.setEnabled(false);
+ editAccessAction.setEnabled(false);
+ viewAccessAction.setEnabled(false);
+
+ tool.removeAction(setPasswordAction);
+ tool.removeAction(editAccessAction);
+ tool.removeAction(viewAccessAction);
+
if (repository.isConnected()) {
- editAccessAction.setEnabled(isUserAdmin(repository));
if (repository.getServer().canSetPassword()) {
tool.addAction(setPasswordAction);
+ setPasswordAction.setEnabled(true);
+ }
+ if (isUserAdmin(repository)) {
+ tool.addAction(editAccessAction);
+ editAccessAction.setEnabled(true);
+ }
+ else if (!isAnonymousUserOrNotConnected(repository)) {
+ tool.addAction(viewAccessAction);
+ viewAccessAction.setEnabled(true);
}
}
- else {
- editAccessAction.setEnabled(false);
- tool.removeAction(setPasswordAction);
- }
+
if (infoDialog != null && infoDialog.isVisible()) {
infoDialog.updateConnectionStatus();
}
diff --git a/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/server/RepositoryFileSystemTest.java b/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/server/RepositoryFileSystemTest.java
index c4a938236f..6b7b5030d7 100644
--- a/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/server/RepositoryFileSystemTest.java
+++ b/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/server/RepositoryFileSystemTest.java
@@ -58,7 +58,7 @@ public class RepositoryFileSystemTest extends AbstractGhidraHeadedIntegrationTes
FileUtilities.deleteDir(serverRoot);
serverRoot.mkdir();
- mgr = new RepositoryManager(serverRoot, false, false, 0, false);
+ mgr = new RepositoryManager(serverRoot, false, 0, false);
mgr.getUserManager().addUser(USER);
repository = mgr.createRepository(USER, "My_Repository");
diff --git a/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/server/RepositoryManagerTest.java b/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/server/RepositoryManagerTest.java
index 273ed4ae52..d47682fe08 100644
--- a/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/server/RepositoryManagerTest.java
+++ b/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/server/RepositoryManagerTest.java
@@ -15,8 +15,7 @@
*/
package ghidra.server;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.*;
import java.io.File;
@@ -61,7 +60,7 @@ public class RepositoryManagerTest extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testCreateRepositoryManager() throws Exception {
- mgr = new RepositoryManager(root, false, false, 0, false);
+ mgr = new RepositoryManager(root, false, 0, false);
assertNotNull(mgr);
String[] userNames = mgr.getAllUsers("User_0");
@@ -71,7 +70,7 @@ public class RepositoryManagerTest extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testCreateRepositoryManagerWithAnonymous() throws Exception {
- mgr = new RepositoryManager(root, false, false, 0, true);
+ mgr = new RepositoryManager(root, false, 0, true);
assertNotNull(mgr);
String[] userNames = mgr.getAllUsers("User_0");
@@ -83,7 +82,7 @@ public class RepositoryManagerTest extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testCreateRepository() throws Exception {
- mgr = new RepositoryManager(root, false, false, 0, false);
+ mgr = new RepositoryManager(root, false, 0, false);
Repository rep = mgr.createRepository("User_0", "REPOSITORY_A");
assertNotNull(rep);
@@ -91,7 +90,7 @@ public class RepositoryManagerTest extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testCreateRepositoryAnonymous() throws Exception {
- mgr = new RepositoryManager(root, false, false, 0, true);
+ mgr = new RepositoryManager(root, false, 0, true);
Repository rep = mgr.createRepository("User_0", "REPOSITORY_A");
assertNotNull(rep);
@@ -107,7 +106,7 @@ public class RepositoryManagerTest extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testCreateDuplicateRepository() throws Exception {
- mgr = new RepositoryManager(root, false, false, 0, false);
+ mgr = new RepositoryManager(root, false, 0, false);
mgr.createRepository("User_0", "REPOSITORY_A");
try {
mgr.createRepository("User_5", "REPOSITORY_A");
@@ -119,7 +118,7 @@ public class RepositoryManagerTest extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testGetRepository() throws Exception {
- mgr = new RepositoryManager(root, false, false, 0, true);
+ mgr = new RepositoryManager(root, false, 0, true);
Repository rep1 = mgr.createRepository("User_0", "REPOSITORY_A");
addUsers("User_0", true, rep1);
@@ -148,7 +147,7 @@ public class RepositoryManagerTest extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testGetRepositoryBadUser() throws Exception {
- mgr = new RepositoryManager(root, false, false, 0, false);
+ mgr = new RepositoryManager(root, false, 0, false);
mgr.createRepository("User_0", "REPOSITORY_A");
try {
diff --git a/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/server/RepositoryTest.java b/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/server/RepositoryTest.java
index bce010f19a..aeadceb3f3 100644
--- a/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/server/RepositoryTest.java
+++ b/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/server/RepositoryTest.java
@@ -49,7 +49,7 @@ public class RepositoryTest extends AbstractGhidraHeadedIntegrationTest {
FileUtilities.deleteDir(serverRoot);
serverRoot.mkdir();
- mgr = new RepositoryManager(serverRoot, false, false, 0, false);
+ mgr = new RepositoryManager(serverRoot, false, 0, false);
mgr.getUserManager().addUser(userName);
repository = mgr.createRepository(userName, REPOSITORY_NAME);