[NET]
authorZiliang Guo <drakekaizer666@gmail.com>
Tue, 30 Apr 2013 02:57:30 +0000 (02:57 +0000)
committerZiliang Guo <drakekaizer666@gmail.com>
Tue, 30 Apr 2013 02:57:30 +0000 (02:57 +0000)
Implementation of pause, continue, and help commands for net service application. Patch by theflash.
Core-7131 #resolve

svn path=/trunk/; revision=58894

reactos/base/applications/network/net/CMakeLists.txt
reactos/base/applications/network/net/cmdContinue.c [new file with mode: 0644]
reactos/base/applications/network/net/cmdHelpMsg.c [new file with mode: 0644]
reactos/base/applications/network/net/cmdPause.c [new file with mode: 0644]
reactos/base/applications/network/net/help.c
reactos/base/applications/network/net/main.c
reactos/base/applications/network/net/net.h

index 279abd3..728cb07 100644 (file)
@@ -5,6 +5,9 @@ list(APPEND SOURCE
     main.c
     cmdstart.c
     cmdStop.c
+    cmdHelpMsg.c
+    cmdPause.c
+    cmdContinue.c
     help.c)
 
 add_executable(net ${SOURCE})
diff --git a/reactos/base/applications/network/net/cmdContinue.c b/reactos/base/applications/network/net/cmdContinue.c
new file mode 100644 (file)
index 0000000..d8b69c8
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PROJECT:         ReactOS net command
+ * FILE:            cmdContinue.c
+ * PURPOSE:
+ *
+ * PROGRAMMERS:     Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
+ */
+
+#include "net.h"
+
+int cmdContinue(int argc, wchar_t *argv[])
+{
+    int errorCode = 0;
+    SC_HANDLE hManager, hService;
+    SERVICE_STATUS status;
+    if(argc != 3)
+    {
+        puts("Usage: NET CONTINUE <Service Name>");
+        return 1;
+    }
+
+    hManager=OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ENUMERATE_SERVICE);
+    if(hManager == NULL)
+    {
+        printf("[OpenSCManager] Error: %d\n", errorCode = GetLastError());
+        return errorCode;
+    }
+    
+    hService = OpenService(hManager, argv[2], SERVICE_PAUSE_CONTINUE);
+    
+    if(hService == NULL)
+    {
+        printf("[OpenService] Error: %d\n", errorCode=GetLastError());
+        CloseServiceHandle(hManager);
+        return errorCode;
+    }
+
+    if(!ControlService(hService, SERVICE_CONTROL_CONTINUE, &status))
+    {
+        printf("[ControlService] Error: %d\n", errorCode=GetLastError());
+    }
+
+    CloseServiceHandle(hService);
+    CloseServiceHandle(hManager);
+    
+    return errorCode;
+}
+
+/* EOF */
+
diff --git a/reactos/base/applications/network/net/cmdHelpMsg.c b/reactos/base/applications/network/net/cmdHelpMsg.c
new file mode 100644 (file)
index 0000000..15a66c9
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PROJECT:         ReactOS net command
+ * FILE:            cmdHelpmsg.c
+ * PURPOSE:
+ *
+ * PROGRAMMERS:     Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
+ */
+
+#include "net.h"
+#include "stdlib.h"
+
+int cmdHelpMsg(int argc, wchar_t *argv[])
+{
+    wchar_t *endptr;
+    LPSTR lpBuffer;
+    if(argc<3)
+    {
+        puts("Usage: NET HELPMSG <Error Code>");
+        return 1;
+    }
+    long errNum=wcstol(argv[2], &endptr, 10);
+    if(*endptr != 0)
+    {
+        puts("Usage: NET HELPMSG <Error Code>");
+        return 1;
+    }
+
+    /* Unicode printing is not supported in ReactOS yet */
+    if(FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+                      NULL,
+                      errNum,
+                      LANG_USER_DEFAULT,
+                      (LPSTR)&lpBuffer,
+                      0,
+                      NULL))
+    {
+        printf("\n%s\n", lpBuffer);
+        LocalFree(lpBuffer);
+    }
+    else printf("Unrecognized error code: %ld\n", errNum);
+    
+    return 0;
+}
+
+/* EOF */
+
diff --git a/reactos/base/applications/network/net/cmdPause.c b/reactos/base/applications/network/net/cmdPause.c
new file mode 100644 (file)
index 0000000..2731a60
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PROJECT:         ReactOS net command
+ * FILE:            cmdPause.c
+ * PURPOSE:
+ *
+ * PROGRAMMERS:     Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
+ */
+
+#include "net.h"
+
+int cmdPause(int argc, wchar_t *argv[])
+{
+    int errorCode=0;
+    SC_HANDLE hManager, hService;
+    SERVICE_STATUS status;
+    if(argc != 3)
+    {
+        puts("Usage: NET PAUSE <Service Name>");
+        return 1;
+    }
+
+    hManager = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ENUMERATE_SERVICE);
+    if(hManager == NULL)
+    {
+        printf("[OpenSCManager] Error: %d\n", errorCode=GetLastError());
+        return errorCode;
+    }
+    
+    hService=OpenService(hManager, argv[2], SERVICE_PAUSE_CONTINUE);
+    if(hService == NULL)
+    {
+        printf("[OpenService] Error: %d\n", errorCode=GetLastError());
+        CloseServiceHandle(hManager);
+        return errorCode;
+    }
+    
+    if(!ControlService(hService, SERVICE_CONTROL_PAUSE, &status))
+    {
+        printf("[ControlService] Error: %d\n", errorCode=GetLastError());
+    }
+
+    CloseServiceHandle(hService);
+    CloseServiceHandle(hManager);
+
+    return errorCode;
+}
+
+/* EOF */
+
index 4e33cc2..089f4a6 100644 (file)
@@ -11,7 +11,7 @@
 
 INT cmdHelp(INT argc, WCHAR **argv)
 {
-    if (argc > 3)
+    if (argc != 3)
     {
       return 0;
     }
index 638a21f..8f22696 100644 (file)
@@ -21,14 +21,15 @@ COMMAND cmds[] =
     {L"accounts",   unimplemented},
     {L"computer",   unimplemented},
     {L"config",     unimplemented},
-    {L"continue",   unimplemented},
+    {L"continue",   cmdContinue},
     {L"file",       unimplemented},
     {L"group",      unimplemented},
     {L"help",       cmdHelp},
-    {L"helpmsg",    unimplemented},
+    {L"helpmsg",    cmdHelpMsg},
     {L"localgroup", unimplemented},
     {L"name",       unimplemented},
     {L"print",      unimplemented},
+    {L"pause",      cmdPause},
     {L"send",       unimplemented},
     {L"session",    unimplemented},
     {L"share",      unimplemented},
@@ -39,7 +40,7 @@ COMMAND cmds[] =
     {L"use",        unimplemented},
     {L"user",       unimplemented},
     {L"view",       unimplemented},
-
+    {NULL,          NULL}
 };
 
 int wmain(int argc, WCHAR **argv)
index f7c1123..660033f 100644 (file)
@@ -19,3 +19,6 @@ INT unimplemented(INT argc, WCHAR **argv);
 INT cmdHelp(INT argc, WCHAR **argv);
 INT cmdStart(INT argc, WCHAR **argv);
 INT cmdStop(INT argc, WCHAR **argv);
+int cmdHelpMsg(int argc, wchar_t *argv[]);
+int cmdPause(int argc, wchar_t *argv[]);
+int cmdContinue(int argc, wchar_t *argv[]);