4 * Copyright 1996 Marcus Meissner
22 /**************************************************************************
23 * RtlLengthRequiredSid [NTDLL]
26 RtlLengthRequiredSid(DWORD nrofsubauths
) {
27 return sizeof(DWORD
)*nrofsubauths
+sizeof(SID
);
30 /**************************************************************************
31 * RtlLengthSid [NTDLL]
34 RtlLengthSid(LPSID sid
) {
35 return sizeof(DWORD
)*sid
->SubAuthorityCount
+sizeof(SID
);
38 /**************************************************************************
39 * RtlCreateAcl [NTDLL]
42 RtlCreateAcl(LPACL acl
,DWORD size
,DWORD rev
) {
43 if (rev
!=ACL_REVISION
)
44 return STATUS_INVALID_PARAMETER
;
46 return STATUS_BUFFER_TOO_SMALL
;
48 return STATUS_INVALID_PARAMETER
;
50 memset(acl
,'\0',sizeof(ACL
));
51 acl
->AclRevision
= rev
;
57 /**************************************************************************
58 * RtlFirstFreeAce [NTDLL]
59 * looks for the AceCount+1 ACE, and if it is still within the alloced
60 * ACL, return a pointer to it
63 RtlFirstFreeAce(LPACL acl
,LPACE_HEADER
*x
) {
68 ace
= (LPACE_HEADER
)(acl
+1);
69 for (i
=0;i
<acl
->AceCount
;i
++) {
70 if ((DWORD
)ace
>=(((DWORD
)acl
)+acl
->AclSize
))
72 ace
= (LPACE_HEADER
)(((BYTE
*)ace
)+ace
->AceSize
);
74 if ((DWORD
)ace
>=(((DWORD
)acl
)+acl
->AclSize
))
80 /**************************************************************************
84 RtlAddAce(LPACL acl
,DWORD rev
,DWORD xnrofaces
,LPACE_HEADER acestart
,DWORD acelen
){
85 LPACE_HEADER ace
,targetace
;
88 if (acl
->AclRevision
!= ACL_REVISION
)
89 return STATUS_INVALID_PARAMETER
;
90 if (!RtlFirstFreeAce(acl
,&targetace
))
91 return STATUS_INVALID_PARAMETER
;
92 nrofaces
=0;ace
=acestart
;
93 while (((DWORD
)ace
-(DWORD
)acestart
)<acelen
) {
95 ace
= (LPACE_HEADER
)(((BYTE
*)ace
)+ace
->AceSize
);
97 if ((DWORD
)targetace
+acelen
>(DWORD
)acl
+acl
->AclSize
) /* too much aces */
98 return STATUS_INVALID_PARAMETER
;
99 memcpy((LPBYTE
)targetace
,acestart
,acelen
);
100 acl
->AceCount
+=nrofaces
;
104 /**************************************************************************
105 * RtlCreateSecurityDescriptor [NTDLL]
108 RtlCreateSecurityDescriptor(LPSECURITY_DESCRIPTOR lpsd
,DWORD rev
) {
109 if (rev
!=SECURITY_DESCRIPTOR_REVISION
)
110 return STATUS_UNKNOWN_REVISION
;
111 memset(lpsd
,'\0',sizeof(*lpsd
));
112 lpsd
->Revision
= SECURITY_DESCRIPTOR_REVISION
;
116 /**************************************************************************
117 * RtlSetDaclSecurityDescriptor [NTDLL]
120 RtlSetDaclSecurityDescriptor (
121 LPSECURITY_DESCRIPTOR lpsd
,BOOL32 daclpresent
,LPACL dacl
,BOOL32 dacldefaulted
123 if (lpsd
->Revision
!=SECURITY_DESCRIPTOR_REVISION
)
124 return STATUS_UNKNOWN_REVISION
;
125 if (lpsd
->Control
& SE_SELF_RELATIVE
)
126 return STATUS_INVALID_SECURITY_DESCR
;
128 lpsd
->Control
&= ~SE_DACL_PRESENT
;
131 lpsd
->Control
|= SE_DACL_PRESENT
;
134 lpsd
->Control
|= SE_DACL_DEFAULTED
;
136 lpsd
->Control
&= ~SE_DACL_DEFAULTED
;
140 /**************************************************************************
141 * RtlSetSaclSecurityDescriptor [NTDLL]
144 RtlSetSaclSecurityDescriptor (
145 LPSECURITY_DESCRIPTOR lpsd
,BOOL32 saclpresent
,LPACL sacl
,BOOL32 sacldefaulted
147 if (lpsd
->Revision
!=SECURITY_DESCRIPTOR_REVISION
)
148 return STATUS_UNKNOWN_REVISION
;
149 if (lpsd
->Control
& SE_SELF_RELATIVE
)
150 return STATUS_INVALID_SECURITY_DESCR
;
152 lpsd
->Control
&= ~SE_SACL_PRESENT
;
155 lpsd
->Control
|= SE_SACL_PRESENT
;
158 lpsd
->Control
|= SE_SACL_DEFAULTED
;
160 lpsd
->Control
&= ~SE_SACL_DEFAULTED
;
164 /**************************************************************************
165 * RtlSetOwnerSecurityDescriptor [NTDLL]
168 RtlSetOwnerSecurityDescriptor (LPSECURITY_DESCRIPTOR lpsd
,LPSID owner
,BOOL32 ownerdefaulted
) {
169 if (lpsd
->Revision
!=SECURITY_DESCRIPTOR_REVISION
)
170 return STATUS_UNKNOWN_REVISION
;
171 if (lpsd
->Control
& SE_SELF_RELATIVE
)
172 return STATUS_INVALID_SECURITY_DESCR
;
176 lpsd
->Control
|= SE_OWNER_DEFAULTED
;
178 lpsd
->Control
&= ~SE_OWNER_DEFAULTED
;
182 /**************************************************************************
183 * RtlSetOwnerSecurityDescriptor [NTDLL]
186 RtlSetGroupSecurityDescriptor (LPSECURITY_DESCRIPTOR lpsd
,LPSID group
,BOOL32 groupdefaulted
) {
187 if (lpsd
->Revision
!=SECURITY_DESCRIPTOR_REVISION
)
188 return STATUS_UNKNOWN_REVISION
;
189 if (lpsd
->Control
& SE_SELF_RELATIVE
)
190 return STATUS_INVALID_SECURITY_DESCR
;
194 lpsd
->Control
|= SE_GROUP_DEFAULTED
;
196 lpsd
->Control
&= ~SE_GROUP_DEFAULTED
;
201 /**************************************************************************
202 * RtlNormalizeProcessParams [NTDLL]
205 RtlNormalizeProcessParams(LPVOID x
)
207 fprintf(stdnimp
,"RtlNormalizeProcessParams(%p), stub.\n",x
);
211 /**************************************************************************
212 * RtlInitializeSid [NTDLL]
215 RtlInitializeSid(LPSID lpsid
,LPSID_IDENTIFIER_AUTHORITY lpsidauth
,DWORD c
) {
218 if (a
>=SID_MAX_SUB_AUTHORITIES
)
220 lpsid
->SubAuthorityCount
= a
;
221 lpsid
->Revision
= SID_REVISION
;
222 memcpy(&(lpsid
->IdentifierAuthority
),lpsidauth
,sizeof(SID_IDENTIFIER_AUTHORITY
));
226 /**************************************************************************
227 * RtlSubAuthoritySid [NTDLL]
230 RtlSubAuthoritySid(LPSID lpsid
,DWORD nr
) {
231 return &(lpsid
->SubAuthority
[nr
]);
234 /**************************************************************************
235 * RtlSubAuthorityCountSid [NTDLL]
238 RtlSubAuthorityCountSid(LPSID lpsid
) {
239 return ((LPBYTE
)lpsid
)+1;
242 /**************************************************************************
246 RtlCopySid(DWORD len
,LPSID to
,LPSID from
) {
247 if (len
<(from
->SubAuthorityCount
*4+8))
248 return STATUS_BUFFER_TOO_SMALL
;
249 memmove(to
,from
,from
->SubAuthorityCount
*4+8);
250 return STATUS_SUCCESS
;
253 /**************************************************************************
254 * RtlAnsiStringToUnicodeString [NTDLL]
257 RtlAnsiStringToUnicodeString(LPUNICODE_STRING uni
,LPANSI_STRING ansi
,BOOL32 doalloc
) {
258 DWORD unilen
= (ansi
->Length
+1)*sizeof(WCHAR
);
261 return STATUS_INVALID_PARAMETER_2
;
262 uni
->Length
= unilen
;
264 uni
->MaximumLength
= unilen
;
265 uni
->Buffer
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,unilen
);
267 return STATUS_NO_MEMORY
;
269 if (unilen
>uni
->MaximumLength
)
270 return STATUS_BUFFER_OVERFLOW
;
271 lstrcpynAtoW(uni
->Buffer
,ansi
->Buffer
,unilen
/2);
272 return STATUS_SUCCESS
;
275 /**************************************************************************
276 * RtlOemStringToUnicodeString [NTDLL]
279 RtlOemStringToUnicodeString(LPUNICODE_STRING uni
,LPSTRING ansi
,BOOL32 doalloc
) {
280 DWORD unilen
= (ansi
->Length
+1)*sizeof(WCHAR
);
283 return STATUS_INVALID_PARAMETER_2
;
284 uni
->Length
= unilen
;
286 uni
->MaximumLength
= unilen
;
287 uni
->Buffer
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,unilen
);
289 return STATUS_NO_MEMORY
;
291 if (unilen
>uni
->MaximumLength
)
292 return STATUS_BUFFER_OVERFLOW
;
293 lstrcpynAtoW(uni
->Buffer
,ansi
->Buffer
,unilen
/2);
294 return STATUS_SUCCESS
;
296 /**************************************************************************
297 * RtlMultiByteToUnicodeN [NTDLL]
298 * FIXME: multibyte support
301 RtlMultiByteToUnicodeN(LPWSTR unistr
,DWORD unilen
,LPDWORD reslen
,LPSTR oemstr
,DWORD oemlen
) {
308 x
=(LPWSTR
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,(len
+1)*sizeof(WCHAR
));
309 lstrcpynAtoW(x
,oemstr
,len
+1);
310 memcpy(unistr
,x
,len
*2);
311 if (reslen
) *reslen
= len
*2;
315 /**************************************************************************
316 * RtlOemToUnicodeN [NTDLL]
319 RtlOemToUnicodeN(LPWSTR unistr
,DWORD unilen
,LPDWORD reslen
,LPSTR oemstr
,DWORD oemlen
) {
326 x
=(LPWSTR
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,(len
+1)*sizeof(WCHAR
));
327 lstrcpynAtoW(x
,oemstr
,len
+1);
328 memcpy(unistr
,x
,len
*2);
329 if (reslen
) *reslen
= len
*2;
333 /**************************************************************************
334 * RtlInitString [NTDLL]
337 RtlInitAnsiString(LPANSI_STRING target
,LPCSTR source
) {
338 target
->Length
= target
->MaximumLength
= 0;
339 target
->Buffer
= (LPSTR
)source
;
342 target
->Length
= lstrlen32A(target
->Buffer
);
343 target
->MaximumLength
= target
->Length
+1;
345 /**************************************************************************
346 * RtlInitString [NTDLL]
349 RtlInitString(LPSTRING target
,LPCSTR source
) {
350 target
->Length
= target
->MaximumLength
= 0;
351 target
->Buffer
= (LPSTR
)source
;
354 target
->Length
= lstrlen32A(target
->Buffer
);
355 target
->MaximumLength
= target
->Length
+1;
358 /**************************************************************************
359 * RtlInitUnicodeString [NTDLL]
362 RtlInitUnicodeString(LPUNICODE_STRING target
,LPCWSTR source
) {
363 target
->Length
= target
->MaximumLength
= 0;
364 target
->Buffer
= (LPWSTR
)source
;
367 target
->Length
= lstrlen32W(target
->Buffer
)*2;
368 target
->MaximumLength
= target
->Length
+2;
371 /**************************************************************************
372 * RtlInitUnicodeString [NTDLL]
375 RtlFreeUnicodeString(LPUNICODE_STRING str
) {
377 HeapFree(GetProcessHeap(),0,str
);
380 /**************************************************************************
381 * RtlUnicodeToOemN [NTDLL]
384 RtlUnicodeToOemN(LPSTR oemstr
,DWORD oemlen
,LPDWORD reslen
,LPWSTR unistr
,DWORD unilen
) {
391 x
=(LPSTR
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,len
+1);
392 lstrcpynWtoA(x
,unistr
,len
+1);
393 memcpy(oemstr
,x
,len
);
394 if (reslen
) *reslen
= len
;
398 /**************************************************************************
399 * RtlUnicodeStringToOemString [NTDLL]
402 RtlUnicodeStringToOemString(LPUNICODE_STRING uni
,LPANSI_STRING oem
,BOOL32 alloc
)
405 oem
->Buffer
= (LPSTR
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,uni
->Length
/2)+1;
406 oem
->MaximumLength
= uni
->Length
/2+1;
408 oem
->Length
= uni
->Length
/2;
409 lstrcpynWtoA(oem
->Buffer
,uni
->Buffer
,uni
->Length
/2+1);
413 /**************************************************************************
414 * RtlNtStatusToDosErro [NTDLL]
417 RtlNtStatusToDosError(DWORD error
) {
418 /* FIXME: map STATUS_ to ERROR_ */
422 /**************************************************************************
423 * RtlGetNtProductType [NTDLL]
426 RtlGetNtProductType(LPVOID x
) {
427 /* FIXME : find documentation for this one */
431 /**************************************************************************
432 * RtlUpcaseUnicodeString [NTDLL]
435 RtlUpcaseUnicodeString(LPUNICODE_STRING dest
,LPUNICODE_STRING src
,BOOL32 doalloc
) {
441 dest
->MaximumLength
= len
;
442 dest
->Buffer
= (LPWSTR
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,len
);
444 return STATUS_NO_MEMORY
;
447 if (dest
->MaximumLength
< len
)
448 return STATUS_BUFFER_OVERFLOW
;
449 s
=dest
->Buffer
;t
=src
->Buffer
;
450 for (i
=0;i
<len
;i
++) {
455 return STATUS_SUCCESS
;
458 /**************************************************************************
459 * RtlxOemStringToUnicodeSize [NTDLL]
462 RtlxOemStringToUnicodeSize(LPSTRING str
) {
463 return str
->Length
*2+2;
466 /**************************************************************************
467 * RtlxAnsiStringToUnicodeSize [NTDLL]
470 RtlxAnsiStringToUnicodeSize(LPANSI_STRING str
) {
471 return str
->Length
*2+2;
474 /**************************************************************************
475 * RtlDosPathNameToNtPathName_U [NTDLL]
477 * FIXME: convert to UNC or whatever is expected here
480 RtlDosPathNameToNtPathName_U(
481 LPWSTR from
,LPUNICODE_STRING us
,DWORD x2
,DWORD x3
483 LPSTR fromA
= HEAP_strdupWtoA(GetProcessHeap(),0,from
);
485 fprintf(stderr
,"RtlDosPathNameToNtPathName_U(%s,%p,%08lx,%08lx)\n",
489 RtlInitUnicodeString(us
,HEAP_strdupW(GetProcessHeap(),0,from
));
493 /**************************************************************************
497 NtOpenFile(DWORD x1
,DWORD flags
,DWORD x3
,DWORD x4
,DWORD alignment
,DWORD x6
) {
498 fprintf(stderr
,"NtOpenFile(%08lx,%08lx,%08lx,%08lx,%08lx,%08lx)\n",
499 x1
,flags
,x3
,x4
,alignment
,x6
501 /* returns file io completion status */