From 4541bb7cc8b06ab1f13c59fe380060c0a097b79d Mon Sep 17 00:00:00 2001 From: kichik Date: Mon, 4 Nov 2002 15:40:55 +0000 Subject: [PATCH] UserInfo DLL to get user group and name git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1585 212acab6-be3b-0410-9dea-997c60f758d6 --- Contrib/UserInfo/UserInfo.c | 108 ++++++++++++++++++++++++++++++++ Contrib/UserInfo/UserInfo.dsp | 112 ++++++++++++++++++++++++++++++++++ Contrib/UserInfo/UserInfo.dsw | 29 +++++++++ Contrib/UserInfo/UserInfo.nsi | 10 +++ Plugins/UserInfo.dll | Bin 0 -> 3584 bytes 5 files changed, 259 insertions(+) create mode 100644 Contrib/UserInfo/UserInfo.c create mode 100644 Contrib/UserInfo/UserInfo.dsp create mode 100644 Contrib/UserInfo/UserInfo.dsw create mode 100644 Contrib/UserInfo/UserInfo.nsi create mode 100644 Plugins/UserInfo.dll diff --git a/Contrib/UserInfo/UserInfo.c b/Contrib/UserInfo/UserInfo.c new file mode 100644 index 00000000..6855ac5e --- /dev/null +++ b/Contrib/UserInfo/UserInfo.c @@ -0,0 +1,108 @@ +#include +#include "..\exdll\exdll.h" + +void __declspec(dllexport) GetName(HWND hwndParent, int string_size, + char *variables, stack_t **stacktop) +{ + EXDLL_INIT(); + + { + DWORD dwStringSize = g_stringsize; + stack_t *th; + if (!g_stacktop) return; + th = (stack_t*) GlobalAlloc(GPTR, sizeof(stack_t) + g_stringsize); + GetUserName(th->text, &dwStringSize); + th->next = *g_stacktop; + *g_stacktop = th; + } +} + +void __declspec(dllexport) GetGroup(HWND hwndParent, int string_size, + char *variables, stack_t **stacktop) +{ + EXDLL_INIT(); + + { + HANDLE hThread; + TOKEN_GROUPS *ptg = NULL; + DWORD cbTokenGroups; + DWORD i, j; + + SID_IDENTIFIER_AUTHORITY SystemSidAuthority = SECURITY_NT_AUTHORITY; + + char *group = ""; + + // First we must open a handle to the access token for this thread. + + if (OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, FALSE, &hThread) || + OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hThread)) + { + // Then we must query the size of the group information associated with + // the token. Note that we expect a FALSE result from GetTokenInformation + // because we've given it a NULL buffer. On exit cbTokenGroups will tell + // the size of the group information. + + if (!GetTokenInformation (hThread, TokenGroups, NULL, 0, &cbTokenGroups) && + GetLastError() == ERROR_INSUFFICIENT_BUFFER) + { + + // Now we allocate a buffer for the group information. + // Since _alloca allocates on the stack, we don't have + // to explicitly deallocate it. That happens automatically + // when we exit this function. + + if (ptg = GlobalAlloc(GPTR, cbTokenGroups)) + { + + // Now we ask for the group information again. + // This may fail if an administrator has added this account + // to an additional group between our first call to + // GetTokenInformation and this one. + + if (GetTokenInformation(hThread, TokenGroups, ptg, cbTokenGroups, &cbTokenGroups)) + { + + struct group + { + DWORD auth_id; + char *name; + } groups[] = { + {DOMAIN_ALIAS_RID_GUESTS, "Guest"}, + {DOMAIN_ALIAS_RID_USERS, "User"}, + {DOMAIN_ALIAS_RID_POWER_USERS, "Power"}, + {DOMAIN_ALIAS_RID_ADMINS, "Admin"} + }; + + // Finally we'll iterate through the list of groups for this access + // token looking for a match against the SID we created above. + + for (i = 0; i < sizeof(groups)/sizeof(struct group); i++) + { + PSID psid = 0; + AllocateAndInitializeSid( + &SystemSidAuthority, + 2, + SECURITY_BUILTIN_DOMAIN_RID, + groups[i].auth_id, + 0, 0, 0, 0, 0, 0, + &psid + ); + if (psid == 0) continue; + for (j = 0; j < ptg->GroupCount; j++) + if (EqualSid(ptg->Groups[j].Sid, psid)) + group = groups[i].name; + FreeSid(psid); + } + } + } + } + } + + pushstring(group); + } +} + +BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) +{ + return TRUE; +} diff --git a/Contrib/UserInfo/UserInfo.dsp b/Contrib/UserInfo/UserInfo.dsp new file mode 100644 index 00000000..d492cda6 --- /dev/null +++ b/Contrib/UserInfo/UserInfo.dsp @@ -0,0 +1,112 @@ +# Microsoft Developer Studio Project File - Name="UserInfo" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=UserInfo - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "UserInfo.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "UserInfo.mak" CFG="UserInfo - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "UserInfo - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "UserInfo - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "UserInfo - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "UserInfo_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "UserInfo_EXPORTS" /FD /c +# SUBTRACT CPP /YX +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /entry:"_DllMainCRTStartup" /dll /machine:I386 /nodefaultlib /out:"../../Plugins/UserInfo.dll" /opt:nowin98 +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "UserInfo - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "UserInfo_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "UserInfo_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "UserInfo - Win32 Release" +# Name "UserInfo - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\UserInfo.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=..\exdll\exdll.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/Contrib/UserInfo/UserInfo.dsw b/Contrib/UserInfo/UserInfo.dsw new file mode 100644 index 00000000..99b98d9a --- /dev/null +++ b/Contrib/UserInfo/UserInfo.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "UserInfo"=.\UserInfo.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/Contrib/UserInfo/UserInfo.nsi b/Contrib/UserInfo/UserInfo.nsi new file mode 100644 index 00000000..c5ae5fbd --- /dev/null +++ b/Contrib/UserInfo/UserInfo.nsi @@ -0,0 +1,10 @@ +Name "UserInfo.dll test" +OutFile UserInfo.exe + +Section + UserInfo::GetName + Pop $0 + UserInfo::GetGroup + Pop $1 + MessageBox MB_OK 'User "$0" in group "$1"' +SectionEnd \ No newline at end of file diff --git a/Plugins/UserInfo.dll b/Plugins/UserInfo.dll new file mode 100644 index 0000000000000000000000000000000000000000..6548fd57707cc672d969b252b7155b05004c6a10 GIT binary patch literal 3584 zcmeHJU1%It6h50KajlzVkX@+MpV>CnitRF!G^L>p?AF}I(ENPIt#<*Ue0v zovF32n?TlKL8%W4f-T8Y6;u#f>Vv^R(nfPP*v5|+NIR-+xvfg?9*pQR&ade3DoypsTkRT zJo8TP$S&m5?>^7@v1GiLV%MrnVE}EOa(LsycvC562C9Sic`A!dA|tB49~S{3B1j^+ ztQbNDng=HZ*ChqrNEk@5%e<&w3<8`$>j4qq5V_Z)Fu+r5`PQ?Gn0p<6$kNVP==W2R zR3Fv6+yu%5*ypgM_MV<@nrj_}uPj!U%9&?EPyM$_ zH02$N%?-tV9E$xk6#IE7Hb2gOshD63doacg)M9SDL^-m-QF}XXQc_+wu)ApXa&yhV z?>Ngm^E(YbvPYw-GS?Q|uLnnK24~Ra2KJymTR2}c_ywu9ztqOTu^cPZ417ZS+x<_Y zM_JiBFoNc1CfLm#c-K#`scl%%1p6|`wP}HCw{~)E#>=%kBG+c|Q4#80oKP<2!*Yo7 zY|gcsZl=Uk8TKP!J&iG+b;z*`x!7Xk!)G7Qj+eW(&)x3^{Jbmc9;dl!D#sRFw&<{e z)4rG;_a5|`-%wNlpJE|9;mx|D`PM1dUYM=GT92Q6?#5WQiKYxz<0U%B9z3<>LvtI* z}=BBuG*(T&xQhClnq!;9HBY2!}d!63jnL;}%)s6*^R_z*;QMS$Cg&k@%U z?<0ub6glI|pD2q63sIuiXunv}{?7mFHSc&@(#B~u9ZAzCC*f()tTr`cG1D|mfCkc^ zv`tgfEyXnAS|$SrR@u6GO-)SzytgHtvCMe?t9k^EvSS^rt-dalNT&gIQgnAlGdt8i zEduZz95FR5noPhnu$OH$O(Hx5{Q9b;Mf60gp0tu`I(eRl!2^_`%XmrCTlE(Wvrn~> zh7OlKo&B1=R1^0Ce86qRnu?}Kb5BHRE!DDmVx@nXTR2k>I`CD)aUJz3#5AIdzWInB zP`-S{wFqRgHHhO8Tucs zk^<6pX|L2I9hQztr=&BIAzhH(mM%&kN>`-o(u}kqJu27B5xG