4 * Copyright 1996 Marcus Meissner
22 /**************************************************************************
23 * RtlLengthRequiredSid [NTDLL]
25 DWORD WINAPI
RtlLengthRequiredSid(DWORD nrofsubauths
)
27 return sizeof(DWORD
)*nrofsubauths
+sizeof(SID
);
30 /**************************************************************************
31 * RtlLengthSid [NTDLL]
33 DWORD WINAPI
RtlLengthSid(LPSID sid
)
35 return sizeof(DWORD
)*sid
->SubAuthorityCount
+sizeof(SID
);
38 /**************************************************************************
39 * RtlCreateAcl [NTDLL]
42 * This should return NTSTATUS
44 DWORD WINAPI
RtlCreateAcl(LPACL acl
,DWORD size
,DWORD rev
)
46 if (rev
!=ACL_REVISION
)
47 return STATUS_INVALID_PARAMETER
;
49 return STATUS_BUFFER_TOO_SMALL
;
51 return STATUS_INVALID_PARAMETER
;
53 memset(acl
,'\0',sizeof(ACL
));
54 acl
->AclRevision
= rev
;
60 /**************************************************************************
61 * RtlFirstFreeAce [NTDLL]
62 * looks for the AceCount+1 ACE, and if it is still within the alloced
63 * ACL, return a pointer to it
65 BOOL32 WINAPI
RtlFirstFreeAce(LPACL acl
,LPACE_HEADER
*x
)
71 ace
= (LPACE_HEADER
)(acl
+1);
72 for (i
=0;i
<acl
->AceCount
;i
++) {
73 if ((DWORD
)ace
>=(((DWORD
)acl
)+acl
->AclSize
))
75 ace
= (LPACE_HEADER
)(((BYTE
*)ace
)+ace
->AceSize
);
77 if ((DWORD
)ace
>=(((DWORD
)acl
)+acl
->AclSize
))
83 /**************************************************************************
87 WINAPI
RtlAddAce(LPACL acl
,DWORD rev
,DWORD xnrofaces
,
88 LPACE_HEADER acestart
,DWORD acelen
)
90 LPACE_HEADER ace
,targetace
;
93 if (acl
->AclRevision
!= ACL_REVISION
)
94 return STATUS_INVALID_PARAMETER
;
95 if (!RtlFirstFreeAce(acl
,&targetace
))
96 return STATUS_INVALID_PARAMETER
;
97 nrofaces
=0;ace
=acestart
;
98 while (((DWORD
)ace
-(DWORD
)acestart
)<acelen
) {
100 ace
= (LPACE_HEADER
)(((BYTE
*)ace
)+ace
->AceSize
);
102 if ((DWORD
)targetace
+acelen
>(DWORD
)acl
+acl
->AclSize
) /* too much aces */
103 return STATUS_INVALID_PARAMETER
;
104 memcpy((LPBYTE
)targetace
,acestart
,acelen
);
105 acl
->AceCount
+=nrofaces
;
109 /**************************************************************************
110 * RtlCreateSecurityDescriptor [NTDLL]
113 WINAPI
RtlCreateSecurityDescriptor(LPSECURITY_DESCRIPTOR lpsd
,DWORD rev
)
115 if (rev
!=SECURITY_DESCRIPTOR_REVISION
)
116 return STATUS_UNKNOWN_REVISION
;
117 memset(lpsd
,'\0',sizeof(*lpsd
));
118 lpsd
->Revision
= SECURITY_DESCRIPTOR_REVISION
;
122 /**************************************************************************
123 * RtlSetDaclSecurityDescriptor [NTDLL]
126 WINAPI
RtlSetDaclSecurityDescriptor ( LPSECURITY_DESCRIPTOR lpsd
,BOOL32 daclpresent
,LPACL dacl
,BOOL32 dacldefaulted
)
128 if (lpsd
->Revision
!=SECURITY_DESCRIPTOR_REVISION
)
129 return STATUS_UNKNOWN_REVISION
;
130 if (lpsd
->Control
& SE_SELF_RELATIVE
)
131 return STATUS_INVALID_SECURITY_DESCR
;
133 lpsd
->Control
&= ~SE_DACL_PRESENT
;
136 lpsd
->Control
|= SE_DACL_PRESENT
;
139 lpsd
->Control
|= SE_DACL_DEFAULTED
;
141 lpsd
->Control
&= ~SE_DACL_DEFAULTED
;
145 /**************************************************************************
146 * RtlSetSaclSecurityDescriptor [NTDLL]
149 WINAPI
RtlSetSaclSecurityDescriptor (
150 LPSECURITY_DESCRIPTOR lpsd
,BOOL32 saclpresent
,LPACL sacl
,BOOL32 sacldefaulted
153 if (lpsd
->Revision
!=SECURITY_DESCRIPTOR_REVISION
)
154 return STATUS_UNKNOWN_REVISION
;
155 if (lpsd
->Control
& SE_SELF_RELATIVE
)
156 return STATUS_INVALID_SECURITY_DESCR
;
158 lpsd
->Control
&= ~SE_SACL_PRESENT
;
161 lpsd
->Control
|= SE_SACL_PRESENT
;
164 lpsd
->Control
|= SE_SACL_DEFAULTED
;
166 lpsd
->Control
&= ~SE_SACL_DEFAULTED
;
170 /**************************************************************************
171 * RtlSetOwnerSecurityDescriptor [NTDLL]
174 WINAPI
RtlSetOwnerSecurityDescriptor (LPSECURITY_DESCRIPTOR lpsd
,LPSID owner
,BOOL32 ownerdefaulted
)
176 if (lpsd
->Revision
!=SECURITY_DESCRIPTOR_REVISION
)
177 return STATUS_UNKNOWN_REVISION
;
178 if (lpsd
->Control
& SE_SELF_RELATIVE
)
179 return STATUS_INVALID_SECURITY_DESCR
;
183 lpsd
->Control
|= SE_OWNER_DEFAULTED
;
185 lpsd
->Control
&= ~SE_OWNER_DEFAULTED
;
189 /**************************************************************************
190 * RtlSetOwnerSecurityDescriptor [NTDLL]
193 WINAPI
RtlSetGroupSecurityDescriptor (LPSECURITY_DESCRIPTOR lpsd
,LPSID group
,BOOL32 groupdefaulted
)
195 if (lpsd
->Revision
!=SECURITY_DESCRIPTOR_REVISION
)
196 return STATUS_UNKNOWN_REVISION
;
197 if (lpsd
->Control
& SE_SELF_RELATIVE
)
198 return STATUS_INVALID_SECURITY_DESCR
;
202 lpsd
->Control
|= SE_GROUP_DEFAULTED
;
204 lpsd
->Control
&= ~SE_GROUP_DEFAULTED
;
209 /**************************************************************************
210 * RtlNormalizeProcessParams [NTDLL]
212 LPVOID WINAPI
RtlNormalizeProcessParams(LPVOID x
)
214 FIXME(ntdll
,"(%p), stub\n",x
);
218 /**************************************************************************
219 * RtlInitializeSid [NTDLL]
221 DWORD WINAPI
RtlInitializeSid(LPSID lpsid
,LPSID_IDENTIFIER_AUTHORITY lpsidauth
,
226 if (a
>=SID_MAX_SUB_AUTHORITIES
)
228 lpsid
->SubAuthorityCount
= a
;
229 lpsid
->Revision
= SID_REVISION
;
230 memcpy(&(lpsid
->IdentifierAuthority
),lpsidauth
,sizeof(SID_IDENTIFIER_AUTHORITY
));
234 /**************************************************************************
235 * RtlSubAuthoritySid [NTDLL]
237 LPDWORD WINAPI
RtlSubAuthoritySid(LPSID lpsid
,DWORD nr
)
239 return &(lpsid
->SubAuthority
[nr
]);
242 /**************************************************************************
243 * RtlSubAuthorityCountSid [NTDLL]
245 LPBYTE WINAPI
RtlSubAuthorityCountSid(LPSID lpsid
)
247 return ((LPBYTE
)lpsid
)+1;
250 /**************************************************************************
253 DWORD WINAPI
RtlCopySid(DWORD len
,LPSID to
,LPSID from
)
255 if (len
<(from
->SubAuthorityCount
*4+8))
256 return STATUS_BUFFER_TOO_SMALL
;
257 memmove(to
,from
,from
->SubAuthorityCount
*4+8);
258 return STATUS_SUCCESS
;
261 /**************************************************************************
262 * RtlAnsiStringToUnicodeString [NTDLL]
265 WINAPI
RtlAnsiStringToUnicodeString(LPUNICODE_STRING uni
,LPANSI_STRING ansi
,BOOL32 doalloc
)
267 DWORD unilen
= (ansi
->Length
+1)*sizeof(WCHAR
);
270 return STATUS_INVALID_PARAMETER_2
;
271 uni
->Length
= unilen
;
273 uni
->MaximumLength
= unilen
;
274 uni
->Buffer
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,unilen
);
276 return STATUS_NO_MEMORY
;
278 if (unilen
>uni
->MaximumLength
)
279 return STATUS_BUFFER_OVERFLOW
;
280 lstrcpynAtoW(uni
->Buffer
,ansi
->Buffer
,unilen
/2);
281 return STATUS_SUCCESS
;
284 /**************************************************************************
285 * RtlOemStringToUnicodeString [NTDLL]
288 WINAPI
RtlOemStringToUnicodeString(LPUNICODE_STRING uni
,LPSTRING ansi
,BOOL32 doalloc
)
290 DWORD unilen
= (ansi
->Length
+1)*sizeof(WCHAR
);
293 return STATUS_INVALID_PARAMETER_2
;
294 uni
->Length
= unilen
;
296 uni
->MaximumLength
= unilen
;
297 uni
->Buffer
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,unilen
);
299 return STATUS_NO_MEMORY
;
301 if (unilen
>uni
->MaximumLength
)
302 return STATUS_BUFFER_OVERFLOW
;
303 lstrcpynAtoW(uni
->Buffer
,ansi
->Buffer
,unilen
/2);
304 return STATUS_SUCCESS
;
306 /**************************************************************************
307 * RtlMultiByteToUnicodeN [NTDLL]
308 * FIXME: multibyte support
311 WINAPI
RtlMultiByteToUnicodeN(LPWSTR unistr
,DWORD unilen
,LPDWORD reslen
,LPSTR oemstr
,DWORD oemlen
)
319 x
=(LPWSTR
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,(len
+1)*sizeof(WCHAR
));
320 lstrcpynAtoW(x
,oemstr
,len
+1);
321 memcpy(unistr
,x
,len
*2);
322 if (reslen
) *reslen
= len
*2;
326 /**************************************************************************
327 * RtlOemToUnicodeN [NTDLL]
330 WINAPI
RtlOemToUnicodeN(LPWSTR unistr
,DWORD unilen
,LPDWORD reslen
,LPSTR oemstr
,DWORD oemlen
)
338 x
=(LPWSTR
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,(len
+1)*sizeof(WCHAR
));
339 lstrcpynAtoW(x
,oemstr
,len
+1);
340 memcpy(unistr
,x
,len
*2);
341 if (reslen
) *reslen
= len
*2;
345 /**************************************************************************
346 * RtlInitAnsiString [NTDLL]
348 VOID WINAPI
RtlInitAnsiString(LPANSI_STRING 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;
357 /**************************************************************************
358 * RtlInitString [NTDLL]
360 VOID WINAPI
RtlInitString(LPSTRING target
,LPCSTR source
)
362 target
->Length
= target
->MaximumLength
= 0;
363 target
->Buffer
= (LPSTR
)source
;
366 target
->Length
= lstrlen32A(target
->Buffer
);
367 target
->MaximumLength
= target
->Length
+1;
370 /**************************************************************************
371 * RtlInitUnicodeString [NTDLL]
373 VOID WINAPI
RtlInitUnicodeString(LPUNICODE_STRING target
,LPCWSTR source
)
375 target
->Length
= target
->MaximumLength
= 0;
376 target
->Buffer
= (LPWSTR
)source
;
379 target
->Length
= lstrlen32W(target
->Buffer
)*2;
380 target
->MaximumLength
= target
->Length
+2;
383 /**************************************************************************
384 * RtlFreeUnicodeString [NTDLL]
386 VOID WINAPI
RtlFreeUnicodeString(LPUNICODE_STRING str
)
389 HeapFree(GetProcessHeap(),0,str
->Buffer
);
392 /**************************************************************************
393 * RtlUnicodeToOemN [NTDLL]
396 WINAPI
RtlUnicodeToOemN(LPSTR oemstr
,DWORD oemlen
,LPDWORD reslen
,LPWSTR unistr
,DWORD unilen
)
404 x
=(LPSTR
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,len
+1);
405 lstrcpynWtoA(x
,unistr
,len
+1);
406 memcpy(oemstr
,x
,len
);
407 if (reslen
) *reslen
= len
;
411 /**************************************************************************
412 * RtlUnicodeStringToOemString [NTDLL]
415 WINAPI
RtlUnicodeStringToOemString(LPANSI_STRING oem
,LPUNICODE_STRING uni
,BOOL32 alloc
)
418 oem
->Buffer
= (LPSTR
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,uni
->Length
/2)+1;
419 oem
->MaximumLength
= uni
->Length
/2+1;
421 oem
->Length
= uni
->Length
/2;
422 lstrcpynWtoA(oem
->Buffer
,uni
->Buffer
,uni
->Length
/2+1);
426 /**************************************************************************
427 * RtlUnicodeStringToAnsiString [NTDLL]
430 WINAPI
RtlUnicodeStringToAnsiString(LPUNICODE_STRING uni
,LPANSI_STRING oem
,BOOL32 alloc
)
433 oem
->Buffer
= (LPSTR
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,uni
->Length
/2)+1;
434 oem
->MaximumLength
= uni
->Length
/2+1;
436 oem
->Length
= uni
->Length
/2;
437 lstrcpynWtoA(oem
->Buffer
,uni
->Buffer
,uni
->Length
/2+1);
441 /**************************************************************************
442 * RtlNtStatusToDosErro [NTDLL]
444 DWORD WINAPI
RtlNtStatusToDosError(DWORD error
)
446 FIXME(ntdll
, "(%lx): map STATUS_ to ERROR_\n",error
);
450 /**************************************************************************
451 * RtlGetNtProductType [NTDLL]
453 DWORD WINAPI
RtlGetNtProductType(LPVOID x
)
455 FIXME(ntdll
, "(%p): stub\n", x
);
459 /**************************************************************************
460 * RtlUpcaseUnicodeString [NTDLL]
462 DWORD WINAPI
RtlUpcaseUnicodeString(LPUNICODE_STRING dest
,LPUNICODE_STRING src
,BOOL32 doalloc
)
469 dest
->MaximumLength
= len
;
470 dest
->Buffer
= (LPWSTR
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,len
);
472 return STATUS_NO_MEMORY
;
475 if (dest
->MaximumLength
< len
)
476 return STATUS_BUFFER_OVERFLOW
;
477 s
=dest
->Buffer
;t
=src
->Buffer
;
478 /* len is in bytes */
479 for (i
=0;i
<len
/2;i
++)
480 s
[i
] = towupper(t
[i
]);
481 return STATUS_SUCCESS
;
484 /**************************************************************************
485 * RtlxOemStringToUnicodeSize [NTDLL]
487 UINT32 WINAPI
RtlxOemStringToUnicodeSize(LPSTRING str
)
489 return str
->Length
*2+2;
492 /**************************************************************************
493 * RtlxAnsiStringToUnicodeSize [NTDLL]
495 UINT32 WINAPI
RtlxAnsiStringToUnicodeSize(LPANSI_STRING str
)
497 return str
->Length
*2+2;
500 /**************************************************************************
501 * RtlIsTextUnicode [NTDLL]
503 * Apply various feeble heuristics to guess whether
504 * the text buffer contains Unicode.
505 * FIXME: should implement more tests.
507 DWORD WINAPI
RtlIsTextUnicode(LPVOID buf
, DWORD len
, DWORD
*pf
)
510 DWORD flags
= -1, out_flags
= 0;
517 * Apply various tests to the text string. According to the
518 * docs, each test "passed" sets the corresponding flag in
519 * the output flags. But some of the tests are mutually
520 * exclusive, so I don't see how you could pass all tests ...
523 /* Check for an odd length ... pass if even. */
525 out_flags
|= IS_TEXT_UNICODE_ODD_LENGTH
;
527 /* Check for the special unicode marker byte. */
529 out_flags
|= IS_TEXT_UNICODE_SIGNATURE
;
532 * Check whether the string passed all of the tests.
534 flags
&= ITU_IMPLEMENTED_TESTS
;
535 if ((out_flags
& flags
) != flags
)
543 /**************************************************************************
544 * RtlDosPathNameToNtPathName_U [NTDLL]
546 * FIXME: convert to UNC or whatever is expected here
548 BOOL32 WINAPI
RtlDosPathNameToNtPathName_U(
549 LPWSTR from
,LPUNICODE_STRING us
,DWORD x2
,DWORD x3
)
551 LPSTR fromA
= HEAP_strdupWtoA(GetProcessHeap(),0,from
);
553 FIXME(ntdll
,"(%s,%p,%08lx,%08lx)\n",fromA
,us
,x2
,x3
);
555 RtlInitUnicodeString(us
,HEAP_strdupW(GetProcessHeap(),0,from
));
559 /**************************************************************************
562 DWORD WINAPI
NtOpenFile(DWORD x1
,DWORD flags
,DWORD x3
,DWORD x4
,DWORD alignment
,DWORD x6
)
564 FIXME(ntdll
,"(%08lx,%08lx,%08lx,%08lx,%08lx,%08lx): stub\n",
565 x1
,flags
,x3
,x4
,alignment
,x6
);
566 /* returns file io completion status */
571 /**************************************************************************
572 * NTDLL_chkstk (NTDLL.862)
575 * Should this be WINAPI?
577 void NTDLL_chkstk(void)
579 /* FIXME: should subtract %eax bytes from stack pointer */
580 FIXME(ntdll
, "(void): stub\n");
584 /**************************************************************************
585 * NtOpenDirectoryObject [NTDLL.124]
587 DWORD WINAPI
NtOpenDirectoryObject(DWORD x1
,DWORD x2
,DWORD x3
)
589 FIXME(ntdll
,"(%lx,%lx,%lx): stub\n",x1
,x2
,x3
);
594 /******************************************************************************
595 * NtQueryDirectoryObject [NTDLL.149]
597 DWORD WINAPI
NtQueryDirectoryObject( DWORD x1
, DWORD x2
, DWORD x3
, DWORD x4
,
598 DWORD x5
, DWORD x6
, DWORD x7
)
600 FIXME(ntdll
,"(%lx,%lx,%lx,%lx,%lx,%lx,%lx): stub\n",x1
,x2
,x3
,x4
,x5
,x6
,x7
);
605 /**************************************************************************
606 * RtlFreeAnsiString [NTDLL.373]
608 VOID WINAPI
RtlFreeAnsiString(LPANSI_STRING AnsiString
)
610 if( AnsiString
->Buffer
)
611 HeapFree( GetProcessHeap(),0,AnsiString
->Buffer
);
615 /******************************************************************************
616 * NtQuerySystemInformation [NTDLL.168]
618 DWORD WINAPI
NtQuerySystemInformation( DWORD x1
, DWORD x2
, DWORD x3
, DWORD x4
)
620 FIXME(ntdll
,"(%lx,%lx,%lx,%lx): stub\n",x1
,x2
,x3
,x4
);
625 /******************************************************************************
626 * NtQueryObject [NTDLL.161]
628 DWORD WINAPI
NtQueryObject( DWORD x1
, DWORD x2
,DWORD x3
, DWORD x4
, DWORD x5
)
630 FIXME(ntdll
,"(%lx,%lx,%lx,%lx,%lx): stub\n",x1
,x2
,x3
,x4
,x5
);
635 /******************************************************************************
636 * RtlTimeToElapsedTimeFields [NTDLL.502]
638 DWORD WINAPI
RtlTimeToElapsedTimeFields( DWORD x1
, DWORD x2
)
640 FIXME(ntdll
,"(%lx,%lx): stub\n",x1
,x2
);
645 /******************************************************************************
646 * NtSetInformationProcess [NTDLL.207]
648 DWORD WINAPI
NtSetInformationProcess( DWORD x1
, DWORD x2
, DWORD x3
, DWORD x4
)
650 FIXME(ntdll
,"(%lx,%lx,%lx,%lx): stub\n",x1
,x2
,x3
,x4
);
654 /******************************************************************************
655 * NtFsControlFile [NTDLL.108]
657 VOID WINAPI
NtFsControlFile(VOID
)
659 FIXME(ntdll
,"(void): stub\n");
662 /******************************************************************************
663 * RtlExtendedLargeIntegerDivide [NTDLL.359]
665 INT32 WINAPI
RtlExtendedLargeIntegerDivide(
666 LARGE_INTEGER dividend
,
670 #if SIZEOF_LONG_LONG==8
671 long long x1
= *(long long*)÷nd
;
674 *rest
= x1
% divisor
;
677 FIXME(ntdll
,"((%d<<32)+%d,%d,%p), implement this using normal integer arithmetic!\n",dividend
.HighPart
,dividend
.LowPart
,divisor
,rest
);
682 /******************************************************************************
683 * RtlExtendedLargeIntegerMultiply [NTDLL.359]
684 * Note: This even works, since gcc returns 64bit values in eax/edx just like
685 * the caller expects. However... The relay code won't grok this I think.
687 long long /*LARGE_INTEGER*/
688 WINAPI
RtlExtendedIntegerMultiply(
689 LARGE_INTEGER factor1
,INT32 factor2
691 #if SIZEOF_LONG_LONG==8
692 return (*(long long*)&factor1
)*factor2
;
694 FIXME(ntdll
,"((%d<<32)+%d,%ld), implement this using normal integer arithmetic!\n",factor1
.HighPart
,factor1
.LowPart
,factor2
);
699 DWORD WINAPI
NtOpenKey(DWORD x1
,DWORD x2
,DWORD x3
) {
700 FIXME(ntdll
,"(0x%08lx(%s),0x%08lx,0x%08lx),stub!\n",x1
,
701 debugstr_w(*(LPWSTR
*)x1
),x2
,x3
);
703 return RegOpenKey32W(x2
,*(LPWSTR
*)x1
,x3
);
706 DWORD WINAPI
NtQueryValueKey(DWORD x1
,DWORD x2
,DWORD x3
,DWORD x4
,DWORD x5
,DWORD x6
) {
707 FIXME(ntdll
,"(%08lx,%08lx,%08lx,%08lx,%08lx,%08lx),stub!\n",
713 DWORD WINAPI
NtQueryTimerResolution(DWORD x1
,DWORD x2
,DWORD x3
) {
714 FIXME(ntdll
,"(0x%08lx,0x%08lx,0x%08lx), stub!\n",x1
,x2
,x3
);
718 DWORD WINAPI
NtClose(DWORD x1
) {
719 FIXME(ntdll
,"(0x%08lx),stub!\n",x1
);
723 DWORD WINAPI
NtQueryInformationProcess(DWORD x1
,DWORD x2
,DWORD x3
,DWORD x4
,DWORD x5
) {
724 FIXME(ntdll
,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",
730 DWORD WINAPI
RtlFormatCurrentUserKeyPath()
732 FIXME(ntdll
,"(): stub\n");