示例#1
0
 /**
  * Constructor
  *
  * checks if the pgsql interface is available, otherwise it will
  * set the variable $success of the basis class to false
  *
  * @author Matthias Grimm <*****@*****.**>
  * @author Andreas Gohr <*****@*****.**>
  */
 function auth_pgsql()
 {
     global $conf;
     $this->cnf = $conf['auth']['pgsql'];
     if (!$this->cnf['port']) {
         $this->cnf['port'] = 5432;
     }
     if (method_exists($this, 'auth_basic')) {
         parent::auth_basic();
     }
     if (!function_exists('pg_connect')) {
         if ($this->cnf['debug']) {
             msg("PgSQL err: PHP Postgres extension not found.", -1);
         }
         $this->success = false;
         return;
     }
     $this->defaultgroup = $conf['defaultgroup'];
     // set capabilities based upon config strings set
     if (empty($this->cnf['user']) || empty($this->cnf['password']) || empty($this->cnf['database'])) {
         if ($this->cnf['debug']) {
             msg("PgSQL err: insufficient configuration.", -1, __LINE__, __FILE__);
         }
         $this->success = false;
         return;
     }
     $this->cando['addUser'] = $this->_chkcnf(array('getUserInfo', 'getGroups', 'addUser', 'getUserID', 'getGroupID', 'addGroup', 'addUserGroup'));
     $this->cando['delUser'] = $this->_chkcnf(array('getUserID', 'delUser', 'delUserRefs'));
     $this->cando['modLogin'] = $this->_chkcnf(array('getUserID', 'updateUser', 'UpdateTarget'));
     $this->cando['modPass'] = $this->cando['modLogin'];
     $this->cando['modName'] = $this->cando['modLogin'];
     $this->cando['modMail'] = $this->cando['modLogin'];
     $this->cando['modGroups'] = $this->_chkcnf(array('getUserID', 'getGroups', 'getGroupID', 'addGroup', 'addUserGroup', 'delGroup', 'getGroupID', 'delUserGroup'));
     /* getGroups is not yet supported
        $this->cando['getGroups']    = $this->_chkcnf(array('getGroups',
                                                            'getGroupID')); */
     $this->cando['getUsers'] = $this->_chkcnf(array('getUsers', 'getUserInfo', 'getGroups'));
     $this->cando['getUserCount'] = $this->_chkcnf(array('getUsers'));
 }
示例#2
0
 /**
  * Constructor
  *
  * Heavily modified from the original auth_mysql
  * constructor written by Matthias Grimm.
  *
  * @author  Alex Shepherd  <*****@*****.**>
  **/
 function auth_drupal7()
 {
     global $conf;
     $this->cnf = $conf['auth']['mysql'];
     if (method_exists($this, 'auth_basic')) {
         parent::auth_basic();
     }
     if (!function_exists('mysql_connect')) {
         if ($this->cnf['debug']) {
             msg("MySQL err: PHP MySQL extension not found.", -1, __LINE__, __FILE__);
         }
         $this->success = false;
         return;
     }
     global $USERINFO;
     $this->cando['addUser'] = false;
     $this->cando['delUser'] = false;
     $this->cando['modLogin'] = false;
     $this->cando['modGroups'] = $this->cando['modLogin'];
     $this->cando['getUsers'] = true;
     $this->cando['getUserCount'] = true;
     // Try to log user in using Drupal's session cookie
     $sesscookie = false;
     $cookies = $_COOKIE;
     foreach ($cookies as $cookie => $value) {
         // Find a likely Drupal cookie
         if (substr($cookie, 0, 4) == 'SESS' && strlen($cookie) == 36) {
             $sesscookie = $value;
         }
         // Now find the session in the Drupal database
         if ($this->_openDB()) {
             $sql = $conf['SQLFindSession'];
             $sql = str_replace('%{sessioncookie}', $sesscookie, $sql);
             $result = $this->_queryDB($sql);
             if ($result !== false) {
                 if ($result[0]['name']) {
                     $uid = $result[0]['uid'];
                     $USERINFO['name'] = $result[0]['name'];
                     $USERINFO['mail'] = $result[0]['name'];
                     $USERINFO['pass'] = '';
                     $USERINFO['grps'] = array();
                     // Now do groups
                     //            $sql = "SELECT r.name FROM users_roles u INNER JOIN
                     //                    role r WHERE u.uid='%{uid}' && u.rid=r.rid";
                     $sql = $conf['SQLFindRoles'];
                     $sql = str_replace('%{uid}', $uid, $sql);
                     $result = $this->_queryDB($sql);
                     if ($result !== false) {
                         foreach ($result as $key => $val) {
                             foreach ($val as $k => $v) {
                                 $USERINFO['grps'][] = $v;
                             }
                         }
                     }
                     // Now set up session variables
                     $_SERVER['REMOTE_USER'] = $result[0]['name'];
                     $_SESSION[DOKU_COOKIE]['auth']['user'] = $USERINFO['name'];
                     $_SESSION[DOKU_COOKIE]['auth']['buid'] = auth_browseruid();
                     $_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO;
                     break;
                 } else {
                     // Could not find session data. Ignore cookie.
                     continue;
                 }
             }
             $this->_closeDB();
         } else {
             msg("Database Connection Failed. Please check your configuration.", -1, __LINE__, __FILE__);
             $this->success = false;
         }
     }
     // If DOKU_COOKIE session is ok, pass to trustExternal
     if ($_SESSION[DOKU_COOKIE]['auth']['user'] != '') {
         $this->cando['external'] = true;
     }
 }