-/* $Id$
- *
- * COPYRIGHT: See COPYING in the top level directory
+/*
+ * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
- * FILE: lib/advapi32/misc/shutdown.c
+ * FILE: dll/win32/advapi32/misc/shutdown.c
* PURPOSE: System shutdown functions
- * PROGRAMMER: Emanuele Aliberti
- * UPDATE HISTORY:
- * 19990413 EA created
- * 19990515 EA
+ * PROGRAMMER: Lee Schroeder <spaceseel at gmail dot com>
+ * Emanuele Aliberti
*/
#include <advapi32.h>
-WINE_DEFAULT_DEBUG_CHANNEL(advapi);
-
-#define USZ {0,0,0}
-
-/**********************************************************************
- * AbortSystemShutdownW
- *
- * @unimplemented
- */
-BOOL WINAPI
-AbortSystemShutdownW(LPCWSTR lpMachineName)
-{
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return FALSE;
-}
+WINE_DEFAULT_DEBUG_CHANNEL(advapi);
/**********************************************************************
* AbortSystemShutdownA
*
- * @unimplemented
+ * see AbortSystemShutdownW
*/
BOOL WINAPI
AbortSystemShutdownA(LPCSTR lpMachineName)
Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE);
if (STATUS_SUCCESS != Status)
{
- SetLastError(RtlNtStatusToDosError(Status));
- return FALSE;
+ SetLastError(RtlNtStatusToDosError(Status));
+ return FALSE;
}
rv = AbortSystemShutdownW(MachineNameW.Buffer);
/**********************************************************************
- * InitiateSystemShutdownW
+ * AbortSystemShutdownW
*
- * @unimplemented
+ * @implemented
*/
BOOL WINAPI
-InitiateSystemShutdownW(LPWSTR lpMachineName,
- LPWSTR lpMessage,
- DWORD dwTimeout,
- BOOL bForceAppsClosed,
- BOOL bRebootAfterShutdown)
+AbortSystemShutdownW(LPCWSTR lpMachineName)
{
- SHUTDOWN_ACTION Action = ShutdownNoReboot;
- NTSTATUS Status;
+ DWORD dwError;
- if (lpMachineName)
+ RpcTryExcept
{
- /* FIXME: remote machine shutdown not supported yet */
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return FALSE;
+ dwError = BaseAbortSystemShutdown((PREGISTRY_SERVER_NAME)lpMachineName);
+ }
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ dwError = RtlNtStatusToDosError(RpcExceptionCode());
}
+ RpcEndExcept;
- if (dwTimeout)
+ if (dwError != ERROR_SUCCESS)
{
+ TRACE("BaseAbortSystemShutdown() failed (Error %lu)\n", dwError);
+ SetLastError(dwError);
+ return FALSE;
}
- Status = NtShutdownSystem(Action);
- SetLastError(RtlNtStatusToDosError(Status));
- return FALSE;
+ return TRUE;
}
/**********************************************************************
* InitiateSystemShutdownA
*
- * @unimplemented
+ * @implemented
*/
BOOL
WINAPI
BOOL bForceAppsClosed,
BOOL bRebootAfterShutdown)
{
- ANSI_STRING MachineNameA;
- ANSI_STRING MessageA;
- UNICODE_STRING MachineNameW;
- UNICODE_STRING MessageW;
- NTSTATUS Status;
- INT LastError;
- BOOL rv;
+ ANSI_STRING MachineNameA, MessageA;
+ UNICODE_STRING MachineNameW, MessageW;
+ NTSTATUS Status;
+ BOOL res;
- MachineNameW.Buffer = NULL;
- MessageW.Buffer = NULL;
+ MachineNameW.Buffer = NULL;
+ MessageW.Buffer = NULL;
if (lpMachineName)
{
Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE);
if (STATUS_SUCCESS != Status)
{
+ if(MachineNameW.Buffer)
+ RtlFreeUnicodeString(&MachineNameW);
+
SetLastError(RtlNtStatusToDosError(Status));
return FALSE;
}
Status = RtlAnsiStringToUnicodeString(&MessageW, &MessageA, TRUE);
if (STATUS_SUCCESS != Status)
{
- if (MachineNameW.Buffer)
- {
- RtlFreeUnicodeString(&MachineNameW);
- }
+ if (MessageW.Buffer)
+ RtlFreeUnicodeString(&MessageW);
SetLastError(RtlNtStatusToDosError(Status));
return FALSE;
}
}
- rv = InitiateSystemShutdownW(MachineNameW.Buffer,
- MessageW.Buffer,
- dwTimeout,
- bForceAppsClosed,
- bRebootAfterShutdown);
- LastError = GetLastError();
+ res = InitiateSystemShutdownW(MachineNameW.Buffer,
+ MessageW.Buffer,
+ dwTimeout,
+ bForceAppsClosed,
+ bRebootAfterShutdown);
+
+ /* Clear the values of both strings */
if (lpMachineName)
- {
RtlFreeUnicodeString(&MachineNameW);
- }
if (lpMessage)
- {
RtlFreeUnicodeString(&MessageW);
+
+ return res;
+}
+
+
+/**********************************************************************
+ * InitiateSystemShutdownW
+ *
+ * @implemented
+ */
+BOOL WINAPI
+InitiateSystemShutdownW(LPWSTR lpMachineName,
+ LPWSTR lpMessage,
+ DWORD dwTimeout,
+ BOOL bForceAppsClosed,
+ BOOL bRebootAfterShutdown)
+{
+ UNICODE_STRING Message;
+ DWORD dwError;
+
+ RtlInitUnicodeString(&Message, lpMessage);
+
+ RpcTryExcept
+ {
+ dwError = BaseInitiateSystemShutdown((PREGISTRY_SERVER_NAME)lpMachineName,
+ (PRPC_UNICODE_STRING)&Message,
+ dwTimeout,
+ bForceAppsClosed,
+ bRebootAfterShutdown);
}
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ dwError = RtlNtStatusToDosError(RpcExceptionCode());
+ }
+ RpcEndExcept;
- SetLastError(LastError);
- return rv;
+ if (dwError != ERROR_SUCCESS)
+ {
+ TRACE("BaseInitiateSystemShutdown() failed (Error %lu)\n", dwError);
+ SetLastError(dwError);
+ return FALSE;
+ }
+
+ return TRUE;
}
+
/******************************************************************************
- * InitiateSystemShutdownExW [ADVAPI32.@]
+ * InitiateSystemShutdownExA [ADVAPI32.@]
*
- * see InitiateSystemShutdownExA
+ * see InitiateSystemShutdownExW
*/
BOOL WINAPI
-InitiateSystemShutdownExW(LPWSTR lpMachineName,
- LPWSTR lpMessage,
+InitiateSystemShutdownExA(LPSTR lpMachineName,
+ LPSTR lpMessage,
DWORD dwTimeout,
BOOL bForceAppsClosed,
BOOL bRebootAfterShutdown,
DWORD dwReason)
{
- UNIMPLEMENTED;
- return TRUE;
+ ANSI_STRING MachineNameA, MessageA;
+ UNICODE_STRING MachineNameW, MessageW;
+ NTSTATUS Status;
+ BOOL res;
+
+ MachineNameW.Buffer = NULL;
+ MessageW.Buffer = NULL;
+
+ if (lpMachineName)
+ {
+ RtlInitAnsiString(&MachineNameA, lpMachineName);
+ Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE);
+ if (STATUS_SUCCESS != Status)
+ {
+ if(MachineNameW.Buffer)
+ RtlFreeUnicodeString(&MachineNameW);
+
+ SetLastError(RtlNtStatusToDosError(Status));
+ return FALSE;
+ }
+ }
+
+ if (lpMessage)
+ {
+ RtlInitAnsiString(&MessageA, lpMessage);
+ Status = RtlAnsiStringToUnicodeString(&MessageW, &MessageA, TRUE);
+ if (STATUS_SUCCESS != Status)
+ {
+ if (MessageW.Buffer)
+ RtlFreeUnicodeString(&MessageW);
+
+ SetLastError(RtlNtStatusToDosError(Status));
+ return FALSE;
+ }
+ }
+
+ res = InitiateSystemShutdownExW(MachineNameW.Buffer,
+ MessageW.Buffer,
+ dwTimeout,
+ bForceAppsClosed,
+ bRebootAfterShutdown,
+ dwReason);
+
+ /* Clear the values of both strings */
+ if (lpMachineName)
+ RtlFreeUnicodeString(&MachineNameW);
+
+ if (lpMessage)
+ RtlFreeUnicodeString(&MessageW);
+
+ return res;
}
+
+/******************************************************************************
+ * InitiateSystemShutdownExW [ADVAPI32.@]
+ *
+ * @unimplemented
+ */
BOOL WINAPI
-InitiateSystemShutdownExA(LPSTR lpMachineName,
- LPSTR lpMessage,
+InitiateSystemShutdownExW(LPWSTR lpMachineName,
+ LPWSTR lpMessage,
DWORD dwTimeout,
BOOL bForceAppsClosed,
BOOL bRebootAfterShutdown,
DWORD dwReason)
{
- UNIMPLEMENTED;
- return TRUE;
+ UNICODE_STRING Message;
+ DWORD dwError;
+
+ RtlInitUnicodeString(&Message, lpMessage);
+
+ RpcTryExcept
+ {
+ dwError = BaseInitiateSystemShutdownEx((PREGISTRY_SERVER_NAME)lpMachineName,
+ (PRPC_UNICODE_STRING)&Message,
+ dwTimeout,
+ bForceAppsClosed,
+ bRebootAfterShutdown,
+ dwReason);
+ }
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ dwError = RpcExceptionCode();
+ }
+ RpcEndExcept;
+
+ if (dwError != ERROR_SUCCESS)
+ {
+ TRACE("BaseInitiateSystemShutdownEx() failed (Error %lu)\n", dwError);
+ SetLastError(dwError);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+/******************************************************************************
+ * InitiateShutdownW [ADVAPI32.@]
+ *
+ * @unimplemented
+ */
+DWORD WINAPI
+InitiateShutdownW(LPWSTR lpMachineName,
+ LPWSTR lpMessage,
+ DWORD dwGracePeriod,
+ DWORD dwShutdownFlags,
+ DWORD dwReason)
+{
+ UNIMPLEMENTED;
+ return ERROR_SUCCESS;
+}
+
+/******************************************************************************
+ * InitiateShutdownA [ADVAPI32.@]
+ *
+ * see InitiateShutdownW
+ */
+DWORD WINAPI
+InitiateShutdownA(LPSTR lpMachineName,
+ LPSTR lpMessage,
+ DWORD dwGracePeriod,
+ DWORD dwShutdownFlags,
+ DWORD dwReason)
+{
+ ANSI_STRING MachineNameA, MessageA;
+ UNICODE_STRING MachineNameW, MessageW;
+ NTSTATUS Status;
+ INT LastError;
+ DWORD rv;
+
+ MachineNameW.Buffer = NULL;
+ MessageW.Buffer = NULL;
+
+ if (lpMachineName)
+ {
+ RtlInitAnsiString(&MachineNameA, lpMachineName);
+ Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE);
+ if (STATUS_SUCCESS != Status)
+ {
+ if(MachineNameW.Buffer)
+ RtlFreeUnicodeString(&MachineNameW);
+
+ SetLastError(RtlNtStatusToDosError(Status));
+ return FALSE;
+ }
+ }
+
+ if (lpMessage)
+ {
+ RtlInitAnsiString(&MessageA, lpMessage);
+ Status = RtlAnsiStringToUnicodeString(&MessageW, &MessageA, TRUE);
+ if (STATUS_SUCCESS != Status)
+ {
+ if (MessageW.Buffer)
+ RtlFreeUnicodeString(&MessageW);
+
+ SetLastError(RtlNtStatusToDosError(Status));
+ return FALSE;
+ }
+ }
+
+ rv = InitiateShutdownW(MachineNameW.Buffer,
+ MessageW.Buffer,
+ dwGracePeriod,
+ dwShutdownFlags,
+ dwReason);
+ LastError = GetLastError();
+
+ /* Clear the values of both strings */
+ if (lpMachineName)
+ RtlFreeUnicodeString(&MachineNameW);
+
+ if (lpMessage)
+ RtlFreeUnicodeString(&MessageW);
+
+ SetLastError(LastError);
+ return rv;
}
/* EOF */