[NTOS]: Start using colored pages. This will help performance on real systems signifi...
[reactos.git] / base / applications / network / net / cmdStop.c
1
2 /*
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS net command
5 * FILE:
6 * PURPOSE:
7 *
8 * PROGRAMMERS: Magnus Olsen (greatlord@reactos.org)
9 */
10
11 #include "net.h"
12
13 INT cmdStop(INT argc, CHAR **argv )
14 {
15 char *string;
16 long size = 100*sizeof(char);
17
18 if (argc>4)
19 {
20 help();
21 return 0;
22 }
23
24 if (argc==2)
25 {
26 string = (char *) malloc(size);
27 if (string != NULL)
28 {
29 sprintf(string,"rpcclient -c \"service enum\"");
30 system(string);
31 free(string);
32 }
33 return 0;
34 }
35
36 if (argc==3)
37 {
38 stop_service(argv[1]);
39 return 0;
40 }
41
42 return 0;
43 }
44
45
46 INT stop_service(CHAR *service)
47 {
48
49 CHAR *srvlst;
50 LONG pos=0;
51 LONG old_pos=0;
52 LONG row_size=0;
53 LONG size=0;
54
55 CHAR *row; /* we assume display name can max be 20 row and each row is 80 char */
56
57
58 /* Get the size for srvlst */
59 myCreateProcessStartGetSzie("rpcclient -c \"service enum\"", &size);
60 if (size==0)
61 {
62 return 0;
63 }
64
65 srvlst = (CHAR *) malloc(size);
66 if (srvlst == NULL)
67 {
68 return 0;
69 }
70 /* Get the server list */
71 myCreateProcessStart("rpcclient -c \"service enum\"", srvlst, size);
72
73
74 /* scan after display name */
75 while (pos<size)
76 {
77 old_pos = pos;
78
79 if (1 == row_scanner_service(srvlst, &pos, size, service, NULL))
80 {
81 row_size = (pos - old_pos)+32; /* 32 buffer for command */
82 pos = old_pos;
83 row = (CHAR *) malloc(row_size*sizeof(CHAR));
84 if (row == NULL)
85 {
86 free(srvlst);
87 return 0;
88 }
89 memset(row,0,row_size*sizeof(CHAR));
90 if (1 == row_scanner_service(srvlst, &pos, size, service, &row[27]))
91 {
92 /*
93 display name found
94 now we can start the service
95 */
96
97 memcpy(row,"rpcclient -c \"service stop %s\"\"",27*sizeof(CHAR));
98 row_size = strlen(row);
99 row[row_size] = '\"';
100 system(row);
101 }
102 free(row);
103 }
104 }
105
106 free(srvlst);
107 return 0;
108 }