From 831ed3c67440f40f047a587f1d45e3df307d16a4 Mon Sep 17 00:00:00 2001 From: "Nikolay.Pianikov" Date: Wed, 23 Nov 2016 12:50:47 +0300 Subject: [PATCH] #6 - Support Unix OS - use socat and su --- cmd/runAs.sh | 11 +---------- ...ingsGenerator.java => LinuxSettingsGenerator.java} | 5 +---- .../resources/META-INF/build-agent-plugin-runAs.xml | 11 ++++++----- ...ratorTest.java => LinuxSettingsGeneratorTest.java} | 6 +++--- runAs-agent/src/test/resources/testng-runAs.xml | 2 +- .../buildServerResources/runAsBuildFeature.jsp | 6 +++--- 6 files changed, 15 insertions(+), 26 deletions(-) rename runAs-agent/src/main/java/jetbrains/buildServer/runAs/agent/{UnixSettingsGenerator.java => LinuxSettingsGenerator.java} (80%) rename runAs-agent/src/test/java/jetbrains/buildServer/runAs/agent/{UnixSettingsGeneratorTest.java => LinuxSettingsGeneratorTest.java} (91%) diff --git a/cmd/runAs.sh b/cmd/runAs.sh index 9638eb6..380c70f 100644 --- a/cmd/runAs.sh +++ b/cmd/runAs.sh @@ -1,16 +1,7 @@ #!/bin/bash -echo param1=$1 -echo param2=$2 -echo param3=$3 - args=$(cat "$1") command=$2 password=$3 -echo args=$args -echo command=$command -echo password=$password - -echo -e "$password\n" | sudo --preserve-env --set-home --stdin $args $command -#sudo --preserve-env -set-home --stdin $args #scommand +(sleep .3; echo "$password") | socat - EXEC:'su -c $command $args',pty,ctty,setsid \ No newline at end of file diff --git a/runAs-agent/src/main/java/jetbrains/buildServer/runAs/agent/UnixSettingsGenerator.java b/runAs-agent/src/main/java/jetbrains/buildServer/runAs/agent/LinuxSettingsGenerator.java similarity index 80% rename from runAs-agent/src/main/java/jetbrains/buildServer/runAs/agent/UnixSettingsGenerator.java rename to runAs-agent/src/main/java/jetbrains/buildServer/runAs/agent/LinuxSettingsGenerator.java index 2a95c89..5a46b44 100644 --- a/runAs-agent/src/main/java/jetbrains/buildServer/runAs/agent/UnixSettingsGenerator.java +++ b/runAs-agent/src/main/java/jetbrains/buildServer/runAs/agent/LinuxSettingsGenerator.java @@ -7,9 +7,8 @@ import jetbrains.buildServer.util.Converter; import org.jetbrains.annotations.NotNull; -public class UnixSettingsGenerator implements ResourceGenerator { +public class LinuxSettingsGenerator implements ResourceGenerator { private static final String LINE_SEPARATOR = System.getProperty("line.separator"); - private static final String USER_CMD_KEY = "--user"; @NotNull @Override @@ -18,8 +17,6 @@ public String create(@NotNull final Settings settings) { final String user = settings.getUser(); if(!StringUtil.isEmptyOrSpaces(user)) { - sb.append(USER_CMD_KEY); - sb.append(' '); sb.append(settings.getUser()); } diff --git a/runAs-agent/src/main/resources/META-INF/build-agent-plugin-runAs.xml b/runAs-agent/src/main/resources/META-INF/build-agent-plugin-runAs.xml index b13a9f2..f03e93d 100644 --- a/runAs-agent/src/main/resources/META-INF/build-agent-plugin-runAs.xml +++ b/runAs-agent/src/main/resources/META-INF/build-agent-plugin-runAs.xml @@ -26,19 +26,20 @@ - + - - + + - + + - + diff --git a/runAs-agent/src/test/java/jetbrains/buildServer/runAs/agent/UnixSettingsGeneratorTest.java b/runAs-agent/src/test/java/jetbrains/buildServer/runAs/agent/LinuxSettingsGeneratorTest.java similarity index 91% rename from runAs-agent/src/test/java/jetbrains/buildServer/runAs/agent/UnixSettingsGeneratorTest.java rename to runAs-agent/src/test/java/jetbrains/buildServer/runAs/agent/LinuxSettingsGeneratorTest.java index f3b4390..1eb33a4 100644 --- a/runAs-agent/src/test/java/jetbrains/buildServer/runAs/agent/UnixSettingsGeneratorTest.java +++ b/runAs-agent/src/test/java/jetbrains/buildServer/runAs/agent/LinuxSettingsGeneratorTest.java @@ -11,7 +11,7 @@ import static org.assertj.core.api.BDDAssertions.then; -public class UnixSettingsGeneratorTest { +public class LinuxSettingsGeneratorTest { private static final String ourlineSeparator = System.getProperty("line.separator"); private Mockery myCtx; @@ -24,7 +24,7 @@ public void setUp() @Test() public void shouldGenerateContent() { // Given - final String expectedContent = "--user nik"; + final String expectedContent = "nik"; final List additionalArgs = Arrays.asList(new CommandLineArgument("arg1", CommandLineArgument.Type.PARAMETER), new CommandLineArgument("arg 2", CommandLineArgument.Type.PARAMETER)); final ResourceGenerator instance = createInstance(); @@ -40,6 +40,6 @@ public void shouldGenerateContent() { @NotNull private ResourceGenerator createInstance() { - return new UnixSettingsGenerator(); + return new LinuxSettingsGenerator(); } } diff --git a/runAs-agent/src/test/resources/testng-runAs.xml b/runAs-agent/src/test/resources/testng-runAs.xml index 816baef..a20bb62 100644 --- a/runAs-agent/src/test/resources/testng-runAs.xml +++ b/runAs-agent/src/test/resources/testng-runAs.xml @@ -3,7 +3,7 @@ - + diff --git a/runAs-server/src/main/resources/buildServerResources/runAsBuildFeature.jsp b/runAs-server/src/main/resources/buildServerResources/runAsBuildFeature.jsp index 87fcf9a..7bd36f2 100644 --- a/runAs-server/src/main/resources/buildServerResources/runAsBuildFeature.jsp +++ b/runAs-server/src/main/resources/buildServerResources/runAsBuildFeature.jsp @@ -7,7 +7,7 @@ - This build feature allows running build steps under the specified Windows user account. + This build feature allows running build steps under the specified user account. @@ -17,7 +17,7 @@ - Specify the user name in the formats "username" or "doman\username" or "username@domain" + Specify the user name." @@ -28,6 +28,6 @@ - Specify the user's password for agents under the Windows OS and current user's password for Linux. + Specify the password.