Article View: borland.public.cppbuilder.nativeapi
Article #7678Re: user impersonation
From: Costin
Date: Fri, 07 Jan 2005 12:05
Date: Fri, 07 Jan 2005 12:05
29 lines
2441 bytes
2441 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:41ddc480$2@newsgroups.borland.com...
>
> "Costin" <decbis@yahoo.com> wrote in message
> news:41ddbfd3@newsgroups.borland.com...
>
>> 1. LogonUser & ImpersonateLoggedOnUser both succeed (valid user/pass)
>> 2. RegConnectRegistry fails with ACCESS DENIED (user does not have
>> enough rights)
>> 3. This will still happend even if I supply the user/pass of a user
>> with
>> enough rights.
>
> Did you remove the impersonation each time?
>
>
> Gambit
>
>
Yes.
Here is a typical code sequence:
//---------------------------------------------------------------------------
bool __fastcall ImpersonateUser(String UserName,String UserPassword,String
UserDomain,HANDLE&token){
if(!LogonUser(UserName.c_str(),UserDomain.c_str(),UserPassword.c_str(),LOGON32_LOGON_INTERACTIVE/*LOGON32_LOGON_NETWORK*/,LOGON32_PROVIDER_DEFAULT,&token)){ token=NULL; return false; } if(!ImpersonateLoggedOnUser(token)){ token=NULL; return false; } return true;}//---------------------------------------------------------------------------HANDLE token;bool rez;DWORD drez;HKEY hk;rez=ImpersonateUser(User,Password,Domain,token);if(rez){ drez=RegConnectRegistry(Address,HKEY_LOCAL_MACHINE,&hk); if(drez==ERROR_SUCCESS) RegCloseKey(hk); ShowMessage(SysErrorMessage(drez));}if(token) CloseHandle(token);
Technical Details
Message-ID:
<41de7bc9@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<41ddbfd3@newsgroups.borland.com> <41ddc480$2@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,c4e8c83fb5b37558 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Costin" <decbis@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <41ddbfd3@newsgroups.borland.com> <41ddc480$2@newsgroups.borland.com> Subject: Re: user impersonation Date: Fri, 7 Jan 2005 14:05:01 +0200 Lines: 30 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 82.208.172.102 Message-ID: <41de7bc9@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1105099721 82.208.172.102 (7 Jan 2005 04:08:41 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail