Platform SDK: Active Directory, ADSI, and Directory Services

Composing the SPNs for a Service with an SCP

The following code fragment composes an SPN for a service that uses a service connection point. The returned SPN has the following format:

ServiceClass/host/ServiceName

where ServiceClass and ServiceName correspond to the pszDNofSCP and pszServiceClass parameters. In this example, host defaults to the DNS name of the local computer.

DWORD
SpnCompose(
    TCHAR ***pspn,          // Output: an array of SPNs
    unsigned long *pulSpn,  // Output: the number of SPNs returned
    TCHAR *pszDNofSCP,      // Input: DN of the service's SCP
    TCHAR* pszServiceClass) // Input: the name of the service's class
{
DWORD   dwStatus;    
 
dwStatus = DsGetSpn(
    DS_SPN_SERVICE,   // Type of SPN to create (enumerated type)
    pszServiceClass,  // Service class - a name in this case
    pszDNofSCP,       // Service name - DN of the service's SCP
    0,                // Default: omit port component of SPN
    0,                // Number of entries in hostnames and ports arrays
    NULL,             // Array of hostnames. Default is local computer
    NULL,             // Array of ports. Default omits port component
    pulSpn,           // Receives number of SPNs returned in array
    pspn              // Receives array of SPN(s)
    );
 
return dwStatus;
}