ntdll: Fix the various structures returned by NtQuerySystemInformation for 64-bit.
[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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <time.h>
29
30 #define NONAMELESSUNION
31 #include "ntstatus.h"
32 #define WIN32_NO_STATUS
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
35 #include "windef.h"
36 #include "winternl.h"
37 #include "ntdll_misc.h"
38 #include "wine/server.h"
39
40 #ifdef __APPLE__
41 #include <mach/mach_init.h>
42 #include <mach/mach_host.h>
43 #include <mach/vm_map.h>
44 #endif
45
46 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
47
48 /*
49  *      Token
50  */
51
52 /******************************************************************************
53  *  NtDuplicateToken            [NTDLL.@]
54  *  ZwDuplicateToken            [NTDLL.@]
55  */
56 NTSTATUS WINAPI NtDuplicateToken(
57         IN HANDLE ExistingToken,
58         IN ACCESS_MASK DesiredAccess,
59         IN POBJECT_ATTRIBUTES ObjectAttributes,
60         IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
61         IN TOKEN_TYPE TokenType,
62         OUT PHANDLE NewToken)
63 {
64     NTSTATUS status;
65
66     TRACE("(%p,0x%08x,%p,0x%08x,0x%08x,%p)\n",
67         ExistingToken, DesiredAccess, ObjectAttributes,
68         ImpersonationLevel, TokenType, NewToken);
69         dump_ObjectAttributes(ObjectAttributes);
70
71     if (ObjectAttributes && ObjectAttributes->SecurityQualityOfService)
72     {
73         SECURITY_QUALITY_OF_SERVICE *SecurityQOS = ObjectAttributes->SecurityQualityOfService;
74         TRACE("ObjectAttributes->SecurityQualityOfService = {%d, %d, %d, %s}\n",
75             SecurityQOS->Length, SecurityQOS->ImpersonationLevel,
76             SecurityQOS->ContextTrackingMode,
77             SecurityQOS->EffectiveOnly ? "TRUE" : "FALSE");
78         ImpersonationLevel = SecurityQOS->ImpersonationLevel;
79     }
80
81     SERVER_START_REQ( duplicate_token )
82     {
83         req->handle              = wine_server_obj_handle( ExistingToken );
84         req->access              = DesiredAccess;
85         req->attributes          = ObjectAttributes ? ObjectAttributes->Attributes : 0;
86         req->primary             = (TokenType == TokenPrimary);
87         req->impersonation_level = ImpersonationLevel;
88         status = wine_server_call( req );
89         if (!status) *NewToken = wine_server_ptr_handle( reply->new_handle );
90     }
91     SERVER_END_REQ;
92
93     return status;
94 }
95
96 /******************************************************************************
97  *  NtOpenProcessToken          [NTDLL.@]
98  *  ZwOpenProcessToken          [NTDLL.@]
99  */
100 NTSTATUS WINAPI NtOpenProcessToken(
101         HANDLE ProcessHandle,
102         DWORD DesiredAccess,
103         HANDLE *TokenHandle)
104 {
105     return NtOpenProcessTokenEx( ProcessHandle, DesiredAccess, 0, TokenHandle );
106 }
107
108 /******************************************************************************
109  *  NtOpenProcessTokenEx   [NTDLL.@]
110  *  ZwOpenProcessTokenEx   [NTDLL.@]
111  */
112 NTSTATUS WINAPI NtOpenProcessTokenEx( HANDLE process, DWORD access, DWORD attributes,
113                                       HANDLE *handle )
114 {
115     NTSTATUS ret;
116
117     TRACE("(%p,0x%08x,0x%08x,%p)\n", process, access, attributes, handle);
118
119     SERVER_START_REQ( open_token )
120     {
121         req->handle     = wine_server_obj_handle( process );
122         req->access     = access;
123         req->attributes = attributes;
124         req->flags      = 0;
125         ret = wine_server_call( req );
126         if (!ret) *handle = wine_server_ptr_handle( reply->token );
127     }
128     SERVER_END_REQ;
129     return ret;
130 }
131
132 /******************************************************************************
133  *  NtOpenThreadToken           [NTDLL.@]
134  *  ZwOpenThreadToken           [NTDLL.@]
135  */
136 NTSTATUS WINAPI NtOpenThreadToken(
137         HANDLE ThreadHandle,
138         DWORD DesiredAccess,
139         BOOLEAN OpenAsSelf,
140         HANDLE *TokenHandle)
141 {
142     return NtOpenThreadTokenEx( ThreadHandle, DesiredAccess, OpenAsSelf, 0, TokenHandle );
143 }
144
145 /******************************************************************************
146  *  NtOpenThreadTokenEx   [NTDLL.@]
147  *  ZwOpenThreadTokenEx   [NTDLL.@]
148  */
149 NTSTATUS WINAPI NtOpenThreadTokenEx( HANDLE thread, DWORD access, BOOLEAN as_self, DWORD attributes,
150                                      HANDLE *handle )
151 {
152     NTSTATUS ret;
153
154     TRACE("(%p,0x%08x,%u,0x%08x,%p)\n", thread, access, as_self, attributes, handle );
155
156     SERVER_START_REQ( open_token )
157     {
158         req->handle     = wine_server_obj_handle( thread );
159         req->access     = access;
160         req->attributes = attributes;
161         req->flags      = OPEN_TOKEN_THREAD;
162         if (as_self) req->flags |= OPEN_TOKEN_AS_SELF;
163         ret = wine_server_call( req );
164         if (!ret) *handle = wine_server_ptr_handle( reply->token );
165     }
166     SERVER_END_REQ;
167
168     return ret;
169 }
170
171 /******************************************************************************
172  *  NtAdjustPrivilegesToken             [NTDLL.@]
173  *  ZwAdjustPrivilegesToken             [NTDLL.@]
174  *
175  * FIXME: parameters unsafe
176  */
177 NTSTATUS WINAPI NtAdjustPrivilegesToken(
178         IN HANDLE TokenHandle,
179         IN BOOLEAN DisableAllPrivileges,
180         IN PTOKEN_PRIVILEGES NewState,
181         IN DWORD BufferLength,
182         OUT PTOKEN_PRIVILEGES PreviousState,
183         OUT PDWORD ReturnLength)
184 {
185     NTSTATUS ret;
186
187     TRACE("(%p,0x%08x,%p,0x%08x,%p,%p)\n",
188         TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength);
189
190     SERVER_START_REQ( adjust_token_privileges )
191     {
192         req->handle = wine_server_obj_handle( TokenHandle );
193         req->disable_all = DisableAllPrivileges;
194         req->get_modified_state = (PreviousState != NULL);
195         if (!DisableAllPrivileges)
196         {
197             wine_server_add_data( req, NewState->Privileges,
198                                   NewState->PrivilegeCount * sizeof(NewState->Privileges[0]) );
199         }
200         if (PreviousState && BufferLength >= FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
201             wine_server_set_reply( req, PreviousState->Privileges,
202                                    BufferLength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
203         ret = wine_server_call( req );
204         if (PreviousState)
205         {
206             *ReturnLength = reply->len + FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges );
207             PreviousState->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
208         }
209     }
210     SERVER_END_REQ;
211
212     return ret;
213 }
214
215 /******************************************************************************
216 *  NtQueryInformationToken              [NTDLL.@]
217 *  ZwQueryInformationToken              [NTDLL.@]
218 *
219 * NOTES
220 *  Buffer for TokenUser:
221 *   0x00 TOKEN_USER the PSID field points to the SID
222 *   0x08 SID
223 *
224 */
225 NTSTATUS WINAPI NtQueryInformationToken(
226         HANDLE token,
227         TOKEN_INFORMATION_CLASS tokeninfoclass,
228         PVOID tokeninfo,
229         ULONG tokeninfolength,
230         PULONG retlen )
231 {
232     ULONG len;
233     NTSTATUS status = STATUS_SUCCESS;
234
235     TRACE("(%p,%d,%p,%d,%p)\n",
236           token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
237
238     switch (tokeninfoclass)
239     {
240     case TokenOwner:
241         len = sizeof(TOKEN_OWNER) + sizeof(SID);
242         break;
243     case TokenPrimaryGroup:
244         len = sizeof(TOKEN_PRIMARY_GROUP);
245         break;
246     case TokenDefaultDacl:
247         len = sizeof(TOKEN_DEFAULT_DACL);
248         break;
249     case TokenSource:
250         len = sizeof(TOKEN_SOURCE);
251         break;
252     case TokenType:
253         len = sizeof (TOKEN_TYPE);
254         break;
255     case TokenImpersonationLevel:
256         len = sizeof(SECURITY_IMPERSONATION_LEVEL);
257         break;
258     case TokenStatistics:
259         len = sizeof(TOKEN_STATISTICS);
260         break;
261     default:
262         len = 0;
263     }
264
265     if (retlen) *retlen = len;
266
267     if (tokeninfolength < len)
268         return STATUS_BUFFER_TOO_SMALL;
269
270     switch (tokeninfoclass)
271     {
272     case TokenUser:
273         SERVER_START_REQ( get_token_user )
274         {
275             TOKEN_USER * tuser = tokeninfo;
276             PSID sid = (PSID) (tuser + 1);
277             DWORD sid_len = tokeninfolength < sizeof(TOKEN_USER) ? 0 : tokeninfolength - sizeof(TOKEN_USER);
278
279             req->handle = wine_server_obj_handle( token );
280             wine_server_set_reply( req, sid, sid_len );
281             status = wine_server_call( req );
282             if (retlen) *retlen = reply->user_len + sizeof(TOKEN_USER);
283             if (status == STATUS_SUCCESS)
284             {
285                 tuser->User.Sid = sid;
286                 tuser->User.Attributes = 0;
287             }
288         }
289         SERVER_END_REQ;
290         break;
291     case TokenGroups:
292     {
293         char stack_buffer[256];
294         unsigned int server_buf_len = sizeof(stack_buffer);
295         void *buffer = stack_buffer;
296         BOOLEAN need_more_memory = FALSE;
297
298         /* we cannot work out the size of the server buffer required for the
299          * input size, since there are two factors affecting how much can be
300          * stored in the buffer - number of groups and lengths of sids */
301         do
302         {
303             SERVER_START_REQ( get_token_groups )
304             {
305                 TOKEN_GROUPS *groups = tokeninfo;
306
307                 req->handle = wine_server_obj_handle( token );
308                 wine_server_set_reply( req, buffer, server_buf_len );
309                 status = wine_server_call( req );
310                 if (status == STATUS_BUFFER_TOO_SMALL)
311                 {
312                     if (buffer == stack_buffer)
313                         buffer = RtlAllocateHeap(GetProcessHeap(), 0, reply->user_len);
314                     else
315                         buffer = RtlReAllocateHeap(GetProcessHeap(), 0, buffer, reply->user_len);
316                     if (!buffer) return STATUS_NO_MEMORY;
317
318                     server_buf_len = reply->user_len;
319                     need_more_memory = TRUE;
320                 }
321                 else if (status == STATUS_SUCCESS)
322                 {
323                     struct token_groups *tg = buffer;
324                     unsigned int *attr = (unsigned int *)(tg + 1);
325                     ULONG i;
326                     const int non_sid_portion = (sizeof(struct token_groups) + tg->count * sizeof(unsigned long));
327                     SID *sids = (SID *)((char *)tokeninfo + FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ));
328                     ULONG needed_bytes = FIELD_OFFSET( TOKEN_GROUPS, Groups[tg->count] ) +
329                         reply->user_len - non_sid_portion;
330
331                     if (retlen) *retlen = needed_bytes;
332
333                     if (needed_bytes <= tokeninfolength)
334                     {
335                         groups->GroupCount = tg->count;
336                         memcpy( sids, (char *)buffer + non_sid_portion,
337                                 reply->user_len - non_sid_portion );
338
339                         for (i = 0; i < tg->count; i++)
340                         {
341                             groups->Groups[i].Attributes = attr[i];
342                             groups->Groups[i].Sid = sids;
343                             sids = (SID *)((char *)sids + RtlLengthSid(sids));
344                         }
345                     }
346                     else status = STATUS_BUFFER_TOO_SMALL;
347                 }
348                 else if (retlen) *retlen = 0;
349             }
350             SERVER_END_REQ;
351         } while (need_more_memory);
352         if (buffer != stack_buffer) RtlFreeHeap(GetProcessHeap(), 0, buffer);
353         break;
354     }
355     case TokenPrimaryGroup:
356         if (tokeninfo)
357         {
358             TOKEN_PRIMARY_GROUP *tgroup = tokeninfo;
359             SID_IDENTIFIER_AUTHORITY sid = {SECURITY_NT_AUTHORITY};
360             RtlAllocateAndInitializeSid( &sid,
361                                          2,
362                                          SECURITY_BUILTIN_DOMAIN_RID,
363                                          DOMAIN_ALIAS_RID_ADMINS,
364                                          0, 0, 0, 0, 0, 0,
365                                          &(tgroup->PrimaryGroup));
366         }
367         break;
368     case TokenPrivileges:
369         SERVER_START_REQ( get_token_privileges )
370         {
371             TOKEN_PRIVILEGES *tpriv = tokeninfo;
372             req->handle = wine_server_obj_handle( token );
373             if (tpriv && tokeninfolength > FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ))
374                 wine_server_set_reply( req, tpriv->Privileges, tokeninfolength - FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) );
375             status = wine_server_call( req );
376             if (retlen) *retlen = FIELD_OFFSET( TOKEN_PRIVILEGES, Privileges ) + reply->len;
377             if (tpriv) tpriv->PrivilegeCount = reply->len / sizeof(LUID_AND_ATTRIBUTES);
378         }
379         SERVER_END_REQ;
380         break;
381     case TokenOwner:
382         if (tokeninfo)
383         {
384             TOKEN_OWNER *owner = tokeninfo;
385             PSID sid = (PSID) (owner + 1);
386             SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
387             RtlInitializeSid(sid, &localSidAuthority, 1);
388             *(RtlSubAuthoritySid(sid, 0)) = SECURITY_INTERACTIVE_RID;
389             owner->Owner = sid;
390         }
391         break;
392     case TokenImpersonationLevel:
393         SERVER_START_REQ( get_token_impersonation_level )
394         {
395             SECURITY_IMPERSONATION_LEVEL *impersonation_level = tokeninfo;
396             req->handle = wine_server_obj_handle( token );
397             status = wine_server_call( req );
398             if (status == STATUS_SUCCESS)
399                 *impersonation_level = reply->impersonation_level;
400         }
401         SERVER_END_REQ;
402         break;
403     case TokenStatistics:
404         SERVER_START_REQ( get_token_statistics )
405         {
406             TOKEN_STATISTICS *statistics = tokeninfo;
407             req->handle = wine_server_obj_handle( token );
408             status = wine_server_call( req );
409             if (status == STATUS_SUCCESS)
410             {
411                 statistics->TokenId.LowPart  = reply->token_id.low_part;
412                 statistics->TokenId.HighPart = reply->token_id.high_part;
413                 statistics->AuthenticationId.LowPart  = 0; /* FIXME */
414                 statistics->AuthenticationId.HighPart = 0; /* FIXME */
415                 statistics->ExpirationTime.u.HighPart = 0x7fffffff;
416                 statistics->ExpirationTime.u.LowPart  = 0xffffffff;
417                 statistics->TokenType = reply->primary ? TokenPrimary : TokenImpersonation;
418                 statistics->ImpersonationLevel = reply->impersonation_level;
419
420                 /* kernel information not relevant to us */
421                 statistics->DynamicCharged = 0;
422                 statistics->DynamicAvailable = 0;
423
424                 statistics->GroupCount = reply->group_count;
425                 statistics->PrivilegeCount = reply->privilege_count;
426                 statistics->ModifiedId.LowPart  = reply->modified_id.low_part;
427                 statistics->ModifiedId.HighPart = reply->modified_id.high_part;
428             }
429         }
430         SERVER_END_REQ;
431         break;
432     case TokenType:
433         SERVER_START_REQ( get_token_statistics )
434         {
435             TOKEN_TYPE *token_type = tokeninfo;
436             req->handle = wine_server_obj_handle( token );
437             status = wine_server_call( req );
438             if (status == STATUS_SUCCESS)
439                 *token_type = reply->primary ? TokenPrimary : TokenImpersonation;
440         }
441         SERVER_END_REQ;
442         break;
443     default:
444         {
445             ERR("Unhandled Token Information class %d!\n", tokeninfoclass);
446             return STATUS_NOT_IMPLEMENTED;
447         }
448     }
449     return status;
450 }
451
452 /******************************************************************************
453 *  NtSetInformationToken                [NTDLL.@]
454 *  ZwSetInformationToken                [NTDLL.@]
455 */
456 NTSTATUS WINAPI NtSetInformationToken(
457         HANDLE TokenHandle,
458         TOKEN_INFORMATION_CLASS TokenInformationClass,
459         PVOID TokenInformation,
460         ULONG TokenInformationLength)
461 {
462     FIXME("%p %d %p %u\n", TokenHandle, TokenInformationClass,
463           TokenInformation, TokenInformationLength);
464     return STATUS_NOT_IMPLEMENTED;
465 }
466
467 /******************************************************************************
468 *  NtAdjustGroupsToken          [NTDLL.@]
469 *  ZwAdjustGroupsToken          [NTDLL.@]
470 */
471 NTSTATUS WINAPI NtAdjustGroupsToken(
472         HANDLE TokenHandle,
473         BOOLEAN ResetToDefault,
474         PTOKEN_GROUPS NewState,
475         ULONG BufferLength,
476         PTOKEN_GROUPS PreviousState,
477         PULONG ReturnLength)
478 {
479     FIXME("%p %d %p %u %p %p\n", TokenHandle, ResetToDefault,
480           NewState, BufferLength, PreviousState, ReturnLength);
481     return STATUS_NOT_IMPLEMENTED;
482 }
483
484 /******************************************************************************
485 *  NtPrivilegeCheck             [NTDLL.@]
486 *  ZwPrivilegeCheck             [NTDLL.@]
487 */
488 NTSTATUS WINAPI NtPrivilegeCheck(
489     HANDLE ClientToken,
490     PPRIVILEGE_SET RequiredPrivileges,
491     PBOOLEAN Result)
492 {
493     NTSTATUS status;
494     SERVER_START_REQ( check_token_privileges )
495     {
496         req->handle = wine_server_obj_handle( ClientToken );
497         req->all_required = ((RequiredPrivileges->Control & PRIVILEGE_SET_ALL_NECESSARY) ? TRUE : FALSE);
498         wine_server_add_data( req, RequiredPrivileges->Privilege,
499             RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
500         wine_server_set_reply( req, RequiredPrivileges->Privilege,
501             RequiredPrivileges->PrivilegeCount * sizeof(RequiredPrivileges->Privilege[0]) );
502
503         status = wine_server_call( req );
504
505         if (status == STATUS_SUCCESS)
506             *Result = (reply->has_privileges ? TRUE : FALSE);
507     }
508     SERVER_END_REQ;
509     return status;
510 }
511
512 /*
513  *      Section
514  */
515
516 /******************************************************************************
517  *  NtQuerySection      [NTDLL.@]
518  */
519 NTSTATUS WINAPI NtQuerySection(
520         IN HANDLE SectionHandle,
521         IN SECTION_INFORMATION_CLASS SectionInformationClass,
522         OUT PVOID SectionInformation,
523         IN ULONG Length,
524         OUT PULONG ResultLength)
525 {
526         FIXME("(%p,%d,%p,0x%08x,%p) stub!\n",
527         SectionHandle,SectionInformationClass,SectionInformation,Length,ResultLength);
528         return 0;
529 }
530
531 /*
532  *      ports
533  */
534
535 /******************************************************************************
536  *  NtCreatePort                [NTDLL.@]
537  *  ZwCreatePort                [NTDLL.@]
538  */
539 NTSTATUS WINAPI NtCreatePort(PHANDLE PortHandle,POBJECT_ATTRIBUTES ObjectAttributes,
540                              ULONG MaxConnectInfoLength,ULONG MaxDataLength,PULONG reserved)
541 {
542   FIXME("(%p,%p,%u,%u,%p),stub!\n",PortHandle,ObjectAttributes,
543         MaxConnectInfoLength,MaxDataLength,reserved);
544   return STATUS_NOT_IMPLEMENTED;
545 }
546
547 /******************************************************************************
548  *  NtConnectPort               [NTDLL.@]
549  *  ZwConnectPort               [NTDLL.@]
550  */
551 NTSTATUS WINAPI NtConnectPort(
552         PHANDLE PortHandle,
553         PUNICODE_STRING PortName,
554         PSECURITY_QUALITY_OF_SERVICE SecurityQos,
555         PLPC_SECTION_WRITE WriteSection,
556         PLPC_SECTION_READ ReadSection,
557         PULONG MaximumMessageLength,
558         PVOID ConnectInfo,
559         PULONG pConnectInfoLength)
560 {
561     FIXME("(%p,%s,%p,%p,%p,%p,%p,%p),stub!\n",
562           PortHandle,debugstr_w(PortName->Buffer),SecurityQos,
563           WriteSection,ReadSection,MaximumMessageLength,ConnectInfo,
564           pConnectInfoLength);
565     if (ConnectInfo && pConnectInfoLength)
566         TRACE("\tMessage = %s\n",debugstr_an(ConnectInfo,*pConnectInfoLength));
567     return STATUS_NOT_IMPLEMENTED;
568 }
569
570 /******************************************************************************
571  *  NtListenPort                [NTDLL.@]
572  *  ZwListenPort                [NTDLL.@]
573  */
574 NTSTATUS WINAPI NtListenPort(HANDLE PortHandle,PLPC_MESSAGE pLpcMessage)
575 {
576   FIXME("(%p,%p),stub!\n",PortHandle,pLpcMessage);
577   return STATUS_NOT_IMPLEMENTED;
578 }
579
580 /******************************************************************************
581  *  NtAcceptConnectPort [NTDLL.@]
582  *  ZwAcceptConnectPort [NTDLL.@]
583  */
584 NTSTATUS WINAPI NtAcceptConnectPort(
585         PHANDLE PortHandle,
586         ULONG PortIdentifier,
587         PLPC_MESSAGE pLpcMessage,
588         BOOLEAN Accept,
589         PLPC_SECTION_WRITE WriteSection,
590         PLPC_SECTION_READ ReadSection)
591 {
592   FIXME("(%p,%u,%p,%d,%p,%p),stub!\n",
593         PortHandle,PortIdentifier,pLpcMessage,Accept,WriteSection,ReadSection);
594   return STATUS_NOT_IMPLEMENTED;
595 }
596
597 /******************************************************************************
598  *  NtCompleteConnectPort       [NTDLL.@]
599  *  ZwCompleteConnectPort       [NTDLL.@]
600  */
601 NTSTATUS WINAPI NtCompleteConnectPort(HANDLE PortHandle)
602 {
603   FIXME("(%p),stub!\n",PortHandle);
604   return STATUS_NOT_IMPLEMENTED;
605 }
606
607 /******************************************************************************
608  *  NtRegisterThreadTerminatePort       [NTDLL.@]
609  *  ZwRegisterThreadTerminatePort       [NTDLL.@]
610  */
611 NTSTATUS WINAPI NtRegisterThreadTerminatePort(HANDLE PortHandle)
612 {
613   FIXME("(%p),stub!\n",PortHandle);
614   return STATUS_NOT_IMPLEMENTED;
615 }
616
617 /******************************************************************************
618  *  NtRequestWaitReplyPort              [NTDLL.@]
619  *  ZwRequestWaitReplyPort              [NTDLL.@]
620  */
621 NTSTATUS WINAPI NtRequestWaitReplyPort(
622         HANDLE PortHandle,
623         PLPC_MESSAGE pLpcMessageIn,
624         PLPC_MESSAGE pLpcMessageOut)
625 {
626   FIXME("(%p,%p,%p),stub!\n",PortHandle,pLpcMessageIn,pLpcMessageOut);
627   if(pLpcMessageIn)
628   {
629     TRACE("Message to send:\n");
630     TRACE("\tDataSize            = %u\n",pLpcMessageIn->DataSize);
631     TRACE("\tMessageSize         = %u\n",pLpcMessageIn->MessageSize);
632     TRACE("\tMessageType         = %u\n",pLpcMessageIn->MessageType);
633     TRACE("\tVirtualRangesOffset = %u\n",pLpcMessageIn->VirtualRangesOffset);
634     TRACE("\tClientId.UniqueProcess = %p\n",pLpcMessageIn->ClientId.UniqueProcess);
635     TRACE("\tClientId.UniqueThread  = %p\n",pLpcMessageIn->ClientId.UniqueThread);
636     TRACE("\tMessageId           = %u\n",pLpcMessageIn->MessageId);
637     TRACE("\tSectionSize         = %u\n",pLpcMessageIn->SectionSize);
638     TRACE("\tData                = %s\n",
639       debugstr_an((const char*)pLpcMessageIn->Data,pLpcMessageIn->DataSize));
640   }
641   return STATUS_NOT_IMPLEMENTED;
642 }
643
644 /******************************************************************************
645  *  NtReplyWaitReceivePort      [NTDLL.@]
646  *  ZwReplyWaitReceivePort      [NTDLL.@]
647  */
648 NTSTATUS WINAPI NtReplyWaitReceivePort(
649         HANDLE PortHandle,
650         PULONG PortIdentifier,
651         PLPC_MESSAGE ReplyMessage,
652         PLPC_MESSAGE Message)
653 {
654   FIXME("(%p,%p,%p,%p),stub!\n",PortHandle,PortIdentifier,ReplyMessage,Message);
655   return STATUS_NOT_IMPLEMENTED;
656 }
657
658 /*
659  *      Misc
660  */
661
662  /******************************************************************************
663  *  NtSetIntervalProfile        [NTDLL.@]
664  *  ZwSetIntervalProfile        [NTDLL.@]
665  */
666 NTSTATUS WINAPI NtSetIntervalProfile(
667         ULONG Interval,
668         KPROFILE_SOURCE Source)
669 {
670     FIXME("%u,%d\n", Interval, Source);
671     return STATUS_SUCCESS;
672 }
673
674 /******************************************************************************
675  * NtQuerySystemInformation [NTDLL.@]
676  * ZwQuerySystemInformation [NTDLL.@]
677  *
678  * ARGUMENTS:
679  *  SystemInformationClass      Index to a certain information structure
680  *      SystemTimeAdjustmentInformation SYSTEM_TIME_ADJUSTMENT
681  *      SystemCacheInformation          SYSTEM_CACHE_INFORMATION
682  *      SystemConfigurationInformation  CONFIGURATION_INFORMATION
683  *      observed (class/len):
684  *              0x0/0x2c
685  *              0x12/0x18
686  *              0x2/0x138
687  *              0x8/0x600
688  *              0x25/0xc
689  *  SystemInformation   caller supplies storage for the information structure
690  *  Length              size of the structure
691  *  ResultLength        Data written
692  */
693 NTSTATUS WINAPI NtQuerySystemInformation(
694         IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
695         OUT PVOID SystemInformation,
696         IN ULONG Length,
697         OUT PULONG ResultLength)
698 {
699     NTSTATUS    ret = STATUS_SUCCESS;
700     ULONG       len = 0;
701
702     TRACE("(0x%08x,%p,0x%08x,%p)\n",
703           SystemInformationClass,SystemInformation,Length,ResultLength);
704
705     switch (SystemInformationClass)
706     {
707     case SystemBasicInformation:
708         {
709             SYSTEM_BASIC_INFORMATION sbi;
710
711             virtual_get_system_info( &sbi );
712             len = sizeof(sbi);
713
714             if ( Length == len)
715             {
716                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
717                 else memcpy( SystemInformation, &sbi, len);
718             }
719             else ret = STATUS_INFO_LENGTH_MISMATCH;
720         }
721         break;
722     case SystemCpuInformation:
723         {
724             SYSTEM_CPU_INFORMATION sci;
725
726             /* FIXME: move some code from kernel/cpu.c to process this */
727             sci.Architecture = PROCESSOR_ARCHITECTURE_INTEL;
728             sci.Level = 6; /* 686, aka Pentium II+ */
729             sci.Revision = 0;
730             sci.Reserved = 0;
731             sci.FeatureSet = 0x1fff;
732             len = sizeof(sci);
733
734             if ( Length >= len)
735             {
736                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
737                 else memcpy( SystemInformation, &sci, len);
738             }
739             else ret = STATUS_INFO_LENGTH_MISMATCH;
740         }
741         break;
742     case SystemPerformanceInformation:
743         {
744             SYSTEM_PERFORMANCE_INFORMATION spi;
745             static BOOL fixme_written = FALSE;
746
747             memset(&spi, 0 , sizeof(spi));
748             len = sizeof(spi);
749
750             if (Length >= len)
751             {
752                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
753                 else memcpy( SystemInformation, &spi, len);
754             }
755             else ret = STATUS_INFO_LENGTH_MISMATCH;
756             if(!fixme_written) {
757                 FIXME("info_class SYSTEM_PERFORMANCE_INFORMATION\n");
758                 fixme_written = TRUE;
759             }
760         }
761         break;
762     case SystemTimeOfDayInformation:
763         {
764             SYSTEM_TIMEOFDAY_INFORMATION sti;
765
766             memset(&sti, 0 , sizeof(sti));
767
768             /* liKeSystemTime, liExpTimeZoneBias, uCurrentTimeZoneId */
769             sti.liKeBootTime.QuadPart = server_start_time;
770
771             if (Length <= sizeof(sti))
772             {
773                 len = Length;
774                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
775                 else memcpy( SystemInformation, &sti, Length);
776             }
777             else ret = STATUS_INFO_LENGTH_MISMATCH;
778         }
779         break;
780     case SystemProcessInformation:
781         {
782             SYSTEM_PROCESS_INFORMATION* spi = (SYSTEM_PROCESS_INFORMATION*)SystemInformation;
783             SYSTEM_PROCESS_INFORMATION* last = NULL;
784             HANDLE hSnap = 0;
785             WCHAR procname[1024];
786             WCHAR* exename;
787             DWORD wlen = 0;
788             DWORD procstructlen = 0;
789
790             SERVER_START_REQ( create_snapshot )
791             {
792                 req->flags      = SNAP_PROCESS | SNAP_THREAD;
793                 req->attributes = 0;
794                 if (!(ret = wine_server_call( req )))
795                     hSnap = wine_server_ptr_handle( reply->handle );
796             }
797             SERVER_END_REQ;
798             len = 0;
799             while (ret == STATUS_SUCCESS)
800             {
801                 SERVER_START_REQ( next_process )
802                 {
803                     req->handle = wine_server_obj_handle( hSnap );
804                     req->reset = (len == 0);
805                     wine_server_set_reply( req, procname, sizeof(procname)-sizeof(WCHAR) );
806                     if (!(ret = wine_server_call( req )))
807                     {
808                         /* Make sure procname is 0 terminated */
809                         procname[wine_server_reply_size(reply) / sizeof(WCHAR)] = 0;
810
811                         /* Get only the executable name, not the path */
812                         if ((exename = strrchrW(procname, '\\')) != NULL) exename++;
813                         else exename = procname;
814
815                         wlen = (strlenW(exename) + 1) * sizeof(WCHAR);
816
817                         procstructlen = sizeof(*spi) + wlen + ((reply->threads - 1) * sizeof(SYSTEM_THREAD_INFORMATION));
818
819                         if (Length >= len + procstructlen)
820                         {
821                             /* ftCreationTime, ftUserTime, ftKernelTime;
822                              * vmCounters, ioCounters
823                              */
824  
825                             memset(spi, 0, sizeof(*spi));
826
827                             spi->NextEntryOffset = procstructlen - wlen;
828                             spi->dwThreadCount = reply->threads;
829
830                             /* spi->pszProcessName will be set later on */
831
832                             spi->dwBasePriority = reply->priority;
833                             spi->UniqueProcessId = UlongToHandle(reply->pid);
834                             spi->ParentProcessId = UlongToHandle(reply->ppid);
835                             spi->HandleCount = reply->handles;
836
837                             /* spi->ti will be set later on */
838
839                             len += procstructlen;
840                         }
841                         else ret = STATUS_INFO_LENGTH_MISMATCH;
842                     }
843                 }
844                 SERVER_END_REQ;
845  
846                 if (ret != STATUS_SUCCESS)
847                 {
848                     if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
849                     break;
850                 }
851                 else /* Length is already checked for */
852                 {
853                     int     i, j;
854
855                     /* set thread info */
856                     i = j = 0;
857                     while (ret == STATUS_SUCCESS)
858                     {
859                         SERVER_START_REQ( next_thread )
860                         {
861                             req->handle = wine_server_obj_handle( hSnap );
862                             req->reset = (j == 0);
863                             if (!(ret = wine_server_call( req )))
864                             {
865                                 j++;
866                                 if (UlongToHandle(reply->pid) == spi->UniqueProcessId)
867                                 {
868                                     /* ftKernelTime, ftUserTime, ftCreateTime;
869                                      * dwTickCount, dwStartAddress
870                                      */
871
872                                     memset(&spi->ti[i], 0, sizeof(spi->ti));
873
874                                     spi->ti[i].CreateTime.QuadPart = 0xdeadbeef;
875                                     spi->ti[i].ClientId.UniqueProcess = UlongToHandle(reply->pid);
876                                     spi->ti[i].ClientId.UniqueThread  = UlongToHandle(reply->tid);
877                                     spi->ti[i].dwCurrentPriority = reply->base_pri + reply->delta_pri;
878                                     spi->ti[i].dwBasePriority = reply->base_pri;
879                                     i++;
880                                 }
881                             }
882                         }
883                         SERVER_END_REQ;
884                     }
885                     if (ret == STATUS_NO_MORE_FILES) ret = STATUS_SUCCESS;
886
887                     /* now append process name */
888                     spi->ProcessName.Buffer = (WCHAR*)((char*)spi + spi->NextEntryOffset);
889                     spi->ProcessName.Length = wlen - sizeof(WCHAR);
890                     spi->ProcessName.MaximumLength = wlen;
891                     memcpy( spi->ProcessName.Buffer, exename, wlen );
892                     spi->NextEntryOffset += wlen;
893
894                     last = spi;
895                     spi = (SYSTEM_PROCESS_INFORMATION*)((char*)spi + spi->NextEntryOffset);
896                 }
897             }
898             if (ret == STATUS_SUCCESS && last) last->NextEntryOffset = 0;
899             if (hSnap) NtClose(hSnap);
900         }
901         break;
902     case SystemProcessorPerformanceInformation:
903         {
904             SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi = NULL;
905             unsigned int cpus = 0;
906             int out_cpus = Length / sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
907
908             if (out_cpus == 0)
909             {
910                 len = 0;
911                 ret = STATUS_INFO_LENGTH_MISMATCH;
912                 break;
913             }
914             else
915 #ifdef __APPLE__
916             {
917                 processor_cpu_load_info_data_t *pinfo;
918                 mach_msg_type_number_t info_count;
919
920                 if (host_processor_info (mach_host_self (),
921                                          PROCESSOR_CPU_LOAD_INFO,
922                                          &cpus,
923                                          (processor_info_array_t*)&pinfo,
924                                          &info_count) == 0)
925                 {
926                     int i;
927                     cpus = min(cpus,out_cpus);
928                     len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
929                     sppi = RtlAllocateHeap(GetProcessHeap(), 0,len);
930                     for (i = 0; i < cpus; i++)
931                     {
932                         sppi[i].liIdleTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_IDLE];
933                         sppi[i].liKernelTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_SYSTEM];
934                         sppi[i].liUserTime.QuadPart = pinfo[i].cpu_ticks[CPU_STATE_USER];
935                     }
936                     vm_deallocate (mach_task_self (), (vm_address_t) pinfo, info_count * sizeof(natural_t));
937                 }
938             }
939 #else
940             {
941                 FILE *cpuinfo = fopen("/proc/stat","r");
942                 if (cpuinfo)
943                 {
944                     unsigned usr,nice,sys;
945                     unsigned long idle;
946                     int count;
947                     char name[10];
948                     char line[255];
949
950                     /* first line is combined usage */
951                     if (fgets(line,255,cpuinfo))
952                         count = sscanf(line,"%s %u %u %u %lu",name, &usr, &nice,
953                                    &sys, &idle);
954                     else
955                         count = 0;
956                     /* we set this up in the for older non-smp enabled kernels */
957                     if (count == 5 && strcmp(name,"cpu")==0)
958                     {
959                         sppi = RtlAllocateHeap(GetProcessHeap(), 0,
960                                                sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
961                         sppi->liIdleTime.QuadPart = idle;
962                         sppi->liKernelTime.QuadPart = sys;
963                         sppi->liUserTime.QuadPart = usr;
964                         cpus = 1;
965                         len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
966                     }
967
968                     do
969                     {
970                         if (fgets(line,255,cpuinfo))
971                             count = sscanf(line,"%s %u %u %u %lu",name, &usr,
972                                        &nice, &sys, &idle);
973                         else
974                             count = 0;
975                         if (count == 5 && strncmp(name,"cpu",3)==0)
976                         {
977                             out_cpus --;
978                             if (name[3]=='0') /* first cpu */
979                             {
980                                 sppi->liIdleTime.QuadPart = idle;
981                                 sppi->liKernelTime.QuadPart = sys;
982                                 sppi->liUserTime.QuadPart = usr;
983                             }
984                             else /* new cpu */
985                             {
986                                 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * (cpus+1);
987                                 sppi = RtlReAllocateHeap(GetProcessHeap(), 0, sppi, len);
988                                 sppi[cpus].liIdleTime.QuadPart = idle;
989                                 sppi[cpus].liKernelTime.QuadPart = sys;
990                                 sppi[cpus].liUserTime.QuadPart = usr;
991                                 cpus++;
992                             }
993                         }
994                         else
995                             break;
996                     } while (out_cpus > 0);
997                     fclose(cpuinfo);
998                 }
999             }
1000 #endif
1001
1002             if (cpus == 0)
1003             {
1004                 static int i = 1;
1005
1006                 sppi = RtlAllocateHeap(GetProcessHeap(),0,sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
1007
1008                 memset(sppi, 0 , sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
1009                 FIXME("stub info_class SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION\n");
1010
1011                 /* many programs expect these values to change so fake change */
1012                 len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
1013                 sppi->liKernelTime.QuadPart = 1 * i;
1014                 sppi->liUserTime.QuadPart = 2 * i;
1015                 sppi->liIdleTime.QuadPart = 3 * i;
1016                 i++;
1017             }
1018
1019             if (Length >= len)
1020             {
1021                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1022                 else memcpy( SystemInformation, sppi, len);
1023             }
1024             else ret = STATUS_INFO_LENGTH_MISMATCH;
1025
1026             RtlFreeHeap(GetProcessHeap(),0,sppi);
1027         }
1028         break;
1029     case SystemModuleInformation:
1030         /* FIXME: should be system-wide */
1031         if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1032         else ret = LdrQueryProcessModuleInformation( SystemInformation, Length, &len );
1033         break;
1034     case SystemHandleInformation:
1035         {
1036             SYSTEM_HANDLE_INFORMATION shi;
1037
1038             memset(&shi, 0, sizeof(shi));
1039             len = sizeof(shi);
1040
1041             if ( Length >= len)
1042             {
1043                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1044                 else memcpy( SystemInformation, &shi, len);
1045             }
1046             else ret = STATUS_INFO_LENGTH_MISMATCH;
1047             FIXME("info_class SYSTEM_HANDLE_INFORMATION\n");
1048         }
1049         break;
1050     case SystemCacheInformation:
1051         {
1052             SYSTEM_CACHE_INFORMATION sci;
1053
1054             memset(&sci, 0, sizeof(sci)); /* FIXME */
1055             len = sizeof(sci);
1056
1057             if ( Length >= len)
1058             {
1059                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1060                 else memcpy( SystemInformation, &sci, len);
1061             }
1062             else ret = STATUS_INFO_LENGTH_MISMATCH;
1063             FIXME("info_class SYSTEM_CACHE_INFORMATION\n");
1064         }
1065         break;
1066     case SystemInterruptInformation:
1067         {
1068             SYSTEM_INTERRUPT_INFORMATION sii;
1069
1070             memset(&sii, 0, sizeof(sii));
1071             len = sizeof(sii);
1072
1073             if ( Length >= len)
1074             {
1075                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1076                 else memcpy( SystemInformation, &sii, len);
1077             }
1078             else ret = STATUS_INFO_LENGTH_MISMATCH;
1079             FIXME("info_class SYSTEM_INTERRUPT_INFORMATION\n");
1080         }
1081         break;
1082     case SystemKernelDebuggerInformation:
1083         {
1084             SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi;
1085
1086             skdi.DebuggerEnabled = FALSE;
1087             skdi.DebuggerNotPresent = TRUE;
1088             len = sizeof(skdi);
1089
1090             if ( Length >= len)
1091             {
1092                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1093                 else memcpy( SystemInformation, &skdi, len);
1094             }
1095             else ret = STATUS_INFO_LENGTH_MISMATCH;
1096         }
1097         break;
1098     case SystemRegistryQuotaInformation:
1099         {
1100             /* Something to do with the size of the registry             *
1101              * Since we don't have a size limitation, fake it            *
1102              * This is almost certainly wrong.                           *
1103              * This sets each of the three words in the struct to 32 MB, *
1104              * which is enough to make the IE 5 installer happy.         */
1105             SYSTEM_REGISTRY_QUOTA_INFORMATION srqi;
1106
1107             srqi.RegistryQuotaAllowed = 0x2000000;
1108             srqi.RegistryQuotaUsed = 0x200000;
1109             srqi.Reserved1 = (void*)0x200000;
1110             len = sizeof(srqi);
1111
1112             if ( Length >= len)
1113             {
1114                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
1115                 else
1116                 {
1117                     FIXME("SystemRegistryQuotaInformation: faking max registry size of 32 MB\n");
1118                     memcpy( SystemInformation, &srqi, len);
1119                 }
1120             }
1121             else ret = STATUS_INFO_LENGTH_MISMATCH;
1122         }
1123         break;
1124     default:
1125         FIXME("(0x%08x,%p,0x%08x,%p) stub\n",
1126               SystemInformationClass,SystemInformation,Length,ResultLength);
1127
1128         /* Several Information Classes are not implemented on Windows and return 2 different values 
1129          * STATUS_NOT_IMPLEMENTED or STATUS_INVALID_INFO_CLASS
1130          * in 95% of the cases it's STATUS_INVALID_INFO_CLASS, so use this as the default
1131         */
1132         ret = STATUS_INVALID_INFO_CLASS;
1133     }
1134
1135     if (ResultLength) *ResultLength = len;
1136
1137     return ret;
1138 }
1139
1140 /******************************************************************************
1141  * NtSetSystemInformation [NTDLL.@]
1142  * ZwSetSystemInformation [NTDLL.@]
1143  */
1144 NTSTATUS WINAPI NtSetSystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG Length)
1145 {
1146     FIXME("(0x%08x,%p,0x%08x) stub\n",SystemInformationClass,SystemInformation,Length);
1147     return STATUS_SUCCESS;
1148 }
1149
1150 /******************************************************************************
1151  *  NtCreatePagingFile          [NTDLL.@]
1152  *  ZwCreatePagingFile          [NTDLL.@]
1153  */
1154 NTSTATUS WINAPI NtCreatePagingFile(
1155         PUNICODE_STRING PageFileName,
1156         PLARGE_INTEGER MinimumSize,
1157         PLARGE_INTEGER MaximumSize,
1158         PLARGE_INTEGER ActualSize)
1159 {
1160     FIXME("(%p %p %p %p) stub\n", PageFileName, MinimumSize, MaximumSize, ActualSize);
1161     return STATUS_SUCCESS;
1162 }
1163
1164 /******************************************************************************
1165  *  NtDisplayString                             [NTDLL.@]
1166  *
1167  * writes a string to the nt-textmode screen eg. during startup
1168  */
1169 NTSTATUS WINAPI NtDisplayString ( PUNICODE_STRING string )
1170 {
1171     STRING stringA;
1172     NTSTATUS ret;
1173
1174     if (!(ret = RtlUnicodeStringToAnsiString( &stringA, string, TRUE )))
1175     {
1176         MESSAGE( "%.*s", stringA.Length, stringA.Buffer );
1177         RtlFreeAnsiString( &stringA );
1178     }
1179     return ret;
1180 }
1181
1182 /******************************************************************************
1183  *  NtInitiatePowerAction                       [NTDLL.@]
1184  *
1185  */
1186 NTSTATUS WINAPI NtInitiatePowerAction(
1187         IN POWER_ACTION SystemAction,
1188         IN SYSTEM_POWER_STATE MinSystemState,
1189         IN ULONG Flags,
1190         IN BOOLEAN Asynchronous)
1191 {
1192         FIXME("(%d,%d,0x%08x,%d),stub\n",
1193                 SystemAction,MinSystemState,Flags,Asynchronous);
1194         return STATUS_NOT_IMPLEMENTED;
1195 }
1196         
1197
1198 /******************************************************************************
1199  *  NtPowerInformation                          [NTDLL.@]
1200  *
1201  */
1202 NTSTATUS WINAPI NtPowerInformation(
1203         IN POWER_INFORMATION_LEVEL InformationLevel,
1204         IN PVOID lpInputBuffer,
1205         IN ULONG nInputBufferSize,
1206         IN PVOID lpOutputBuffer,
1207         IN ULONG nOutputBufferSize)
1208 {
1209         TRACE("(%d,%p,%d,%p,%d)\n",
1210                 InformationLevel,lpInputBuffer,nInputBufferSize,lpOutputBuffer,nOutputBufferSize);
1211         switch(InformationLevel) {
1212                 case SystemPowerCapabilities: {
1213                         PSYSTEM_POWER_CAPABILITIES PowerCaps = (PSYSTEM_POWER_CAPABILITIES)lpOutputBuffer;
1214                         FIXME("semi-stub: SystemPowerCapabilities\n");
1215                         if (nOutputBufferSize < sizeof(SYSTEM_POWER_CAPABILITIES))
1216                                 return STATUS_BUFFER_TOO_SMALL;
1217                         /* FIXME: These values are based off a native XP desktop, should probably use APM/ACPI to get the 'real' values */
1218                         PowerCaps->PowerButtonPresent = TRUE;
1219                         PowerCaps->SleepButtonPresent = FALSE;
1220                         PowerCaps->LidPresent = FALSE;
1221                         PowerCaps->SystemS1 = TRUE;
1222                         PowerCaps->SystemS2 = FALSE;
1223                         PowerCaps->SystemS3 = FALSE;
1224                         PowerCaps->SystemS4 = TRUE;
1225                         PowerCaps->SystemS5 = TRUE;
1226                         PowerCaps->HiberFilePresent = TRUE;
1227                         PowerCaps->FullWake = TRUE;
1228                         PowerCaps->VideoDimPresent = FALSE;
1229                         PowerCaps->ApmPresent = FALSE;
1230                         PowerCaps->UpsPresent = FALSE;
1231                         PowerCaps->ThermalControl = FALSE;
1232                         PowerCaps->ProcessorThrottle = FALSE;
1233                         PowerCaps->ProcessorMinThrottle = 100;
1234                         PowerCaps->ProcessorMaxThrottle = 100;
1235                         PowerCaps->DiskSpinDown = TRUE;
1236                         PowerCaps->SystemBatteriesPresent = FALSE;
1237                         PowerCaps->BatteriesAreShortTerm = FALSE;
1238                         PowerCaps->BatteryScale[0].Granularity = 0;
1239                         PowerCaps->BatteryScale[0].Capacity = 0;
1240                         PowerCaps->BatteryScale[1].Granularity = 0;
1241                         PowerCaps->BatteryScale[1].Capacity = 0;
1242                         PowerCaps->BatteryScale[2].Granularity = 0;
1243                         PowerCaps->BatteryScale[2].Capacity = 0;
1244                         PowerCaps->AcOnLineWake = PowerSystemUnspecified;
1245                         PowerCaps->SoftLidWake = PowerSystemUnspecified;
1246                         PowerCaps->RtcWake = PowerSystemSleeping1;
1247                         PowerCaps->MinDeviceWakeState = PowerSystemUnspecified;
1248                         PowerCaps->DefaultLowLatencyWake = PowerSystemUnspecified;
1249                         return STATUS_SUCCESS;
1250                 }
1251                 default:
1252                         FIXME("Unimplemented NtPowerInformation action: %d\n", InformationLevel);
1253                         return STATUS_NOT_IMPLEMENTED;
1254         }
1255 }
1256
1257 /******************************************************************************
1258  *  NtShutdownSystem                            [NTDLL.@]
1259  *
1260  */
1261 NTSTATUS WINAPI NtShutdownSystem(SHUTDOWN_ACTION Action)
1262 {
1263     FIXME("%d\n",Action);
1264     return STATUS_SUCCESS;
1265 }
1266
1267 /******************************************************************************
1268  *  NtAllocateLocallyUniqueId (NTDLL.@)
1269  */
1270 NTSTATUS WINAPI NtAllocateLocallyUniqueId(PLUID Luid)
1271 {
1272     NTSTATUS status;
1273
1274     TRACE("%p\n", Luid);
1275
1276     if (!Luid)
1277         return STATUS_ACCESS_VIOLATION;
1278
1279     SERVER_START_REQ( allocate_locally_unique_id )
1280     {
1281         status = wine_server_call( req );
1282         if (!status)
1283         {
1284             Luid->LowPart = reply->luid.low_part;
1285             Luid->HighPart = reply->luid.high_part;
1286         }
1287     }
1288     SERVER_END_REQ;
1289
1290     return status;
1291 }
1292
1293 /******************************************************************************
1294  *        VerSetConditionMask   (NTDLL.@)
1295  */
1296 ULONGLONG WINAPI VerSetConditionMask( ULONGLONG dwlConditionMask, DWORD dwTypeBitMask,
1297                                       BYTE dwConditionMask)
1298 {
1299     if(dwTypeBitMask == 0)
1300         return dwlConditionMask;
1301     dwConditionMask &= 0x07;
1302     if(dwConditionMask == 0)
1303         return dwlConditionMask;
1304
1305     if(dwTypeBitMask & VER_PRODUCT_TYPE)
1306         dwlConditionMask |= dwConditionMask << 7*3;
1307     else if (dwTypeBitMask & VER_SUITENAME)
1308         dwlConditionMask |= dwConditionMask << 6*3;
1309     else if (dwTypeBitMask & VER_SERVICEPACKMAJOR)
1310         dwlConditionMask |= dwConditionMask << 5*3;
1311     else if (dwTypeBitMask & VER_SERVICEPACKMINOR)
1312         dwlConditionMask |= dwConditionMask << 4*3;
1313     else if (dwTypeBitMask & VER_PLATFORMID)
1314         dwlConditionMask |= dwConditionMask << 3*3;
1315     else if (dwTypeBitMask & VER_BUILDNUMBER)
1316         dwlConditionMask |= dwConditionMask << 2*3;
1317     else if (dwTypeBitMask & VER_MAJORVERSION)
1318         dwlConditionMask |= dwConditionMask << 1*3;
1319     else if (dwTypeBitMask & VER_MINORVERSION)
1320         dwlConditionMask |= dwConditionMask << 0*3;
1321     return dwlConditionMask;
1322 }
1323
1324 /******************************************************************************
1325  *  NtAccessCheckAndAuditAlarm   (NTDLL.@)
1326  *  ZwAccessCheckAndAuditAlarm   (NTDLL.@)
1327  */
1328 NTSTATUS WINAPI NtAccessCheckAndAuditAlarm(PUNICODE_STRING SubsystemName, HANDLE HandleId, PUNICODE_STRING ObjectTypeName,
1329                                            PUNICODE_STRING ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor,
1330                                            ACCESS_MASK DesiredAccess, PGENERIC_MAPPING GenericMapping, BOOLEAN ObjectCreation,
1331                                            PACCESS_MASK GrantedAccess, PBOOLEAN AccessStatus, PBOOLEAN GenerateOnClose)
1332 {
1333     FIXME("(%s, %p, %s, %p, 0x%08x, %p, %d, %p, %p, %p), stub\n", debugstr_us(SubsystemName), HandleId,
1334           debugstr_us(ObjectTypeName), SecurityDescriptor, DesiredAccess, GenericMapping, ObjectCreation,
1335           GrantedAccess, AccessStatus, GenerateOnClose);
1336
1337     return STATUS_NOT_IMPLEMENTED;
1338 }