4.1.4.2.14 LookupSPN

 procedure LookupSPN(flags: DWORD, name: unicodestring): set of DSName

Informative summary of behavior: LookupSPN is a helper function that implements the service principal name (SPN) lookup algorithm.

  
 rt: set of DSName
 obj: DSName
 dcGuid: GUID
 spnMappings: set of unicodestring
 mappedSpn: unicodestring
  
 /* First, try to look up the SPN directly. */
 rt := LookupAttr(flags, servicePrincipalName, name)
 if rt ≠ null then
   return rt
 endif
  
 /* Obtain SPN mappings value. */
 obj := DescendantObject(ConfigNC(), 
     "CN=Directory Service,CN=Windows NT,CN=Services,")
 spnMappings := obj!sPNMappings
 if spnMappings ≠ null
   mappedSpn := MapSPN(name, spnMappings)
   if mappedSpn ≠ null then
     /* try to lookup a mapped SPN */
     rt := LookupAttr(flags, servicePrincipalName, mappedSpn)
     if rt ≠ null then
       return rt
     endif
   endif
 endif
 /* Try to find replication SPN, which might not be present in our
  * NC replicas yet. */
 if GetServiceClassFromSPN(name) = DRS_SPN_CLASS and
     GetServiceNameFromSPN(name) = 
       DomainNameFromDN(DefaultNC()!distinguishedName) then
   /* Yes, it looks like a replication SPN. Try to find DC by guid. */
   dcGuid := GuidFromString(false, GetInstanceNameFromSPN(name))
   if dcGuid ≠ null then
     /* Find DSA object with this objectGUID value. */
     obj := select one o from subtree ConfigNC()
         where o!objectGUID = dcGuid
     if obj ≠ null then
       /* Get the server object. */
       obj := obj!parent
       if obj ≠ null then
         /* server!serverReference points to the DC's computer
          * object.*/
         rt := {obj!serverReference}
       endif
     endif
   endif
 endif
  
 return rt