---
name: "ldap_is_dns_dn"
section: "3"
platform: "linux"
package: "libopenldap-dev"
version: "1:1.2.12-1"
release: "Debian 2.2 (Potato)"
platforms: ["linux"]
url: "https://new.carta.tech/ldap_get_dn"
---

# ldap\_is\_dns\_dn(3)

LDAP DN handling routines

Part of [ldap\_get\_dn(3)](/ldap_get_dn/3.md).

## NAME

ldap\_get\_dn, ldap\_explode\_dn, ldap\_dn2ufn, ldap\_is\_dns\_dn, ldap\_explode\_dns - LDAP DN handling routines

## SYNOPSIS

```
#include <lber.h>
#include <ldap.h>
```

**char \*ldap\_get\_dn(ld, entry)** **LDAP \*ld;** **LDAPMessage \*entry;**

**char \*\*ldap\_explode\_dn(dn, notypes)** **char \*dn;** **int notypes;**

**char \*ldap\_dn2ufn(dn)** **char \*dn;**

**int ldap\_is\_dns\_dn(dn)** **char \*dn;**

**char \*\*ldap\_explode\_dns(dn)** **char \*dn;**

## DESCRIPTION

**These routines allow LDAP entry names (Distinguished Names, or DNs)** **to be obtained, parsed, converted to a user-friendly form, and tested.** **A DN has the form described in RFC 1779 "A String Representation of** **Distinguished Names", unless it is an experimental DNS-style DN** **which takes the form of an RFC 822 mail address.**

**The** **ldap\_get\_dn()** **routine takes an** *entry* **as returned by** [**ldap\_first\_entry**(3)](/ldap_first_entry/3.md) **or** [**ldap\_next\_entry**(3)](/ldap_next_entry/3.md) **and returns a copy of** **the entry's DN.  Space for the DN will have been obtained via** [**malloc**(3)](/malloc/3.md), **and should be freed by the caller by a call to** [**free**(3)](/free/3.md).

**The** **ldap\_explode\_dn()** **routine takes a DN as returned by** **ldap\_get\_dn()** **and breaks it up into its component parts.  Each part is known as a** **Relative Distinguished Name, or RDN.** **ldap\_explode\_dn()** **returns a** **NULL-terminated array, each component of which contains an RDN from the** **DN.  The** *notypes* **parameter is used to request that only the RDN** **values be returned, not their types.  For example, the DN "cn=Bob,** **c=US" would return as either { "cn=Bob", "c=US", NULL } or { "Bob",** **"US", NULL }, depending on whether notypes was 0 or 1, respectively.** **The result can be freed by calling** [**ldap\_value\_free**(3)](/ldap_value_free/3.md).

**ldap\_dn2ufn()** **is used to turn a DN as returned by** **ldap\_get\_dn()** **into a more user-friendly form, stripping off type names.  See** **RFC 1781 "Using the Directory to Achieve User Friendly Naming"** **for more details on the UFN format.  The space for the UFN returned** **is obtained by a call to** [**malloc**(3)](/malloc/3.md), **and the user is responsible for freeing it via a call to** [**free**(3)](/free/3.md).

**ldap\_is\_dns\_dn()** **returns non-zero if the dn string is an experimental** **DNS-style DN (generally in the form of an RFC 822 e-mail address).  It** **returns zero if the dn appears to be an RFC 1779 format DN.**

**ldap\_explode\_dns()** **takes a DNS-style DN and breaks it up into its** **component parts.** **ldap\_explode\_dns()** **returns a NULL-terminated array.** **For example, the DN "mcs.umich.edu" will return { "mcs", "umich", "edu",** **NULL }.  The result can be freed by calling** [**ldap\_value\_free**(3)](/ldap_value_free/3.md).

## ERRORS

**If an error occurs in** **ldap\_get\_dn()**, **NULL is returned and the** **ld\_errno** **field in the** *ld* **parameter is set to indicate the error.  See** [**ldap\_error**(3)](/ldap_error/3.md) **for a description of possible error codes.** **ldap\_explode\_dn()**, **ldap\_explode\_dns()** **and** **ldap\_dn2ufn()** **will return NULL with** [**errno**(3)](/errno/3.md) **set appropriately in case of trouble.**

## NOTES

**These routines malloc memory that the caller must free.**

## SEE ALSO

**[ldap(3)](/ldap/3.md),** **[ldap\_first\_entry(3)](/ldap_first_entry/3.md),** **[ldap\_error(3)](/ldap_error/3.md),** **[ldap\_value\_free(3)](/ldap_value_free/3.md)**

## ACKNOWLEDGEMENTS

**OpenLDAP** **is developed and maintained by The OpenLDAP Project (http://www.openldap.org/).** **OpenLDAP** **is derived from University of Michigan LDAP 3.3 Release.**
