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

Automatically generate a config file compatible with LibreSSL #215

Closed
wants to merge 1 commit into from
Closed

Automatically generate a config file compatible with LibreSSL #215

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Jul 15, 2018

Address issue #76 by generating a config file with the substitutions having been performed by either envsubst from GNU gettext, or Perl, if available.

LibreSSL does not support environment variable substitution. Work around
this by generating a config file with the substitutions having been
performed by either envsubst from GNU gettext, or Perl, if available.
@TinCanTech
Copy link
Collaborator

EasyRSA 3 now supports libressl, so this PR should probably be closed.

@ghost
Copy link
Author

ghost commented Sep 22, 2019

The current implementation is unsafe. It would be preferable not to use sed but the options are limited when aiming for portability. Bash would do, but bash isn't sh. The ed utility can't be relied upon because most Linux vendors ignore the fact that it's a standard utility.

Given the use of sed, I would suggest the use of a custom escaping routine at least. Consider the following program.

#!/bin/sh

escape() {
	printf %s "$1" | sed -e 's/\([,&\]\)/\\\1/g'
}

set -- 'foo,bar' 'foo\1bar' 'foo&bar'

echo "Bad method ..."
i=1
for value in "$@"; do
	printf 'Sample %u: ' "$i"
	printf '%s\n' '$SOME_VAR' | sed -e "s,\$SOME_VAR,$value),"
	: $((i += 1))
done

echo "Improved method ..."
i=1
for value in "$@"; do
	printf 'Sample %u: ' "$i"
	printf '%s\n' '$SOME_VAR' | sed -e "s,\$SOME_VAR,$(escape "$value"),"
	: $((i += 1))
done

On my system, the results are as follows:-

Bad method ...
Sample 1: sed: -e expression #1, char 17: unknown option to `s'
Sample 2: sed: -e expression #1, char 22: invalid reference \1 on `s' command's RHS
Sample 3: foo$SOME_VARbar)
Improved method ...
Sample 1: foo,bar
Sample 2: foo\1bar
Sample 3: foo&bar

EDIT: Goofed my own sample code. Fixed.

@TinCanTech
Copy link
Collaborator

The current implementation is unsafe

Improvements are welcome in the form of tested PRs.

@ghost
Copy link
Author

ghost commented Sep 22, 2019

The problem has been adequately explained; I'm not submitting another PR. I will, however, close this one.

@ghost ghost closed this Sep 22, 2019
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant