summaryrefslogtreecommitdiffstats
path: root/lib/class/auth.class.php
diff options
context:
space:
mode:
authorPaul Arthur <paul.arthur@flowerysong.com>2013-01-28 18:12:09 -0500
committerPaul Arthur <paul.arthur@flowerysong.com>2013-01-28 21:23:15 -0500
commit0451840fa34dfcffd86a00be8dbda9e4abd3f4d3 (patch)
tree4a85560044fb2b58075f272eaeafa32c7b1c975e /lib/class/auth.class.php
parentad4ba9ff9a32930a835f18b36bb2f3dda1f588d3 (diff)
downloadampache-0451840fa34dfcffd86a00be8dbda9e4abd3f4d3.tar.gz
ampache-0451840fa34dfcffd86a00be8dbda9e4abd3f4d3.tar.bz2
ampache-0451840fa34dfcffd86a00be8dbda9e4abd3f4d3.zip
Add 'external' auth method
Based on merge request #11
Diffstat (limited to 'lib/class/auth.class.php')
-rw-r--r--lib/class/auth.class.php55
1 files changed, 54 insertions, 1 deletions
diff --git a/lib/class/auth.class.php b/lib/class/auth.class.php
index a59e2ad4..dacf15d5 100644
--- a/lib/class/auth.class.php
+++ b/lib/class/auth.class.php
@@ -184,7 +184,60 @@ class Auth {
}
return $results;
- } // local_auth
+ }
+
+ /**
+ * external_auth
+ *
+ * Calls an external program compatible with mod_authnz_external
+ * such as pwauth.
+ */
+ private static function external_auth($username, $password) {
+ $authenticator = Config::get('external_authenticator');
+ if (!$authenticator) {
+ return array(
+ 'success' => false,
+ 'error' => 'No external authenticator configured'
+ );
+ }
+
+ //FIXME: should we do input sanitization?
+ $proc = proc_open($authenticator,
+ array(
+ 0 => array('pipe', 'r'),
+ 1 => array('pipe', 'w'),
+ 2 => array('pipe', 'w')
+ ), $pipes);
+
+ if (is_resource($proc)) {
+ fwrite($pipes[0], $username."\n".$password."\n");
+ fclose($pipes[0]);
+ fclose($pipes[1]);
+ if ($stderr = fread($pipes[2], 8192)) {
+ debug_event('external_auth', $stderr, 5);
+ }
+ fclose($pipes[2]);
+ }
+ else {
+ return array(
+ 'success' => false,
+ 'error' => 'Failed to run external authenticator'
+ );
+ }
+
+ if (proc_close($proc) == 0) {
+ return array(
+ 'success' => true,
+ 'type' => 'external',
+ 'username' => $username
+ );
+ }
+
+ return array(
+ 'success' => false,
+ 'error' => 'The external authenticator did not accept the login'
+ );
+ }
/**
* ldap_auth