From b90babbfd2425e201c372f631c47019572d0f4ac Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Mon, 12 Sep 2016 20:38:48 +0200 Subject: [PATCH] add opnsense-auth helper for pam support, https://github.com/opnsense/core/issues/998 --- src/sbin/opnsense-auth | 85 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 src/sbin/opnsense-auth diff --git a/src/sbin/opnsense-auth b/src/sbin/opnsense-auth new file mode 100755 index 000000000..952cf26b4 --- /dev/null +++ b/src/sbin/opnsense-auth @@ -0,0 +1,85 @@ +#!/usr/local/bin/php + +// password= +// service= (to be implemented) +$fp = fopen('php://stdin', 'r'); +$auth_data = array(); +while (!empty($line=trim(fgets($fp)))) { + $parts = explode("=", $line); + if (count($parts) >= 2) { + // key value pair + $propname = array_shift($parts); + $propvalue = implode("=", $parts); + $auth_data[$propname] = $propvalue; + } +} + +$exit_status = -1; +if (!empty($auth_data['user']) && !empty($auth_data['password'])) { + $authcfg = auth_get_authserver("Local Database"); + $authcfg_fallback = auth_get_authserver("Local Database"); + + if (isset($config['system']['webgui']['authmode'])) { + $authcfg = auth_get_authserver($config['system']['webgui']['authmode']); + } + + if (!empty($config['system']['webgui']['authmode_fallback'])) { + if ($config['system']['webgui']['authmode_fallback'] == "__NO_FALLBACK__") { + // no fallback + $authcfg_fallback = false; + } else { + $authcfg_fallback = auth_get_authserver($config['system']['webgui']['authmode_fallback']); + } + } + + if (authenticate_user($auth_data['user'], $auth_data['password'], $authcfg)) { + // auth OK + syslog(LOG_NOTICE, "user '".$auth_data['user']."' authenticated successfully\n"); + $exit_status = 0; + } elseif ($authcfg != $authcfg_fallback && $authcfg_fallback !== false && + authenticate_user($auth_data['user'], $auth_data['password'], $authcfg_fallback)) { + // auth OK, using fallback + syslog(LOG_NOTICE, "user '".$auth_data['user']."' authenticated successfully (using fallback)\n"); + $exit_status = 0; + } else { + syslog(LOG_WARNING, "user '".$auth_data['user']."' could not authenticate.\n"); + } +} + +// failed auth, return exit status -1 +closelog(); +exit($exit_status);