Github user neykov commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/624#discussion_r110630192
--- Diff:
utils/common/src/main/java/org/apache/brooklyn/util/ssh/BashCommands.java ---
@@ -91,12 +91,23 @@ public static String ok(String command) {
* If null is supplied, it is returned (sometimes used to indicate no
command desired).
*/
public static String sudo(String command) {
+ if (command==null) return null;
if (command.startsWith("( ") || command.endsWith(" &"))
return sudoNew(command);
else
return sudoOld(command);
}
+ public static String authSudo(String command, String password) {
+ checkNotNull(password, "password must not be null");
+ if (command==null) return null;
+ if (command.startsWith("( ") || command.endsWith(" &")) {
+ throw new UnsupportedOperationException("authSudo supports
only simple commands, not those wrapped in parentheses or backgrounded:
cmd="+command);
+ }
+ // some OS's (which?) fail if you try running sudo when you're
already root (dumb but true)
+ return format("( if test \"$UID\" -eq 0; then ( %s ); else echo -e
'%s\\n' | sudo -E -S -- %s; fi )", command, password, command);
--- End diff --
Will fail if `password` contains single quotes.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---