IOPLEX
Communications Software
Plexcel for PHP - Active Directory PHP Integration
plexcel_new
plexcel_status
plexcel_find_authorities_by_domain
plexcel_get_authority
plexcel_get_domain
plexcel_log
plexcel_preamble
plexcel_authenticate
plexcel_sso
plexcel_logon
plexcel_logoff
plexcel_accept_token
plexcel_is_member_of
plexcel_set_password
plexcel_change_password
plexcel_gen_service_keytab
plexcel_search_objects
plexcel_get_account
plexcel_add_object
plexcel_modify_object
plexcel_delete_object
plexcel_rename_object
plexcel_set_attrdefs
plexcel_get_attrdefs
plexcel_set_conv_attrdefs

plexcel_find_authorities_by_domain

Printer Friendly Format

Synopsis

array plexcel_find_authorities_by_domain(string $name, int $nn, int $flags)

Description

The plexcel_find_authorities_by_domain function performs DNS SRV queries for specific services and returns an array of server hostnames.

The $name parameter is the name to be queried. The DNS SRV lookup logic tries successively shorter name suffixes until the name is resolved. See The DNS SRV Lookup Logic section below for details.

If the $name parameter is NULL , the default domain will be queried. The default domain is the domain of the HTTP service account.

The $nn parameter currently is not used and should be 0 .

The $flags parameter specifies the service of interest using the below constants. If multiple flags are bitwise OR'd together, servers providing any of the specified services will be returned.

Flag DNS SRV Lookup Names
PLEXCEL_AUTHORITY_KERBEROS _kerberos._tcp.dc._msdcs.<name> _kerberos._udp.dc._msdcs.<name>
PLEXCEL_AUTHORITY_KPASSWD kpasswd._tcp.<name> _kpasswd._udp.<name>
PLEXCEL_AUTHORITY_LDAP _ldap._tcp.dc._msdcs.<name>
PLEXCEL_AUTHORITY_GC _gc._tcp.<name>
PLEXCEL_AUTHORITY_CHKHOST This flag is special, see below.

The DNS SRV Lookup Logic

The DNS SRV lookup logic tries successively shorter name suffixes until the name is successfully resolved. For example, if there is one Global Catalog server gc1.example.com and the below code is used, the algorithm will try four separate DNS queries:

// if the GC for h1.nyc.us.example.com is gc1.example.com,
// the algorithm tries the following DNS SRV lookups
// _gc._tcp.h1.nyc.us.example.com (not found)
//    _gc._tcp.nyc.us.example.com (not found)
//        _gc._tcp.us.example.com (not found)
//           _gc._tcp.example.com (success -> gc1.example.com)
$name = 'h1.nyc.us.example.com';
$gcs = plexcel_find_authorities_by_domain($name, PLEXCEL_AUTHORITY_GC);
A plexcel_find_authorities_by_domain example with lookup algorithm comments

The PLEXCEL_AUTHORITY_CHKHOST Flag

This PLEXCEL_AUTHORITY_CHKHOST flag indicates that $name is a hostname that should be validated by performing the normal DNS SRV lookup logic but, at each step, checking to see if the $name is in the list of query results. This algorithm verifies that $name does or does not provide the desired service. If $name does provide the service, only $name is returned. If $name was not in a list or no query was successful, FALSE is returned.

This flag is used internally by the LDAP URL binding code to permit it to accept both a hostname and domain name. Use this flag to give your applications the same behavior.

Returns

The plexcel_find_authorities_by_domain function returns an array of server hostnames offering the specified service or FALSE to indicate that no servers were found.

Example

The following PHP script determined when the user bcarter last logged on by queries each domain controller for the user's lastLogon attribute (the lastLogon attribute is not replicated and therefore all domain controllers must be queried separately).

<?php
$name = 'bcarter';
$host = '';
$lastLogon = 0;


        $dcs = plexcel_find_authorities_by_domain(NULL,
      

                    0,
      

                    PLEXCEL_AUTHORITY_LDAP);
      
$attrdefs = array(
    'lastLogon' => array(
        'type' => PLEXCEL_TYPE_INT64,
        'flags' => PLEXCEL_SINGLE_VALUED,
        'conv' => PLEXCEL_CONV_TIME1970M_X_TIME1601));
foreach ($dcs as $dc) {
    $px = plexcel_new($dc, NULL);
    // normalize lastLogon to milliseconds since 1970 for use with date()
    plexcel_set_attrdefs($px, $attrdefs);
    $acct = plexcel_get_account($px, $name, array('lastLogon'));
    if (isset($acct['lastLogon']) && $acct['lastLogon'] > $lastLogon) {
        $host = $dc;
        $lastLogon = $acct['lastLogon'];
    }
}
echo "$name last logged onto $host on " . date('M j, Y g:i:s A', $lastLogon / 1000.0);
?>
Properly determining the lastLogon time with plexcel_find_authorities_by_domain
© 2008 IOPLEX Software | Contact Us | Policies