ReactOS  0.4.14-dev-342-gdc047f9
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/lsasrv/utils.c
5  * PURPOSE: Utility functions
6  *
7  * PROGRAMMERS: Eric Kohl
8  */
9 
10 #include "lsasrv.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 INT
66  _In_ UINT uId,
67  _In_ USHORT usLanguage)
68 {
69  HGLOBAL hmem;
70  HRSRC hrsrc;
71  WCHAR *p;
72  UINT i, string_num;
73 
74  /* Use loword (incremented by 1) as resourceid */
75 // hrsrc = FindResourceExW(hInstance,
76 // MAKEINTRESOURCEW((LOWORD(uId) >> 4) + 1),
77 // (LPWSTR)RT_STRING,
78 // usLanguage);
79  hrsrc = FindResourceW(hInstance,
80  MAKEINTRESOURCEW((LOWORD(uId) >> 4) + 1),
81  (LPWSTR)RT_STRING);
82  if (!hrsrc)
83  return 0;
84 
85  hmem = LoadResource(hInstance, hrsrc);
86  if (!hmem)
87  return 0;
88 
89  p = LockResource(hmem);
90  string_num = uId & 0x000f;
91  for (i = 0; i < string_num; i++)
92  p += *p + 1;
93 
94  return *p + 1;
95 }
96 
97 
98 INT
101  _In_ UINT uId,
102  _In_ USHORT usLanguage,
104  _Out_ INT nBufferMax)
105 {
106  HGLOBAL hmem;
107  HRSRC hrsrc;
108  WCHAR *p;
109  int string_num;
110  int i;
111 
112  /* Use loword (incremented by 1) as resourceid */
113 // hrsrc = FindResourceExW(hInstance,
114 // MAKEINTRESOURCEW((LOWORD(uId) >> 4) + 1),
115 // (LPWSTR)RT_STRING,
116 // usLanguage);
117  hrsrc = FindResourceW(hInstance,
118  MAKEINTRESOURCEW((LOWORD(uId) >> 4) + 1),
119  (LPWSTR)RT_STRING);
120  if (!hrsrc)
121  return 0;
122 
123  hmem = LoadResource(hInstance, hrsrc);
124  if (!hmem)
125  return 0;
126 
127  p = LockResource(hmem);
128  string_num = uId & 0x000f;
129  for (i = 0; i < string_num; i++)
130  p += *p + 1;
131 
132  i = min(nBufferMax - 1, *p);
133  if (i > 0)
134  {
135  memcpy(lpBuffer, p + 1, i * sizeof(WCHAR));
136  lpBuffer[i] = 0;
137  }
138  else
139  {
140  if (nBufferMax > 1)
141  {
142  lpBuffer[0] = 0;
143  return 0;
144  }
145  }
146 
147  return i;
148 }
149 
150 
151 PSID
153  PSID SrcSid,
154  ULONG Rid)
155 {
156  ULONG Rids[8] = {0, 0, 0, 0, 0, 0, 0, 0};
157  UCHAR RidCount;
158  PSID DstSid;
159  ULONG i;
160 
161  RidCount = *RtlSubAuthorityCountSid(SrcSid);
162  if (RidCount >= 8)
163  return NULL;
164 
165  for (i = 0; i < RidCount; i++)
166  Rids[i] = *RtlSubAuthoritySid(SrcSid, i);
167 
168  Rids[RidCount] = Rid;
169  RidCount++;
170 
172  RidCount,
173  Rids[0],
174  Rids[1],
175  Rids[2],
176  Rids[3],
177  Rids[4],
178  Rids[5],
179  Rids[6],
180  Rids[7],
181  &DstSid);
182 
183  return DstSid;
184 }
185 
186 /* EOF */
INT LsapGetResourceStringLengthEx(_In_ HINSTANCE hInstance, _In_ UINT uId, _In_ USHORT usLanguage)
Definition: utils.c:64
INT LsapLoadString(HINSTANCE hInstance, UINT uId, LPWSTR lpBuffer, INT nBufferMax)
Definition: utils.c:17
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
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
int32_t INT
Definition: typedefs.h:56
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
PSID LsapAppendRidToSid(PSID SrcSid, ULONG Rid)
Definition: utils.c:152
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
smooth NULL
Definition: ftsmooth.c:416
#define _Out_
Definition: no_sal2.h:323
__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
INT LsapLoadStringEx(_In_ HINSTANCE hInstance, _In_ UINT uId, _In_ USHORT usLanguage, _Out_ LPWSTR lpBuffer, _Out_ INT nBufferMax)
Definition: utils.c:99
unsigned char UCHAR
Definition: xmlstorage.h:181
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define RT_STRING
Definition: pedump.c:368
#define _In_
Definition: no_sal2.h:204
unsigned short USHORT
Definition: pedump.c:61
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
unsigned int ULONG
Definition: retypes.h:1
#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