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