ReactOS 0.4.16-dev-197-g92996da
utils.c File Reference
#include "samsrv.h"
#include <winuser.h>
Include dependency graph for utils.c:

Go to the source code of this file.

Functions

INT SampLoadString (HINSTANCE hInstance, UINT uId, LPWSTR lpBuffer, INT nBufferMax)
 
BOOL SampIsSetupRunning (VOID)
 
PSID AppendRidToSid (PSID SrcSid, ULONG Rid)
 
NTSTATUS SampGetRidFromSid (IN PSID Sid, OUT PULONG Rid)
 
NTSTATUS SampCheckAccountName (IN PRPC_UNICODE_STRING AccountName, IN USHORT MaxLength)
 

Function Documentation

◆ AppendRidToSid()

PSID AppendRidToSid ( PSID  SrcSid,
ULONG  Rid 
)

Definition at line 103 of file utils.c.

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}
#define NULL
Definition: types.h:112
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
NTSYSAPI PULONG NTAPI RtlSubAuthoritySid(_In_ PSID Sid, _In_ ULONG SubAuthority)
NTSYSAPI PSID_IDENTIFIER_AUTHORITY NTAPI RtlIdentifierAuthoritySid(PSID Sid)
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
uint32_t ULONG
Definition: typedefs.h:59
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ SampCheckAccountName()

NTSTATUS SampCheckAccountName ( IN PRPC_UNICODE_STRING  AccountName,
IN USHORT  MaxLength 
)

Definition at line 154 of file utils.c.

156{
157 if (AccountName->Length > MaxLength * sizeof(WCHAR))
159
160 return STATUS_SUCCESS;
161}
#define STATUS_INVALID_ACCOUNT_NAME
Definition: ntstatus.h:334
#define STATUS_SUCCESS
Definition: shellext.h:65
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by SampSetAliasName(), SampSetGroupName(), SampSetUserName(), SamrCreateAliasInDomain(), SamrCreateGroupInDomain(), SamrCreateUser2InDomain(), and SamrCreateUserInDomain().

◆ SampGetRidFromSid()

NTSTATUS SampGetRidFromSid ( IN PSID  Sid,
OUT PULONG  Rid 
)

Definition at line 138 of file utils.c.

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}
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1145
#define STATUS_INVALID_SID
Definition: ntstatus.h:356

Referenced by SamrRemoveMemberFromForeignDomain().

◆ SampIsSetupRunning()

BOOL SampIsSetupRunning ( VOID  )

Definition at line 64 of file utils.c.

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}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
#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
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define DWORD
Definition: nt_native.h:44
#define L(x)
Definition: ntvdm.h:50
#define REG_DWORD
Definition: sdbapi.c:596
#define TRACE(s)
Definition: solgame.cpp:4
unsigned char * LPBYTE
Definition: typedefs.h:53
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by SamIInitialize().

◆ SampLoadString()

INT SampLoadString ( HINSTANCE  hInstance,
UINT  uId,
LPWSTR  lpBuffer,
INT  nBufferMax 
)

Definition at line 17 of file utils.c.

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}
HINSTANCE hInstance
Definition: charmap.c:19
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
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
GLfloat GLfloat p
Definition: glext.h:8902
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define min(a, b)
Definition: monoChain.cc:55
#define LOWORD(l)
Definition: pedump.c:82
#define RT_STRING
Definition: pedump.c:368
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by SampInitializeSAM().