update for HEAD-2003021201
[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 WINBOOL
24 STDCALL
25 AbortSystemShutdownW(LPCWSTR lpMachineName)
26 {
27     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
28     return FALSE;
29 }
30
31
32 /**********************************************************************
33  *      AbortSystemShutdownA
34  */
35 BOOL
36 STDCALL
37 AbortSystemShutdownA(LPCSTR lpMachineName)
38 {
39     ANSI_STRING MachineNameA;
40     UNICODE_STRING MachineNameW;
41     NTSTATUS Status;
42     BOOL rv;
43
44     RtlInitAnsiString(&MachineNameA, (LPSTR)lpMachineName);
45     Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE);
46     if (STATUS_SUCCESS != Status) {
47             SetLastError(RtlNtStatusToDosError(Status));
48             return FALSE;
49     }
50     rv = AbortSystemShutdownW(MachineNameW.Buffer);
51     RtlFreeAnsiString(&MachineNameA);
52     RtlFreeUnicodeString(&MachineNameW);
53     SetLastError(ERROR_SUCCESS);
54     return rv;
55 }
56
57
58 /**********************************************************************
59  *      InitiateSystemShutdownW
60  */
61 BOOL
62 STDCALL
63 InitiateSystemShutdownW(
64     LPWSTR  lpMachineName,
65     LPWSTR  lpMessage,
66     DWORD   dwTimeout,
67     BOOL    bForceAppsClosed,
68     BOOL    bRebootAfterShutdown)
69 {
70     SHUTDOWN_ACTION Action = ShutdownNoReboot;
71     NTSTATUS        Status;
72
73     if (lpMachineName) {
74     /* FIXME: remote machine shutdown not supported yet */
75         SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
76         return FALSE;
77     }
78     if (dwTimeout) {
79     }
80     Status = NtShutdownSystem(Action);
81     SetLastError(RtlNtStatusToDosError(Status));
82     return FALSE;
83 }
84
85
86 /**********************************************************************
87  *      InitiateSystemShutdownA
88 */
89 BOOL
90 STDCALL
91 InitiateSystemShutdownA(
92     LPSTR   lpMachineName,
93     LPSTR   lpMessage,
94     DWORD   dwTimeout,
95     BOOL    bForceAppsClosed,
96     BOOL    bRebootAfterShutdown)
97 {
98     ANSI_STRING     MachineNameA;
99     ANSI_STRING     MessageA;
100     UNICODE_STRING  MachineNameW;
101     UNICODE_STRING  MessageW;
102     NTSTATUS        Status;
103     INT         LastError;
104     BOOL        rv;
105
106     if (lpMachineName) {
107         RtlInitAnsiString(&MachineNameA, lpMachineName);
108         Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE);
109         if (STATUS_SUCCESS != Status) {
110             RtlFreeAnsiString(&MachineNameA);
111             SetLastError(RtlNtStatusToDosError(Status));
112             return FALSE;
113         }
114     }
115     if (lpMessage) {
116         RtlInitAnsiString(&MessageA, lpMessage);
117         Status = RtlAnsiStringToUnicodeString(&MessageW, &MessageA, TRUE);
118         if (STATUS_SUCCESS != Status) {
119             if (MachineNameW.Length) {
120                 RtlFreeAnsiString(&MachineNameA);
121                 RtlFreeUnicodeString(&MachineNameW);
122             }
123             RtlFreeAnsiString(&MessageA);
124             SetLastError(RtlNtStatusToDosError(Status));
125             return FALSE;
126         }
127     }
128     rv = InitiateSystemShutdownW(
129             MachineNameW.Buffer,
130             MessageW.Buffer,
131             dwTimeout,
132             bForceAppsClosed,
133             bRebootAfterShutdown);
134     LastError = GetLastError();
135     if (lpMachineName) {
136         RtlFreeAnsiString(&MachineNameA);
137         RtlFreeUnicodeString(&MachineNameW);
138     }
139     if (lpMessage) {
140         RtlFreeAnsiString(&MessageA);
141         RtlFreeUnicodeString(&MessageW);
142     }
143     SetLastError(LastError);
144     return rv;
145 }
146
147 /* EOF */