ReactOS 0.4.15-dev-7942-gd23573b
main.c File Reference
#include "net.h"
Include dependency graph for main.c:

Go to the source code of this file.

Classes

struct  _COMMAND
 

Macros

#define MAX_BUFFER_SIZE   4096
 

Typedefs

typedef struct _COMMAND COMMAND
 
typedef struct _COMMANDPCOMMAND
 

Functions

VOID PrintPaddedResourceString (UINT uID, INT nPaddedLength)
 
VOID PrintPadding (WCHAR chr, INT nPaddedLength)
 
DWORD TranslateAppMessage (DWORD dwMessage)
 
VOID PrintMessageStringV (DWORD dwMessage,...)
 
VOID PrintMessageString (DWORD dwMessage)
 
VOID PrintPaddedMessageString (DWORD dwMessage, INT nPaddedLength)
 
VOID PrintErrorMessage (DWORD dwError)
 
VOID PrintNetMessage (DWORD dwMessage)
 
VOID ReadFromConsole (LPWSTR lpInput, DWORD dwLength, BOOL bEcho)
 
int wmain (int argc, WCHAR **argv)
 
INT unimplemented (INT argc, WCHAR **argv)
 

Variables

COMMAND cmds []
 
HMODULE hModuleNetMsg = NULL
 

Macro Definition Documentation

◆ MAX_BUFFER_SIZE

#define MAX_BUFFER_SIZE   4096

Definition at line 12 of file main.c.

Typedef Documentation

◆ COMMAND

◆ PCOMMAND

Function Documentation

◆ PrintErrorMessage()

VOID PrintErrorMessage ( DWORD  dwError)

Definition at line 171 of file main.c.

173{
174 WCHAR szErrorBuffer[16];
176 PWSTR pErrorInserts[2] = {NULL, NULL};
177
178 if (dwError >= MIN_LANMAN_MESSAGE_ID && dwError <= MAX_LANMAN_MESSAGE_ID)
179 {
183 dwError,
185 (LPWSTR)&pBuffer,
186 0,
187 NULL);
188 if (pBuffer)
189 {
190 ConPrintf(StdErr, L"%s\n", pBuffer);
192 pBuffer = NULL;
193 }
194 }
195 else
196 {
199 NULL,
200 dwError,
202 (LPWSTR)&pBuffer,
203 0,
204 NULL);
205 if (pBuffer)
206 {
207 ConPrintf(StdErr, L"%s\n", pBuffer);
209 pBuffer = NULL;
210 }
211 }
212
213 if (dwError != ERROR_SUCCESS)
214 {
215 /* Format insert for the 3514 message */
216 swprintf(szErrorBuffer, L"%lu", dwError);
217 pErrorInserts[0] = szErrorBuffer;
218
219 /* Format and print the 3514 message */
223 3514,
225 (LPWSTR)&pBuffer,
226 0,
227 (va_list *)pErrorInserts);
228 if (pBuffer)
229 {
230 ConPrintf(StdErr, L"%s\n", pBuffer);
232 pBuffer = NULL;
233 }
234 }
235}
char * va_list
Definition: acmsvcex.h:78
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define StdErr
Definition: fc.c:15
HMODULE hModuleNetMsg
Definition: main.c:46
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
#define swprintf
Definition: precomp.h:40
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define MAX_LANMAN_MESSAGE_ID
Definition: lmcons.h:11
#define MIN_LANMAN_MESSAGE_ID
Definition: lmcons.h:10
#define L(x)
Definition: ntvdm.h:50
PVOID pBuffer
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
uint16_t * PWSTR
Definition: typedefs.h:56
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:420
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:423
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:419
#define FORMAT_MESSAGE_ARGUMENT_ARRAY
Definition: winbase.h:424
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:422
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ PrintMessageString()

◆ PrintMessageStringV()

VOID PrintMessageStringV ( DWORD  dwMessage,
  ... 
)

Definition at line 93 of file main.c.

96{
99
100 va_start(args, dwMessage);
101
104 dwMessage,
106 (LPWSTR)&pBuffer,
107 0,
108 &args);
109 va_end(args);
110
111 if (pBuffer)
112 {
115 pBuffer = NULL;
116 }
117}
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
Definition: match.c:390

Referenced by cmdAccounts(), cmdConfig(), cmdUse(), cmdUser(), DisplayServerStatistics(), DisplayWorkstationStatistics(), EnumerateGroups(), EnumerateLocalGroups(), EnumerateUsers(), and PrintError().

◆ PrintNetMessage()

VOID PrintNetMessage ( DWORD  dwMessage)

◆ PrintPaddedMessageString()

VOID PrintPaddedMessageString ( DWORD  dwMessage,
INT  nPaddedLength 
)

Definition at line 143 of file main.c.

146{
149
153 dwMessage,
155 (LPWSTR)&pBuffer,
156 0,
157 NULL);
158 if (pBuffer)
159 {
162 pBuffer = NULL;
163 }
164
165 if (dwLength < (DWORD)nPaddedLength)
166 PrintPadding(L' ', (DWORD)nPaddedLength - dwLength);
167}
VOID PrintPadding(WCHAR chr, INT nPaddedLength)
Definition: main.c:63
static DWORD DWORD * dwLength
Definition: fusion.c:86
unsigned long DWORD
Definition: ntddk_ex.h:95

Referenced by cmdAccounts(), DisplayGroup(), DisplayLocalGroup(), DisplayServerConfig(), DisplayServerStatistics(), DisplayShare(), DisplayUser(), DisplayWorkstationConfig(), and DisplayWorkstationStatistics().

◆ PrintPaddedResourceString()

VOID PrintPaddedResourceString ( UINT  uID,
INT  nPaddedLength 
)

Definition at line 50 of file main.c.

53{
55
57 if (nLength < nPaddedLength)
58 PrintPadding(L' ', nPaddedLength - nLength);
59}
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
int32_t INT
Definition: typedefs.h:58
_In_ DWORD nLength
Definition: wincon.h:473

◆ PrintPadding()

VOID PrintPadding ( WCHAR  chr,
INT  nPaddedLength 
)

Definition at line 63 of file main.c.

66{
67 INT i;
68 WCHAR szMsgBuffer[MAX_BUFFER_SIZE];
69
70 for (i = 0; i < nPaddedLength; i++)
71 szMsgBuffer[i] = chr;
72 szMsgBuffer[nPaddedLength] = UNICODE_NULL;
73
74 ConPuts(StdOut, szMsgBuffer);
75}
#define MAX_BUFFER_SIZE
Definition: main.c:12
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define UNICODE_NULL

Referenced by DisplayGroup(), DisplayLocalGroup(), DisplayUser(), EnumerateGroups(), EnumerateLocalGroups(), EnumerateShares(), EnumerateUsers(), EnumSessions(), PrintLogonHours(), PrintPaddedMessageString(), and PrintPaddedResourceString().

◆ ReadFromConsole()

VOID ReadFromConsole ( LPWSTR  lpInput,
DWORD  dwLength,
BOOL  bEcho 
)

Definition at line 264 of file main.c.

268{
269 DWORD dwOldMode;
270 DWORD dwRead = 0;
272 LPWSTR p;
273 PCHAR pBuf;
274
275 pBuf = HeapAlloc(GetProcessHeap(), 0, dwLength - 1);
276 ZeroMemory(lpInput, dwLength * sizeof(WCHAR));
278 GetConsoleMode(hFile, &dwOldMode);
279
281
282 ReadFile(hFile, (PVOID)pBuf, dwLength - 1, &dwRead, NULL);
283
284 MultiByteToWideChar(CP_OEMCP, 0, pBuf, dwRead, lpInput, dwLength - 1);
285 HeapFree(GetProcessHeap(), 0, pBuf);
286
287 for (p = lpInput; *p; p++)
288 {
289 if (*p == L'\x0d')
290 {
291 *p = L'\0';
292 break;
293 }
294 }
295
296 SetConsoleMode(hFile, dwOldMode);
297}
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
BOOL bEcho
Definition: batch.c:73
#define GetProcessHeap()
Definition: compat.h:736
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define MultiByteToWideChar
Definition: compat.h:110
BOOL WINAPI GetConsoleMode(HANDLE hConsoleHandle, LPDWORD lpMode)
Definition: console.c:1569
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
Definition: console.c:1606
GLfloat GLfloat p
Definition: glext.h:8902
_In_ HANDLE hFile
Definition: mswsock.h:90
char * PCHAR
Definition: typedefs.h:51
#define ZeroMemory
Definition: winbase.h:1712
#define STD_INPUT_HANDLE
Definition: winbase.h:267
#define ENABLE_ECHO_INPUT
Definition: wincon.h:80
#define ENABLE_LINE_INPUT
Definition: wincon.h:79
#define CP_OEMCP
Definition: winnls.h:231

Referenced by ReadPassword().

◆ TranslateAppMessage()

DWORD TranslateAppMessage ( DWORD  dwMessage)

Definition at line 79 of file main.c.

81{
82 switch (dwMessage)
83 {
84 case NERR_Success:
85 return 3500; // APPERR_3500
86 case ERROR_MORE_DATA:
87 return 3513; // APPERR_3513
88 }
89 return dwMessage;
90}
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define NERR_Success
Definition: lmerr.h:5

Referenced by cmdUser().

◆ unimplemented()

INT unimplemented ( INT  argc,
WCHAR **  argv 
)

Definition at line 352 of file main.c.

353{
354 ConPuts(StdOut, L"This command is not implemented yet\n");
355 return 1;
356}

◆ wmain()

int wmain ( int  argc,
WCHAR **  argv 
)

Definition at line 300 of file main.c.

301{
302 WCHAR szDllBuffer[MAX_PATH];
303 PCOMMAND cmdptr;
304 int nResult = 0;
305 BOOL bRun = FALSE;
306
307 /* Initialize the Console Standard Streams */
309
310 /* Load netmsg.dll */
311 GetSystemDirectoryW(szDllBuffer, ARRAYSIZE(szDllBuffer));
312 wcscat(szDllBuffer, L"\\netmsg.dll");
313
314 hModuleNetMsg = LoadLibrary(szDllBuffer);
315 if (hModuleNetMsg == NULL)
316 {
317 ConPrintf(StdErr, L"Failed to load netmsg.dll\n");
318 return 1;
319 }
320
321 if (argc < 2)
322 {
323 nResult = 1;
324 goto done;
325 }
326
327 /* Scan the command table */
328 for (cmdptr = cmds; cmdptr->name; cmdptr++)
329 {
330 if (_wcsicmp(argv[1], cmdptr->name) == 0)
331 {
332 nResult = cmdptr->func(argc, argv);
333 bRun = TRUE;
334 break;
335 }
336 }
337
338done:
339 if (bRun == FALSE)
340 {
341 PrintMessageString(4381);
342 ConPuts(StdOut, L"\n");
343 PrintNetMessage(MSG_NET_SYNTAX);
344 }
345
346 if (hModuleNetMsg != NULL)
348
349 return nResult;
350}
static int argc
Definition: ServiceArgs.c:12
#define ConInitStdStreams()
Definition: fc.c:13
VOID PrintNetMessage(DWORD dwMessage)
Definition: main.c:239
VOID PrintMessageString(DWORD dwMessage)
Definition: main.c:120
COMMAND cmds[]
Definition: main.c:21
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2313
unsigned int BOOL
Definition: ntddk_ex.h:94
#define argv
Definition: mplay32.c:18
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
Definition: main.c:15
WCHAR * name
Definition: main.c:16
INT(* func)(INT, WCHAR **)
Definition: main.c:17
#define LoadLibrary
Definition: winbase.h:3862

Variable Documentation

◆ cmds

COMMAND cmds[]
Initial value:
=
{
{L"accounts", cmdAccounts},
{L"computer", cmdComputer},
{L"config", cmdConfig},
{L"continue", cmdContinue},
{L"file", unimplemented},
{L"group", cmdGroup},
{L"help", cmdHelp},
{L"helpmsg", cmdHelpMsg},
{L"localgroup", cmdLocalGroup},
{L"pause", cmdPause},
{L"session", cmdSession},
{L"share", cmdShare},
{L"start", cmdStart},
{L"statistics", cmdStatistics},
{L"stop", cmdStop},
{L"syntax", cmdSyntax},
{L"time", unimplemented},
{L"use", cmdUse},
{L"user", cmdUser},
{L"view", unimplemented},
}
INT unimplemented(INT argc, WCHAR **argv)
Definition: main.c:352
INT cmdAccounts(INT argc, WCHAR **argv)
Definition: cmdAccounts.c:13
INT cmdComputer(INT argc, WCHAR **argv)
Definition: cmdComputer.c:11
INT cmdConfig(INT argc, WCHAR **argv)
Definition: cmdConfig.c:165
INT cmdContinue(INT argc, WCHAR **argv)
Definition: cmdContinue.c:12
INT cmdGroup(INT argc, WCHAR **argv)
Definition: cmdGroup.c:154
INT cmdHelpMsg(INT argc, WCHAR **argv)
Definition: cmdHelpMsg.c:14
INT cmdHelp(INT argc, WCHAR **argv)
Definition: cmdHelp.c:12
INT cmdSyntax(INT argc, WCHAR **argv)
Definition: cmdHelp.c:180
INT cmdLocalGroup(INT argc, WCHAR **argv)
INT cmdPause(INT argc, WCHAR **argv)
Definition: cmdPause.c:12
INT cmdSession(_In_ INT argc, _In_ WCHAR **argv)
Definition: cmdSession.c:91
INT cmdShare(INT argc, WCHAR **argv)
Definition: cmdShare.c:94
INT cmdStart(INT argc, WCHAR **argv)
Definition: cmdStart.c:172
INT cmdStatistics(INT argc, WCHAR **argv)
INT cmdStop(INT argc, WCHAR **argv)
Definition: cmdStop.c:12
INT cmdUse(INT argc, WCHAR **argv)
Definition: cmdUse.c:104
INT cmdUser(INT argc, WCHAR **argv)
Definition: cmdUser.c:1148

Definition at line 21 of file main.c.

Referenced by DoCommand(), handle_arrow_key(), handle_edit_event(), help_main(), HelpCommand(), HelpCommandList(), test_OleCommandTarget(), and wmain().

◆ hModuleNetMsg