ReactOS  0.4.14-dev-358-gbef841c
utils.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: Security Account Manager (SAM) Server
4  * FILE: reactos/dll/win32/samsrv/utils.c
5  * PURPOSE: Utility functions
6  *
7  * PROGRAMMERS: Eric Kohl
8  */
9 
10 #include "samsrv.h"
11 
12 #include <winuser.h>
13 
14 /* FUNCTIONS ***************************************************************/
15 
16 INT
18  UINT uId,
20  INT nBufferMax)
21 {
22  HGLOBAL hmem;
23  HRSRC hrsrc;
24  WCHAR *p;
25  int string_num;
26  int i;
27 
28  /* Use loword (incremented by 1) as resourceid */
29  hrsrc = FindResourceW(hInstance,
30  MAKEINTRESOURCEW((LOWORD(uId) >> 4) + 1),
31  (LPWSTR)RT_STRING);
32  if (!hrsrc)
33  return 0;
34 
35  hmem = LoadResource(hInstance, hrsrc);
36  if (!hmem)
37  return 0;
38 
39  p = LockResource(hmem);
40  string_num = uId & 0x000f;
41  for (i = 0; i < string_num; i++)
42  p += *p + 1;
43 
44  i = min(nBufferMax - 1, *p);
45  if (i > 0)
46  {
47  memcpy(lpBuffer, p + 1, i * sizeof(WCHAR));
48  lpBuffer[i] = 0;
49  }
50  else
51  {
52  if (nBufferMax > 1)
53  {
54  lpBuffer[0] = 0;
55  return 0;
56  }
57  }
58 
59  return i;
60 }
61 
62 
63 BOOL
65 {
66  DWORD dwError;
67  HKEY hKey;
68  DWORD dwType;
69  DWORD dwSize;
70  DWORD dwSetupType;
71 
72  TRACE("SampIsSetupRunning()\n");
73 
74  /* Open key */
76  L"SYSTEM\\Setup",
77  0,
79  &hKey);
80  if (dwError != ERROR_SUCCESS)
81  return FALSE;
82 
83  /* Read key */
84  dwSize = sizeof(DWORD);
85  dwError = RegQueryValueExW(hKey,
86  L"SetupType",
87  NULL,
88  &dwType,
89  (LPBYTE)&dwSetupType,
90  &dwSize);
91 
92  /* Close key, and check if returned values are correct */
93  RegCloseKey(hKey);
94  if (dwError != ERROR_SUCCESS || dwType != REG_DWORD || dwSize != sizeof(DWORD))
95  return FALSE;
96 
97  TRACE("SampIsSetupRunning() returns %s\n", (dwSetupType != 0) ? "TRUE" : "FALSE");
98  return (dwSetupType != 0);
99 }
100 
101 
102 PSID
104  ULONG Rid)
105 {
106  ULONG Rids[8] = {0, 0, 0, 0, 0, 0, 0, 0};
107  UCHAR RidCount;
108  PSID DstSid;
109  ULONG i;
110 
111  RidCount = *RtlSubAuthorityCountSid(SrcSid);
112  if (RidCount >= 8)
113  return NULL;
114 
115  for (i = 0; i < RidCount; i++)
116  Rids[i] = *RtlSubAuthoritySid(SrcSid, i);
117 
118  Rids[RidCount] = Rid;
119  RidCount++;
120 
122  RidCount,
123  Rids[0],
124  Rids[1],
125  Rids[2],
126  Rids[3],
127  Rids[4],
128  Rids[5],
129  Rids[6],
130  Rids[7],
131  &DstSid);
132 
133  return DstSid;
134 }
135 
136 
137 NTSTATUS
139  OUT PULONG Rid)
140 {
141  UCHAR RidCount;
142 
143  RidCount = *RtlSubAuthorityCountSid(Sid);
144  if (RidCount < 1)
145  return STATUS_INVALID_SID;
146 
147  *Rid = *RtlSubAuthoritySid(Sid, RidCount - 1);
148 
149  return STATUS_SUCCESS;
150 }
151 
152 
153 NTSTATUS
155  IN USHORT MaxLength)
156 {
157  if (AccountName->Length > MaxLength * sizeof(WCHAR))
159 
160  return STATUS_SUCCESS;
161 }
162 
163 /* EOF */
#define IN
Definition: typedefs.h:38
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG NTSTATUS
Definition: precomp.h:26
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
NTSYSAPI PULONG NTAPI RtlSubAuthoritySid(_In_ PSID Sid, _In_ ULONG SubAuthority)
NTSTATUS SampGetRidFromSid(IN PSID Sid, OUT PULONG Rid)
Definition: utils.c:138
NTSYSAPI NTSTATUS NTAPI RtlAllocateAndInitializeSid(IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN UCHAR SubAuthorityCount, IN ULONG SubAuthority0, IN ULONG SubAuthority1, IN ULONG SubAuthority2, IN ULONG SubAuthority3, IN ULONG SubAuthority4, IN ULONG SubAuthority5, IN ULONG SubAuthority6, IN ULONG SubAuthority7, OUT PSID *Sid)
Definition: sid.c:290
#define DWORD
Definition: nt_native.h:44
int32_t INT
Definition: typedefs.h:56
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
NTSTATUS SampCheckAccountName(IN PRPC_UNICODE_STRING AccountName, IN USHORT MaxLength)
Definition: utils.c:154
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HINSTANCE hInstance
Definition: charmap.c:20
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
smooth NULL
Definition: ftsmooth.c:416
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1104
#define STATUS_INVALID_SID
Definition: ntstatus.h:342
BOOL SampIsSetupRunning(VOID)
Definition: utils.c:64
INT SampLoadString(HINSTANCE hInstance, UINT uId, LPWSTR lpBuffer, INT nBufferMax)
Definition: utils.c:17
#define STATUS_INVALID_ACCOUNT_NAME
Definition: ntstatus.h:320
#define TRACE(s)
Definition: solgame.cpp:4
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
NTSYSAPI PSID_IDENTIFIER_AUTHORITY NTAPI RtlIdentifierAuthoritySid(PSID Sid)
NTSYSAPI PUCHAR NTAPI RtlSubAuthorityCountSid(IN PSID Sid)
Definition: sid.c:104
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define RT_STRING
Definition: pedump.c:368
PSID AppendRidToSid(PSID SrcSid, ULONG Rid)
Definition: utils.c:103
unsigned short USHORT
Definition: pedump.c:61
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
unsigned int * PULONG
Definition: retypes.h:1
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
GLfloat GLfloat p
Definition: glext.h:8902
WCHAR * LPWSTR
Definition: xmlstorage.h:184
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define REG_DWORD
Definition: sdbapi.c:596
#define LOWORD(l)
Definition: pedump.c:82
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12