🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #13215

Re: Testing Admin rights...

#13215
From: Remy Lebeau (TeamB)
Date: Sat, 25 Oct 2003 02:45
88 lines
4135 bytes
"Mike Collins" <mikec@kr8.co.uk> wrote in message
news:3f99d8fe$1@newsgroups.borland.com...

> Is there any way to test if the currently logged on user has
> Administration privileges (other than coding some hack like
> trying to assign full access to a TRegistry object and checking
> if / why it failed :-)

Look for a process that is running under the user's account (such as
explorer.exe or even your own app), extract its associated Access Token that
is assigned by the OS, and then extract the SID description from it and see
if it belongs to the Admin group.  For example:

    bool IsAdmin(void)
    {
        HANDLE hAccessToken = NULL;
        PTOKEN_GROUPS ptgGroups = NULL;
        DWORD dwInfoBufferSize = 0;
        PSID psidAdministrators = NULL;
        SID_IDENTIFIER_AUTHORITY siaNtAuthority = SECURITY_NT_AUTHORITY;
        bool bIsAdmin = false;

        // Open the security token associated with this process
        if( OpenProcessToken(GetCurrentProcess(), TOKEN_READ,
&hAccessToken) )
        {
            // Try to get group information associated with this process
            GetTokenInformation(hAccessToken, TokenGroups, NULL, 0,
&dwInfoBufferSize);
            if( dwInfoBufferSize )
            {
                ptgGroups = (PTOKEN_GROUPS) GlobalAlloc(GPTR,
dwInfoBufferSize);
                if( ptgGroups )
                {
                    if( GetTokenInformation(hAccessToken, TokenGroups,
ptgGroups, dwInfoBufferSize, &dwInfoBufferSize) )
                    {
                        // Allocate/Initialise a security descriptor with
information about admin rights
                        if( AllocateAndInitializeSid(&siaNtAuthority, 2,
SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
&psidAdministrators) )
                        {
                            // Check this processes rights against those of
an admin
                            for(UINT i = 0; i < ptgGroups->GroupCount; ++i)
                            {
                                if( EqualSid(psidAdministrators,
ptgGroups->Groups[i].Sid) )
                                {
                                    bIsAdmin = true;
                                    break;
                                }
                            }

                            // Free the descriptor
                            FreeSid(psidAdministrators);
                        }
                    }

                    // free token group info
                    GlobalFree(ptgGroups);
                }
            }

            // Free token
            CloseHandle(hAccessToken);
        }

        // Return admin status to caller
        return bIsAdmin;
    }

> On another completely different note

You should have posted a separate discussion thread for it.

> I've just written a stub DLL and when I examine it's EAT I see, in
> addition to my defined export functions, a function / method / entry
> for ___CPPdebugHook.  I can hazard a guess at what it is, but
> what exactly does it do and how can I remove it.

It is for Borland's use, and no, you cannot remove it.


Gambit
Technical Details
Message-ID: <3f99e30e$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3f99d8fe$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,d6c94c7dab41d4e4
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-10-24 20:09:12 PST
From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3f99d8fe$1@newsgroups.borland.com>
Subject: Re: Testing Admin rights...
Date: Fri, 24 Oct 2003 19:45:01 -0700
Lines: 90
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 67.22.137.75
Message-ID: <3f99e30e$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1067049742 67.22.137.75 (24 Oct 2003 19:42:22 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail