<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SEC_E_INVALID_HANDLE error in InitializeClient()  while trying to do LoginBySSPI() in vSphere Command-Line Interface Discussions</title>
    <link>https://communities.vmware.com/t5/vSphere-Command-Line-Interface/SEC-E-INVALID-HANDLE-error-in-InitializeClient-while-trying-to/m-p/267349#M23</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The PowerCLI forum is located at: &lt;A href="https://communities.vmware.com/c-3256"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The forum you're currently posting in is vCLI&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;=========================================================================&lt;/P&gt;&lt;P&gt;William Lam&lt;/P&gt;&lt;P&gt;VMware vExpert 2009&lt;/P&gt;&lt;P&gt;VMware ESX/ESXi scripts and resources at: &lt;A href="http://engineering.ucsb.edu/~duonglt/vmware/"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.vmware.com/d-9852"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.vmware.com/c-3075"&gt;VMware Code Central - Scripts/Sample code for Developers and Administrators&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.vmware.com/c-2414"&gt;VMware Developer Comuunity&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://twitter.com/lamw"&gt;Twitter: @lamw&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG src="http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you find this information useful, please award points for "correct" or "helpful".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 23 Oct 2009 22:34:18 GMT</pubDate>
    <dc:creator>lamw</dc:creator>
    <dc:date>2009-10-23T22:34:18Z</dc:date>
    <item>
      <title>SEC_E_INVALID_HANDLE error in InitializeClient()  while trying to do LoginBySSPI()</title>
      <link>https://communities.vmware.com/t5/vSphere-Command-Line-Interface/SEC-E-INVALID-HANDLE-error-in-InitializeClient-while-trying-to/m-p/267348#M22</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to login to my VMware vSphere 4 server using the PowerCLI api.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The purpose of the project is to automatically take snapshot of the virtual machines. However the purpose is accomplished. But before moving to production, we had to change from Login() to LoginBySSPI() for enabling integrated login.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At this point, the problem arose. Whatever, I do it does not login, fromt he vmware forum i understood that the sspichallenge code should be sent again to be authenticated. When i do that it throws the SEC_E_INVALID_HANDLE error at the initializeClient() function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; code snippet is as follows&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I get error in the InitializeClient() function when it is called the second time from the catch section,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in the first call to InitializeClient(), i get the clientToken of byte[55]&lt;/P&gt;&lt;P&gt;and then when i pass it to loginbysspi i get the sspichallenge exception, from which i get the base64token and again pass to the initializeclient() so that i can get the server token and eventually pass to the LoginbySSPI(), but this time it fails at &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if (&lt;SPAN __default_attr="#ff0000" __jive_macro_name="color"&gt;ss != SEC_E_OK &amp;amp;&amp;amp; ss != SEC_I_CONTINUE_NEEDED&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;throw new Exception("InitializeSecurityContext() failed!!!");&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;SPAN __default_attr="#ff0000" __jive_macro_name="color"&gt;with ss = -2146893055&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;below is the code.... &lt;BR /&gt; VimClient VMClient; &lt;BR /&gt; SessionManager sm; &lt;BR /&gt; private void button1_Click(object sender, EventArgs e) &lt;BR /&gt; { &lt;BR /&gt; try &lt;BR /&gt; { &lt;BR /&gt; VMClient = new VimClient(); &lt;BR /&gt; VMClient.Connect("vmware", CommunicationProtocol.Https, 443);&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;var tokenString = Convert.ToBase64String(net.sf.vitfordotnet.mo.Sessionmanager.getToken()); &lt;BR /&gt; DoLogin(tokenString);&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;sm = new SessionManager(VMClient, VMClient.ServiceContent.SessionManager); &lt;BR /&gt; sm.LoginBySSPI(tokenString, null); &lt;BR /&gt; } &lt;BR /&gt; catch (VMware.Vim.VimException ex) &lt;BR /&gt; { &lt;BR /&gt; var mf = ex.MethodFault; &lt;BR /&gt; // There was a challenge (response)! &lt;BR /&gt; if (mf is SSPIChallenge) &lt;BR /&gt; { &lt;BR /&gt; var sc = (SSPIChallenge)mf; &lt;BR /&gt; var st_b64 = sc.Base64Token; &lt;BR /&gt; byte[] st = null; &lt;BR /&gt; byte[] ct; &lt;BR /&gt; bool cc; &lt;BR /&gt; st = Convert.FromBase64String(st_b64); &lt;BR /&gt; // Complete the credentials acquisition, this time with &lt;BR /&gt; // the second part of the package. &lt;BR /&gt; var ch = new SSPIHelper(); &lt;BR /&gt; ch.InitializeClient(out ct, st, out cc); &lt;BR /&gt; var ct_b64 = Convert.ToBase64String(ct); &lt;BR /&gt; DoLogin(ct_b64); &lt;BR /&gt; } &lt;BR /&gt; } &lt;BR /&gt; NameValueCollection filter = new NameValueCollection(); &lt;BR /&gt; filter.Add("name", "^" + "CG001876" + "$"); &lt;BR /&gt; VirtualMachine vm = (VirtualMachine)VMClient.FindEntityView(typeof(VirtualMachine), null, filter, null); &lt;BR /&gt; } &lt;BR /&gt; public void DoLogin(string tokenStr) &lt;BR /&gt; { &lt;BR /&gt; SessionManager sm = new SessionManager(VMClient, VMClient.ServiceContent.SessionManager); &lt;BR /&gt; UserSession us = sm.LoginBySSPI(tokenStr, null); &lt;BR /&gt; }&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Oct 2009 14:46:34 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/vSphere-Command-Line-Interface/SEC-E-INVALID-HANDLE-error-in-InitializeClient-while-trying-to/m-p/267348#M22</guid>
      <dc:creator>vinubaby</dc:creator>
      <dc:date>2009-10-23T14:46:34Z</dc:date>
    </item>
    <item>
      <title>Re: SEC_E_INVALID_HANDLE error in InitializeClient()  while trying to do LoginBySSPI()</title>
      <link>https://communities.vmware.com/t5/vSphere-Command-Line-Interface/SEC-E-INVALID-HANDLE-error-in-InitializeClient-while-trying-to/m-p/267349#M23</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The PowerCLI forum is located at: &lt;A href="https://communities.vmware.com/c-3256"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The forum you're currently posting in is vCLI&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;=========================================================================&lt;/P&gt;&lt;P&gt;William Lam&lt;/P&gt;&lt;P&gt;VMware vExpert 2009&lt;/P&gt;&lt;P&gt;VMware ESX/ESXi scripts and resources at: &lt;A href="http://engineering.ucsb.edu/~duonglt/vmware/"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.vmware.com/d-9852"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.vmware.com/c-3075"&gt;VMware Code Central - Scripts/Sample code for Developers and Administrators&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.vmware.com/c-2414"&gt;VMware Developer Comuunity&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://twitter.com/lamw"&gt;Twitter: @lamw&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG src="http://engineering.ucsb.edu/~duonglt/vmware/vexpert_silver_icon.jpg" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you find this information useful, please award points for "correct" or "helpful".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Oct 2009 22:34:18 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/vSphere-Command-Line-Interface/SEC-E-INVALID-HANDLE-error-in-InitializeClient-while-trying-to/m-p/267349#M23</guid>
      <dc:creator>lamw</dc:creator>
      <dc:date>2009-10-23T22:34:18Z</dc:date>
    </item>
  </channel>
</rss>

