|
Posted by Swapnil D on April 18, 2006, 2:03 am
If you were Registered and logged in, you could reply and use other advanced thread options Hello all,
I already tried posting to microsoft.public.security and
microsoft.public.security.crypto but did
not get a reply. Perhaps someone here can help
Thanks and Regards
Swapnil D.
"Swapnil D" <none> wrote in message
> Hello All,
> Heres how to reproduce the problem. The code is given below(Console
> Application)
>
> 1.Put an valid username, dominmane but INVALID password and connect to an
> REMOTE SQL server. The Connect call fails (this is expected behavior)
> 2. Run the program once again this time with the same domian name and
> username but CORRECT password. The connect call fails the first time
> (Unexpected behavior)
> 3. Run the program again with the same username, domainname and VALID
> password. It works this time (Expected behavior)
>
> I would like to know, why it does not work the first time after a previos
> authentication has failed,
> also is there a workaround for this.
>
> Please remember the the SQL Server is on a REMOTE machine
>
> Please replace
> <username>
> <domainname>
> <password>
> <SQL Server MachineName> with valid names
>
> Regards
> Swapnil D.
>
>
//-------------------------------------------------------------------------------------------------------
> #include "stdafx.h"
>
> #import "C:\Program Files\Microsoft SQL
> Server\Tools\Binn\sqldmo.dll" no_namespace
>
> int main(int argc, char* argv[])
> {
> ::CoInitialize(NULL);
>
> _SQLServerPtr spSQLServer;
> HRESULT hr;
>
> try
> {
> hr = spSQLServer.CreateInstance(__uuidof(SQLServer));
>
> if(FAILED(hr))
> {
> printf("ERROR : Failed in call to CoCreateInstance");
> return 0;
> }
>
> hr = spSQLServer->put_QueryTimeout(60);
> if(FAILED(hr))
> {
> printf("ERROR : Failed in call to spSQLServer->put_QueryTimeout()");
> return 0;
> }
>
> spSQLServer->PutLoginSecure(TRUE);
>
> HANDLE hToken;
>
>
>
if(!::LogonUser("<username>","<domainname>","<password>",LOGON32_LOGON_NEW_CREDENTIALS,
> LOGON32_PROVIDER_WINNT50,&hToken))
> {
> printf("ERROR : Failed in call to ::LogonUser()");
> return 0;
> }
>
> if(!::ImpersonateLoggedOnUser(hToken))
> {
> printf("ERROR : Failed in call to ::ImpersonateLoggedOnUser()");
> return 0;
> }
>
> hr = spSQLServer->Connect(CComVariant("<SQL Server MachineName>"));
> if(FAILED(hr))
> {
> printf("ERROR : Failed in call to spSQLServer->Connect()");
> return 0;
> }
>
> if(!::RevertToSelf())
> {
> printf("ERROR : Failed in call to ::RevertToSelf()");
> return 0;
> }
>
> }
> catch(...)
> {
> hr = spSQLServer->Close();
> if(FAILED(hr))
> printf("ERROR : Failed in call to spSQLServer->Close()");
>
> if(!::RevertToSelf())
> {
> printf("ERROR : Failed in call to ::RevertToSelf()");
> return 0;
> }
> }
> return 0;
> }
>
>
|