Invalid handle from InitializeSecurityContext

Announcements and discussion for PInvoke

Invalid handle from InitializeSecurityContext

Postby Hariharasudhan » Thu Mar 04, 2010 6:29 pm

Hi All,

I went thorugh the code in ... ityContext

Instead of kerberos authentication, i wish to implement Windows authentication . I modifed the AcquireCredentials method as follows:

Code: Select all
returnValue = AcquireCredentialsHandle(_sAccountName, "NTLM", SECPKG_CRED_OUTBOUND,
                                                           HANDLE.Zero, HANDLE.Zero, HANDLE.Zero, HANDLE.Zero,
                                                           ref _hOutboundCred, ref ClientLifeTime);

I got returnvalue zero for above method call.

But the initializeSecurityContext returns SEC_E_INVALID_HANDLE. Please see below code :

Code: Select all
ss = InitializeSecurityContext(ref _hOutboundCred,
                       _sAccountName, // null string pszTargetName,
                        0,//int Reserved1,
                        SECURITY_NETWORK_DREP, //int TargetDataRep
                        IntPtr.Zero,    //Always zero first time around...
                        0, //int Reserved2,
                        out _hClientContext, //pHandle CtxtHandle = SecHandle
                        out ClientToken,//ref SecBufferDesc pOutput, //PSecBufferDesc
                        out ContextAttributes,//ref int pfContextAttr,
                        out ClientLifeTime); //ref IntPtr ptsExpiry ); //PTimeStamp

Please help me in this regard.
Posts: 1
Joined: Thu Mar 04, 2010 6:09 pm

Postby Paul.Martin » Wed Mar 10, 2010 6:10 pm

SEC_E_INVALID_HANDLE will be returned if the _hOutboundCred handle is either null or is not valid.
The one thing to check if you are basing your code on the example is that both the client and server are using NTLM authenitication.

If this is not the problem then let us know and we can look a bit deeper into your code.
Posts: 83
Joined: Wed Feb 03, 2010 10:20 am
Location: Cambridgeshire

Return to PInvoke.Net

Who is online

Users browsing this forum: No registered users and 0 guests