mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 19:42:36 +02:00
GP-0 correct backward compatibility issue for project owner
This commit is contained in:
parent
f64c38ef7f
commit
ba5fcdf4ed
2 changed files with 63 additions and 27 deletions
|
@ -116,11 +116,11 @@ public class DefaultProjectData implements ProjectData {
|
|||
try {
|
||||
init(false, isInWritableProject);
|
||||
if (resetOwner) {
|
||||
owner = SystemUtilities.getUserName();
|
||||
owner = getUserName();
|
||||
properties.putString(OWNER, owner);
|
||||
properties.writeState();
|
||||
}
|
||||
else if (isInWritableProject && !SystemUtilities.getUserName().equals(owner)) {
|
||||
else if (isInWritableProject && !isOwner(owner)) {
|
||||
if (owner == null) {
|
||||
throw new NotOwnerException("Older projects may only be opened as a View.\n" +
|
||||
"You must first create a new project or open an existing current project, \n" +
|
||||
|
@ -185,7 +185,7 @@ public class DefaultProjectData implements ProjectData {
|
|||
DefaultProjectData(LocalFileSystem fileSystem, FileSystem versionedFileSystem)
|
||||
throws IOException {
|
||||
this.localStorageLocator = new ProjectLocator(null, "Test");
|
||||
owner = SystemUtilities.getUserName();
|
||||
owner = getUserName();
|
||||
boolean success = false;
|
||||
try {
|
||||
synchronized (fileSystem) {
|
||||
|
@ -217,6 +217,34 @@ public class DefaultProjectData implements ProjectData {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean isOwner(String name) {
|
||||
// Tolerate user name using either the new or old format
|
||||
return SystemUtilities.getUserName().equals(name) || getUserName().equals(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user name in a format consistent with the older {@link SystemUtilities#getUserName()}
|
||||
* implementation. This is done to ensure we can still recognize the OWNER of older
|
||||
* projects.
|
||||
*
|
||||
* @return current user name using legacy formatting.
|
||||
*/
|
||||
private String getUserName() {
|
||||
String uname = System.getProperty("user.name");
|
||||
|
||||
// Remove the spaces since some operating systems allow
|
||||
// spaces and some do not, Java's File class doesn't
|
||||
String userName = uname;
|
||||
if (uname.indexOf(" ") >= 0) {
|
||||
userName = "";
|
||||
StringTokenizer tokens = new StringTokenizer(uname, " ", false);
|
||||
while (tokens.hasMoreTokens()) {
|
||||
userName += tokens.nextToken();
|
||||
}
|
||||
}
|
||||
return userName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the contents of the project properties file to include the following values if relavent:
|
||||
* {@value #OWNER}, {@value #SERVER_NAME}, {@value #REPOSITORY_NAME}, {@value #PORT_NUMBER}
|
||||
|
@ -276,7 +304,7 @@ public class DefaultProjectData implements ProjectData {
|
|||
throw new ReadOnlyException(
|
||||
"Project " + localStorageLocator.getName() + " is read-only");
|
||||
}
|
||||
owner = properties.getString(OWNER, SystemUtilities.getUserName());
|
||||
owner = properties.getString(OWNER, getUserName());
|
||||
}
|
||||
else {
|
||||
owner = "<unknown>"; // Unknown owner
|
||||
|
@ -298,7 +326,7 @@ public class DefaultProjectData implements ProjectData {
|
|||
}
|
||||
|
||||
if (!properties.exists()) {
|
||||
owner = SystemUtilities.getUserName();
|
||||
owner = getUserName();
|
||||
properties.putString(OWNER, owner);
|
||||
properties.writeState();
|
||||
}
|
||||
|
|
|
@ -100,15 +100,13 @@ public class SystemUtilities {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the user that is running the ghidra application. This name may be modified to
|
||||
* eliminate any spaces or leading domain name which may be present in Java's
|
||||
* {@code user.name} system property.
|
||||
* @return the user name
|
||||
* Clean the specified user name to eliminate any spaces or leading domain name
|
||||
* which may be present (e.g., "MyDomain\John Doe" becomes "JohnDoe").
|
||||
* @param name user name string to be cleaned-up
|
||||
* @return the clean user name
|
||||
*/
|
||||
public static String getUserName() {
|
||||
if (userName == null) {
|
||||
String uname = System.getProperty("user.name");
|
||||
|
||||
public static String getCleanUserName(String name) {
|
||||
String uname = name;
|
||||
// Remove the spaces since some operating systems allow
|
||||
// spaces and some do not, Java's File class doesn't
|
||||
StringBuilder nameBuf = new StringBuilder();
|
||||
|
@ -125,8 +123,18 @@ public class SystemUtilities {
|
|||
if (slashIndex >= 0) {
|
||||
uname = uname.substring(slashIndex + 1);
|
||||
}
|
||||
return uname;
|
||||
}
|
||||
|
||||
userName = uname;
|
||||
/**
|
||||
* Get the user that is running the application. This name may be modified to
|
||||
* eliminate any spaces or leading domain name which may be present in Java's
|
||||
* {@code user.name} system property (see {@link #getCleanUserName(String)}).
|
||||
* @return the user name
|
||||
*/
|
||||
public static String getUserName() {
|
||||
if (userName == null) {
|
||||
userName = getCleanUserName(System.getProperty("user.name"));
|
||||
}
|
||||
return userName;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue