ReactOS 0.4.16-dev-197-g92996da
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
16INT
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 */
30 MAKEINTRESOURCEW((LOWORD(uId) >> 4) + 1),
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
63BOOL
65{
66 DWORD dwError;
67 HKEY hKey;
68 DWORD dwType;
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 */
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
102PSID
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
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
155 IN USHORT MaxLength)
156{
157 if (AccountName->Length > MaxLength * sizeof(WCHAR))
159
160 return STATUS_SUCCESS;
161}
162
163/* EOF */
LONG NTSTATUS
Definition: precomp.h:26
#define RegCloseKey(hKey)
Definition: registry.h:49
HINSTANCE hInstance
Definition: charmap.c:19
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
NTSTATUS SampCheckAccountName(IN PRPC_UNICODE_STRING AccountName, IN USHORT MaxLength)
Definition: utils.c:154
PSID AppendRidToSid(PSID SrcSid, ULONG Rid)
Definition: utils.c:103
INT SampLoadString(HINSTANCE hInstance, UINT uId, LPWSTR lpBuffer, INT nBufferMax)
Definition: utils.c:17
NTSTATUS SampGetRidFromSid(IN PSID Sid, OUT PULONG Rid)
Definition: utils.c:138
BOOL SampIsSetupRunning(VOID)
Definition: utils.c:64
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
GLfloat GLfloat p
Definition: glext.h:8902
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
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
NTSYSAPI PULONG NTAPI RtlSubAuthoritySid(_In_ PSID Sid, _In_ ULONG SubAuthority)
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1145
NTSYSAPI PSID_IDENTIFIER_AUTHORITY NTAPI RtlIdentifierAuthoritySid(PSID Sid)
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define DWORD
Definition: nt_native.h:44
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
NTSYSAPI PUCHAR NTAPI RtlSubAuthorityCountSid(IN PSID Sid)
Definition: sid.c:104
#define STATUS_INVALID_ACCOUNT_NAME
Definition: ntstatus.h:334
#define STATUS_INVALID_SID
Definition: ntstatus.h:356
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
#define RT_STRING
Definition: pedump.c:368
unsigned short USHORT
Definition: pedump.c:61
#define REG_DWORD
Definition: sdbapi.c:596
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE(s)
Definition: solgame.cpp:4
uint32_t * PULONG
Definition: typedefs.h:59
unsigned char * LPBYTE
Definition: typedefs.h:53
int32_t INT
Definition: typedefs.h:58
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184