minor fixes

This commit is contained in:
Peter Hormanns 2022-01-20 18:46:40 +01:00
parent 48b95db29c
commit 828420d4a7
2 changed files with 9 additions and 1 deletions

View File

@ -92,6 +92,9 @@ public class UnixUserModuleImpl extends AbstractModuleImpl {
if (userName.length() < 7 || userName.charAt(5) != '-' || userName.lastIndexOf('-') > 5) { if (userName.length() < 7 || userName.charAt(5) != '-' || userName.lastIndexOf('-') > 5) {
throw new AuthorisationException(loginUser, "add", newUnixUser, "userId"); throw new AuthorisationException(loginUser, "add", newUnixUser, "userId");
} }
if (userName.length() > 32) {
throw new HSAdminException("username exceeds the allowed length");
}
String passWord = newUnixUser.getPassword(); String passWord = newUnixUser.getPassword();
if (passWord == null || passWord.length() == 0) { if (passWord == null || passWord.length() == 0) {
throw new HSAdminException("password is required"); throw new HSAdminException("password is required");

View File

@ -132,7 +132,7 @@ public class JsonPillarServlet extends HttpServlet {
writer.println(" \"user\": \"" + fullUsername + "\""); writer.println(" \"user\": \"" + fullUsername + "\"");
writer.println(" , \"dirname\": \"" + usernamePostfix + "\""); writer.println(" , \"dirname\": \"" + usernamePostfix + "\"");
writer.println(" , \"uid\": " + user.getUserId()); writer.println(" , \"uid\": " + user.getUserId());
writer.println(" , \"comment\": \"" + user.getComment() + "\""); writer.println(" , \"comment\": \"" + quoteJSON(user.getComment()) + "\"");
writer.println(" , \"shell\": \"" + user.getShell() + "\""); writer.println(" , \"shell\": \"" + user.getShell() + "\"");
writer.println(" , \"homedir\": \"" + user.getHomedir() + "\""); writer.println(" , \"homedir\": \"" + user.getHomedir() + "\"");
writer.println(" , \"quota_soft\": " + user.getQuotaSoftlimit()); writer.println(" , \"quota_soft\": " + user.getQuotaSoftlimit());
@ -222,4 +222,9 @@ public class JsonPillarServlet extends HttpServlet {
transaction.close(); transaction.close();
} }
private String quoteJSON(final String unquoted) {
final String quoted = unquoted.replaceAll("\\\"", "\\\\\"");
return quoted;
}
} }