summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandi <andi@splitbrain.org>2005-04-11 23:13:37 +0200
committerandi <andi@splitbrain.org>2005-04-11 23:13:37 +0200
commita890d25f321e90efa874870f286b4ece553eb863 (patch)
treeb73b63f608692bf74c9d3f9b976936cd06be0dd6
parentaf587fa822e0477bda4288e75b171f81ea8e68ce (diff)
downloadrpg-a890d25f321e90efa874870f286b4ece553eb863.tar.gz
rpg-a890d25f321e90efa874870f286b4ece553eb863.tar.bz2
auth_pgsql added
darcs-hash:20050411211337-9977f-b726b869128025e242e013899b2ac7eb1f753bfb.gz
-rw-r--r--inc/auth_pgsql.php112
1 files changed, 112 insertions, 0 deletions
diff --git a/inc/auth_pgsql.php b/inc/auth_pgsql.php
new file mode 100644
index 000000000..b9044afb4
--- /dev/null
+++ b/inc/auth_pgsql.php
@@ -0,0 +1,112 @@
+<?php
+/**
+ * PgSQL authentication backend
+ * (shamelessly based on the original auth_mysql.php ;-)
+ *
+ * PHP's PgSQL extension is needed
+ *
+ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
+ * @author Alexander Marx < mad-ml [at] madness [dot] at >
+ */
+
+//check for Postgresql extension on load
+if(!function_exists('pg_connect'))
+ msg("PgSQL extension not found",-1);
+
+/**
+ * Execute SQL
+ *
+ * Executes SQL statements and returns the results as list
+ * of hashes. Returns false on error.
+ *
+ */
+function auth_pgsql_runsql($sql_string) {
+ global $conf;
+ $cnf = $conf['auth']['pgsql'];
+
+ $dsn="host=".$cnf['server']." port=5432 dbname=".$cnf['database']." user=".$cnf['user']." password=".$cnf['password'];
+ $link = pg_connect($dsn);
+ if(!$link){
+ msg('PgSQL: Connection to database failed!',-1);
+ return false;
+ }
+
+ $result = pg_query($link, $sql_string);
+ if(!$result){
+ msg('PgSQL: '.pg_last_error($link));
+ return false;
+ }
+
+ for($i=0; $i< pg_num_rows($result); $i++) {
+ $temparray = pg_fetch_assoc($result);
+ $resultarray[]=$temparray;
+ }
+ pg_free_result($result);
+ pg_close($link);
+ return $resultarray;
+}
+
+/**
+ * Check user+password [required auth function]
+ *
+ * Checks if the given user exists and the given
+ * plaintext password is correct
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ * @return bool
+ */
+function auth_checkPass($user,$pass){
+ global $conf;
+ $cnf = $conf['auth']['pgsql'];
+
+ $sql = str_replace('%u',addslashes($user),$cnf['passcheck']);
+ $sql = str_replace('%p',addslashes($pass),$sql);
+ $result = auth_pgsql_runsql($sql);
+ return(count($result));
+}
+
+/**
+ * Return user info [required auth function]
+ *
+ * Returns info about the given user needs to contain
+ * at least these fields:
+ *
+ * name string full name of the user
+ * mail string email addres of the user
+ * grps array list of groups the user is in
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function auth_getUserData($user){
+ global $conf;
+ $cnf = $conf['auth']['pgsql'];
+
+ $sql = str_replace('%u',addslashes($user),$cnf['userinfo']);
+ $result = auth_pgsql_runsql($sql);
+ if(!count($result)) return false;
+ $info = $result[0];
+
+ $sql = str_replace('%u',addslashes($user),$cnf['groups']);
+ $result = auth_pgsql_runsql($sql);
+ if(!count($result)) return false;
+ foreach($result as $row){
+ $info['grps'][] = $row['group'];
+ }
+
+ return $info;
+}
+
+/**
+ * Create a new User [required auth function]
+ *
+ * Not implemented
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function auth_createUser($user,$name,$mail){
+ msg("Sorry. Creating users is not supported by the PgSQL backend, yet",-1);
+ return null;
+}
+
+?>
+