DB_ldap3
[ class tree: DB_ldap3 ] [ index: DB_ldap3 ] [ all elements ]

Source for file ldap3.php

Documentation is available at ldap3.php

  1. <?php
  2. //
  3. // Pear DB LDAP3 - Database independent query interface definition
  4. // for PHP's LDAP extension with protocol version 3.
  5. //
  6. // Copyright (C) 2002-2003 Piotr Roszatycki <dexter@debian.org>
  7. //
  8. //  This library is free software; you can redistribute it and/or
  9. //  modify it under the terms of the GNU Lesser General Public
  10. //  License as published by the Free Software Foundation; either
  11. //  version 2.1 of the License, or (at your option) any later version.
  12. //
  13. //  This library is distributed in the hope that it will be useful,
  14. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. //  Lesser General Public License for more details.
  17. //
  18. //  You should have received a copy of the GNU Lesser General Public
  19. //  License along with this library; if not, write to the Free Software
  20. //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  21. //
  22. // $Id: ldap3.php 255993 2008-03-24 20:27:16Z dufuz $
  23. //
  24.  
  25. require_once 'DB/common.php';
  26. require_once 'DB/ldap2.php';
  27.  
  28. /**
  29.  * LDAP3 DB interface class
  30.  *
  31.  * DB_ldap3 extends DB_ldap2 to provide DB compliant
  32.  * access to LDAP servers with protocol version 3.
  33.  *
  34.  * @author Piotr Roszatycki <dexter@debian.org>
  35.  * @version $Revision: 255993 $
  36.  * @package DB_ldap3
  37.  */
  38.  
  39. class DB_ldap3 extends DB_ldap2
  40. {
  41.     // {{{ connect()
  42.  
  43.     /**
  44.      * Connect and bind to LDAPv3 server with either anonymous
  45.      * or authenticated bind depending on dsn info
  46.      *
  47.      * The format of the supplied DSN:
  48.      *
  49.      *  ldap3://binddn:bindpw@host:port/basedn
  50.      *
  51.      * I.e.:
  52.      *
  53.      *  ldap3://uid=dexter,ou=People,dc=example,dc=net:secret@127.0.0.1/dc=example,dc=net
  54.      *
  55.      * @param $dsn the data source name (see DB::parseDSN for syntax)
  56.      * @param boolean $persistent kept for interface compatibility
  57.      * @return int DB_OK if successfully connected.
  58.      *  A DB error code is returned on failure.
  59.      */
  60.     function connect($dsninfo$persistent = false)
  61.     {
  62.         if (!PEAR::loadExtension('ldap'))
  63.             return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
  64.  
  65.         $this->dsn $dsninfo;
  66.         $type   $dsninfo['phptype'];
  67.         $user   $dsninfo['username'];
  68.         $pw     $dsninfo['password'];
  69.         $host   $dsninfo['hostspec'];
  70.         $port   = empty($dsninfo['port']? 389 : $dsninfo['port'];
  71.  
  72.         $this->param = array(
  73.             'action' =>     'search',
  74.             'base_dn' =>    $this->base_dn $dsninfo['database'],
  75.             'attributes' => array(),
  76.             'attrsonly' =>  0,
  77.             'sizelimit' =>  0,
  78.             'timelimit' =>  0,
  79.             'deref' =>      LDAP_DEREF_NEVER,
  80.             'attribute' =>  '',
  81.             'value' =>      '',
  82.             'newrdn' =>     '',
  83.             'newparent' =>  '',
  84.             'deleteoldrdn'=>false,
  85.             'sort' =>       '',
  86.         );
  87.         $this->last_param $this->param;
  88.         $this->setOption("seqname_format""sn=%s," $dsninfo['database']);
  89.         $this->fetchmode = DB_FETCHMODE_ASSOC;
  90.  
  91.         if ($host{
  92.             $conn @ldap_connect($host$port);
  93.         else {
  94.             return $this->raiseError("unknown host $host");
  95.         }
  96.         if (!$conn{
  97.             return $this->raiseError(DB_ERROR_CONNECT_FAILED);
  98.         }
  99.         if (!@ldap_set_option($connLDAP_OPT_PROTOCOL_VERSION3)) {
  100.             return $this->raiseError(DB_ERROR_CONNECT_FAILED);
  101.         }
  102.         if ($user && $pw{
  103.             $bind @ldap_bind($conn$user$pw);
  104.         else {
  105.             $bind @ldap_bind($conn);
  106.         }
  107.         if (!$bind{
  108.             return $this->raiseError(DB_ERROR_CONNECT_FAILED);
  109.         }
  110.         $this->connection $conn;
  111.         return DB_OK;
  112.     }
  113.  
  114.     // }}}
  115.  
  116. }
  117.  
  118. ?>

Documentation generated on Mon, 11 Mar 2019 15:41:27 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.