Escape backslash in username and other fields, i.e., use single quote.

Add work-around for additional username input.
This commit is contained in:
Andris Raugulis
2018-10-08 00:12:59 +00:00
parent 263bd98b41
commit 1f8db7d309
3 changed files with 18 additions and 7 deletions
+5
View File
@@ -47,3 +47,8 @@ override `password` option in configuration file.
If `openconnect` returns with `ioctl` error, then this version has a bug, which If `openconnect` returns with `ioctl` error, then this version has a bug, which
requires to prefix stdin input with a newline. Set `bug.nl=1` in configuration requires to prefix stdin input with a newline. Set `bug.nl=1` in configuration
file to work-around this issue. file to work-around this issue.
If `openconnect` returns with `fgets (stdin): Resource temporarily unavailable`
error, then this version has a bug, which requires to prefix stdin input with a
username. Set `bug.username=1` in configuration file to work-around this issue.
+1
View File
@@ -10,3 +10,4 @@ gateway = Manual ny1-gw.example.com
openconnect_args = # optional arguments to openconnect openconnect_args = # optional arguments to openconnect
execute = 0 # execute openconnect command execute = 0 # execute openconnect command
bug.nl = 0 # newline work-around for openconnect bug.nl = 0 # newline work-around for openconnect
bug.username = 0 # username work-around for openconnect
+11 -6
View File
@@ -345,17 +345,22 @@ def main():
userauthcookie = paloalto_getconfig(conf, s, saml_username, prelogin_cookie) userauthcookie = paloalto_getconfig(conf, s, saml_username, prelogin_cookie)
log('portal-userauthcookie: {0}'.format(userauthcookie)) log('portal-userauthcookie: {0}'.format(userauthcookie))
username = saml_username
cmd = conf.get('openconnect_cmd') or 'openconnect' cmd = conf.get('openconnect_cmd') or 'openconnect'
cmd += ' --protocol=gp -u "{0}"' cmd += ' --protocol=gp -u \'{0}\''
cmd += ' --usergroup portal:portal-userauthcookie' cmd += ' --usergroup portal:portal-userauthcookie'
cmd += ' --passwd-on-stdin ' + conf.get('openconnect_args', '') + ' "{1}"' cmd += ' --passwd-on-stdin ' + conf.get('openconnect_args', '') + ' \'{1}\''
cmd = cmd.format(saml_username, conf.get('vpn_url')) cmd = cmd.format(username, conf.get('vpn_url'))
gw = (conf.get('gateway') or '').strip() gw = (conf.get('gateway') or '').strip()
nlbug = '\\n' if conf.get('bug.nl', '').lower() in ['1', 'true'] else '' bugs = ''
if conf.get('bug.nl', '').lower() in ['1', 'true']:
bugs += '\\n'
if conf.get('bug.username', '').lower() in ['1', 'true']:
bugs += '{0}\\n'.format(username.replace('\\', '\\\\'))
if len(gw) > 0: if len(gw) > 0:
pcmd = 'printf "' + nlbug + '{0}\\n{1}"'.format(userauthcookie, gw) pcmd = 'printf \'' + bugs + '{0}\\n{1}\''.format(userauthcookie, gw)
else: else:
pcmd = 'printf "' + nlbug + '{0}"'.format(userauthcookie) pcmd = 'printf \'' + bugs + '{0}\''.format(userauthcookie)
print() print()
if conf.get('execute', '').lower() in ['1', 'true']: if conf.get('execute', '').lower() in ['1', 'true']:
cmd = shlex.split(cmd) cmd = shlex.split(cmd)