Beispiel #1
0
        /// <summary>
        /// Convert SPN to a string.
        /// </summary>
        /// <returns>The SPN string.</returns>
        public override string ToString()
        {
            int        length = 0;
            Win32Error err    = SecurityNativeMethods.DsMakeSpn(ServiceClass, ServiceName, InstanceName,
                                                                (ushort)InstancePort, Referrer, ref length, null);

            if (err == Win32Error.SUCCESS)
            {
                return(string.Empty);
            }
            if (err != Win32Error.ERROR_BUFFER_OVERFLOW)
            {
                throw new NtException(err.MapDosErrorToStatus());
            }
            StringBuilder builder = new StringBuilder(length);

            SecurityNativeMethods.DsMakeSpn(ServiceClass, ServiceName, InstanceName,
                                            (ushort)InstancePort, Referrer, ref length, builder).ToNtException();
            return(builder.ToString());
        }