Skip to content

Commit f64c38e

Browse files
committed
GP-0 revised SystemUtilities.getUserName() to eliminate Domain Name
1 parent 96b6175 commit f64c38e

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/client/ClientUtil.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,7 @@ public static void clearRepositoryAdapter(String host, int port) {
171171
* @return default user name
172172
*/
173173
public static String getUserName() {
174-
String name = SystemUtilities.getUserName();
175-
// exclude domain prefix which may be included
176-
int slashIndex = name.lastIndexOf('\\');
177-
if (slashIndex >= 0) {
178-
name = name.substring(slashIndex + 1);
179-
}
180-
return name;
174+
return SystemUtilities.getUserName();
181175
}
182176

183177
/**
@@ -446,8 +440,8 @@ else if (callback instanceof AnonymousCallback) {
446440
static void processSignatureCallback(String serverName, SignatureCallback sigCb)
447441
throws IOException {
448442
try {
449-
SignedToken signedToken = ApplicationKeyManagerUtils.getSignedToken(
450-
sigCb.getRecognizedAuthorities(), sigCb.getToken());
443+
SignedToken signedToken = ApplicationKeyManagerUtils
444+
.getSignedToken(sigCb.getRecognizedAuthorities(), sigCb.getToken());
451445
sigCb.sign(signedToken.certChain, signedToken.signature);
452446
Msg.info(ClientUtil.class, "PKI Authenticating to " + serverName + " as user '" +
453447
signedToken.certChain[0].getSubjectX500Principal() + "'");

Ghidra/Framework/Utility/src/main/java/ghidra/util/SystemUtilities.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private static boolean checkForDevelopmentMode() {
9191
if (url.getPath().contains("/build/libs")) {
9292
return true; // Source repository Gradle JavaExec task mode
9393
}
94-
return switch(url.getProtocol()) {
94+
return switch (url.getProtocol()) {
9595
case "file" -> true; // Eclipse run config mode (class files)
9696
case "jar" -> false; // Release mode (jar files)
9797
case "bundleresource" -> false; // GhidraDev Utility.jar access mode
@@ -100,25 +100,33 @@ private static boolean checkForDevelopmentMode() {
100100
}
101101

102102
/**
103-
* Get the user that is running the ghidra application
103+
* Get the user that is running the ghidra application. This name may be modified to
104+
* eliminate any spaces or leading domain name which may be present in Java's
105+
* {@code user.name} system property.
104106
* @return the user name
105107
*/
106108
public static String getUserName() {
107109
if (userName == null) {
108110
String uname = System.getProperty("user.name");
109111

110-
// remove the spaces since some operating systems allow
112+
// Remove the spaces since some operating systems allow
111113
// spaces and some do not, Java's File class doesn't
114+
StringBuilder nameBuf = new StringBuilder();
112115
if (uname.indexOf(" ") >= 0) {
113-
userName = "";
114116
StringTokenizer tokens = new StringTokenizer(uname, " ", false);
115117
while (tokens.hasMoreTokens()) {
116-
userName += tokens.nextToken();
118+
nameBuf.append(tokens.nextToken());
117119
}
120+
uname = nameBuf.toString();
118121
}
119-
else {
120-
userName = uname;
122+
123+
// Remove leading Domain Name if present
124+
int slashIndex = uname.lastIndexOf('\\');
125+
if (slashIndex >= 0) {
126+
uname = uname.substring(slashIndex + 1);
121127
}
128+
129+
userName = uname;
122130
}
123131
return userName;
124132
}

0 commit comments

Comments
 (0)