Class abook_ldap_server

Description

Address book backend for LDAP server

An array with the following elements must be passed to the class constructor (elements marked ? are optional)

Main settings:

    host      => LDAP server hostname, IP-address or any other URI compatible
                 with used LDAP library.
    base      => LDAP server root (base dn). Empty string allowed.
  ? port      => LDAP server TCP port number (default: 389)
  ? charset   => LDAP server charset (default: utf-8)
  ? name      => Name for LDAP server (default "LDAP: hostname")
                 Used to tag the result data
  ? maxrows   => Maximum # of rows in search result
  ? timeout   => Timeout for LDAP operations (in seconds, default: 30)
                 Might not work for all LDAP libraries or servers.
  ? binddn    => LDAP Bind DN.
  ? bindpw    => LDAP Bind Password.
  ? protocol  => LDAP Bind protocol.
Advanced settings:
  ? filter    => Filter expression to limit ldap search results.
    You can use this to *limit* the result set, based on specific
    requirements. The filter must be enclosed in parentheses, e.g.:
    '(objectclass=mailRecipient)'
    or '(&(objectclass=mailRecipient)(obectclass=myCustomClass))'
    The default value is empty.

  ? search_expression => Custom expression to expand ldap searches.
    This can help *expand* the result set, because of hits in more
    LDAP attributes. It must be a printf()-style string with either
    one placeholder '%s', or, if you want to repeat the expression
    many times, '%1$s'. The default value is:
    '(|(cn=*%1$s*)(mail=*%1$s*)(sn=*%1$s*))'
    that is, the search expression is search in the fields cn (common
    name), sn (surname) and mail.

  ? limit_scope => Limits scope to base DN (Specific to Win2k3 ADS).
  ? listing   => Controls listing of LDAP directory.
  ? writeable => Controls write access to address book
  ? search_tree => Controls subtree or one level search.
  ? starttls  => Controls use of StartTLS on LDAP connections
NOTE. This class should not be used directly. Use addressbook_init() function instead.

Located in /functions/abook_ldap_server.php (line 79)

addressbook_backend
   |
   --abook_ldap_server
Variable Summary
string $basedn
string $binddn
string $bindpw
string $bname
bool $bound
string $btype
string $charset
string $filter
boolean $limit_scope
object PHP $linkid
boolean $listing
integer $maxrows
integer $port
integer $protocol
boolean $search_tree
string $server
string $sname
boolean $starttls
integer $timeout
boolean $writeable
Method Summary
abook_ldap_server abook_ldap_server (array $param)
abook_ldap_server __construct (array $param)
boolean add (array $userdata)
string charset_decode (string $str)
string charset_encode (string $str)
string get_attr_name (integer $attr)
string ldapspecialchars (string $string)
boolean ldap_add (string $dn, array $data)
string ldap_error (string $sError)
bool ldap_modify (string $dn, array $data, array $deleted_attribs)
boolean ldap_remove (string $dn)
boolean ldap_rename (string $sourcedn, string $targetdn, string $parent)
array ldap_search (string $expression, [boolean $singleentry = false])
array list_addr ()
array lookup (string $value, [integer $field = SM_ABOOK_FIELD_NICKNAME])
boolean modify (string $alias, array $userdata)
bool open ([bool $new = false])
string quotevalue (string $string)
boolean remove (array $aliases)
array search (string $expr)
Variables
string $basedn = '' (line 105)
  • var: LDAP base DN
string $binddn = '' (line 141)
  • var: DN to bind to (non-anonymous bind)
  • since: 1.5.0 and 1.4.3
string $bindpw = '' (line 146)
  • var: password to bind with (non-anonymous bind)
  • since: 1.5.0 and 1.4.3
string $bname = 'ldap_server' (line 87)
  • var: backend name

Redefinition of:
addressbook_backend::$bname
Internal backend name
bool $bound = false (line 117)
  • var: True if LDAP server is bound
string $btype = 'remote' (line 83)
  • var: backend type

Redefinition of:
addressbook_backend::$btype
Backend type
string $charset = 'utf-8' (line 109)
  • var: charset used for entries in LDAP server
string $filter = '' (line 126)
  • var: ldap filter
  • since: 1.5.1
boolean $limit_scope = false (line 156)
  • var: limits scope to base dn
  • since: 1.5.1
object PHP $linkid = false (line 113)
  • var: LDAP link ID
boolean $listing = false (line 161)
  • var: controls listing of directory
  • since: 1.5.1
integer $maxrows = 250 (line 121)
  • var: max rows in result
integer $port = 389 (line 101)
  • var: LDAP server port
integer $protocol = '' (line 151)
  • var: protocol used to connect to ldap server
  • since: 1.5.0 and 1.4.3
string $search_expression = '(|(cn=*%1$s*)(mail=*%1$s*)(sn=*%1$s*))' (line 132)
  • var: printf()-style ldap search expression. The default is to search for same string in cn, mail and sn.
  • since: 1.5.2
boolean $search_tree = true (line 172)
  • var: controls ldap search type. only first level entries are displayed if set to false
  • since: 1.5.1
string $server = '' (line 97)
  • var: LDAP server name or address or url
string $sname = 'LDAP' (line 93)
  • var: displayed name

Redefinition of:
addressbook_backend::$sname
Displayed backend name
boolean $starttls = false (line 178)
  • var: controls use of StartTLS on ldap connections. Requires php 4.2+ and protocol >= 3
  • since: 1.5.1
integer $timeout = 30 (line 136)
  • var: timeout of LDAP operations (in seconds)
boolean $writeable = false (line 166)
  • var: true if removing/adding/modifying entries is allowed
  • since: 1.5.2

Redefinition of:
addressbook_backend::$writeable
Writeable flag

Inherited Variables

Inherited from addressbook_backend

addressbook_backend::$bnum
addressbook_backend::$error
Methods
Constructor abook_ldap_server (line 264)

Constructor (PHP4 style, kept for compatibility reasons)

Connects to the database

abook_ldap_server abook_ldap_server (array $param)
  • array $param: connection options
Constructor __construct (line 185)

Constructor (PHP5 style, required in some future version of PHP)

Connects to the database

abook_ldap_server __construct (array $param)
  • array $param: connection options
add (line 828)

Add address

  • since: 1.5.2
boolean add (array $userdata)
  • array $userdata: new data

Redefinition of:
addressbook_backend::add()
Add entry to backend
charset_decode (line 377)

Decode from charset used by this LDAP server to charset used by translation

Uses SquirrelMail charset_decode functions

  • return: decoded string
string charset_decode (string $str)
  • string $str: string that has to be decoded
charset_encode (line 361)

Encode string to the charset used by this LDAP server

  • return: encoded string
string charset_encode (string $str)
  • string $str: string that has to be encoded
get_attr_name (line 695)

Determine internal attribute name given one of the SquirrelMail SM_ABOOK_FIELD_* constants

  • return: The desired attribute name, or the string "ERROR" if the $field is not understood (the caller is responsible for handing errors)
string get_attr_name (integer $attr)
  • integer $attr: The SM_ABOOK_FIELD_* contant to look up
ldapspecialchars (line 394)

Sanitizes ldap search strings.

See rfc2254

string ldapspecialchars (string $string)
  • string $string
ldap_add (line 555)

Add an entry to LDAP server.

Warning: You must make sure that the arguments are correctly formated and sanitize use of special ldap keywords.

  • return: result (false on error)
  • since: 1.5.2
boolean ldap_add (string $dn, array $data)
  • string $dn: the dn of the entry to be added
  • array $data: the values of the entry to be added
ldap_error (line 672)

Get error from LDAP resource if possible

Should get error from server using the ldap_errno() and ldap_err2str() functions

  • return: error message
  • since: 1.5.1
string ldap_error (string $sError)
  • string $sError: error message used when ldap error functions and connection resource are unavailable
ldap_modify (line 644)

Modify the values of an entry on LDAP server.

Warning: You must make sure that the arguments are correctly formated and sanitize use of special ldap keywords.

  • return: result (false on error)
  • since: 1.5.2
bool ldap_modify (string $dn, array $data, array $deleted_attribs)
  • string $dn: the dn of the entry to be modified
  • array $data: the new values of the entry
  • array $deleted_attribs: attributes that should be deleted.
ldap_remove (line 578)

Remove an entry from LDAP server.

Warning: You must make sure that the argument is correctly formated and sanitize use of special ldap keywords.

  • return: result (false on error)
  • since: 1.5.2
boolean ldap_remove (string $dn)
  • string $dn: the dn of the entry to remove
ldap_rename (line 603)

Rename an entry on LDAP server.

Warning: You must make sure that the arguments are correctly formated and sanitize use of special ldap keywords.

  • return: result (false on error)
  • since: 1.5.2
boolean ldap_rename (string $sourcedn, string $targetdn, string $parent)
  • string $sourcedn: the dn of the entry to be renamed
  • string $targetdn: the dn which $sourcedn should be renamed to
  • string $parent: the dn of the parent entry
ldap_search (line 430)

Search LDAP server.

Warning: You must make sure that ldap query is correctly formated and sanitize use of special ldap keywords.

  • return: search results (false on error)
  • since: 1.5.1
array ldap_search (string $expression, [boolean $singleentry = false])
  • string $expression: ldap query
  • boolean $singleentry: (since 1.5.2) whether we are looking for a single entry. Boolean true forces LDAP_SCOPE_BASE search.
list_addr (line 807)

List all entries present in LDAP server

maxrows setting might limit list of returned entries. Careful with this -- it could get quite large for big sites.

  • return: all entries in ldap server
array list_addr ()

Redefinition of:
addressbook_backend::list_addr()
List all entries in backend
lookup (line 781)

Lookup an address by the indicated field.

  • return: Array with lookup results when the value was found, an empty array if the value was not found.
  • since: 1.5.2
array lookup (string $value, [integer $field = SM_ABOOK_FIELD_NICKNAME])
  • string $value: The value to look up
  • integer $field: The field to look in, should be one of the SM_ABOOK_FIELD_* constants defined in include/constants.php (OPTIONAL; defaults to nickname field) NOTE: uniqueness is only guaranteed when the nickname field is used here; otherwise, the first matching address is returned.

Redefinition of:
addressbook_backend::lookup()
Find entry in backend by the indicated field
modify (line 900)

Modify address

  • since: 1.5.2
boolean modify (string $alias, array $userdata)
  • string $alias: modified alias
  • array $userdata: new data

Redefinition of:
addressbook_backend::modify()
Modify entry in backend
open (line 273)

Open the LDAP server.

bool open ([bool $new = false])
  • bool $new: is it a new connection
quotevalue (line 414)

Prepares user input for use in a ldap query.

Function converts input string to character set used in LDAP server (charset_encode() method) and sanitizes it (ldapspecialchars()).

  • return: ldap encoded string
  • since: 1.5.2
string quotevalue (string $string)
  • string $string: string to encode
remove (line 876)

Delete address

  • since: 1.5.2
boolean remove (array $aliases)
  • array $aliases: array of entries that have to be removed.

Redefinition of:
addressbook_backend::remove()
Remove entry from backend
search (line 719)

Search the LDAP server

  • return: search results
array search (string $expr)
  • string $expr: search expression

Redefinition of:
addressbook_backend::search()
Search for entries in backend

Inherited Methods

Inherited From addressbook_backend

addressbook_backend::add()
addressbook_backend::fullname()
addressbook_backend::list_addr()
addressbook_backend::lookup()
addressbook_backend::modify()
addressbook_backend::remove()
addressbook_backend::search()
addressbook_backend::set_error()

Documentation generated on Mon, 13 Jan 2020 04:21:55 +0100 by phpDocumentor 1.4.3