#!/usr/local/bin/php * password= * service= */ $fp = fopen('php://stdin', 'r'); $auth_data = array(); $line = ''; while (($char = fgetc($fp)) !== false) { if ($char !== "\0") { $line .= $char; } elseif (strlen($line)) { $parts = explode('=', $line, 2); if (count($parts) == 2) { $auth_data[$parts[0]] = $parts[1]; } $line = ''; } else { break; } } $is_authenticated = false; $exit_status = -1; if (!empty($auth_data['user']) && isset($auth_data['password'])) { $authFactory = new \OPNsense\Auth\AuthenticationFactory(); $is_authenticated = $authFactory->authenticate($auth_data['service'], $auth_data['user'], $auth_data['password']); if ($is_authenticated) { $authProps = $authFactory->getLastAuthProperties(); if (!empty($authProps)) { /* dump authentication response data to stdout */ echo json_encode($authProps, JSON_INVALID_UTF8_IGNORE) ."\n"; } $exit_status = 0; } else { if (getUserEntry($auth_data['user']) === false) { /* signal user unknown, so PAM may consider other options */ $exit_status = 2; } } } closelog(); exit($exit_status);