4 * Copyright 1996 Marcus Meissner
21 /**************************************************************************
22 * RtlLengthRequiredSid [NTDLL]
24 DWORD WINAPI RtlLengthRequiredSid(DWORD nrofsubauths)
26 return sizeof(DWORD)*nrofsubauths+sizeof(SID);
29 /**************************************************************************
30 * RtlLengthSid [NTDLL]
32 DWORD WINAPI RtlLengthSid(LPSID sid)
34 return sizeof(DWORD)*sid->SubAuthorityCount+sizeof(SID);
37 /**************************************************************************
38 * RtlCreateAcl [NTDLL]
40 DWORD /* NTSTATUS */ WINAPI RtlCreateAcl(LPACL acl,DWORD size,DWORD rev)
42 if (rev!=ACL_REVISION)
43 return STATUS_INVALID_PARAMETER;
45 return STATUS_BUFFER_TOO_SMALL;
47 return STATUS_INVALID_PARAMETER;
49 memset(acl,'\0',sizeof(ACL));
50 acl->AclRevision = rev;
56 /**************************************************************************
57 * RtlFirstFreeAce [NTDLL]
58 * looks for the AceCount+1 ACE, and if it is still within the alloced
59 * ACL, return a pointer to it
61 BOOL32 WINAPI RtlFirstFreeAce(LPACL acl,LPACE_HEADER *x)
67 ace = (LPACE_HEADER)(acl+1);
68 for (i=0;i<acl->AceCount;i++) {
69 if ((DWORD)ace>=(((DWORD)acl)+acl->AclSize))
71 ace = (LPACE_HEADER)(((BYTE*)ace)+ace->AceSize);
73 if ((DWORD)ace>=(((DWORD)acl)+acl->AclSize))
79 /**************************************************************************
82 DWORD /* NTSTATUS */ WINAPI RtlAddAce(LPACL acl,DWORD rev,DWORD xnrofaces,
83 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]
107 DWORD /* NTSTATUS */ WINAPI 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]
119 DWORD /* NTSTATUS */ WINAPI RtlSetDaclSecurityDescriptor ( LPSECURITY_DESCRIPTOR lpsd,BOOL32 daclpresent,LPACL dacl,BOOL32 dacldefaulted )
121 if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
122 return STATUS_UNKNOWN_REVISION;
123 if (lpsd->Control & SE_SELF_RELATIVE)
124 return STATUS_INVALID_SECURITY_DESCR;
126 lpsd->Control &= ~SE_DACL_PRESENT;
129 lpsd->Control |= SE_DACL_PRESENT;
132 lpsd->Control |= SE_DACL_DEFAULTED;
134 lpsd->Control &= ~SE_DACL_DEFAULTED;
138 /**************************************************************************
139 * RtlSetSaclSecurityDescriptor [NTDLL]
141 DWORD /* NTSTATUS */ WINAPI RtlSetSaclSecurityDescriptor (
142 LPSECURITY_DESCRIPTOR lpsd,BOOL32 saclpresent,LPACL sacl,BOOL32 sacldefaulted
145 if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
146 return STATUS_UNKNOWN_REVISION;
147 if (lpsd->Control & SE_SELF_RELATIVE)
148 return STATUS_INVALID_SECURITY_DESCR;
150 lpsd->Control &= ~SE_SACL_PRESENT;
153 lpsd->Control |= SE_SACL_PRESENT;
156 lpsd->Control |= SE_SACL_DEFAULTED;
158 lpsd->Control &= ~SE_SACL_DEFAULTED;
162 /**************************************************************************
163 * RtlSetOwnerSecurityDescriptor [NTDLL]
165 DWORD /* NTSTATUS */ WINAPI RtlSetOwnerSecurityDescriptor (LPSECURITY_DESCRIPTOR lpsd,LPSID owner,BOOL32 ownerdefaulted)
167 if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
168 return STATUS_UNKNOWN_REVISION;
169 if (lpsd->Control & SE_SELF_RELATIVE)
170 return STATUS_INVALID_SECURITY_DESCR;
174 lpsd->Control |= SE_OWNER_DEFAULTED;
176 lpsd->Control &= ~SE_OWNER_DEFAULTED;
180 /**************************************************************************
181 * RtlSetOwnerSecurityDescriptor [NTDLL]
183 DWORD /* NTSTATUS */ WINAPI RtlSetGroupSecurityDescriptor (LPSECURITY_DESCRIPTOR lpsd,LPSID group,BOOL32 groupdefaulted)
185 if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
186 return STATUS_UNKNOWN_REVISION;
187 if (lpsd->Control & SE_SELF_RELATIVE)
188 return STATUS_INVALID_SECURITY_DESCR;
192 lpsd->Control |= SE_GROUP_DEFAULTED;
194 lpsd->Control &= ~SE_GROUP_DEFAULTED;
199 /**************************************************************************
200 * RtlNormalizeProcessParams [NTDLL]
202 LPVOID WINAPI RtlNormalizeProcessParams(LPVOID x)
204 fprintf(stdnimp,"RtlNormalizeProcessParams(%p), stub.\n",x);
208 /**************************************************************************
209 * RtlInitializeSid [NTDLL]
211 DWORD WINAPI RtlInitializeSid(LPSID lpsid,LPSID_IDENTIFIER_AUTHORITY lpsidauth,
216 if (a>=SID_MAX_SUB_AUTHORITIES)
218 lpsid->SubAuthorityCount = a;
219 lpsid->Revision = SID_REVISION;
220 memcpy(&(lpsid->IdentifierAuthority),lpsidauth,sizeof(SID_IDENTIFIER_AUTHORITY));
224 /**************************************************************************
225 * RtlSubAuthoritySid [NTDLL]
227 LPDWORD WINAPI RtlSubAuthoritySid(LPSID lpsid,DWORD nr)
229 return &(lpsid->SubAuthority[nr]);
232 /**************************************************************************
233 * RtlSubAuthorityCountSid [NTDLL]
235 LPBYTE WINAPI RtlSubAuthorityCountSid(LPSID lpsid)
237 return ((LPBYTE)lpsid)+1;
240 /**************************************************************************
243 DWORD WINAPI RtlCopySid(DWORD len,LPSID to,LPSID from)
245 if (len<(from->SubAuthorityCount*4+8))
246 return STATUS_BUFFER_TOO_SMALL;
247 memmove(to,from,from->SubAuthorityCount*4+8);
248 return STATUS_SUCCESS;
251 /**************************************************************************
252 * RtlAnsiStringToUnicodeString [NTDLL]
254 DWORD /* NTSTATUS */ WINAPI RtlAnsiStringToUnicodeString(LPUNICODE_STRING uni,LPANSI_STRING ansi,BOOL32 doalloc)
256 DWORD unilen = (ansi->Length+1)*sizeof(WCHAR);
259 return STATUS_INVALID_PARAMETER_2;
260 uni->Length = unilen;
262 uni->MaximumLength = unilen;
263 uni->Buffer = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,unilen);
265 return STATUS_NO_MEMORY;
267 if (unilen>uni->MaximumLength)
268 return STATUS_BUFFER_OVERFLOW;
269 lstrcpynAtoW(uni->Buffer,ansi->Buffer,unilen/2);
270 return STATUS_SUCCESS;
273 /**************************************************************************
274 * RtlOemStringToUnicodeString [NTDLL]
276 DWORD /* NTSTATUS */ WINAPI RtlOemStringToUnicodeString(LPUNICODE_STRING uni,LPSTRING ansi,BOOL32 doalloc)
278 DWORD unilen = (ansi->Length+1)*sizeof(WCHAR);
281 return STATUS_INVALID_PARAMETER_2;
282 uni->Length = unilen;
284 uni->MaximumLength = unilen;
285 uni->Buffer = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,unilen);
287 return STATUS_NO_MEMORY;
289 if (unilen>uni->MaximumLength)
290 return STATUS_BUFFER_OVERFLOW;
291 lstrcpynAtoW(uni->Buffer,ansi->Buffer,unilen/2);
292 return STATUS_SUCCESS;
294 /**************************************************************************
295 * RtlMultiByteToUnicodeN [NTDLL]
296 * FIXME: multibyte support
298 DWORD /* NTSTATUS */ WINAPI RtlMultiByteToUnicodeN(LPWSTR unistr,DWORD unilen,LPDWORD reslen,LPSTR oemstr,DWORD oemlen)
306 x=(LPWSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
307 lstrcpynAtoW(x,oemstr,len+1);
308 memcpy(unistr,x,len*2);
309 if (reslen) *reslen = len*2;
313 /**************************************************************************
314 * RtlOemToUnicodeN [NTDLL]
316 DWORD /* NTSTATUS */ WINAPI RtlOemToUnicodeN(LPWSTR unistr,DWORD unilen,LPDWORD reslen,LPSTR oemstr,DWORD oemlen)
324 x=(LPWSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
325 lstrcpynAtoW(x,oemstr,len+1);
326 memcpy(unistr,x,len*2);
327 if (reslen) *reslen = len*2;
331 /**************************************************************************
332 * RtlInitString [NTDLL]
334 VOID WINAPI RtlInitAnsiString(LPANSI_STRING target,LPCSTR source)
336 target->Length = target->MaximumLength = 0;
337 target->Buffer = (LPSTR)source;
340 target->Length = lstrlen32A(target->Buffer);
341 target->MaximumLength = target->Length+1;
343 /**************************************************************************
344 * RtlInitString [NTDLL]
346 VOID WINAPI RtlInitString(LPSTRING target,LPCSTR source)
348 target->Length = target->MaximumLength = 0;
349 target->Buffer = (LPSTR)source;
352 target->Length = lstrlen32A(target->Buffer);
353 target->MaximumLength = target->Length+1;
356 /**************************************************************************
357 * RtlInitUnicodeString [NTDLL]
359 VOID WINAPI RtlInitUnicodeString(LPUNICODE_STRING target,LPCWSTR source)
361 target->Length = target->MaximumLength = 0;
362 target->Buffer = (LPWSTR)source;
365 target->Length = lstrlen32W(target->Buffer)*2;
366 target->MaximumLength = target->Length+2;
369 /**************************************************************************
370 * RtlFreeUnicodeString [NTDLL]
372 VOID WINAPI RtlFreeUnicodeString(LPUNICODE_STRING str)
375 HeapFree(GetProcessHeap(),0,str->Buffer);
378 /**************************************************************************
379 * RtlUnicodeToOemN [NTDLL]
381 DWORD /* NTSTATUS */ WINAPI RtlUnicodeToOemN(LPSTR oemstr,DWORD oemlen,LPDWORD reslen,LPWSTR unistr,DWORD unilen)
389 x=(LPSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len+1);
390 lstrcpynWtoA(x,unistr,len+1);
391 memcpy(oemstr,x,len);
392 if (reslen) *reslen = len;
396 /**************************************************************************
397 * RtlUnicodeStringToOemString [NTDLL]
399 DWORD /* NTSTATUS */ WINAPI RtlUnicodeStringToOemString(LPANSI_STRING oem,LPUNICODE_STRING uni,BOOL32 alloc)
402 oem->Buffer = (LPSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,uni->Length/2)+1;
403 oem->MaximumLength = uni->Length/2+1;
405 oem->Length = uni->Length/2;
406 lstrcpynWtoA(oem->Buffer,uni->Buffer,uni->Length/2+1);
410 /**************************************************************************
411 * RtlUnicodeStringToAnsiString [NTDLL]
413 DWORD /* NTSTATUS */ WINAPI RtlUnicodeStringToAnsiString(LPUNICODE_STRING uni,LPANSI_STRING oem,BOOL32 alloc)
416 oem->Buffer = (LPSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,uni->Length/2)+1;
417 oem->MaximumLength = uni->Length/2+1;
419 oem->Length = uni->Length/2;
420 lstrcpynWtoA(oem->Buffer,uni->Buffer,uni->Length/2+1);
424 /**************************************************************************
425 * RtlNtStatusToDosErro [NTDLL]
427 DWORD WINAPI RtlNtStatusToDosError(DWORD error)
429 /* FIXME: map STATUS_ to ERROR_ */
433 /**************************************************************************
434 * RtlGetNtProductType [NTDLL]
436 DWORD WINAPI RtlGetNtProductType(LPVOID x)
438 /* FIXME : find documentation for this one */
442 /**************************************************************************
443 * RtlUpcaseUnicodeString [NTDLL]
445 DWORD WINAPI RtlUpcaseUnicodeString(LPUNICODE_STRING dest,LPUNICODE_STRING src,BOOL32 doalloc)
452 dest->MaximumLength = len;
453 dest->Buffer = (LPWSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,len);
455 return STATUS_NO_MEMORY;
458 if (dest->MaximumLength < len)
459 return STATUS_BUFFER_OVERFLOW;
460 s=dest->Buffer;t=src->Buffer;
461 /* len is in bytes */
462 for (i=0;i<len/2;i++)
464 return STATUS_SUCCESS;
467 /**************************************************************************
468 * RtlxOemStringToUnicodeSize [NTDLL]
470 UINT32 WINAPI RtlxOemStringToUnicodeSize(LPSTRING str)
472 return str->Length*2+2;
475 /**************************************************************************
476 * RtlxAnsiStringToUnicodeSize [NTDLL]
478 UINT32 WINAPI RtlxAnsiStringToUnicodeSize(LPANSI_STRING str)
480 return str->Length*2+2;
483 /**************************************************************************
484 * RtlDosPathNameToNtPathName_U [NTDLL]
486 * FIXME: convert to UNC or whatever is expected here
488 BOOL32 WINAPI RtlDosPathNameToNtPathName_U(
489 LPWSTR from,LPUNICODE_STRING us,DWORD x2,DWORD x3)
491 LPSTR fromA = HEAP_strdupWtoA(GetProcessHeap(),0,from);
493 fprintf(stderr,"RtlDosPathNameToNtPathName_U(%s,%p,%08lx,%08lx)\n",
497 RtlInitUnicodeString(us,HEAP_strdupW(GetProcessHeap(),0,from));
501 /**************************************************************************
504 DWORD WINAPI NtOpenFile(DWORD x1,DWORD flags,DWORD x3,DWORD x4,DWORD alignment,DWORD x6)
506 fprintf(stderr,"NtOpenFile(%08lx,%08lx,%08lx,%08lx,%08lx,%08lx)\n",
507 x1,flags,x3,x4,alignment,x6
509 /* returns file io completion status */
514 /**************************************************************************
515 * NTDLL_chkstk (NTDLL.862)
517 void NTDLL_chkstk(void)
519 /* FIXME: should subtract %eax bytes from stack pointer */