ReactOS  0.4.15-dev-499-g1f31905
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 }
NTSYSAPI PULONG NTAPI RtlSubAuthoritySid(_In_ PSID Sid, _In_ ULONG SubAuthority)
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
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
smooth NULL
Definition: ftsmooth.c:416
NTSYSAPI PSID_IDENTIFIER_AUTHORITY NTAPI RtlIdentifierAuthoritySid(PSID Sid)
NTSYSAPI PUCHAR NTAPI RtlSubAuthorityCountSid(IN PSID Sid)
Definition: sid.c:104
unsigned char UCHAR
Definition: xmlstorage.h:181
unsigned int ULONG
Definition: retypes.h:1

◆ 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:320
__wchar_t WCHAR
Definition: xmlstorage.h:180
return STATUS_SUCCESS
Definition: btrfs.c:3014

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 }
NTSYSAPI PULONG NTAPI RtlSubAuthoritySid(_In_ PSID Sid, _In_ ULONG SubAuthority)
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1103
#define STATUS_INVALID_SID
Definition: ntstatus.h:342
NTSYSAPI PUCHAR NTAPI RtlSubAuthorityCountSid(IN PSID Sid)
Definition: sid.c:104
unsigned char UCHAR
Definition: xmlstorage.h:181
return STATUS_SUCCESS
Definition: btrfs.c:3014

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;
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 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define DWORD
Definition: nt_native.h:44
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
smooth NULL
Definition: ftsmooth.c:416
#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
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define REG_DWORD
Definition: sdbapi.c:596
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#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 */
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 }
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
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
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define RT_STRING
Definition: pedump.c:368
#define min(a, b)
Definition: monoChain.cc:55
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
GLfloat GLfloat p
Definition: glext.h:8902
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define LOWORD(l)
Definition: pedump.c:82

Referenced by SampInitializeSAM().