Sweden-Number/win32/security.c

183 lines
5.9 KiB
C
Raw Normal View History

Release 970215 Sat Feb 15 11:59:17 1997 Alexandre Julliard <julliard@lrc.epfl.ch> * [*/*] Converted a lot of functions to Win32 types. Removed HWND type. Fri Feb 14 15:09:19 1997 Onno Hovers <onno@stack.nl> * [memory/global.c] Implemented GMEM_MOVEABLE blocks for Win32. Fri Feb 14 00:24:39 1997 Alex Korobka <alex@trantor.pharm.sunysb.edu> * [loader/task.c] [windows/queue.c] Do not read X events while in the intertask SendMessage(). * [misc/lstr.c] Fixed CharPrev32A(). * [windows/hook.c] [include/hook.h] Restored broken WH_CALLWNDPROC functionality for dialogs, etc... * [windows/win.c] [windows/defwnd.c] [windows/mdi.c] [windows/event.c] [controls/edit.c] Added WIN_ISWIN32 flag to windows created by Win32 calls. Several new Win32 messages are sent when this flag is on. * [msdos/dosmem.c] [memory/global.c] Some changes in DOS memory allocation. Fri Feb 7 21:46:03 1997 Andrew Taylor <andrew@riscan.com> * [win32/security.c] Added SID manipulation functions. * [include/debug.h] Added debugging class "security". Fri Feb 7 20:46:33 1997 Robert Pouliot <krynos@clic.net> * [debugger/msc.c] [debugger/source.c] [documentation/wine_os2.txt] [loader/signal.c] Some more changes for OS/2. Doesn't work yet. Fri Feb 7 09:31:17 1997 Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de> * [scheduler/process.c] Added ExpandEnvironmentStrings*. * [misc/ntdll.c] [include/ntdll.h] Added some new functions. * [objects/cursoricon.c] CURSORICON_LoadHandler: check against some bizarre out of memory conditions. * [windows/mdi.c] Fixed DefFrameProc32*, added TranslateMDISysAccel32. Wed Feb 5 01:31:05 1997 John Zero <john@globe.graphisoft.hu> * [resources/sysres_Hu.rc] [misc/ole2nls.c] [misc/main.c] [programs/progman/Hu.rc] [programs/winhelp/Hu.rc] Added Hungarian language support.
1997-02-15 15:29:56 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "windows.h"
#include "ntdll.h"
#include "xmalloc.h"
#include "stddebug.h"
#include "debug.h"
BOOL32 IsValidSid (LPSID pSid);
BOOL32 EqualSid (LPSID pSid1, LPSID pSid2);
BOOL32 EqualPrefixSid (LPSID pSid1, LPSID pSid2);
DWORD GetSidLengthRequired (BYTE nSubAuthorityCount);
BOOL32 AllocateAndInitializeSid (LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount, DWORD nSubAuthority0, DWORD nSubAuthority1, DWORD nSubAuthority2, DWORD nSubAuthority3, DWORD nSubAuthority4, DWORD nSubAuthority5, DWORD nSubAuthority6, DWORD nSubAuthority7, LPSID *pSid);
VOID *FreeSid(LPSID pSid);
BOOL32 InitializeSid (LPSID pSid, LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount);
LPSID_IDENTIFIER_AUTHORITY GetSidIdentifierAuthority (LPSID pSid);
DWORD *GetSidSubAuthority (LPSID pSid, DWORD nSubAuthority);
BYTE *GetSidSubAuthorityCount (LPSID pSid);
DWORD GetLengthSid (LPSID pSid);
BOOL32 CopySid (DWORD nDestinationSidLength, LPSID pDestinationSid, LPSID pSourceSid);
/***********************************************************************
* IsValidSid (ADVAPI.80)
*/
BOOL32 IsValidSid (LPSID pSid) {
if (!pSid || pSid->Revision != SID_REVISION)
return FALSE;
return TRUE;
}
/***********************************************************************
* EqualSid (ADVAPI.40)
*/
BOOL32 EqualSid (LPSID pSid1, LPSID pSid2) {
if (!IsValidSid(pSid1) || !IsValidSid(pSid2))
return FALSE;
if (*GetSidSubAuthorityCount(pSid1) != *GetSidSubAuthorityCount(pSid2))
return FALSE;
if (memcmp(pSid1, pSid2, GetLengthSid(pSid1)) != 0)
return FALSE;
return TRUE;
}
/***********************************************************************
* EqualPrefixSid (ADVAPI.39)
*/
BOOL32 EqualPrefixSid (LPSID pSid1, LPSID pSid2) {
if (!IsValidSid(pSid1) || !IsValidSid(pSid2))
return FALSE;
if (*GetSidSubAuthorityCount(pSid1) != *GetSidSubAuthorityCount(pSid2))
return FALSE;
if (memcmp(pSid1, pSid2, GetSidLengthRequired(pSid1->SubAuthorityCount - 1))
!= 0)
return FALSE;
return TRUE;
}
/***********************************************************************
* GetSidLengthRequired (ADVAPI.63)
*/
DWORD GetSidLengthRequired (BYTE nSubAuthorityCount) {
return sizeof (SID) + (nSubAuthorityCount - 1 * sizeof (DWORD));
}
/***********************************************************************
* AllocateAndInitializeSid (ADVAPI.11)
*/
BOOL32 AllocateAndInitializeSid (LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
BYTE nSubAuthorityCount,
DWORD nSubAuthority0, DWORD nSubAuthority1,
DWORD nSubAuthority2, DWORD nSubAuthority3,
DWORD nSubAuthority4, DWORD nSubAuthority5,
DWORD nSubAuthority6, DWORD nSubAuthority7,
LPSID *pSid) {
*pSid = xmalloc(GetSidLengthRequired(nSubAuthorityCount));
(*pSid)->Revision = SID_REVISION;
if (pIdentifierAuthority)
memcpy(&(*pSid)->IdentifierAuthority, pIdentifierAuthority,
sizeof (SID_IDENTIFIER_AUTHORITY));
*GetSidSubAuthorityCount(*pSid) = nSubAuthorityCount;
if (nSubAuthorityCount > 0)
*GetSidSubAuthority(*pSid, 0) = nSubAuthority0;
if (nSubAuthorityCount > 1)
*GetSidSubAuthority(*pSid, 1) = nSubAuthority1;
if (nSubAuthorityCount > 2)
*GetSidSubAuthority(*pSid, 2) = nSubAuthority2;
if (nSubAuthorityCount > 3)
*GetSidSubAuthority(*pSid, 3) = nSubAuthority3;
if (nSubAuthorityCount > 4)
*GetSidSubAuthority(*pSid, 4) = nSubAuthority4;
if (nSubAuthorityCount > 5)
*GetSidSubAuthority(*pSid, 5) = nSubAuthority5;
if (nSubAuthorityCount > 6)
*GetSidSubAuthority(*pSid, 6) = nSubAuthority6;
if (nSubAuthorityCount > 7)
*GetSidSubAuthority(*pSid, 7) = nSubAuthority7;
return TRUE;
}
/***********************************************************************
* FreeSid (ADVAPI.42)
*/
VOID *FreeSid(LPSID pSid) {
free(pSid);
return NULL;
}
/***********************************************************************
* InitializeSid (ADVAPI.74)
*/
BOOL32 InitializeSid (LPSID pSid, LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
BYTE nSubAuthorityCount) {
int i;
pSid->Revision = SID_REVISION;
if (pIdentifierAuthority)
memcpy(&pSid->IdentifierAuthority, pIdentifierAuthority,
sizeof (SID_IDENTIFIER_AUTHORITY));
*GetSidSubAuthorityCount(pSid) = nSubAuthorityCount;
for (i = 0; i < nSubAuthorityCount; i++)
*GetSidSubAuthority(pSid, i) = 0;
return TRUE;
}
/***********************************************************************
* GetSidIdentifierAuthority (ADVAPI.62)
*/
LPSID_IDENTIFIER_AUTHORITY GetSidIdentifierAuthority (LPSID pSid) {
return &pSid->IdentifierAuthority;
}
/***********************************************************************
* GetSidSubAuthority (ADVAPI.64)
*/
DWORD *GetSidSubAuthority (LPSID pSid, DWORD nSubAuthority) {
return &pSid->SubAuthority[nSubAuthority];
}
/***********************************************************************
* GetSidSubAuthorityCount (ADVAPI.65)
*/
BYTE *GetSidSubAuthorityCount (LPSID pSid) {
return &pSid->SubAuthorityCount;
}
/***********************************************************************
* GetLengthSid (ADVAPI.48)
*/
DWORD GetLengthSid (LPSID pSid) {
return GetSidLengthRequired(*GetSidSubAuthorityCount(pSid));
}
/***********************************************************************
* CopySid (ADVAPI.24)
*/
BOOL32 CopySid (DWORD nDestinationSidLength, LPSID pDestinationSid,
LPSID pSourceSid) {
if (!IsValidSid(pSourceSid))
return FALSE;
if (nDestinationSidLength < GetLengthSid(pSourceSid))
return FALSE;
memcpy(pDestinationSid, pSourceSid, GetLengthSid(pSourceSid));
return TRUE;
}