OpenVPN / openvpn

OpenVPN is an open source VPN daemon
http://openvpn.net
Other
10.25k stars 2.92k forks source link

Proposal: a parameter to trigger just a syntax check and exit #566

Closed matthiasries closed 2 weeks ago

matthiasries commented 2 weeks ago

Hi, is there interest for a --check-syntax parameter. Using this parameter would check the syntax of the config file and the remaining parameters, then exit with rc 0 or rc 1 in case of a syntax error.

I'm not sure if it should be call syntax-check, sanity-check or something else.

I almost get this behaviour if I add --version as the last parameter and check stdout for the string "OpenVPN". The return code of openvpn is of course not 0

openvpn --config test.ovpn --version |grep -q OpenVPN

This would allow for a check in automation/deployment. Ansible for example has the option to validate changes before applying them.

- name: add comp-lzo to openvpn config
  lineinfile:
    path: '/etc/openvpn/server.conf'
    regexp: '^comp-lzo'
    insertafter: '^client'
    line: 'comp-lzo'
    validate: "openvpn --check-syntax --config '%s' "
  notify: restart-openvpn
schwabe commented 2 weeks ago

The return code of --version is 0 if the config is parsed correctly and 1 otherwise. So already already gives the behaviour you want.

You can also use --show-tls for that. That will also parse the whole config

matthiasries commented 2 weeks ago

--show-tls works for me --version and --help return 1 on my old openvpn. tested it on a newer version, works.

I wanted to know if a patch with this parameter / non intrusive "feature" would have a chance to be accepted. If someone except for me wants a check feature. But I guess if there is a work around than there is no need for more parameters.