Author: weiden Date: Fri Aug 3 19:14:49 2007 New Revision: 28137
URL: http://svn.reactos.org/svn/reactos?rev=28137&view=rev Log: Patch by Frode Lillerud frode@enkelt.no - Basic implementation of logoff.exe See issue #2509 for more details.
Added: trunk/reactos/base/applications/logoff/ trunk/reactos/base/applications/logoff/lang/ trunk/reactos/base/applications/logoff/lang/en-US.rc (with props) trunk/reactos/base/applications/logoff/lang/nb-NO.rc (with props) trunk/reactos/base/applications/logoff/logoff.c (with props) trunk/reactos/base/applications/logoff/logoff.rbuild (with props) trunk/reactos/base/applications/logoff/logoff.rc (with props) trunk/reactos/base/applications/logoff/misc.c (with props) trunk/reactos/base/applications/logoff/precomp.h (with props) trunk/reactos/base/applications/logoff/resource.h (with props) trunk/reactos/base/applications/logoff/rsrc.rc (with props) Modified: trunk/reactos/base/applications/applications.rbuild trunk/reactos/boot/bootdata/packages/reactos.dff
Modified: trunk/reactos/base/applications/applications.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/applicati... ============================================================================== --- trunk/reactos/base/applications/applications.rbuild (original) +++ trunk/reactos/base/applications/applications.rbuild Fri Aug 3 19:14:49 2007 @@ -24,6 +24,9 @@ </directory> <directory name="hostname"> <xi:include href="hostname/hostname.rbuild" /> +</directory> +<directory name="logoff"> + <xi:include href="logoff/logoff.rbuild" /> </directory> <directory name="msconfig"> <xi:include href="msconfig/msconfig.rbuild" />
Added: trunk/reactos/base/applications/logoff/lang/en-US.rc URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/logoff/la... ============================================================================== --- trunk/reactos/base/applications/logoff/lang/en-US.rc (added) +++ trunk/reactos/base/applications/logoff/lang/en-US.rc Fri Aug 3 19:14:49 2007 @@ -1,0 +1,15 @@ +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +STRINGTABLE DISCARDABLE +{ + +IDS_USAGE, "Terminates a session.\n\n\ + /v\t\tDisplays information about the actions performed.\n\ + /?\t\tShows this information.\n\n" + +IDS_LOGOFF_REMOTE, "Terminating session on remote machine." +IDS_LOGOFF_LOCAL, "Terminating the current session on this machine." + +IDS_ILLEGAL_PARAM, "Invalid parameter(s)\n" +} +/* EOF */
Propchange: trunk/reactos/base/applications/logoff/lang/en-US.rc ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/reactos/base/applications/logoff/lang/nb-NO.rc URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/logoff/la... ============================================================================== --- trunk/reactos/base/applications/logoff/lang/nb-NO.rc (added) +++ trunk/reactos/base/applications/logoff/lang/nb-NO.rc Fri Aug 3 19:14:49 2007 @@ -1,0 +1,16 @@ +LANGUAGE LANG_NORWEGIAN, SUBLANG_NEUTRAL + +STRINGTABLE DISCARDABLE +{ + +IDS_USAGE, "Avslutter en sesjon.\n\n\ + /v\t\tViser informasjon om handlingen som utføres.\n\ + /?\t\tViser denne informasjonen.\n\n" + +IDS_LOGOFF_REMOTE, "Logger av økt på en annen maskin" +IDS_LOGOFF_LOCAL, "Logger av økten på denne maskinen." + +IDS_ILLEGAL_PARAM, "En eller flere ugyldige parametre.\n" +} + +/* EOF */
Propchange: trunk/reactos/base/applications/logoff/lang/nb-NO.rc ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/reactos/base/applications/logoff/logoff.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/logoff/lo... ============================================================================== --- trunk/reactos/base/applications/logoff/logoff.c (added) +++ trunk/reactos/base/applications/logoff/logoff.c Fri Aug 3 19:14:49 2007 @@ -1,0 +1,146 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS logoff utility + * FILE: base\applications\logoff\logoff.c + * PURPOSE: Logoff current session, or another session, potentially on another machine + * AUTHOR: 30.07.2007 - Frode Lillerud + */ + +/* Note + * This application is a lightweight version of shutdown.exe. It is intended to be function-compatible + * with Windows' system32\logoff.exe commandline application. + */ + +#define NDEBUG +#include "precomp.h" + +//Commandline argument switches +LPTSTR szRemoteServerName = NULL; +BOOL bVerbose; + +//---------------------------------------------------------------------- +// +//Retrieve resource string and output the Usage to the console +// +//---------------------------------------------------------------------- +static void PrintUsage() { + LPTSTR lpUsage = NULL; + + if (AllocAndLoadString(&lpUsage, GetModuleHandle(NULL), IDS_USAGE)) { + _putts(lpUsage); + } + +} + +//---------------------------------------------------------------------- +// +// Writes the last error as both text and error code to the console. +// +//---------------------------------------------------------------------- +void DisplayLastError() +{ + int errorCode = GetLastError(); + LPTSTR lpMsgBuf; + + // Display the error message to the user + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + errorCode, + LANG_USER_DEFAULT, + (LPTSTR) &lpMsgBuf, + 0, + NULL); + + _ftprintf(stderr, lpMsgBuf); + _ftprintf(stderr, _T("Error code: %d\n"), errorCode); + + LocalFree(lpMsgBuf); +} + +//---------------------------------------------------------------------- +// +//Sets flags based on commandline arguments +// +//---------------------------------------------------------------------- +BOOL ParseCommandLine(int argc, TCHAR *argv[]) +{ + int i; + LPTSTR lpIllegalMsg; + + //FIXME: Add handling of commandline arguments to select the session number and name, and also name of remote machine + //Example: logoff.exe 4 /SERVER:Master should logoff session number 4 on remote machine called Master. + + for (i = 1; i < argc; i++) { + switch(argv[i][0]){ + case '-': + case '/': + // -v (verbose) + if (argv[i][1] == 'v') { + bVerbose = TRUE; + break; //continue parsing the arguments + } + // -? (usage) + else if(argv[i][1] == '?') { + return FALSE; //display the Usage + } + default: + //Invalid parameter detected + if (AllocAndLoadString(&lpIllegalMsg, GetModuleHandle(NULL), IDS_ILLEGAL_PARAM)) + _putts(lpIllegalMsg); + return FALSE; + } + } + + return TRUE; +} + +//---------------------------------------------------------------------- +// +//Main entry for program +// +//---------------------------------------------------------------------- +int _tmain(int argc, TCHAR *argv[]) +{ + LPTSTR lpLogoffRemote, lpLogoffLocal; + + // + // Parse command line + // + if (!ParseCommandLine(argc, argv)) { + PrintUsage(); + return 1; + } + + // + //Should we log off session on remote server? + // + if (szRemoteServerName) { + if (bVerbose) { + if (AllocAndLoadString(&lpLogoffRemote, GetModuleHandle(NULL), IDS_LOGOFF_REMOTE)) + _putts(lpLogoffRemote); + } + + //FIXME: Add Remote Procedure Call to logoff user on a remote machine + _ftprintf(stderr, "Remote Procedure Call in logoff.exe has not been implemented"); + } + // + //Perform logoff of current session on local machine instead + // + else { + if (bVerbose) { + //Get resource string, and print it. + if (AllocAndLoadString(&lpLogoffLocal, GetModuleHandle(NULL), IDS_LOGOFF_LOCAL)) + _putts(lpLogoffLocal); + } + + //Actual logoff + if (!ExitWindows(NULL, NULL)) { + DisplayLastError(); + return 1; + } + } + + return 0; +} +/* EOF */
Propchange: trunk/reactos/base/applications/logoff/logoff.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/reactos/base/applications/logoff/logoff.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/logoff/lo... ============================================================================== --- trunk/reactos/base/applications/logoff/logoff.rbuild (added) +++ trunk/reactos/base/applications/logoff/logoff.rbuild Fri Aug 3 19:14:49 2007 @@ -1,0 +1,14 @@ +<?xml version="1.0"?> +<!DOCTYPE project SYSTEM "tools/rbuild/project.dtd"> +<module name="logoff" type="win32cui" installbase="system32" installname="logoff.exe"> + <include base="logoff">.</include> + <define name="__USE_W32API" /> + <define name="WINVER">0x0501</define> + <library>advapi32</library> + <library>user32</library> + <library>kernel32</library> + <file>misc.c</file> + <file>logoff.c</file> + <file>logoff.rc</file> + <pch>precomp.h</pch> +</module>
Propchange: trunk/reactos/base/applications/logoff/logoff.rbuild ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/reactos/base/applications/logoff/logoff.rc URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/logoff/lo... ============================================================================== --- trunk/reactos/base/applications/logoff/logoff.rc (added) +++ trunk/reactos/base/applications/logoff/logoff.rc Fri Aug 3 19:14:49 2007 @@ -1,0 +1,9 @@ +#include <windows.h> +#include "resource.h" + +#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Logoff Utility\0" +#define REACTOS_STR_INTERNAL_NAME "logoff\0" +#define REACTOS_STR_ORIGINAL_FILENAME "logoff.exe\0" +#include <reactos/version.rc> + +#include "rsrc.rc"
Propchange: trunk/reactos/base/applications/logoff/logoff.rc ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/reactos/base/applications/logoff/misc.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/logoff/mi... ============================================================================== --- trunk/reactos/base/applications/logoff/misc.c (added) +++ trunk/reactos/base/applications/logoff/misc.c Fri Aug 3 19:14:49 2007 @@ -1,0 +1,63 @@ +#include "precomp.h" + +static INT +LengthOfStrResource(IN HINSTANCE hInst, + IN UINT uID) +{ + HRSRC hrSrc; + HGLOBAL hRes; + LPWSTR lpName, lpStr; + + if (hInst == NULL) + { + return -1; + } + + /* There are always blocks of 16 strings */ + lpName = (LPWSTR)MAKEINTRESOURCE((uID >> 4) + 1); + + /* Find the string table block */ + if ((hrSrc = FindResourceW(hInst, lpName, (LPWSTR)RT_STRING)) && + (hRes = LoadResource(hInst, hrSrc)) && + (lpStr = (WCHAR*) LockResource(hRes))) + { + UINT x; + + /* Find the string we're looking for */ + uID &= 0xF; /* position in the block, same as % 16 */ + for (x = 0; x < uID; x++) + { + lpStr += (*lpStr) + 1; + } + + /* Found the string */ + return (int)(*lpStr); + } + return -1; +} + +INT +AllocAndLoadString(OUT LPTSTR *lpTarget, + IN HINSTANCE hInst, + IN UINT uID) +{ + INT ln; + + ln = LengthOfStrResource(hInst, + uID); + if (ln++ > 0) + { + (*lpTarget) = (LPTSTR)LocalAlloc(LMEM_FIXED, + ln * sizeof(TCHAR)); + if ((*lpTarget) != NULL) + { + INT Ret; + if (!(Ret = LoadString(hInst, uID, *lpTarget, ln))) + { + LocalFree((HLOCAL)(*lpTarget)); + } + return Ret; + } + } + return 0; +}
Propchange: trunk/reactos/base/applications/logoff/misc.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/reactos/base/applications/logoff/precomp.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/logoff/pr... ============================================================================== --- trunk/reactos/base/applications/logoff/precomp.h (added) +++ trunk/reactos/base/applications/logoff/precomp.h Fri Aug 3 19:14:49 2007 @@ -1,0 +1,16 @@ +#ifndef __SHUTDOWN_PRECOMP_H +#define __SHUTDOWN_PRECOMP_H + +#include <stdio.h> +#include <stdlib.h> +#include <windows.h> +#include <tchar.h> +#include <reason.h> //shutdown codes +#include "resource.h" + +// misc.c +INT AllocAndLoadString(OUT LPTSTR *lpTarget, + IN HINSTANCE hInst, + IN UINT uID); + +#endif
Propchange: trunk/reactos/base/applications/logoff/precomp.h ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/reactos/base/applications/logoff/resource.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/logoff/re... ============================================================================== --- trunk/reactos/base/applications/logoff/resource.h (added) +++ trunk/reactos/base/applications/logoff/resource.h Fri Aug 3 19:14:49 2007 @@ -1,0 +1,4 @@ +#define IDS_USAGE 1000 +#define IDS_LOGOFF_REMOTE 1001 +#define IDS_LOGOFF_LOCAL 1002 +#define IDS_ILLEGAL_PARAM 1003
Propchange: trunk/reactos/base/applications/logoff/resource.h ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/reactos/base/applications/logoff/rsrc.rc URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/logoff/rs... ============================================================================== --- trunk/reactos/base/applications/logoff/rsrc.rc (added) +++ trunk/reactos/base/applications/logoff/rsrc.rc Fri Aug 3 19:14:49 2007 @@ -1,0 +1,5 @@ +#include <windows.h> +#include "resource.h" + +#include "lang/en-US.rc" +#include "lang/nb-NO.rc"
Propchange: trunk/reactos/base/applications/logoff/rsrc.rc ------------------------------------------------------------------------------ svn:eol-style = native
Modified: trunk/reactos/boot/bootdata/packages/reactos.dff URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/bootdata/packages/reac... ============================================================================== --- trunk/reactos/boot/bootdata/packages/reactos.dff (original) +++ trunk/reactos/boot/bootdata/packages/reactos.dff Fri Aug 3 19:14:49 2007 @@ -41,6 +41,7 @@ base\applications\games\winemine\winemine.exe 1 base\applications\hh\hh.exe 1 base\applications\hostname\hostname.exe 1 +base\applications\logoff\logoff.exe 1 base\applications\msconfig\msconfig.exe 1 base\applications\network\arp\arp.exe 1 base\applications\network\route\route.exe 1