GP-0 revised SystemUtilities.getUserName() to eliminate Domain Name

This commit is contained in:
ghidra1 2023-08-17 11:02:40 -04:00
parent 96b61753a0
commit f64c38ef7f
2 changed files with 18 additions and 16 deletions

View file

@ -171,13 +171,7 @@ public class ClientUtil {
* @return default user name
*/
public static String getUserName() {
String name = SystemUtilities.getUserName();
// exclude domain prefix which may be included
int slashIndex = name.lastIndexOf('\\');
if (slashIndex >= 0) {
name = name.substring(slashIndex + 1);
}
return name;
return SystemUtilities.getUserName();
}
/**
@ -446,8 +440,8 @@ public class ClientUtil {
static void processSignatureCallback(String serverName, SignatureCallback sigCb)
throws IOException {
try {
SignedToken signedToken = ApplicationKeyManagerUtils.getSignedToken(
sigCb.getRecognizedAuthorities(), sigCb.getToken());
SignedToken signedToken = ApplicationKeyManagerUtils
.getSignedToken(sigCb.getRecognizedAuthorities(), sigCb.getToken());
sigCb.sign(signedToken.certChain, signedToken.signature);
Msg.info(ClientUtil.class, "PKI Authenticating to " + serverName + " as user '" +
signedToken.certChain[0].getSubjectX500Principal() + "'");

View file

@ -91,7 +91,7 @@ public class SystemUtilities {
if (url.getPath().contains("/build/libs")) {
return true; // Source repository Gradle JavaExec task mode
}
return switch(url.getProtocol()) {
return switch (url.getProtocol()) {
case "file" -> true; // Eclipse run config mode (class files)
case "jar" -> false; // Release mode (jar files)
case "bundleresource" -> false; // GhidraDev Utility.jar access mode
@ -100,26 +100,34 @@ public class SystemUtilities {
}
/**
* Get the user that is running the ghidra application
* 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
*/
public static String getUserName() {
if (userName == null) {
String uname = System.getProperty("user.name");
// remove the spaces since some operating systems allow
// Remove the spaces since some operating systems allow
// spaces and some do not, Java's File class doesn't
StringBuilder nameBuf = new StringBuilder();
if (uname.indexOf(" ") >= 0) {
userName = "";
StringTokenizer tokens = new StringTokenizer(uname, " ", false);
while (tokens.hasMoreTokens()) {
userName += tokens.nextToken();
nameBuf.append(tokens.nextToken());
}
uname = nameBuf.toString();
}
else {
// Remove leading Domain Name if present
int slashIndex = uname.lastIndexOf('\\');
if (slashIndex >= 0) {
uname = uname.substring(slashIndex + 1);
}
userName = uname;
}
}
return userName;
}