GetZoneByPath

Returns a zone object with all of its related Centrify-specific data given its LDAP path.

Syntax

IZone GetZoneByPath(string path)

Parameter

Specify the following parameter when using this method:

Parameter Description

path

The full LDAP path to the individual zone object you want to retrieve.

Return value

If the operation is successful, GetZoneByPath returns the zone object and its related data as Centrify.DirectControl.API.IZone.

Discussion

The LDAP path to a zone uses the following format:

LDAP://[domain/]attr=name,[...],dc=domain_part,[...]

For example, if you use the default parent location for zones in the domain arcade.com, the LDAP path for the “default” zone is:

LDAP://cn=default,cn=zones,cn=Centrify,cn=program data, dc=arcade,dc=com

Note:   The LDAP portion of the path is case sensitive. If you are unsure of the LDAP path for a zone, you can use the adinfo command on any computer in the zone to display the path.

Exceptions

GetZoneByPath may throw one of the following exceptions:

  • COMException if an LDAP error occurs. LDAP errors can occur if the connection to the LDAP server fails, the connection times out, invalid credentials are presented, or there are other problems communicating with Active Directory.
  • ApplicationException if the object cannot be located by the specified path.

Example

The following code sample illustrates using this method in a script:

...
string strUser = args[0];
if (string.IsNullOrEmpty(strUser))
{
    Console.WriteLine("User DN cannot be empty.");
    return;
}
// Obtain an active directory container object
// Cnfigure the test container
DirectoryEntry objRootDSE = new DirectoryEntry("LDAP://rootDSE");
DirectoryEntry objContainer = new DirectoryEntry("LDAP://" + strParent + "," +     objRootDSE.Properties["defaultNamingContext"].Value.ToString());
string strContainerDN = objContainer.Properties["DistinguishedName"].Value as string;
// Create a CIMS object to interact with AD
ICims cims = new Cims();
// Note the lack of the cims.connect function.'
// By default, this application will use the connection to the domain controller
// and existing credentials from the computer already logged in.
IHierarchicalZone objZone =
cims.GetZoneByPath("cn=" + strZone + "," + strContainerDN) as IHierarchicalZone;
IUser objUser = cims.GetUserByPath(strUser);
if (objUser == null)
{
    Console.WriteLine("User " + strUser + " does not exist.");
    return;
}
...