Esempio n. 1
0
 public function lookupUser($credentials)
 {
     $username = $credentials['username'];
     $password = $credentials['password'];
     $this->log('Ldap: looking up user "' . $username . '" in LDAP server ');
     $sourceConfig = $this->source;
     $server = parse_url($sourceConfig['url']);
     if (empty($server['host'])) {
         return false;
         // oops
     }
     $connect = ldap_connect($server['host'], empty($server['port']) ? 389 : $server['port']);
     ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
     ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
     //$connect=ldap_connect($server['host']);
     $this->log('Connected');
     if (!$connect) {
         throw new PHPDS_exception('Unable to connect to the LDAP server');
     }
     if ($sourceConfig['namePattern']) {
         $username = PU_sprintfn($sourceConfig['namePattern'], array($username));
     }
     if (!@ldap_bind($connect, $username, $password)) {
         return false;
         // if we can't bind it's likely the user is unknown or the password is wrong
     }
     $this->log('Bound');
     return true;
 }
Esempio n. 2
0
 /**
  * Build the query based on the private sql and the parameters
  *
  * @since 20100216
  * @since 20100428	(v1.0.1) (greg) use sql() instead of sql
  * @date 20100630 (v1.0.2) (greg) use array_compact to avoid null values
  * @version 1.0.2
  * @author	greg
  * @param $parameters (optional)array, the parameters to inject into the query
  * @return string, the sql query string
  */
 public function build($parameters = null)
 {
     $sql = '';
     try {
         $this->preBuild();
         $sql = $this->sql() . $this->extraBuild($parameters);
         if (!empty($parameters)) {
             if (is_scalar($parameters)) {
                 $parameters = array($parameters);
             }
             if (is_array($parameters)) {
                 if ($this->autoProtect) {
                     $parameters = $this->protectArray($parameters, $this->autoQuote);
                 }
                 $sql = PU_sprintfn($sql, PU_array_compact($parameters));
             }
             //TODO is parameters is neither scalar nor array what should we do?
         }
     } catch (Exception $e) {
         throw new PHPDS_databaseException('Error building sql for <tt>' . get_class() . '</tt>', 0, $e);
     }
     return $sql;
 }
Esempio n. 3
0
 public function test_sprintfn()
 {
     $this->assertEquals('', PU_sprintfn('', array()));
     $this->assertEquals('', PU_sprintfn('', array('a' => 'test')));
     $this->assertEquals('TEST', PU_sprintfn('TEST', array('a' => 'test')));
     $this->assertEquals('TEST test', PU_sprintfn('TEST %s', array('a' => 'test')));
     $this->assertEquals('TEST test', PU_sprintfn('TEST %1$s', array('a' => 'test')));
     $this->assertEquals('TEST test', PU_sprintfn('TEST %(a)s', array('a' => 'test')));
     $this->assertEquals('TEST right', PU_sprintfn('TEST %2$s', array('a' => 'wrong', 'b' => 'right')));
     $this->assertEquals('TEST right', PU_sprintfn('TEST %(b)s', array('a' => 'wrong', 'b' => 'right')));
     $this->setExpectedException('PHPDS_sprintfnException');
     PU_sprintfn('TEST %2$s', array('a' => 'wrong'));
     PU_sprintfn('TEST %(b)s', array('a' => 'wrong'));
 }