update for HEAD-2003091401
[reactos.git] / lib / advapi32 / misc / shutdown.c
1 /* $Id$
2  *
3  * COPYRIGHT:       See COPYING in the top level directory
4  * PROJECT:     ReactOS system libraries
5  * FILE:        lib/advapi32/misc/shutdown.c
6  * PURPOSE:     System shutdown functions
7  * PROGRAMMER:      Emanuele Aliberti
8  * UPDATE HISTORY:
9  *      19990413 EA     created
10  *      19990515 EA
11  */
12
13 #include <windows.h>
14
15 #define NTOS_MODE_USER
16 #include <ntos.h>
17
18 #define USZ {0,0,0}
19
20 /**********************************************************************
21  *      AbortSystemShutdownW
22  *
23  * @unimplemented
24  */
25 WINBOOL
26 STDCALL
27 AbortSystemShutdownW(LPCWSTR lpMachineName)
28 {
29     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
30     return FALSE;
31 }
32
33
34 /**********************************************************************
35  *      AbortSystemShutdownA
36  *
37  * @unimplemented
38  */
39 BOOL
40 STDCALL
41 AbortSystemShutdownA(LPCSTR lpMachineName)
42 {
43     ANSI_STRING MachineNameA;
44     UNICODE_STRING MachineNameW;
45     NTSTATUS Status;
46     BOOL rv;
47
48     RtlInitAnsiString(&MachineNameA, (LPSTR)lpMachineName);
49     Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE);
50     if (STATUS_SUCCESS != Status) {
51             SetLastError(RtlNtStatusToDosError(Status));
52             return FALSE;
53     }
54     rv = AbortSystemShutdownW(MachineNameW.Buffer);
55     RtlFreeAnsiString(&MachineNameA);
56     RtlFreeUnicodeString(&MachineNameW);
57     SetLastError(ERROR_SUCCESS);
58     return rv;
59 }
60
61
62 /**********************************************************************
63  *      InitiateSystemShutdownW
64  *
65  * @unimplemented
66  */
67 BOOL
68 STDCALL
69 InitiateSystemShutdownW(
70     LPWSTR  lpMachineName,
71     LPWSTR  lpMessage,
72     DWORD   dwTimeout,
73     BOOL    bForceAppsClosed,
74     BOOL    bRebootAfterShutdown)
75 {
76     SHUTDOWN_ACTION Action = ShutdownNoReboot;
77     NTSTATUS        Status;
78
79     if (lpMachineName) {
80     /* FIXME: remote machine shutdown not supported yet */
81         SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
82         return FALSE;
83     }
84     if (dwTimeout) {
85     }
86     Status = NtShutdownSystem(Action);
87     SetLastError(RtlNtStatusToDosError(Status));
88     return FALSE;
89 }
90
91
92 /**********************************************************************
93  *      InitiateSystemShutdownA
94  *
95  * @unimplemented
96  */
97 BOOL
98 STDCALL
99 InitiateSystemShutdownA(
100     LPSTR   lpMachineName,
101     LPSTR   lpMessage,
102     DWORD   dwTimeout,
103     BOOL    bForceAppsClosed,
104     BOOL    bRebootAfterShutdown)
105 {
106     ANSI_STRING     MachineNameA;
107     ANSI_STRING     MessageA;
108     UNICODE_STRING  MachineNameW;
109     UNICODE_STRING  MessageW;
110     NTSTATUS        Status;
111     INT         LastError;
112     BOOL        rv;
113
114     if (lpMachineName) {
115         RtlInitAnsiString(&MachineNameA, lpMachineName);
116         Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE);
117         if (STATUS_SUCCESS != Status) {
118             RtlFreeAnsiString(&MachineNameA);
119             SetLastError(RtlNtStatusToDosError(Status));
120             return FALSE;
121         }
122     }
123     if (lpMessage) {
124         RtlInitAnsiString(&MessageA, lpMessage);
125         Status = RtlAnsiStringToUnicodeString(&MessageW, &MessageA, TRUE);
126         if (STATUS_SUCCESS != Status) {
127             if (MachineNameW.Length) {
128                 RtlFreeAnsiString(&MachineNameA);
129                 RtlFreeUnicodeString(&MachineNameW);
130             }
131             RtlFreeAnsiString(&MessageA);
132             SetLastError(RtlNtStatusToDosError(Status));
133             return FALSE;
134         }
135     }
136     rv = InitiateSystemShutdownW(
137             MachineNameW.Buffer,
138             MessageW.Buffer,
139             dwTimeout,
140             bForceAppsClosed,
141             bRebootAfterShutdown);
142     LastError = GetLastError();
143     if (lpMachineName) {
144         RtlFreeAnsiString(&MachineNameA);
145         RtlFreeUnicodeString(&MachineNameW);
146     }
147     if (lpMessage) {
148         RtlFreeAnsiString(&MessageA);
149         RtlFreeUnicodeString(&MessageW);
150     }
151     SetLastError(LastError);
152     return rv;
153 }
154
155 /* EOF */