Skip to content

Commit 146624e

Browse files
committed
[NETSH] Implement the exec command and fix script execution
1 parent bf2ee2f commit 146624e

File tree

6 files changed

+49
-19
lines changed

6 files changed

+49
-19
lines changed

base/applications/network/netsh/context.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,26 @@ UpCommand(
325325
}
326326

327327

328+
DWORD
329+
WINAPI
330+
ExecCommand(
331+
LPCWSTR pwszMachine,
332+
LPWSTR *argv,
333+
DWORD dwCurrentIndex,
334+
DWORD dwArgCount,
335+
DWORD dwFlags,
336+
LPCVOID pvData,
337+
BOOL *pbDone)
338+
{
339+
DPRINT("ExecCommand()\n");
340+
341+
if (dwArgCount - dwCurrentIndex != 1)
342+
return ERROR_INVALID_SYNTAX;
343+
344+
return RunScript(argv[dwCurrentIndex]);
345+
}
346+
347+
328348
DWORD
329349
WINAPI
330350
ExitCommand(
@@ -372,7 +392,7 @@ PopdCommand(
372392
DPRINT("PopdCommand()\n");
373393

374394
if (pContextStackHead == NULL)
375-
return 0;
395+
return ERROR_SUCCESS;
376396

377397
pEntry = pContextStackHead;
378398

@@ -412,7 +432,7 @@ PushdCommand(
412432

413433
pEntry = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CONTEXT_STACK_ENTRY));
414434
if (pEntry == NULL)
415-
return 1;
435+
return ERROR_NOT_ENOUGH_MEMORY;
416436

417437
pEntry->pContext = pCurrentContext;
418438
if (pContextStackHead == NULL)
@@ -446,6 +466,7 @@ CreateRootContext(VOID)
446466
AddContextCommand(pRootContext, L"..", UpCommand, IDS_HLP_UP, IDS_HLP_UP_EX, 0);
447467
AddContextCommand(pRootContext, L"?", NULL, IDS_HLP_HELP, IDS_HLP_HELP_EX, 0);
448468
AddContextCommand(pRootContext, L"bye", ExitCommand, IDS_HLP_EXIT, IDS_HLP_EXIT_EX, 0);
469+
AddContextCommand(pRootContext, L"exec", ExecCommand, IDS_HLP_EXEC, IDS_HLP_EXEC_EX, 0);
449470
AddContextCommand(pRootContext, L"exit", ExitCommand, IDS_HLP_EXIT, IDS_HLP_EXIT_EX, 0);
450471
AddContextCommand(pRootContext, L"help", NULL, IDS_HLP_HELP, IDS_HLP_HELP_EX, 0);
451472
AddContextCommand(pRootContext, L"popd", PopdCommand, IDS_HLP_POPD, IDS_HLP_POPD_EX, 0);

base/applications/network/netsh/interpreter.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ InterpretCommand(
208208
dwError = pCommand->pfnCmdHandler(NULL, argv, dwArgIndex, dwArgCount, 0, NULL, bDone);
209209
if (dwError != ERROR_SUCCESS)
210210
{
211-
ConPrintf(StdOut, L"Error: %lu\n\n", dwError);
212-
ConResPrintf(StdOut, pCommand->dwCmdHlpToken);
211+
ConPrintf(StdOut, L"Commnand: %S Error: %lu\n\n", pCommand->pwszCmdToken, dwError);
213212
}
214213
}
215214

@@ -347,7 +346,7 @@ InterpretScript(
347346
ptr++;
348347
}
349348

350-
return InterpretCommand(args_vector, dwArgCount, &bDone) == FALSE;
349+
return InterpretCommand(args_vector, dwArgCount, &bDone);
351350
}
352351

353352

base/applications/network/netsh/lang/en-US.rc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ END
2222
STRINGTABLE
2323
BEGIN
2424
IDS_HELP_HEADER "\nThe following commands are available:\n"
25-
IDS_HELP_FOOTER "\nHelp Footer\n\n"
25+
IDS_HELP_FOOTER "\nTo view help for a command, type the command, followed by a space, and then\n type ?.\n\n"
2626
IDS_SUBCONTEXT_HEADER "\nThe following sub-contexts are available:\n"
2727

2828
IDS_HLP_UP "Goes up one context level.\n"
@@ -35,6 +35,8 @@ BEGIN
3535
IDS_HLP_POPD_EX "Syntax: popd\n\n Changes to the context on the stack.\n\n"
3636
IDS_HLP_PUSHD "Stores the current context on the stack.\n"
3737
IDS_HLP_PUSHD_EX "Syntax: pushd\n\n Stores the current context on the stack.\n\n"
38+
IDS_HLP_EXEC "Runs a script file.\n"
39+
IDS_HLP_EXEC_EX "Syntax: exec <ScriptFile>\n\n Loads the script file and runs it.\n\n"
3840

3941
IDS_HLP_ADD_HELPER "Installs a helper DLL.\n"
4042
IDS_HLP_ADD_HELPER_EX "Syntax: add helper <dll file name>\n\n Installs the specified helper DLL in netsh.\n\n"

base/applications/network/netsh/netsh.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
/* FUNCTIONS ******************************************************************/
1616

17-
BOOL
17+
DWORD
1818
RunScript(
1919
_In_ LPCWSTR filename)
2020
{
@@ -26,7 +26,7 @@ RunScript(
2626
if (script == NULL)
2727
{
2828
ConResPrintf(StdErr, IDS_OPEN_FAILED, filename);
29-
return FALSE;
29+
return ERROR_FILE_NOT_FOUND;
3030
}
3131

3232
/* Read and process the script */
@@ -35,14 +35,14 @@ RunScript(
3535
if (InterpretScript(tmp_string) == FALSE)
3636
{
3737
fclose(script);
38-
return FALSE;
38+
return ERROR_SUCCESS; /* FIXME */
3939
}
4040
}
4141

4242
/* Close the file */
4343
fclose(script);
4444

45-
return TRUE;
45+
return ERROR_SUCCESS;
4646
}
4747

4848
/*

base/applications/network/netsh/precomp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,10 @@ InterpretCommand(
220220
VOID
221221
InterpretInteractive(VOID);
222222

223+
/* netsh.c */
224+
225+
DWORD
226+
RunScript(
227+
_In_ LPCWSTR filename);
228+
223229
#endif /* PRECOMP_H */

base/applications/network/netsh/resource.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@
3131
#define IDS_HLP_POPD_EX 307
3232
#define IDS_HLP_PUSHD 308
3333
#define IDS_HLP_PUSHD_EX 309
34+
#define IDS_HLP_EXEC 310
35+
#define IDS_HLP_EXEC_EX 311
3436

35-
#define IDS_HLP_ADD_HELPER 310
36-
#define IDS_HLP_ADD_HELPER_EX 311
37-
#define IDS_HLP_DEL_HELPER 312
38-
#define IDS_HLP_DEL_HELPER_EX 313
39-
#define IDS_HLP_SHOW_HELPER 314
40-
#define IDS_HLP_SHOW_HELPER_EX 315
37+
#define IDS_HLP_ADD_HELPER 320
38+
#define IDS_HLP_ADD_HELPER_EX 321
39+
#define IDS_HLP_DEL_HELPER 322
40+
#define IDS_HLP_DEL_HELPER_EX 323
41+
#define IDS_HLP_SHOW_HELPER 324
42+
#define IDS_HLP_SHOW_HELPER_EX 325
4143

42-
#define IDS_HLP_GROUP_ADD 320
43-
#define IDS_HLP_GROUP_DELETE 321
44-
#define IDS_HLP_GROUP_SHOW 322
44+
#define IDS_HLP_GROUP_ADD 330
45+
#define IDS_HLP_GROUP_DELETE 331
46+
#define IDS_HLP_GROUP_SHOW 332

0 commit comments

Comments
 (0)