1 /* 2 * COPYRIGHT: See COPYING in the top level directory 3 * PROJECT: ReactOS system libraries 4 * FILE: dll/win32/advapi32/misc/shutdown.c 5 * PURPOSE: System shutdown functions 6 * PROGRAMMER: Lee Schroeder <spaceseel at gmail dot com> 7 * Emanuele Aliberti 8 */ 9 10 #include <advapi32.h> 11 12 WINE_DEFAULT_DEBUG_CHANNEL(advapi); 13 14 /********************************************************************** 15 * AbortSystemShutdownA 16 * 17 * see AbortSystemShutdownW 18 */ 19 BOOL WINAPI 20 AbortSystemShutdownA(LPCSTR lpMachineName) 21 { 22 ANSI_STRING MachineNameA; 23 UNICODE_STRING MachineNameW; 24 NTSTATUS Status; 25 BOOL rv; 26 27 RtlInitAnsiString(&MachineNameA, (LPSTR)lpMachineName); 28 Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE); 29 if (STATUS_SUCCESS != Status) 30 { 31 SetLastError(RtlNtStatusToDosError(Status)); 32 return FALSE; 33 } 34 35 rv = AbortSystemShutdownW(MachineNameW.Buffer); 36 RtlFreeUnicodeString(&MachineNameW); 37 SetLastError(ERROR_SUCCESS); 38 return rv; 39 } 40 41 42 /********************************************************************** 43 * AbortSystemShutdownW 44 * 45 * @implemented 46 */ 47 BOOL WINAPI 48 AbortSystemShutdownW(LPCWSTR lpMachineName) 49 { 50 DWORD dwError; 51 52 RpcTryExcept 53 { 54 dwError = BaseAbortSystemShutdown((PREGISTRY_SERVER_NAME)lpMachineName); 55 } 56 RpcExcept(EXCEPTION_EXECUTE_HANDLER) 57 { 58 dwError = RtlNtStatusToDosError(RpcExceptionCode()); 59 } 60 RpcEndExcept; 61 62 if (dwError != ERROR_SUCCESS) 63 { 64 TRACE("BaseAbortSystemShutdown() failed (Error %lu)\n", dwError); 65 SetLastError(dwError); 66 return FALSE; 67 } 68 69 return TRUE; 70 } 71 72 73 /********************************************************************** 74 * InitiateSystemShutdownA 75 * 76 * @implemented 77 */ 78 BOOL 79 WINAPI 80 InitiateSystemShutdownA(LPSTR lpMachineName, 81 LPSTR lpMessage, 82 DWORD dwTimeout, 83 BOOL bForceAppsClosed, 84 BOOL bRebootAfterShutdown) 85 { 86 ANSI_STRING MachineNameA, MessageA; 87 UNICODE_STRING MachineNameW, MessageW; 88 NTSTATUS Status; 89 BOOL res; 90 91 MachineNameW.Buffer = NULL; 92 MessageW.Buffer = NULL; 93 94 if (lpMachineName) 95 { 96 RtlInitAnsiString(&MachineNameA, lpMachineName); 97 Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE); 98 if (STATUS_SUCCESS != Status) 99 { 100 if(MachineNameW.Buffer) 101 RtlFreeUnicodeString(&MachineNameW); 102 103 SetLastError(RtlNtStatusToDosError(Status)); 104 return FALSE; 105 } 106 } 107 108 if (lpMessage) 109 { 110 RtlInitAnsiString(&MessageA, lpMessage); 111 Status = RtlAnsiStringToUnicodeString(&MessageW, &MessageA, TRUE); 112 if (STATUS_SUCCESS != Status) 113 { 114 if (MessageW.Buffer) 115 RtlFreeUnicodeString(&MessageW); 116 117 SetLastError(RtlNtStatusToDosError(Status)); 118 return FALSE; 119 } 120 } 121 122 res = InitiateSystemShutdownW(MachineNameW.Buffer, 123 MessageW.Buffer, 124 dwTimeout, 125 bForceAppsClosed, 126 bRebootAfterShutdown); 127 128 /* Clear the values of both strings */ 129 if (lpMachineName) 130 RtlFreeUnicodeString(&MachineNameW); 131 132 if (lpMessage) 133 RtlFreeUnicodeString(&MessageW); 134 135 return res; 136 } 137 138 139 /********************************************************************** 140 * InitiateSystemShutdownW 141 * 142 * @implemented 143 */ 144 BOOL WINAPI 145 InitiateSystemShutdownW(LPWSTR lpMachineName, 146 LPWSTR lpMessage, 147 DWORD dwTimeout, 148 BOOL bForceAppsClosed, 149 BOOL bRebootAfterShutdown) 150 { 151 UNICODE_STRING Message; 152 DWORD dwError; 153 154 RtlInitUnicodeString(&Message, lpMessage); 155 156 RpcTryExcept 157 { 158 dwError = BaseInitiateSystemShutdown((PREGISTRY_SERVER_NAME)lpMachineName, 159 (PRPC_UNICODE_STRING)&Message, 160 dwTimeout, 161 bForceAppsClosed, 162 bRebootAfterShutdown); 163 } 164 RpcExcept(EXCEPTION_EXECUTE_HANDLER) 165 { 166 dwError = RtlNtStatusToDosError(RpcExceptionCode()); 167 } 168 RpcEndExcept; 169 170 if (dwError != ERROR_SUCCESS) 171 { 172 TRACE("BaseInitiateSystemShutdown() failed (Error %lu)\n", dwError); 173 SetLastError(dwError); 174 return FALSE; 175 } 176 177 return TRUE; 178 } 179 180 181 /****************************************************************************** 182 * InitiateSystemShutdownExA [ADVAPI32.@] 183 * 184 * see InitiateSystemShutdownExW 185 */ 186 BOOL WINAPI 187 InitiateSystemShutdownExA(LPSTR lpMachineName, 188 LPSTR lpMessage, 189 DWORD dwTimeout, 190 BOOL bForceAppsClosed, 191 BOOL bRebootAfterShutdown, 192 DWORD dwReason) 193 { 194 ANSI_STRING MachineNameA, MessageA; 195 UNICODE_STRING MachineNameW, MessageW; 196 NTSTATUS Status; 197 BOOL res; 198 199 MachineNameW.Buffer = NULL; 200 MessageW.Buffer = NULL; 201 202 if (lpMachineName) 203 { 204 RtlInitAnsiString(&MachineNameA, lpMachineName); 205 Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE); 206 if (STATUS_SUCCESS != Status) 207 { 208 if(MachineNameW.Buffer) 209 RtlFreeUnicodeString(&MachineNameW); 210 211 SetLastError(RtlNtStatusToDosError(Status)); 212 return FALSE; 213 } 214 } 215 216 if (lpMessage) 217 { 218 RtlInitAnsiString(&MessageA, lpMessage); 219 Status = RtlAnsiStringToUnicodeString(&MessageW, &MessageA, TRUE); 220 if (STATUS_SUCCESS != Status) 221 { 222 if (MessageW.Buffer) 223 RtlFreeUnicodeString(&MessageW); 224 225 SetLastError(RtlNtStatusToDosError(Status)); 226 return FALSE; 227 } 228 } 229 230 res = InitiateSystemShutdownExW(MachineNameW.Buffer, 231 MessageW.Buffer, 232 dwTimeout, 233 bForceAppsClosed, 234 bRebootAfterShutdown, 235 dwReason); 236 237 /* Clear the values of both strings */ 238 if (lpMachineName) 239 RtlFreeUnicodeString(&MachineNameW); 240 241 if (lpMessage) 242 RtlFreeUnicodeString(&MessageW); 243 244 return res; 245 } 246 247 248 /****************************************************************************** 249 * InitiateSystemShutdownExW [ADVAPI32.@] 250 * 251 * @unimplemented 252 */ 253 BOOL WINAPI 254 InitiateSystemShutdownExW(LPWSTR lpMachineName, 255 LPWSTR lpMessage, 256 DWORD dwTimeout, 257 BOOL bForceAppsClosed, 258 BOOL bRebootAfterShutdown, 259 DWORD dwReason) 260 { 261 UNICODE_STRING Message; 262 DWORD dwError; 263 264 RtlInitUnicodeString(&Message, lpMessage); 265 266 RpcTryExcept 267 { 268 dwError = BaseInitiateSystemShutdownEx((PREGISTRY_SERVER_NAME)lpMachineName, 269 (PRPC_UNICODE_STRING)&Message, 270 dwTimeout, 271 bForceAppsClosed, 272 bRebootAfterShutdown, 273 dwReason); 274 } 275 RpcExcept(EXCEPTION_EXECUTE_HANDLER) 276 { 277 dwError = RpcExceptionCode(); 278 } 279 RpcEndExcept; 280 281 if (dwError != ERROR_SUCCESS) 282 { 283 TRACE("BaseInitiateSystemShutdownEx() failed (Error %lu)\n", dwError); 284 SetLastError(dwError); 285 return FALSE; 286 } 287 288 return TRUE; 289 } 290 291 292 /****************************************************************************** 293 * InitiateShutdownW [ADVAPI32.@] 294 * 295 * @unimplemented 296 */ 297 DWORD WINAPI 298 InitiateShutdownW(LPWSTR lpMachineName, 299 LPWSTR lpMessage, 300 DWORD dwGracePeriod, 301 DWORD dwShutdownFlags, 302 DWORD dwReason) 303 { 304 UNIMPLEMENTED; 305 return ERROR_SUCCESS; 306 } 307 308 /****************************************************************************** 309 * InitiateShutdownA [ADVAPI32.@] 310 * 311 * see InitiateShutdownW 312 */ 313 DWORD WINAPI 314 InitiateShutdownA(LPSTR lpMachineName, 315 LPSTR lpMessage, 316 DWORD dwGracePeriod, 317 DWORD dwShutdownFlags, 318 DWORD dwReason) 319 { 320 ANSI_STRING MachineNameA, MessageA; 321 UNICODE_STRING MachineNameW, MessageW; 322 NTSTATUS Status; 323 INT LastError; 324 DWORD rv; 325 326 MachineNameW.Buffer = NULL; 327 MessageW.Buffer = NULL; 328 329 if (lpMachineName) 330 { 331 RtlInitAnsiString(&MachineNameA, lpMachineName); 332 Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE); 333 if (STATUS_SUCCESS != Status) 334 { 335 if(MachineNameW.Buffer) 336 RtlFreeUnicodeString(&MachineNameW); 337 338 SetLastError(RtlNtStatusToDosError(Status)); 339 return FALSE; 340 } 341 } 342 343 if (lpMessage) 344 { 345 RtlInitAnsiString(&MessageA, lpMessage); 346 Status = RtlAnsiStringToUnicodeString(&MessageW, &MessageA, TRUE); 347 if (STATUS_SUCCESS != Status) 348 { 349 if (MessageW.Buffer) 350 RtlFreeUnicodeString(&MessageW); 351 352 SetLastError(RtlNtStatusToDosError(Status)); 353 return FALSE; 354 } 355 } 356 357 rv = InitiateShutdownW(MachineNameW.Buffer, 358 MessageW.Buffer, 359 dwGracePeriod, 360 dwShutdownFlags, 361 dwReason); 362 LastError = GetLastError(); 363 364 /* Clear the values of both strings */ 365 if (lpMachineName) 366 RtlFreeUnicodeString(&MachineNameW); 367 368 if (lpMessage) 369 RtlFreeUnicodeString(&MessageW); 370 371 SetLastError(LastError); 372 return rv; 373 } 374 375 /* EOF */ 376