brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neykov <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #624: Adds authSudo support (for sudo’ing wit...
Date Mon, 10 Apr 2017 11:21:19 GMT
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message