From 1f8db7d3099464d4649ad5b60487312593cd9e58 Mon Sep 17 00:00:00 2001 From: Andris Raugulis Date: Mon, 8 Oct 2018 00:12:59 +0000 Subject: [PATCH] Escape backslash in username and other fields, i.e., use single quote. Add work-around for additional username input. --- README.md | 7 ++++++- gp-okta.conf | 1 + gp-okta.py | 17 +++++++++++------ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7325767..f297a56 100644 --- a/README.md +++ b/README.md @@ -46,4 +46,9 @@ override `password` option in configuration file. 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 -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. + diff --git a/gp-okta.conf b/gp-okta.conf index 15f8e41..ce1fa45 100644 --- a/gp-okta.conf +++ b/gp-okta.conf @@ -10,3 +10,4 @@ gateway = Manual ny1-gw.example.com openconnect_args = # optional arguments to openconnect execute = 0 # execute openconnect command bug.nl = 0 # newline work-around for openconnect +bug.username = 0 # username work-around for openconnect diff --git a/gp-okta.py b/gp-okta.py index e883a0a..9b1f8ae 100755 --- a/gp-okta.py +++ b/gp-okta.py @@ -345,17 +345,22 @@ def main(): userauthcookie = paloalto_getconfig(conf, s, saml_username, prelogin_cookie) log('portal-userauthcookie: {0}'.format(userauthcookie)) + username = saml_username cmd = conf.get('openconnect_cmd') or 'openconnect' - cmd += ' --protocol=gp -u "{0}"' + cmd += ' --protocol=gp -u \'{0}\'' cmd += ' --usergroup portal:portal-userauthcookie' - cmd += ' --passwd-on-stdin ' + conf.get('openconnect_args', '') + ' "{1}"' - cmd = cmd.format(saml_username, conf.get('vpn_url')) + cmd += ' --passwd-on-stdin ' + conf.get('openconnect_args', '') + ' \'{1}\'' + cmd = cmd.format(username, conf.get('vpn_url')) 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: - pcmd = 'printf "' + nlbug + '{0}\\n{1}"'.format(userauthcookie, gw) + pcmd = 'printf \'' + bugs + '{0}\\n{1}\''.format(userauthcookie, gw) else: - pcmd = 'printf "' + nlbug + '{0}"'.format(userauthcookie) + pcmd = 'printf \'' + bugs + '{0}\''.format(userauthcookie) print() if conf.get('execute', '').lower() in ['1', 'true']: cmd = shlex.split(cmd)