mirror of
https://github.com/reactos/reactos.git
synced 2025-02-23 08:55:19 +00:00
Add frist version of ReactOS net command. I finish frist step early that I calc, you need samba-tng rpcclient to use net command in your path. net command only support follow command "net start, net start serivce_display name, net stop", more will follow later.
The help text I need some help with to fill in the info how thuse command work and design the help text better. svn path=/trunk/; revision=23709
This commit is contained in:
parent
10782a0cfa
commit
87b9d209fd
7 changed files with 816 additions and 0 deletions
107
reactos/base/applications/network/net/cmdStop.c
Normal file
107
reactos/base/applications/network/net/cmdStop.c
Normal file
|
@ -0,0 +1,107 @@
|
|||
|
||||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS net command
|
||||
* FILE:
|
||||
* PURPOSE:
|
||||
*
|
||||
* PROGRAMMERS: Magnus Olsen (greatlord@reactos.org)
|
||||
*/
|
||||
|
||||
#include "net.h"
|
||||
|
||||
INT cmdStop(INT argc, CHAR **argv )
|
||||
{
|
||||
char *string;
|
||||
long size = 100*sizeof(char);
|
||||
|
||||
if (argc>4)
|
||||
{
|
||||
help();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argc==2)
|
||||
{
|
||||
string = (char *) malloc(size);
|
||||
if (string != NULL)
|
||||
{
|
||||
sprintf(string,"rpcclient -c \"service enum\"");
|
||||
system(string);
|
||||
free(string);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argc==3)
|
||||
{
|
||||
stop_service(argv[1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
107
reactos/base/applications/network/net/cmdstart.c
Normal file
107
reactos/base/applications/network/net/cmdstart.c
Normal file
|
@ -0,0 +1,107 @@
|
|||
|
||||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS net command
|
||||
* FILE:
|
||||
* PURPOSE:
|
||||
*
|
||||
* PROGRAMMERS: Magnus Olsen (greatlord@reactos.org)
|
||||
*/
|
||||
|
||||
#include "net.h"
|
||||
|
||||
INT cmdStart(INT argc, CHAR **argv )
|
||||
{
|
||||
char *string;
|
||||
long size = 100*sizeof(char);
|
||||
|
||||
if (argc>4)
|
||||
{
|
||||
help();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argc==2)
|
||||
{
|
||||
string = (char *) malloc(size);
|
||||
if (string != NULL)
|
||||
{
|
||||
sprintf(string,"rpcclient -c \"service enum\"");
|
||||
system(string);
|
||||
free(string);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argc==3)
|
||||
{
|
||||
start_service(argv[1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
INT start_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)
|
||||
{
|
||||
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;
|
||||
}
|
199
reactos/base/applications/network/net/help.c
Normal file
199
reactos/base/applications/network/net/help.c
Normal file
|
@ -0,0 +1,199 @@
|
|||
|
||||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS net command
|
||||
* FILE:
|
||||
* PURPOSE:
|
||||
*
|
||||
* PROGRAMMERS: Magnus Olsen (greatlord@reactos.org)
|
||||
*/
|
||||
|
||||
#include "net.h"
|
||||
|
||||
INT cmdHelp(INT argc, CHAR **argv)
|
||||
{
|
||||
if (argc>3)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"ACCOUNTS")==0)
|
||||
{
|
||||
printf("ACCOUNTS\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"COMPUTER")==0)
|
||||
{
|
||||
printf("COMPUTER\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"CONFIG")==0)
|
||||
{
|
||||
printf("CONFIG\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"CONTINUE")==0)
|
||||
{
|
||||
printf("CONTINUE\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"FILE")==0)
|
||||
{
|
||||
printf("FILE\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"GROUP")==0)
|
||||
{
|
||||
printf("GROUP\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"HELP")==0)
|
||||
{
|
||||
printf("HELP\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"HELPMSG")==0)
|
||||
{
|
||||
printf("HELPMSG\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"LOCALGROUP")==0)
|
||||
{
|
||||
printf("LOCALGROUP\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"NAME")==0)
|
||||
{
|
||||
printf("NAME\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"PRINT")==0)
|
||||
{
|
||||
printf("PRINT\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"SEND")==0)
|
||||
{
|
||||
printf("SEND\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"SESSION")==0)
|
||||
{
|
||||
printf("SESSION\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"SHARE")==0)
|
||||
{
|
||||
printf("SHARE\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"START")==0)
|
||||
{
|
||||
printf("START\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"STATISTICS")==0)
|
||||
{
|
||||
printf("STATISTICS\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"STOP")==0)
|
||||
{
|
||||
printf("STOP\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"TIME")==0)
|
||||
{
|
||||
printf("TIME\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"USE")==0)
|
||||
{
|
||||
printf("USE\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"USER")==0)
|
||||
{
|
||||
printf("USER\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0],"VIEW")==0)
|
||||
{
|
||||
printf("VIEW\n");
|
||||
printf("help text\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
help();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void help()
|
||||
{
|
||||
printf("NET ACCOUNTS\n");
|
||||
printf("NET COMPUTER\n");
|
||||
printf("NET CONFIG\n");
|
||||
printf("NET CONFIG SERVER\n");
|
||||
printf("NET CONFIG WORKSTATION\n");
|
||||
printf("NET CONTINUE\n");
|
||||
printf("NET FILE\n");
|
||||
printf("NET GROUP\n");
|
||||
|
||||
printf("NET HELP\n");
|
||||
printf("NET HELPMSG\n");
|
||||
printf("NET LOCALGROUP\n");
|
||||
printf("NET NAME\n");
|
||||
printf("NET PAUSE\n");
|
||||
printf("NET PRINT\n");
|
||||
printf("NET SEND\n");
|
||||
printf("NET SESSION\n");
|
||||
|
||||
printf("NET SHARE\n");
|
||||
printf("NET START\n");
|
||||
printf("NET STATISTICS\n");
|
||||
printf("NET STOP\n");
|
||||
printf("NET TIME\n");
|
||||
printf("NET USE\n");
|
||||
printf("NET USER\n");
|
||||
printf("NET VIEW\n");
|
||||
}
|
138
reactos/base/applications/network/net/main.c
Normal file
138
reactos/base/applications/network/net/main.c
Normal file
|
@ -0,0 +1,138 @@
|
|||
|
||||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS net command
|
||||
* FILE:
|
||||
* PURPOSE:
|
||||
*
|
||||
* PROGRAMMERS: Magnus Olsen (greatlord@reactos.org)
|
||||
*/
|
||||
|
||||
#include "net.h"
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc<2)
|
||||
{
|
||||
help();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (stricmp(argv[1],"ACCOUNTS")==0)
|
||||
{
|
||||
return unimplement();
|
||||
}
|
||||
if (stricmp(argv[1],"COMPUTER")==0)
|
||||
{
|
||||
return unimplement();
|
||||
}
|
||||
if (stricmp(argv[1],"CONFIG")==0)
|
||||
{
|
||||
return unimplement();
|
||||
}
|
||||
if (stricmp(argv[1],"CONTINUE")==0)
|
||||
{
|
||||
return unimplement();
|
||||
}
|
||||
|
||||
if (stricmp(argv[1],"FILE")==0)
|
||||
{
|
||||
return unimplement();
|
||||
}
|
||||
if (stricmp(argv[1],"GROUP")==0)
|
||||
{
|
||||
return unimplement();
|
||||
}
|
||||
if (stricmp(argv[1],"HELP")==0)
|
||||
{
|
||||
return cmdHelp(argc,&argv[1]);
|
||||
}
|
||||
if (stricmp(argv[1],"HELPMSG")==0)
|
||||
{
|
||||
return unimplement();
|
||||
}
|
||||
if (stricmp(argv[1],"LOCALGROUP")==0)
|
||||
{
|
||||
return unimplement();
|
||||
}
|
||||
if (stricmp(argv[1],"NAME")==0)
|
||||
{
|
||||
return unimplement();
|
||||
}
|
||||
if (stricmp(argv[1],"PRINT")==0)
|
||||
{
|
||||
return unimplement();
|
||||
}
|
||||
if (stricmp(argv[1],"SEND")==0)
|
||||
{
|
||||
return unimplement();
|
||||
}
|
||||
if (stricmp(argv[1],"SESSION")==0)
|
||||
{
|
||||
return unimplement();
|
||||
}
|
||||
if (stricmp(argv[1],"SHARE")==0)
|
||||
{
|
||||
return unimplement();
|
||||
}
|
||||
|
||||
if (stricmp(argv[1],"START")==0)
|
||||
{
|
||||
return cmdStart(argc, &argv[1]);
|
||||
}
|
||||
if (stricmp(argv[1],"STATISTICS")==0)
|
||||
{
|
||||
return unimplement();
|
||||
}
|
||||
if (stricmp(argv[1],"STOP")==0)
|
||||
{
|
||||
return cmdStop(argc, &argv[1]);
|
||||
}
|
||||
if (stricmp(argv[1],"TIME")==0)
|
||||
{
|
||||
return unimplement();
|
||||
}
|
||||
if (stricmp(argv[1],"USE")==0)
|
||||
{
|
||||
return unimplement();
|
||||
}
|
||||
if (stricmp(argv[1],"USER")==0)
|
||||
{
|
||||
return unimplement();
|
||||
}
|
||||
if (stricmp(argv[1],"VIEW")==0)
|
||||
{
|
||||
return unimplement();
|
||||
}
|
||||
|
||||
help();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int unimplement()
|
||||
{
|
||||
printf("This command is not implement yet\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
35
reactos/base/applications/network/net/net.h
Normal file
35
reactos/base/applications/network/net/net.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
|
||||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS net command
|
||||
* FILE:
|
||||
* PURPOSE:
|
||||
*
|
||||
* PROGRAMMERS: Magnus Olsen (greatlord@reactos.org)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
|
||||
void help();
|
||||
int unimplement();
|
||||
|
||||
|
||||
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);
|
||||
|
227
reactos/base/applications/network/net/process.c
Normal file
227
reactos/base/applications/network/net/process.c
Normal file
|
@ -0,0 +1,227 @@
|
|||
|
||||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS net command
|
||||
* FILE:
|
||||
* PURPOSE:
|
||||
*
|
||||
* PROGRAMMERS: Magnus Olsen (greatlord@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, &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=0;
|
||||
|
||||
if (!CloseHandle(hStdoutWr))
|
||||
{
|
||||
return 0; /* fail */
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
long dwRead;
|
||||
if( !ReadFile( hStdoutRd, chBuf, 1, &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;
|
||||
}
|
|
@ -13,6 +13,9 @@
|
|||
<directory name="ipconfig">
|
||||
<xi:include href="ipconfig/ipconfig.rbuild" />
|
||||
</directory>
|
||||
<directory name="net">
|
||||
<xi:include href="net/net.rbuild" />
|
||||
</directory>
|
||||
<directory name="netstat">
|
||||
<xi:include href="netstat/netstat.rbuild" />
|
||||
</directory>
|
||||
|
|
Loading…
Reference in a new issue