Implement A->W call for GetNamedSecurityInfo.
[wine] / dlls / ntdll / nt.c
1 /*
2  * NT basis DLL
3  *
4  * This file contains the Nt* API functions of NTDLL.DLL.
5  * In the original ntdll.dll they all seem to just call int 0x2e (down to the NTOSKRNL)
6  *
7  * Copyright 1996-1998 Marcus Meissner
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <time.h>
29 #include "wine/debug.h"
30
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winreg.h"
34 #include "winternl.h"
35 #include "ntdll_misc.h"
36 #include "wine/server.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
39
40 /* Structures used by NtConnectPort */
41
42 typedef struct LpcSectionInfo
43 {
44   DWORD Length;
45   HANDLE SectionHandle;
46   DWORD Param1;
47   DWORD SectionSize;
48   DWORD ClientBaseAddress;
49   DWORD ServerBaseAddress;
50 } LPCSECTIONINFO, *PLPCSECTIONINFO;
51
52 typedef struct LpcSectionMapInfo
53 {
54   DWORD Length;
55   DWORD SectionSize;
56   DWORD ServerBaseAddress;
57 } LPCSECTIONMAPINFO, *PLPCSECTIONMAPINFO;
58
59 /* Structure used by NtAcceptConnectPort, NtReplyWaitReceivePort */
60
61 #define MAX_MESSAGE_DATA 328
62
63 typedef struct LpcMessage
64 {
65   WORD ActualMessageLength;
66   WORD TotalMessageLength;
67   DWORD MessageType;
68   DWORD ClientProcessId;
69   DWORD ClientThreadId;
70   DWORD MessageId;
71   DWORD SharedSectionSize;
72   BYTE MessageData[MAX_MESSAGE_DATA];
73 } LPCMESSAGE, *PLPCMESSAGE;
74
75 /*
76  *      Token
77  */
78
79 /******************************************************************************
80  *  NtDuplicateToken            [NTDLL.@]
81  *  ZwDuplicateToken            [NTDLL.@]
82  */
83 NTSTATUS WINAPI NtDuplicateToken(
84         IN HANDLE ExistingToken,
85         IN ACCESS_MASK DesiredAccess,
86         IN POBJECT_ATTRIBUTES ObjectAttributes,
87         IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
88         IN TOKEN_TYPE TokenType,
89         OUT PHANDLE NewToken)
90 {
91         FIXME("(%p,0x%08lx,%p,0x%08x,0x%08x,%p),stub!\n",
92         ExistingToken, DesiredAccess, ObjectAttributes,
93         ImpersonationLevel, TokenType, NewToken);
94         dump_ObjectAttributes(ObjectAttributes);
95         return 0;
96 }
97
98 /******************************************************************************
99  *  NtOpenProcessToken          [NTDLL.@]
100  *  ZwOpenProcessToken          [NTDLL.@]
101  */
102 NTSTATUS WINAPI NtOpenProcessToken(
103         HANDLE ProcessHandle,
104         DWORD DesiredAccess,
105         HANDLE *TokenHandle)
106 {
107     NTSTATUS ret;
108
109     TRACE("(%p,0x%08lx,%p)\n", ProcessHandle,DesiredAccess, TokenHandle);
110
111     SERVER_START_REQ( open_token )
112     {
113         req->handle = ProcessHandle;
114         req->flags  = 0;
115         ret = wine_server_call( req );
116         if (!ret) *TokenHandle = reply->token;
117     }
118     SERVER_END_REQ;
119
120     return ret;
121 }
122
123 /******************************************************************************
124  *  NtOpenThreadToken           [NTDLL.@]
125  *  ZwOpenThreadToken           [NTDLL.@]
126  */
127 NTSTATUS WINAPI NtOpenThreadToken(
128         HANDLE ThreadHandle,
129         DWORD DesiredAccess,
130         BOOLEAN OpenAsSelf,
131         HANDLE *TokenHandle)
132 {
133     NTSTATUS ret;
134
135     TRACE("(%p,0x%08lx,0x%08x,%p)\n",
136           ThreadHandle,DesiredAccess, OpenAsSelf, TokenHandle);
137
138     SERVER_START_REQ( open_token )
139     {
140         req->handle = ThreadHandle;
141         req->flags  = OPEN_TOKEN_THREAD;
142         if (OpenAsSelf) req->flags |= OPEN_TOKEN_AS_SELF;
143         ret = wine_server_call( req );
144         if (!ret) *TokenHandle = reply->token;
145     }
146     SERVER_END_REQ;
147
148     return ret;
149 }
150
151 /******************************************************************************
152  *  NtAdjustPrivilegesToken             [NTDLL.@]
153  *  ZwAdjustGroupsToken         [NTDLL.@]
154  *
155  * FIXME: parameters unsafe
156  */
157 NTSTATUS WINAPI NtAdjustPrivilegesToken(
158         IN HANDLE TokenHandle,
159         IN BOOLEAN DisableAllPrivileges,
160         IN PTOKEN_PRIVILEGES NewState,
161         IN DWORD BufferLength,
162         OUT PTOKEN_PRIVILEGES PreviousState,
163         OUT PDWORD ReturnLength)
164 {
165         FIXME("(%p,0x%08x,%p,0x%08lx,%p,%p),stub!\n",
166         TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength);
167         return 0;
168 }
169
170 /******************************************************************************
171 *  NtQueryInformationToken              [NTDLL.@]
172 *  ZwQueryInformationToken              [NTDLL.@]
173 *
174 * NOTES
175 *  Buffer for TokenUser:
176 *   0x00 TOKEN_USER the PSID field points to the SID
177 *   0x08 SID
178 *
179 */
180 NTSTATUS WINAPI NtQueryInformationToken(
181         HANDLE token,
182         DWORD tokeninfoclass,
183         LPVOID tokeninfo,
184         DWORD tokeninfolength,
185         LPDWORD retlen )
186 {
187     unsigned int len = 0;
188
189     TRACE("(%p,%ld,%p,%ld,%p)\n",
190           token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
191
192     switch (tokeninfoclass)
193     {
194     case TokenUser:
195         len = sizeof(TOKEN_USER) + sizeof(SID);
196         break;
197     case TokenGroups:
198         len = sizeof(TOKEN_GROUPS);
199         break;
200     case TokenPrivileges:
201         len = sizeof(TOKEN_PRIVILEGES);
202         break;
203     case TokenOwner:
204         len = sizeof(TOKEN_OWNER) + sizeof(SID);
205         break;
206     case TokenPrimaryGroup:
207         len = sizeof(TOKEN_PRIMARY_GROUP);
208         break;
209     case TokenDefaultDacl:
210         len = sizeof(TOKEN_DEFAULT_DACL);
211         break;
212     case TokenSource:
213         len = sizeof(TOKEN_SOURCE);
214         break;
215     case TokenType:
216         len = sizeof (TOKEN_TYPE);
217         break;
218 #if 0
219     case TokenImpersonationLevel:
220     case TokenStatistics:
221 #endif /* 0 */
222     }
223
224     /* FIXME: what if retlen == NULL ? */
225     *retlen = len;
226
227     if (tokeninfolength < len)
228         return STATUS_BUFFER_TOO_SMALL;
229
230     switch (tokeninfoclass)
231     {
232     case TokenUser:
233         if( tokeninfo )
234         {
235             TOKEN_USER * tuser = tokeninfo;
236             PSID sid = (PSID) (tuser + 1);
237             SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
238             RtlInitializeSid(sid, &localSidAuthority, 1);
239             *(RtlSubAuthoritySid(sid, 0)) = SECURITY_INTERACTIVE_RID;
240             tuser->User.Sid = sid;
241         }
242         break;
243     case TokenGroups:
244         if (tokeninfo)
245         {
246             TOKEN_GROUPS *tgroups = tokeninfo;
247             SID_IDENTIFIER_AUTHORITY sid = {SECURITY_NT_AUTHORITY};
248
249             /* we need to show admin privileges ! */
250             tgroups->GroupCount = 1;
251             tgroups->Groups->Attributes = SE_GROUP_ENABLED;
252             RtlAllocateAndInitializeSid( &sid,
253                                          2,
254                                          SECURITY_BUILTIN_DOMAIN_RID,
255                                          DOMAIN_ALIAS_RID_ADMINS,
256                                          0, 0, 0, 0, 0, 0,
257                                          &(tgroups->Groups->Sid));
258         }
259         break;
260     case TokenPrivileges:
261         if (tokeninfo)
262         {
263             TOKEN_PRIVILEGES *tpriv = tokeninfo;
264             tpriv->PrivilegeCount = 1;
265         }
266         break;
267     case TokenOwner:
268         if (tokeninfo)
269         {
270             TOKEN_OWNER *owner = tokeninfo;
271             PSID sid = (PSID) (owner + 1);
272             SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
273             RtlInitializeSid(sid, &localSidAuthority, 1);
274             *(RtlSubAuthoritySid(sid, 0)) = SECURITY_INTERACTIVE_RID;
275             owner->Owner = sid;
276         }
277         break;
278     default:
279         {
280             ERR("Unhandled Token Information class!\n");
281             return STATUS_NOT_IMPLEMENTED;
282         }
283     }
284     return 0;
285 }
286
287 /*
288  *      Section
289  */
290
291 /******************************************************************************
292  *  NtQuerySection      [NTDLL.@]
293  */
294 NTSTATUS WINAPI NtQuerySection(
295         IN HANDLE SectionHandle,
296         IN PVOID SectionInformationClass,
297         OUT PVOID SectionInformation,
298         IN ULONG Length,
299         OUT PULONG ResultLength)
300 {
301         FIXME("(%p,%p,%p,0x%08lx,%p) stub!\n",
302         SectionHandle,SectionInformationClass,SectionInformation,Length,ResultLength);
303         return 0;
304 }
305
306 /*
307  *      ports
308  */
309
310 /******************************************************************************
311  *  NtCreatePort                [NTDLL.@]
312  *  ZwCreatePort                [NTDLL.@]
313  */
314 NTSTATUS WINAPI NtCreatePort(PHANDLE PortHandle,POBJECT_ATTRIBUTES ObjectAttributes,
315                              DWORD MaxConnectInfoLength,DWORD MaxDataLength,DWORD unknown)
316 {
317   FIXME("(%p,%p,0x%08lx,0x%08lx,0x%08lx),stub!\n",PortHandle,ObjectAttributes,
318         MaxConnectInfoLength,MaxDataLength,unknown);
319   return 0;
320 }
321
322 /******************************************************************************
323  *  NtConnectPort               [NTDLL.@]
324  *  ZwConnectPort               [NTDLL.@]
325  */
326 NTSTATUS WINAPI NtConnectPort(PHANDLE PortHandle,PUNICODE_STRING PortName,PVOID Unknown1,
327                               PLPCSECTIONINFO sectionInfo,PLPCSECTIONMAPINFO mapInfo,PVOID Unknown2,
328                               PVOID ConnectInfo,PDWORD pConnectInfoLength)
329 {
330   FIXME("(%p,%s,%p,%p,%p,%p,%p,%p (%ld)),stub!\n",PortHandle,debugstr_w(PortName->Buffer),Unknown1,
331         sectionInfo,mapInfo,Unknown2,ConnectInfo,pConnectInfoLength,pConnectInfoLength?*pConnectInfoLength:-1);
332   if(ConnectInfo && pConnectInfoLength)
333     TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo,*pConnectInfoLength));
334   return 0;
335 }
336
337 /******************************************************************************
338  *  NtListenPort                [NTDLL.@]
339  *  ZwListenPort                [NTDLL.@]
340  */
341 NTSTATUS WINAPI NtListenPort(HANDLE PortHandle,PLPCMESSAGE pLpcMessage)
342 {
343   FIXME("(%p,%p),stub!\n",PortHandle,pLpcMessage);
344   return 0;
345 }
346
347 /******************************************************************************
348  *  NtAcceptConnectPort [NTDLL.@]
349  *  ZwAcceptConnectPort [NTDLL.@]
350  */
351 NTSTATUS WINAPI NtAcceptConnectPort(PHANDLE PortHandle,DWORD Unknown,PLPCMESSAGE pLpcMessage,
352                                     DWORD acceptIt,DWORD Unknown2,PLPCSECTIONMAPINFO mapInfo)
353 {
354   FIXME("(%p,0x%08lx,%p,0x%08lx,0x%08lx,%p),stub!\n",PortHandle,Unknown,pLpcMessage,acceptIt,Unknown2,mapInfo);
355   return 0;
356 }
357
358 /******************************************************************************
359  *  NtCompleteConnectPort       [NTDLL.@]
360  *  ZwCompleteConnectPort       [NTDLL.@]
361  */
362 NTSTATUS WINAPI NtCompleteConnectPort(HANDLE PortHandle)
363 {
364   FIXME("(%p),stub!\n",PortHandle);
365   return 0;
366 }
367
368 /******************************************************************************
369  *  NtRegisterThreadTerminatePort       [NTDLL.@]
370  *  ZwRegisterThreadTerminatePort       [NTDLL.@]
371  */
372 NTSTATUS WINAPI NtRegisterThreadTerminatePort(HANDLE PortHandle)
373 {
374   FIXME("(%p),stub!\n",PortHandle);
375   return 0;
376 }
377
378 /******************************************************************************
379  *  NtRequestWaitReplyPort              [NTDLL.@]
380  *  ZwRequestWaitReplyPort              [NTDLL.@]
381  */
382 NTSTATUS WINAPI NtRequestWaitReplyPort(HANDLE PortHandle,PLPCMESSAGE pLpcMessageIn,PLPCMESSAGE pLpcMessageOut)
383 {
384   FIXME("(%p,%p,%p),stub!\n",PortHandle,pLpcMessageIn,pLpcMessageOut);
385   if(pLpcMessageIn)
386   {
387     TRACE("Message to send:\n");
388     TRACE("\tActualMessageLength = %d\n",pLpcMessageIn->ActualMessageLength);
389     TRACE("\tTotalMessageLength  = %d\n",pLpcMessageIn->TotalMessageLength);
390     TRACE("\tMessageType         = %ld\n",pLpcMessageIn->MessageType);
391     TRACE("\tClientProcessId     = %ld\n",pLpcMessageIn->ClientProcessId);
392     TRACE("\tClientThreadId      = %ld\n",pLpcMessageIn->ClientThreadId);
393     TRACE("\tMessageId           = %ld\n",pLpcMessageIn->MessageId);
394     TRACE("\tSharedSectionSize   = %ld\n",pLpcMessageIn->SharedSectionSize);
395     TRACE("\tMessageData         = %s\n",debugstr_an(pLpcMessageIn->MessageData,pLpcMessageIn->ActualMessageLength));
396   }
397   return 0;
398 }
399
400 /******************************************************************************
401  *  NtReplyWaitReceivePort      [NTDLL.@]
402  *  ZwReplyWaitReceivePort      [NTDLL.@]
403  */
404 NTSTATUS WINAPI NtReplyWaitReceivePort(HANDLE PortHandle,PDWORD Unknown,PLPCMESSAGE pLpcMessageOut,PLPCMESSAGE pLpcMessageIn)
405 {
406   FIXME("(%p,%p,%p,%p),stub!\n",PortHandle,Unknown,pLpcMessageOut,pLpcMessageIn);
407   return 0;
408 }
409
410 /*
411  *      Misc
412  */
413
414  /******************************************************************************
415  *  NtSetIntervalProfile        [NTDLL.@]
416  *  ZwSetIntervalProfile        [NTDLL.@]
417  */
418 NTSTATUS WINAPI NtSetIntervalProfile(DWORD x1,DWORD x2) {
419         FIXME("(0x%08lx,0x%08lx),stub!\n",x1,x2);
420         return 0;
421 }
422
423 /******************************************************************************
424  *  NtQueryPerformanceCounter   [NTDLL.@]
425  */
426 NTSTATUS WINAPI NtQueryPerformanceCounter(
427         IN PLARGE_INTEGER Counter,
428         IN PLARGE_INTEGER Frequency)
429 {
430         FIXME("(%p, 0%p) stub\n",
431         Counter, Frequency);
432         return 0;
433 }
434
435 /******************************************************************************
436  *  NtCreateMailslotFile        [NTDLL.@]
437  *  ZwCreateMailslotFile        [NTDLL.@]
438  */
439 NTSTATUS WINAPI NtCreateMailslotFile(DWORD x1,DWORD x2,DWORD x3,DWORD x4,DWORD x5,DWORD x6,DWORD x7,DWORD x8)
440 {
441         FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,x2,x3,x4,x5,x6,x7,x8);
442         return 0;
443 }
444
445 /******************************************************************************
446  * NtQuerySystemInformation [NTDLL.@]
447  * ZwQuerySystemInformation [NTDLL.@]
448  *
449  * ARGUMENTS:
450  *  SystemInformationClass      Index to a certain information structure
451  *      SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
452  *      SystemCacheInformation          SYSTEM_CACHE_INFORMATION
453  *      SystemConfigurationInformation  CONFIGURATION_INFORMATION
454  *      observed (class/len):
455  *              0x0/0x2c
456  *              0x12/0x18
457  *              0x2/0x138
458  *              0x8/0x600
459  *              0x25/0xc
460  *  SystemInformation   caller supplies storage for the information structure
461  *  Length              size of the structure
462  *  ResultLength        Data written
463  */
464 NTSTATUS WINAPI NtQuerySystemInformation(
465         IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
466         OUT PVOID SystemInformation,
467         IN ULONG Length,
468         OUT PULONG ResultLength)
469 {
470     NTSTATUS    ret = STATUS_SUCCESS;
471     ULONG       len = 0;
472
473     TRACE("(0x%08x,%p,0x%08lx,%p)\n",
474           SystemInformationClass,SystemInformation,Length,ResultLength);
475
476     switch (SystemInformationClass)
477     {
478     case SystemBasicInformation:
479         {
480             SYSTEM_BASIC_INFORMATION* sbi = (SYSTEM_BASIC_INFORMATION*)SystemInformation;
481             if (Length >= sizeof(*sbi))
482             {
483                 sbi->dwUnknown1 = 0;
484                 sbi->uKeMaximumIncrement = 0;
485                 sbi->uPageSize = 1024; /* FIXME */
486                 sbi->uMmNumberOfPhysicalPages = 12345; /* FIXME */
487                 sbi->uMmLowestPhysicalPage = 0; /* FIXME */
488                 sbi->uMmHighestPhysicalPage = 12345; /* FIXME */
489                 sbi->uAllocationGranularity = 65536; /* FIXME */
490                 sbi->pLowestUserAddress = 0; /* FIXME */
491                 sbi->pMmHighestUserAddress = (void*)~0; /* FIXME */
492                 sbi->uKeActiveProcessors = 1; /* FIXME */
493                 sbi->bKeNumberProcessors = 1; /* FIXME */
494                 len = sizeof(*sbi);
495             }
496             else ret = STATUS_INFO_LENGTH_MISMATCH;
497         }
498         break;
499     case SystemPerformanceInformation:
500         {
501             SYSTEM_PERFORMANCE_INFORMATION* spi = (SYSTEM_PERFORMANCE_INFORMATION*)SystemInformation;
502             if (Length >= sizeof(*spi))
503             {
504                 memset(spi, 0, sizeof(*spi)); /* FIXME */
505                 len = sizeof(*spi);
506             }
507             else ret = STATUS_INFO_LENGTH_MISMATCH;
508         }
509         break;
510     case SystemTimeOfDayInformation:
511         {
512             SYSTEM_TIMEOFDAY_INFORMATION* sti = (SYSTEM_TIMEOFDAY_INFORMATION*)SystemInformation;
513             if (Length >= sizeof(*sti))
514             {
515                 sti->liKeBootTime.QuadPart = 0; /* FIXME */
516                 sti->liKeSystemTime.QuadPart = 0; /* FIXME */
517                 sti->liExpTimeZoneBias.QuadPart  = 0; /* FIXME */
518                 sti->uCurrentTimeZoneId = 0; /* FIXME */
519                 sti->dwReserved = 0;
520                 len = sizeof(*sti);
521             }
522             else ret = STATUS_INFO_LENGTH_MISMATCH;
523         }
524         break;
525     case SystemProcessInformation:
526         {
527             SYSTEM_PROCESS_INFORMATION* spi = (SYSTEM_PROCESS_INFORMATION*)SystemInformation;
528             SYSTEM_PROCESS_INFORMATION* last = NULL;
529             HANDLE hSnap = 0;
530             WCHAR procname[1024];
531             DWORD wlen = 0;
532
533             SERVER_START_REQ( create_snapshot )
534             {
535                 req->flags   = SNAP_PROCESS | SNAP_THREAD;
536                 req->inherit = FALSE;
537                 req->pid     = 0;
538                 if (!(ret = wine_server_call( req ))) hSnap = reply->handle;
539             }
540             SERVER_END_REQ;
541             len = 0;
542             while (ret == STATUS_SUCCESS)
543             {
544                 SERVER_START_REQ( next_process )
545                 {
546                     req->handle = hSnap;
547                     req->reset = (len == 0);
548                     wine_server_set_reply( req, procname, sizeof(procname) );
549                     if (!(ret = wine_server_call( req )))
550                     {
551                         wlen = wine_server_reply_size(reply) + sizeof(WCHAR);
552                         if (Length >= len + sizeof(*spi))
553                         {
554                             memset(spi, 0, sizeof(*spi));
555                             spi->dwOffset = sizeof(*spi);
556                             spi->dwThreadCount = reply->threads;
557                             memset(&spi->ftCreationTime, 0, sizeof(spi->ftCreationTime));
558                             /* spi->pszProcessName will be set later on */
559                             spi->dwBasePriority = reply->priority;
560                             spi->dwProcessID = (DWORD)reply->pid;
561                             spi->dwParentProcessID = (DWORD)reply->ppid;
562                             spi->dwHandleCount = reply->handles;
563                             spi->dwVirtualBytesPeak = 0; /* FIXME */
564                             spi->dwVirtualBytes = 0; /* FIXME */
565                             spi->dwPageFaults = 0; /* FIXME */
566                             spi->dwWorkingSetPeak = 0; /* FIXME */
567                             spi->dwWorkingSet = 0; /* FIXME */
568                             spi->dwUnknown5 = 0; /* FIXME */
569                             spi->dwPagedPool = 0; /* FIXME */
570                             spi->dwUnknown6 = 0; /* FIXME */
571                             spi->dwNonPagedPool = 0; /* FIXME */
572                             spi->dwPageFileBytesPeak = 0; /* FIXME */
573                             spi->dwPrivateBytes = 0; /* FIXME */
574                             spi->dwPageFileBytes = 0; /* FIXME */
575                             /* spi->ti will be set later on */
576                             len += sizeof(*spi) - sizeof(spi->ti);
577                         }
578                         else ret = STATUS_INFO_LENGTH_MISMATCH;
579                     }
580                 }
581                 SERVER_END_REQ;
582                 if (ret != STATUS_SUCCESS)
583                 {
584                     if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
585                     break;
586                 }
587                 if (Length >= len + wlen + spi->dwThreadCount * sizeof(THREAD_INFO))
588                 {
589                     int     i, j;
590
591                     /* set thread info */
592                     spi->dwOffset += spi->dwThreadCount * sizeof(THREAD_INFO);
593                     len += spi->dwThreadCount * sizeof(THREAD_INFO);
594                     i = j = 0;
595                     while (ret == STATUS_SUCCESS)
596                     {
597                         SERVER_START_REQ( next_thread )
598                         {
599                             req->handle = hSnap;
600                             req->reset = (j == 0);
601                             if (!(ret = wine_server_call( req )))
602                             {
603                                 j++;
604                                 if (reply->pid == spi->dwProcessID)
605                                 {
606                                     /* ftKernelTime, ftUserTime, ftCreateTime;
607                                      * dwTickCount, dwStartAddress
608                                      */
609                                     spi->ti[i].dwOwningPID = reply->pid;
610                                     spi->ti[i].dwThreadID  = reply->tid;
611                                     spi->ti[i].dwCurrentPriority = reply->base_pri + reply->delta_pri;
612                                     spi->ti[i].dwBasePriority = reply->base_pri;
613                                     i++;
614                                 }
615                             }
616                         }
617                         SERVER_END_REQ;
618                     }
619                     if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
620
621                     /* now append process name */
622                     spi->pszProcessName = (WCHAR*)((char*)spi + spi->dwOffset);
623                     memcpy( spi->pszProcessName, procname, wlen - sizeof(WCHAR) );
624                     spi->pszProcessName[wlen / sizeof(WCHAR)] = 0;
625                     len += wlen;
626                     spi->dwOffset += wlen;
627
628                     last = spi;
629                     spi = (SYSTEM_PROCESS_INFORMATION*)((char*)spi + spi->dwOffset);
630                 }
631                 else ret = STATUS_INFO_LENGTH_MISMATCH;
632             }
633             if (ret == STATUS_SUCCESS && last) last->dwOffset = 0;
634             if (hSnap) NtClose(hSnap);
635         }
636         break;
637     case SystemProcessorPerformanceInformation:
638         {
639             SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* sppi = (SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION*)SystemInformation;
640             if (Length >= sizeof(*sppi))
641             {
642                 memset(sppi, 0, sizeof(*sppi)); /* FIXME */
643                 len = sizeof(*sppi);
644             }
645             else ret = STATUS_INFO_LENGTH_MISMATCH;
646         }
647         break;
648
649     case SystemCacheInformation:
650         {
651             SYSTEM_CACHE_INFORMATION* sci = (SYSTEM_CACHE_INFORMATION*)SystemInformation;
652             if (Length >= sizeof(*sci))
653             {
654                 memset(sci, 0, sizeof(*sci)); /* FIXME */
655                 len = sizeof(*sci);
656             }
657             else ret = STATUS_INFO_LENGTH_MISMATCH;
658         }
659         break;
660     case SystemRegistryQuotaInformation:
661         /* Something to do with the size of the registry             *
662          * Since we don't have a size limitation, fake it            *
663          * This is almost certainly wrong.                           *
664          * This sets each of the three words in the struct to 32 MB, *
665          * which is enough to make the IE 5 installer happy.         */
666         {
667             SYSTEM_REGISTRY_QUOTA_INFORMATION* srqi = (SYSTEM_REGISTRY_QUOTA_INFORMATION*)SystemInformation;
668             if (Length >= sizeof(*srqi))
669             {
670                 FIXME("(0x%08x,%p,0x%08lx,%p) faking max registry size of 32 MB\n",
671                       SystemInformationClass,SystemInformation,Length,ResultLength);
672                 srqi->RegistryQuotaAllowed = 0x2000000;
673                 srqi->RegistryQuotaUsed = 0x200000;
674                 srqi->Reserved1 = (void*)0x200000;
675                 if (ResultLength) *ResultLength = sizeof(*srqi);
676             }
677             else ret = STATUS_INFO_LENGTH_MISMATCH;
678         }
679         break;
680
681     default:
682         FIXME("(0x%08x,%p,0x%08lx,%p) stub\n",
683               SystemInformationClass,SystemInformation,Length,ResultLength);
684         memset(SystemInformation, 0, Length);
685         ret = STATUS_NOT_IMPLEMENTED;
686     }
687     if (ResultLength) *ResultLength = len;
688
689     return ret;
690 }
691
692
693 /******************************************************************************
694  *  NtCreatePagingFile          [NTDLL.@]
695  *  ZwCreatePagingFile          [NTDLL.@]
696  */
697 NTSTATUS WINAPI NtCreatePagingFile(
698         IN PUNICODE_STRING PageFileName,
699         IN ULONG MiniumSize,
700         IN ULONG MaxiumSize,
701         OUT PULONG ActualSize)
702 {
703         FIXME("(%p(%s),0x%08lx,0x%08lx,%p),stub!\n",
704         PageFileName->Buffer, debugstr_w(PageFileName->Buffer),MiniumSize,MaxiumSize,ActualSize);
705         return 0;
706 }
707
708 /******************************************************************************
709  *  NtDisplayString                             [NTDLL.@]
710  *
711  * writes a string to the nt-textmode screen eg. during startup
712  */
713 NTSTATUS WINAPI NtDisplayString ( PUNICODE_STRING string )
714 {
715     STRING stringA;
716     NTSTATUS ret;
717
718     if (!(ret = RtlUnicodeStringToAnsiString( &stringA, string, TRUE )))
719     {
720         MESSAGE( "%.*s", stringA.Length, stringA.Buffer );
721         RtlFreeAnsiString( &stringA );
722     }
723     return ret;
724 }
725
726 /******************************************************************************
727  *  NtPowerInformation                          [NTDLL.@]
728  *
729  */
730 NTSTATUS WINAPI NtPowerInformation(DWORD x1,DWORD x2,DWORD x3,DWORD x4,DWORD x5)
731 {
732         FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub\n",x1,x2,x3,x4,x5);
733         return 0;
734 }
735
736 /******************************************************************************
737  *  NtAllocateLocallyUniqueId (NTDLL.@)
738  *
739  * FIXME: the server should do that
740  */
741 NTSTATUS WINAPI NtAllocateLocallyUniqueId(PLUID Luid)
742 {
743     static LUID luid;
744
745     FIXME("%p (0x%08lx%08lx)\n", Luid, luid.HighPart, luid.LowPart);
746
747     luid.LowPart++;
748     if (luid.LowPart==0)
749         luid.HighPart++;
750     Luid->HighPart = luid.HighPart;
751     Luid->LowPart = luid.LowPart;
752
753     return STATUS_SUCCESS;
754 }
755
756 /******************************************************************************
757  *        VerSetConditionMask   (NTDLL.@)
758  */
759 ULONGLONG WINAPI VerSetConditionMask( ULONGLONG dwlConditionMask, DWORD dwTypeBitMask,
760                                       BYTE dwConditionMask)
761 {
762     if(dwTypeBitMask == 0)
763         return dwlConditionMask;
764     dwConditionMask &= 0x07;
765     if(dwConditionMask == 0)
766         return dwlConditionMask;
767
768     if(dwTypeBitMask & VER_PRODUCT_TYPE)
769         dwlConditionMask |= dwConditionMask << 7*3;
770     else if (dwTypeBitMask & VER_SUITENAME)
771         dwlConditionMask |= dwConditionMask << 6*3;
772     else if (dwTypeBitMask & VER_SERVICEPACKMAJOR)
773         dwlConditionMask |= dwConditionMask << 5*3;
774     else if (dwTypeBitMask & VER_SERVICEPACKMINOR)
775         dwlConditionMask |= dwConditionMask << 4*3;
776     else if (dwTypeBitMask & VER_PLATFORMID)
777         dwlConditionMask |= dwConditionMask << 3*3;
778     else if (dwTypeBitMask & VER_BUILDNUMBER)
779         dwlConditionMask |= dwConditionMask << 2*3;
780     else if (dwTypeBitMask & VER_MAJORVERSION)
781         dwlConditionMask |= dwConditionMask << 1*3;
782     else if (dwTypeBitMask & VER_MINORVERSION)
783         dwlConditionMask |= dwConditionMask << 0*3;
784     return dwlConditionMask;
785 }