Beispiel #1
0
        /// <summary>
        ///  returns the handle for the given credentials.
        ///  The method returns an invalid handle if the username is null or empty.
        /// </summary>
        public static SafeGssCredHandle Create(string username, string password, bool isNtlmOnly)
        {
            if (string.IsNullOrEmpty(username))
            {
                return(new SafeGssCredHandle());
            }

            SafeGssCredHandle retHandle = null;

            using (SafeGssNameHandle userHandle = SafeGssNameHandle.CreateUser(username))
            {
                Status status;
                Status minorStatus;
                if (string.IsNullOrEmpty(password))
                {
                    status = InitiateCredSpNego(out minorStatus, userHandle, out retHandle);
                }
                else
                {
                    status = InitiateCredWithPassword(out minorStatus, isNtlmOnly, userHandle, password, Encoding.UTF8.GetByteCount(password), out retHandle);
                }

                if (status != Status.GSS_S_COMPLETE)
                {
                    retHandle.Dispose();
                    throw new GssApiException(status, minorStatus);
                }
            }

            return(retHandle);
        }
Beispiel #2
0
        /// <summary>
        ///  returns the handle for the given credentials.
        ///  The method returns an invalid handle if the username is null or empty.
        /// </summary>
        public static SafeGssCredHandle Create(string username, string password, bool isNtlmOnly)
        {
            if (isNtlmOnly && !s_IsNtlmInstalled.Value)
            {
                throw new Interop.NetSecurityNative.GssApiException(
                          Interop.NetSecurityNative.Status.GSS_S_BAD_MECH,
                          0,
                          SR.net_gssapi_ntlm_missing_plugin);
            }

            if (string.IsNullOrEmpty(username))
            {
                return(new SafeGssCredHandle());
            }

            SafeGssCredHandle retHandle = null;

            using (SafeGssNameHandle userHandle = SafeGssNameHandle.CreateUser(username))
            {
                Interop.NetSecurityNative.Status status;
                Interop.NetSecurityNative.Status minorStatus;
                if (string.IsNullOrEmpty(password))
                {
                    status = Interop.NetSecurityNative.InitiateCredSpNego(out minorStatus, userHandle, out retHandle);
                }
                else
                {
                    status = Interop.NetSecurityNative.InitiateCredWithPassword(out minorStatus, isNtlmOnly, userHandle, password, Encoding.UTF8.GetByteCount(password), out retHandle);
                }

                if (status != Interop.NetSecurityNative.Status.GSS_S_COMPLETE)
                {
                    retHandle.Dispose();
                    throw new Interop.NetSecurityNative.GssApiException(status, minorStatus, null);
                }
            }

            return(retHandle);
        }