-
Notifications
You must be signed in to change notification settings - Fork 334
Avoid duplicating PermitUserEnvironment #1954
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
base: master
Are you sure you want to change the base?
Conversation
ee66fa0 to
d9868eb
Compare
Do not add a new line if the option is already defined. This avoids adding dupulicated lines and also make sure that the existing explicit setting to disable PermitUserEnvironment is purged. Closes voxpupuli#1953
d9868eb to
383c470
Compare
| case self['platform'] | ||
| when /amazon|debian|ubuntu|archlinux|el-|centos|fedora|redhat|oracle|scientific|opensuse|sles|solaris/ | ||
| directory = tmpdir | ||
| exec(Beaker::Command.new("echo 'PermitUserEnvironment yes' | cat - /etc/ssh/sshd_config > #{directory}/sshd_config.permit")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering why this was built so... complicated in the past.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that tmp file was required because you can't redirect to the input file.
Alternatively we may consider this would be more "safe" though sshd may no load the config file unless it is actually restarted so it feels overcomplicated.
| directory = tmpdir | ||
| exec(Beaker::Command.new("echo 'PermitUserEnvironment yes' | cat - /etc/ssh/sshd_config > #{directory}/sshd_config.permit")) | ||
| exec(Beaker::Command.new("mv #{directory}/sshd_config.permit /etc/ssh/sshd_config")) | ||
| exec(Beaker::Command.new("sed -i -e 's/^PermitUserEnvironment .*/PermitUserEnvironment yes/' -e t -e '1s/^/PermitUserEnvironment yes\\n/' /etc/ssh/sshd_config")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am concerned because sed -i is not portable across sed(1) implementations. Specifically, FreeBSD use standard getopt(3) and the -i option require a value (so it will use -e in this case, shifting all arguments and making the command-line invalid). GNU sed(1) do some magic and only use anything that is "glued" to -i and does not support passing an empty value "the regular way" with -i ''. So the only common supported syntax is -isomething where something is not blank.
Rather than in-place edits, when I write portable code, I generally prefer to have sed print the modified content to stdout, redirect it to a temporary file and move that file over the original one like it was done before.
Currently we do not support running acceptance tests on FreeBSD, but I would love to see that one day
Do not add a new line if the option is already defined. This avoids adding dupulicated lines and also make sure that the existing explicit setting to disable PermitUserEnvironment is purged.
Closes #1953