Author: ekohl
Date: Mon Sep 24 12:37:12 2012
New Revision: 57375
URL:
http://svn.reactos.org/svn/reactos?rev=57375&view=rev
Log:
[NET] CORE-6413
- Convert the application to Unicode.
- Implement "net start" and "net stop" commands that use the service
manager APIs.
Removed:
trunk/reactos/base/applications/network/net/process.c
Modified:
trunk/reactos/base/applications/network/net/CMakeLists.txt
trunk/reactos/base/applications/network/net/cmdStop.c
trunk/reactos/base/applications/network/net/cmdstart.c
trunk/reactos/base/applications/network/net/help.c
trunk/reactos/base/applications/network/net/main.c
trunk/reactos/base/applications/network/net/net.h
Modified: trunk/reactos/base/applications/network/net/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/…
==============================================================================
--- trunk/reactos/base/applications/network/net/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/base/applications/network/net/CMakeLists.txt [iso-8859-1] Mon Sep 24
12:37:12 2012
@@ -5,12 +5,11 @@
main.c
cmdstart.c
cmdStop.c
- help.c
- process.c)
+ help.c)
add_executable(net ${SOURCE})
-set_module_type(net win32cui)
+set_module_type(net win32cui UNICODE)
add_pch(net net.h)
-add_importlibs(net ws2_32 msvcrt kernel32)
+add_importlibs(net advapi32 msvcrt kernel32)
add_cd_file(TARGET net DESTINATION reactos/system32 FOR all)
Modified: trunk/reactos/base/applications/network/net/cmdStop.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/…
==============================================================================
--- trunk/reactos/base/applications/network/net/cmdStop.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/network/net/cmdStop.c [iso-8859-1] Mon Sep 24 12:37:12
2012
@@ -1,4 +1,3 @@
-
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS net command
@@ -10,99 +9,65 @@
#include "net.h"
-INT cmdStop(INT argc, CHAR **argv )
+INT cmdStop(INT argc, WCHAR **argv)
{
- char *string;
- long size = 100*sizeof(char);
+ SC_HANDLE hManager = NULL;
+ SC_HANDLE hService = NULL;
+ SERVICE_STATUS ServiceStatus;
+ DWORD dwError = ERROR_SUCCESS;
+ INT nError = 0;
- if (argc>4)
- {
- help();
- return 0;
- }
+ if (argc != 3)
+ {
+ /* FIXME: Print usage message! */
+ printf("Usage: NET STOP <Service name>\n");
+ return 1;
+ }
- if (argc==2)
- {
- string = (char *) malloc(size);
- if (string != NULL)
- {
- sprintf(string,"rpcclient -c \"service enum\"");
- system(string);
- free(string);
- }
- return 0;
- }
+ hManager = OpenSCManagerW(NULL,
+ SERVICES_ACTIVE_DATABASE,
+ SC_MANAGER_ENUMERATE_SERVICE);
+ if (hManager == NULL)
+ {
+printf("1\n");
+ dwError = GetLastError();
+ nError = 1;
+ goto done;
+ }
- if (argc==3)
- {
- stop_service(argv[1]);
- return 0;
- }
+ hService = OpenServiceW(hManager,
+ argv[2],
+ SERVICE_STOP);
+ if (hService == NULL)
+ {
+printf("2\n");
+ dwError = GetLastError();
+ nError = 1;
+ goto done;
+ }
- return 0;
+ if (!ControlService(hService, SERVICE_CONTROL_STOP, &ServiceStatus))
+ {
+printf("3\n");
+ dwError = GetLastError();
+ nError = 1;
+ goto done;
+ }
+
+done:
+ if (hService != NULL)
+ CloseServiceHandle(hService);
+
+ if (hManager != NULL)
+ CloseServiceHandle(hManager);
+
+ if (dwError != ERROR_SUCCESS)
+ {
+ /* FIXME: Print proper error message */
+ printf("Error: %lu\n", dwError);
+ }
+
+ return nError;
}
-INT stop_service(CHAR *service)
-{
-
- CHAR *srvlst;
- LONG pos=0;
- LONG old_pos=0;
- LONG row_size=0;
- LONG size=0;
-
- CHAR *row; /* we assume display name can max be 20 row and each row is 80 char */
-
-
- /* Get the size for srvlst */
- myCreateProcessStartGetSzie("rpcclient -c \"service enum\"",
&size);
- if (size==0)
- {
- return 0;
- }
-
- srvlst = (CHAR *) malloc(size);
- if (srvlst == NULL)
- {
- return 0;
- }
- /* Get the server list */
- myCreateProcessStart("rpcclient -c \"service enum\"", srvlst,
size);
-
-
- /* scan after display name */
- while (pos<size)
- {
- old_pos = pos;
-
- if (1 == row_scanner_service(srvlst, &pos, size, service, NULL))
- {
- row_size = (pos - old_pos)+32; /* 32 buffer for command */
- pos = old_pos;
- row = (CHAR *) malloc(row_size*sizeof(CHAR));
- if (row == NULL)
- {
- free(srvlst);
- return 0;
- }
- memset(row,0,row_size*sizeof(CHAR));
- if (1 == row_scanner_service(srvlst, &pos, size, service, &row[27]))
- {
- /*
- display name found
- now we can start the service
- */
-
- memcpy(row,"rpcclient -c \"service stop
%s\"\"",27*sizeof(CHAR));
- row_size = strlen(row);
- row[row_size] = '\"';
- system(row);
- }
- free(row);
- }
- }
-
- free(srvlst);
- return 0;
-}
Modified: trunk/reactos/base/applications/network/net/cmdstart.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/…
==============================================================================
--- trunk/reactos/base/applications/network/net/cmdstart.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/network/net/cmdstart.c [iso-8859-1] Mon Sep 24
12:37:12 2012
@@ -1,4 +1,3 @@
-
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS net command
@@ -10,99 +9,171 @@
#include "net.h"
-INT cmdStart(INT argc, CHAR **argv )
+/* Enumerate all running services */
+static
+INT
+EnumerateRunningServices(VOID)
{
- char *string;
- long size = 100*sizeof(char);
+ SC_HANDLE hManager = NULL;
+ SC_HANDLE hService = NULL;
+ DWORD dwBufferSize = 0;
+ DWORD dwServiceCount;
+ DWORD dwResumeHandle = 0;
+ LPENUM_SERVICE_STATUS lpServiceBuffer = NULL;
+ INT i;
+ INT nError = 0;
+ DWORD dwError = ERROR_SUCCESS;
- if (argc>4)
- {
- help();
- return 0;
- }
+ hManager = OpenSCManagerW(NULL,
+ SERVICES_ACTIVE_DATABASE,
+ SC_MANAGER_ENUMERATE_SERVICE);
+ if (hManager == NULL)
+ {
+ dwError = GetLastError();
+ nError = 1;
+ goto done;
+ }
- if (argc==2)
- {
- string = (char *) malloc(size);
- if (string != NULL)
- {
- sprintf(string,"rpcclient -c \"service enum\"");
- system(string);
- free(string);
- }
- return 0;
- }
+ EnumServicesStatusW(hManager,
+ SERVICE_WIN32,
+ SERVICE_ACTIVE,
+ NULL,
+ 0,
+ &dwBufferSize,
+ &dwServiceCount,
+ &dwResumeHandle);
- if (argc==3)
- {
- start_service(argv[1]);
- return 0;
- }
+ if (dwBufferSize != 0)
+ {
+ lpServiceBuffer = HeapAlloc(GetProcessHeap(), 0, dwBufferSize);
+ if (lpServiceBuffer != NULL)
+ {
+ if (EnumServicesStatusW(hManager,
+ SERVICE_WIN32,
+ SERVICE_ACTIVE,
+ lpServiceBuffer,
+ dwBufferSize,
+ &dwBufferSize,
+ &dwServiceCount,
+ &dwResumeHandle))
+ {
+ printf("The following services hav been started:\n\n");
- return 0;
+ for (i = 0; i < dwServiceCount; i++)
+ {
+ printf(" %S\n", lpServiceBuffer[i].lpDisplayName);
+ }
+ }
+
+ HeapFree(GetProcessHeap(), 0, lpServiceBuffer);
+ }
+ }
+
+done:
+ if (hService != NULL)
+ CloseServiceHandle(hService);
+
+ if (hManager != NULL)
+ CloseServiceHandle(hManager);
+
+ if (dwError != ERROR_SUCCESS)
+ {
+ /* FIXME: Print proper error message */
+ printf("Error: %lu\n", dwError);
+ }
+
+ return nError;
}
-INT start_service(CHAR *service)
+/* Start the service argv[2] */
+static
+INT
+StartOneService(INT argc, WCHAR **argv)
{
+ SC_HANDLE hManager = NULL;
+ SC_HANDLE hService = NULL;
+ LPCWSTR *lpArgVectors = NULL;
+ DWORD dwError = ERROR_SUCCESS;
+ INT nError = 0;
+ INT i;
- CHAR *srvlst;
- LONG pos=0;
- LONG old_pos=0;
- LONG row_size=0;
- LONG size=0;
+ hManager = OpenSCManagerW(NULL,
+ SERVICES_ACTIVE_DATABASE,
+ SC_MANAGER_ENUMERATE_SERVICE);
+ if (hManager == NULL)
+ {
+ dwError = GetLastError();
+ nError = 1;
+ goto done;
+ }
- CHAR *row; /* we assume display name can max be 20 row and each row is 80 char */
+ hService = OpenServiceW(hManager,
+ argv[2],
+ SERVICE_START);
+ if (hService == NULL)
+ {
+ dwError = GetLastError();
+ nError = 1;
+ goto done;
+ }
+
+ lpArgVectors = HeapAlloc(GetProcessHeap(),
+ 0,
+ (argc - 2) * sizeof(LPCWSTR));
+ if (lpArgVectors == NULL)
+ {
+ dwError = GetLastError();
+ nError = 1;
+ goto done;
+ }
+
+ for (i = 2; i < argc; i++)
+ {
+ lpArgVectors[i] = argv[i + 2];
+ }
+
+ if (!StartServiceW(hService,
+ (DWORD)argc - 2,
+ lpArgVectors))
+ {
+ dwError = GetLastError();
+ nError = 1;
+ }
+
+done:
+ if (lpArgVectors != NULL)
+ HeapFree(GetProcessHeap(), 0, lpArgVectors);
+
+ if (hService != NULL)
+ CloseServiceHandle(hService);
+
+ if (hManager != NULL)
+ CloseServiceHandle(hManager);
+
+ if (dwError != ERROR_SUCCESS)
+ {
+ /* FIXME: Print proper error message */
+ printf("Error: %lu\n", dwError);
+ }
+
+ return nError;
+}
- /* Get the size for srvlst */
- myCreateProcessStartGetSzie("rpcclient -c \"service enum\"",
&size);
- if (size==0)
- {
- return 0;
- }
+INT
+cmdStart(INT argc, WCHAR **argv)
+{
+ INT nError = 0;
- srvlst = (CHAR *) malloc(size);
- if (srvlst == NULL)
- {
- return 0;
- }
- /* Get the server list */
- myCreateProcessStart("rpcclient -c \"service enum\"", srvlst,
size);
+ if (argc == 2)
+ {
+ nError = EnumerateRunningServices();
+ }
+ else
+ {
+ nError = StartOneService(argc, argv);
+ }
-
- /* scan after display name */
- while (pos<size)
- {
- old_pos = pos;
-
- if (1 == row_scanner_service(srvlst, &pos, size, service, NULL))
- {
- row_size = (pos - old_pos)+32; /* 32 buffer for command */
- pos = old_pos;
- row = (CHAR *) malloc(row_size*sizeof(CHAR));
- if (row == NULL)
- {
- free(srvlst);
- return 0;
- }
- memset(row,0,row_size*sizeof(CHAR));
- if (1 == row_scanner_service(srvlst, &pos, size, service, &row[28]))
- {
- /*
- display name found
- now we can start the service
- */
-
- memcpy(row,"rpcclient -c \"service start
%s\"\"",28*sizeof(CHAR));
- row_size = strlen(row);
- row[row_size] = '\"';
- system(row);
- }
- free(row);
- }
- }
-
- free(srvlst);
- return 0;
+ return nError;
}
Modified: trunk/reactos/base/applications/network/net/help.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/…
==============================================================================
--- trunk/reactos/base/applications/network/net/help.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/network/net/help.c [iso-8859-1] Mon Sep 24 12:37:12
2012
@@ -1,4 +1,3 @@
-
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS net command
@@ -10,154 +9,154 @@
#include "net.h"
-INT cmdHelp(INT argc, CHAR **argv)
+INT cmdHelp(INT argc, WCHAR **argv)
{
- if (argc>3)
+ if (argc > 3)
{
return 0;
}
- if (strcmp(argv[0],"ACCOUNTS")==0)
+ if (_wcsicmp(argv[2],L"ACCOUNTS")==0)
{
puts("ACCOUNTS");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"COMPUTER")==0)
+ if (_wcsicmp(argv[2],L"COMPUTER")==0)
{
puts("COMPUTER");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"CONFIG")==0)
+ if (_wcsicmp(argv[2],L"CONFIG")==0)
{
puts("CONFIG");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"CONTINUE")==0)
+ if (_wcsicmp(argv[2],L"CONTINUE")==0)
{
puts("CONTINUE");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"FILE")==0)
+ if (_wcsicmp(argv[2],L"FILE")==0)
{
puts("FILE");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"GROUP")==0)
+ if (_wcsicmp(argv[2],L"GROUP")==0)
{
puts("GROUP");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"HELP")==0)
+ if (_wcsicmp(argv[2],L"HELP")==0)
{
puts("HELP");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"HELPMSG")==0)
+ if (_wcsicmp(argv[2],L"HELPMSG")==0)
{
puts("HELPMSG");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"LOCALGROUP")==0)
+ if (_wcsicmp(argv[2],L"LOCALGROUP")==0)
{
puts("LOCALGROUP");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"NAME")==0)
+ if (_wcsicmp(argv[2],L"NAME")==0)
{
puts("NAME");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"PRINT")==0)
+ if (_wcsicmp(argv[2],L"PRINT")==0)
{
puts("PRINT");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"SEND")==0)
+ if (_wcsicmp(argv[2],L"SEND")==0)
{
puts("SEND");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"SESSION")==0)
+ if (_wcsicmp(argv[2],L"SESSION")==0)
{
puts("SESSION");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"SHARE")==0)
+ if (_wcsicmp(argv[2],L"SHARE")==0)
{
puts("SHARE");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"START")==0)
+ if (_wcsicmp(argv[2],L"START")==0)
{
puts("START");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"STATISTICS")==0)
+ if (_wcsicmp(argv[2],L"STATISTICS")==0)
{
puts("STATISTICS");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"STOP")==0)
+ if (_wcsicmp(argv[2],L"STOP")==0)
{
puts("STOP");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"TIME")==0)
+ if (_wcsicmp(argv[2],L"TIME")==0)
{
puts("TIME");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"USE")==0)
+ if (_wcsicmp(argv[2],L"USE")==0)
{
puts("USE");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"USER")==0)
+ if (_wcsicmp(argv[2],L"USER")==0)
{
puts("USER");
puts("help text");
return 0;
}
- if (strcmp(argv[0],"VIEW")==0)
+ if (_wcsicmp(argv[2],L"VIEW")==0)
{
puts("VIEW");
puts("help text");
@@ -168,7 +167,8 @@
return 0;
}
-void help()
+
+VOID help(VOID)
{
puts("NET ACCOUNTS");
puts("NET COMPUTER");
Modified: trunk/reactos/base/applications/network/net/main.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/…
==============================================================================
--- trunk/reactos/base/applications/network/net/main.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/network/net/main.c [iso-8859-1] Mon Sep 24 12:37:12
2012
@@ -1,4 +1,3 @@
-
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS net command
@@ -10,112 +9,69 @@
#include "net.h"
+typedef struct _COMMAND
+{
+ WCHAR *name;
+ INT (*func)(INT, WCHAR**);
+// VOID (*help)(INT, WCHAR**);
+} COMMAND, *PCOMMAND;
+
+COMMAND cmds[] =
+{
+ {L"accounts", unimplemented},
+ {L"computer", unimplemented},
+ {L"config", unimplemented},
+ {L"continue", unimplemented},
+ {L"file", unimplemented},
+ {L"group", unimplemented},
+ {L"help", cmdHelp},
+ {L"helpmsg", unimplemented},
+ {L"localgroup", unimplemented},
+ {L"name", unimplemented},
+ {L"print", unimplemented},
+ {L"send", unimplemented},
+ {L"session", unimplemented},
+ {L"share", unimplemented},
+ {L"start", cmdStart},
+ {L"statistics", unimplemented},
+ {L"stop", cmdStop},
+ {L"time", unimplemented},
+ {L"use", unimplemented},
+ {L"user", unimplemented},
+ {L"view", unimplemented},
+
+};
-int main(int argc, char **argv)
+int wmain(int argc, WCHAR **argv)
{
- if (argc<2)
- {
- help();
- return 1;
- }
+ PCOMMAND cmdptr;
- if (_stricmp(argv[1],"ACCOUNTS")==0)
+ if (argc < 2)
{
- return unimplemented();
- }
- if (_stricmp(argv[1],"COMPUTER")==0)
- {
- return unimplemented();
- }
- if (_stricmp(argv[1],"CONFIG")==0)
- {
- return unimplemented();
- }
- if (_stricmp(argv[1],"CONTINUE")==0)
- {
- return unimplemented();
+ help();
+ return 1;
}
- if (_stricmp(argv[1],"FILE")==0)
+ /* Scan the command table */
+ for (cmdptr = cmds; cmdptr->name; cmdptr++)
{
- return unimplemented();
- }
- if (_stricmp(argv[1],"GROUP")==0)
- {
- return unimplemented();
- }
- if (_stricmp(argv[1],"HELP")==0)
- {
- return cmdHelp(argc,&argv[1]);
- }
- if (_stricmp(argv[1],"HELPMSG")==0)
- {
- return unimplemented();
- }
- if (_stricmp(argv[1],"LOCALGROUP")==0)
- {
- return unimplemented();
- }
- if (_stricmp(argv[1],"NAME")==0)
- {
- return unimplemented();
- }
- if (_stricmp(argv[1],"PRINT")==0)
- {
- return unimplemented();
- }
- if (_stricmp(argv[1],"SEND")==0)
- {
- return unimplemented();
- }
- if (_stricmp(argv[1],"SESSION")==0)
- {
- return unimplemented();
- }
- if (_stricmp(argv[1],"SHARE")==0)
- {
- return unimplemented();
- }
-
- if (_stricmp(argv[1],"START")==0)
- {
- return cmdStart(argc, &argv[1]);
- }
- if (_stricmp(argv[1],"STATISTICS")==0)
- {
- return unimplemented();
- }
- if (_stricmp(argv[1],"STOP")==0)
- {
- return cmdStop(argc, &argv[1]);
- }
- if (_stricmp(argv[1],"TIME")==0)
- {
- return unimplemented();
- }
- if (_stricmp(argv[1],"USE")==0)
- {
- return unimplemented();
- }
- if (_stricmp(argv[1],"USER")==0)
- {
- return unimplemented();
- }
- if (_stricmp(argv[1],"VIEW")==0)
- {
- return unimplemented();
+ if (_wcsicmp(argv[1], cmdptr->name) == 0)
+ {
+ return cmdptr->func(argc, argv);
+ }
}
help();
- return 1;
+
+ return 1;
}
-int unimplemented()
+INT unimplemented(INT argc, WCHAR **argv)
{
- puts("This command is not implemented yet");
- return 1;
+ puts("This command is not implemented yet");
+ return 1;
}
Modified: trunk/reactos/base/applications/network/net/net.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/…
==============================================================================
--- trunk/reactos/base/applications/network/net/net.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/network/net/net.h [iso-8859-1] Mon Sep 24 12:37:12
2012
@@ -1,4 +1,3 @@
-
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS net command
@@ -12,24 +11,12 @@
#include <string.h>
#include <stdlib.h>
#include <windows.h>
+#include <winsvc.h>
-void help(void);
-int unimplemented(void);
+VOID help(VOID);
+INT unimplemented(INT argc, WCHAR **argv);
-INT cmdHelp(INT argc, CHAR **argv);
-
-INT cmdStart(INT argc, CHAR **argv );
-INT start_service(CHAR *service);
-
-INT cmdStop(INT argc, CHAR **argv );
-INT stop_service(CHAR *service);
-
-/* Control and start rpcclient */
-BOOL myCreateProcessStartGetSzie(CHAR *cmdline, LONG *size);
-BOOL myCreateProcessStart(CHAR *cmdline, CHAR *srvlst, LONG size);
-BOOL myCreateProcess(HANDLE hChildStdoutWr, HANDLE hChildStdinRd, CHAR *cmdline);
-LONG ReadPipe(HANDLE hStdoutWr, HANDLE hStdoutRd, CHAR *srvlst, LONG size);
-LONG ReadPipeSize(HANDLE hStdoutWr, HANDLE hStdoutRd);
-INT row_scanner_service(CHAR *buffer, LONG* pos, LONG size, CHAR *name,CHAR *save);
-
+INT cmdHelp(INT argc, WCHAR **argv);
+INT cmdStart(INT argc, WCHAR **argv);
+INT cmdStop(INT argc, WCHAR **argv);
Removed: trunk/reactos/base/applications/network/net/process.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/…
==============================================================================
--- trunk/reactos/base/applications/network/net/process.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/network/net/process.c (removed)
@@ -1,229 +1,0 @@
-
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS net command
- * FILE:
- * PURPOSE:
- *
- * PROGRAMMERS: Magnus Olsen (greatlord(a)reactos.org)
- */
-
-#include "net.h"
-
-BOOL myCreateProcessStartGetSzie(CHAR *cmdline, LONG *size)
-{
- HANDLE hChildStdinRd;
- HANDLE hChildStdinWr;
- HANDLE hChildStdoutRd;
- HANDLE hChildStdoutWr;
- SECURITY_ATTRIBUTES saAttr;
-
- saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
- saAttr.bInheritHandle = TRUE;
- saAttr.lpSecurityDescriptor = NULL;
-
- if (! CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0))
- {
- return FALSE;
- }
-
- if (! CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0))
- {
- return FALSE;
- }
-
- myCreateProcess(hChildStdoutWr, hChildStdinRd,"rpcclient -c \"service
enum\"");
- *size = ReadPipeSize(hChildStdoutWr, hChildStdoutRd);
- return TRUE;
-}
-
-BOOL myCreateProcessStart(CHAR *cmdline, CHAR *srvlst, LONG size)
-{
- HANDLE hChildStdinRd;
- HANDLE hChildStdinWr;
- HANDLE hChildStdoutRd;
- HANDLE hChildStdoutWr;
- SECURITY_ATTRIBUTES saAttr;
-
- saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
- saAttr.bInheritHandle = TRUE;
- saAttr.lpSecurityDescriptor = NULL;
-
- if (! CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0))
- {
- return FALSE;
- }
-
- if (! CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0))
- {
- return FALSE;
- }
-
- myCreateProcess(hChildStdoutWr, hChildStdinRd,"rpcclient -c \"service
enum\"");
-
- return ReadPipe(hChildStdoutWr, hChildStdoutRd, srvlst, size);
-}
-
-BOOL myCreateProcess(HANDLE hStdoutWr, HANDLE hStdinRd, CHAR *cmdline)
-{
- PROCESS_INFORMATION piProcInfo;
- STARTUPINFO siStartInfo;
- BOOL status = FALSE;
-
- ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) );
- ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
- siStartInfo.cb = sizeof(STARTUPINFO);
- siStartInfo.hStdError = hStdoutWr;
- siStartInfo.hStdOutput = hStdoutWr;
- siStartInfo.hStdInput = hStdinRd;
- siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
- status = CreateProcess(NULL, cmdline, NULL, NULL,
- TRUE, 0, NULL, NULL, &siStartInfo, &piProcInfo);
-
- if (status != 0)
- {
- CloseHandle(piProcInfo.hProcess);
- CloseHandle(piProcInfo.hThread);
- return status;
- }
- return status;
-}
-
-LONG ReadPipeSize(HANDLE hStdoutWr, HANDLE hStdoutRd)
-{
- CHAR chBuf[2];
- LONG pos=0;
-
- if (!CloseHandle(hStdoutWr))
- {
- return 0; /* fail */
- }
-
- for (;;)
- {
- long dwRead;
- if( !ReadFile( hStdoutRd, chBuf, 1, (LPDWORD)&dwRead, NULL) || dwRead == 0)
- {
- break;
- }
- else
- {
- pos+=dwRead;
- }
- }
- return pos;
-}
-
-LONG ReadPipe(HANDLE hStdoutWr, HANDLE hStdoutRd, CHAR *srvlst, LONG size)
-{
- CHAR chBuf[2];
- LONG pos;
-
- pos=0;
-
- if (!CloseHandle(hStdoutWr))
- {
- return 0; /* fail */
- }
-
- for (;;)
- {
- LONG dwRead;
- if( !ReadFile( hStdoutRd, chBuf, 1, (LPDWORD)&dwRead, NULL) || dwRead == 0)
- {
- break;
- }
- else
- {
- srvlst[pos++] = chBuf[0] ;
- }
- }
- return 0;
-}
-
-INT row_scanner_service(CHAR *buffer, LONG* pos, LONG size,
- CHAR *name,CHAR *save)
-{
- LONG get_semi;
- LONG t;
- LONG row_size=0;
- LONG start_pos;
-
- start_pos = *pos;
-
- if (*pos>=size)
- {
- return 0;
- }
-
-
- /* get row start */
- for (t=start_pos;t<size;t++)
- {
- if (buffer[t]=='\n')
- {
- buffer[t]='\0';
- if (buffer[t-1]==0x09)
- {
- buffer[t-1]='\0';
- }
- if (buffer[t-1]==0x0d)
- {
- buffer[t-1]='\0';
- }
- *pos = t+1;
- row_size = t;
- break;
- }
- }
-
- /* get : */
- get_semi=-1;
- for (t=start_pos;t<row_size;t++)
- {
- if (buffer[t]==':')
- {
- get_semi=t;
- break;
- }
- }
-
- if (get_semi==-1)
- {
- return 0;
- }
-
- /* lock for space */
- for (t=get_semi+1;t<row_size;t++)
- {
- if (!isspace(buffer[t]))
- {
- break;
- }
- }
- if (t==0)
- {
- /* : not found next row*/
- return 0;
- }
-
- /* Compare now */
- if (_strnicmp(name,&buffer[t],strlen(&buffer[t]))==0)
- {
- if (save != NULL)
- {
- /* lock for space */
- for (t=start_pos;t<get_semi;t++)
- {
- if (!isspace(buffer[t]))
- {
- break;
- }
- }
-
- memcpy(save,&buffer[t],get_semi-t);
- }
- return 1;
- }
- return 0;
-}