From 87b9d209fd4c5a6dc8045dad4fd097900fa50be0 Mon Sep 17 00:00:00 2001 From: Magnus Olsen Date: Fri, 25 Aug 2006 17:50:26 +0000 Subject: [PATCH] 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 --- .../base/applications/network/net/cmdStop.c | 107 +++++++++ .../base/applications/network/net/cmdstart.c | 107 +++++++++ reactos/base/applications/network/net/help.c | 199 +++++++++++++++ reactos/base/applications/network/net/main.c | 138 +++++++++++ reactos/base/applications/network/net/net.h | 35 +++ .../base/applications/network/net/process.c | 227 ++++++++++++++++++ .../base/applications/network/network.rbuild | 3 + 7 files changed, 816 insertions(+) create mode 100644 reactos/base/applications/network/net/cmdStop.c create mode 100644 reactos/base/applications/network/net/cmdstart.c create mode 100644 reactos/base/applications/network/net/help.c create mode 100644 reactos/base/applications/network/net/main.c create mode 100644 reactos/base/applications/network/net/net.h create mode 100644 reactos/base/applications/network/net/process.c diff --git a/reactos/base/applications/network/net/cmdStop.c b/reactos/base/applications/network/net/cmdStop.c new file mode 100644 index 00000000000..16f36690403 --- /dev/null +++ b/reactos/base/applications/network/net/cmdStop.c @@ -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 (pos4) + { + 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 (pos3) + { + 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"); +} diff --git a/reactos/base/applications/network/net/main.c b/reactos/base/applications/network/net/main.c new file mode 100644 index 00000000000..1bdd53b80de --- /dev/null +++ b/reactos/base/applications/network/net/main.c @@ -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; +} + + + + + + + + + + + + + + + + + + + diff --git a/reactos/base/applications/network/net/net.h b/reactos/base/applications/network/net/net.h new file mode 100644 index 00000000000..e450dff1c51 --- /dev/null +++ b/reactos/base/applications/network/net/net.h @@ -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 +#include +#include +#include + +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); + diff --git a/reactos/base/applications/network/net/process.c b/reactos/base/applications/network/net/process.c new file mode 100644 index 00000000000..16c3a537bdf --- /dev/null +++ b/reactos/base/applications/network/net/process.c @@ -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 + + +