Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows runas command issue #44736

Open
tsaridas opened this issue Nov 29, 2017 · 15 comments · May be fixed by #65075
Open

Windows runas command issue #44736

tsaridas opened this issue Nov 29, 2017 · 15 comments · May be fixed by #65075
Assignees
Labels
Bug broken, incorrect, or confusing behavior severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around Windows

Comments

@tsaridas
Copy link
Contributor

Description of Issue/Question

salt -L windows-minion cmd.run '"c:\Program Files\dir\file.exe" -g && echo foo' runas=user password=FooBar

will not be able to find file.exe but when you do

salt -L windows-minion cmd.run '"c:\Program Files\dir\file.exe" -g' runas=user password=FooBar

it works.

Versions Report

Checked the code and it has always been like that so it affects all versions when runas is used.

Fix

https://github.com/saltstack/salt/blob/develop/salt/utils/win_runas.py#L344
can be changed to :

cmd = 'cmd /c ({0})'.format(cmd)
@gtmanfred
Copy link
Contributor

Would you mind submitting a PR for this?

Thanks,
Daniel

@gtmanfred gtmanfred added Bug broken, incorrect, or confusing behavior team-windows Windows labels Nov 29, 2017
@gtmanfred gtmanfred added this to the Approved milestone Nov 29, 2017
@gtmanfred
Copy link
Contributor

@tsaridas
Copy link
Contributor Author

maybe @twangboy can have a look ?
I have no problem submitting a pr if he also thinks this is the correct solution.

@twangboy
Copy link
Contributor

@tsaridas That's probably fine. You'll also need to add it here: https://github.com/saltstack/salt/blob/develop/salt/utils/win_runas.py#L418

@damon-atkins
Copy link
Contributor

damon-atkins commented Nov 30, 2017

cmd.shell is meant to invoke the shell to run a command e.g. cmd.exe
cmd.run is meant to run things as is it should not prefix it with a shell.

The above is a bad fix. Please try cmd.shell , these was some code updates which said if Windows the Shell use %COMSPEC%.

@twangboy
Copy link
Contributor

@tsaridas Does cmd.shell fix your issue? If so, I'd like to rescind my above statement.

@tsaridas
Copy link
Contributor Author

@damon-atkins the only thing that cmd.shell does it enable python shell and calls cmd.run .

In cmd._run when setting runas & password python_shell doesn't do anything since it exists before python_shell changes the command.

https://github.com/saltstack/salt/blob/develop/salt/modules/cmdmod.py#L409

I can confirm tomorrow after some testing but code seems to be the same.

@damon-atkins
Copy link
Contributor

So if cmd.shell does not result in runing cmd /s /c then it needs to be fixed.

@tsaridas
Copy link
Contributor Author

tsaridas commented Dec 1, 2017

may I suggest to change to
'cmd /s /c "{0}"'
What do you think ?

@damon-atkins
Copy link
Contributor

That's fine the /s indicates its in " you can look at the current 2016.11 branch for examples in win_pkg, which I fixed a about 2 months ago. Just needs to be coded so its only applied when a shell is wanted (but windows gets cmd instead of a unix shell)

@twangboy
Copy link
Contributor

twangboy commented Dec 1, 2017

@cachedout Should cmd.shell prefix the command with cmd /s /c? Should it open whatever command is passed in the shell? Is that what cmd.shell is supposed to do?

@stale
Copy link

stale bot commented Mar 27, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

@stale stale bot added the stale label Mar 27, 2019
@stale stale bot closed this as completed Apr 3, 2019
@twangboy twangboy reopened this Apr 8, 2019
@stale
Copy link

stale bot commented Apr 8, 2019

Thank you for updating this issue. It is no longer marked as stale.

@stale stale bot removed the stale label Apr 8, 2019
@twangboy twangboy self-assigned this Apr 8, 2019
@stale
Copy link

stale bot commented Jan 8, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

@stale stale bot added the stale label Jan 8, 2020
@stale
Copy link

stale bot commented Jan 14, 2020

Thank you for updating this issue. It is no longer marked as stale.

@stale stale bot removed the stale label Jan 14, 2020
@sagetherage sagetherage added the severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around label May 21, 2021
@twangboy twangboy self-assigned this May 9, 2022
@twangboy twangboy linked a pull request Aug 28, 2023 that will close this issue
3 tasks
@twangboy twangboy modified the milestones: Approved, Chlorine v3007.0 Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants