~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/programs/net/net.c

Version: ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /*
  2  * Copyright 2007 Tim Schwartz
  3  *
  4  * This library is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2.1 of the License, or (at your option) any later version.
  8  *
  9  * This library is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with this library; if not, write to the Free Software
 16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 17  */
 18 
 19 #include <stdio.h>
 20 #include <string.h>
 21 #include <windows.h>
 22 #include <lm.h>
 23 #include "resources.h"
 24 
 25 #define NET_START 0001
 26 #define NET_STOP  0002
 27 
 28 int output_string(int msg, ...)
 29 {
 30     char msg_buffer[8192];
 31     va_list arguments;
 32 
 33     LoadString(GetModuleHandle(NULL), msg, msg_buffer, sizeof(msg_buffer));
 34     va_start(arguments, msg);
 35     vprintf(msg_buffer, arguments);
 36     va_end(arguments);
 37     return 0;
 38 }
 39 
 40 BOOL output_error_string(DWORD error)
 41 {
 42     LPSTR pBuffer;
 43     if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
 44             FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
 45             NULL, error, 0, (LPSTR)&pBuffer, 0, NULL))
 46     {
 47         fputs(pBuffer, stdout);
 48         LocalFree(pBuffer);
 49         return TRUE;
 50     }
 51     return FALSE;
 52 }
 53 
 54 static BOOL net_use(int argc, char *argv[])
 55 {
 56     USE_INFO_2 *buffer, *connection;
 57     DWORD read, total, resume_handle, rc, i;
 58     const char *status_description[] = { "OK", "Paused", "Disconnected", "An error occurred",
 59                                          "A network error occurred", "Connection is being made",
 60                                          "Reconnecting" };
 61     resume_handle = 0;
 62     buffer = NULL;
 63 
 64     if(argc<3)
 65     {
 66         do {
 67             rc = NetUseEnum(NULL, 2, (BYTE **) &buffer, 2048, &read, &total, &resume_handle);
 68             if (rc != ERROR_MORE_DATA && rc != ERROR_SUCCESS)
 69             {
 70                 break;
 71             }
 72 
 73             if(total == 0)
 74             {
 75                 output_string(STRING_NO_ENTRIES);
 76                 break;
 77             }
 78 
 79             output_string(STRING_USE_HEADER);
 80             for (i = 0, connection = buffer; i < read; ++i, ++connection)
 81                 output_string(STRING_USE_ENTRY, status_description[connection->ui2_status], connection->ui2_local,
 82                                 connection->ui2_remote, connection->ui2_refcount);
 83 
 84             if (buffer != NULL) NetApiBufferFree(buffer);
 85         } while (rc == ERROR_MORE_DATA);
 86 
 87         return TRUE;
 88     }
 89 
 90     return FALSE;
 91 }
 92 
 93 static BOOL StopService(SC_HANDLE SCManager, SC_HANDLE serviceHandle)
 94 {
 95     LPENUM_SERVICE_STATUS dependencies = NULL;
 96     DWORD buffer_size = 0;
 97     DWORD count = 0, counter;
 98     BOOL result;
 99     SC_HANDLE dependent_serviceHandle;
100     SERVICE_STATUS_PROCESS ssp;
101 
102     result = EnumDependentServices(serviceHandle, SERVICE_ACTIVE, dependencies, buffer_size, &buffer_size, &count);
103 
104     if(!result && (GetLastError() == ERROR_MORE_DATA))
105     {
106         dependencies = HeapAlloc(GetProcessHeap(), 0, buffer_size);
107         if(EnumDependentServices(serviceHandle, SERVICE_ACTIVE, dependencies, buffer_size, &buffer_size, &count))
108         {
109             for(counter = 0; counter < count; counter++)
110             {
111                 output_string(STRING_STOP_DEP, dependencies[counter].lpDisplayName);
112                 dependent_serviceHandle = OpenService(SCManager, dependencies[counter].lpServiceName, SC_MANAGER_ALL_ACCESS);
113                 if(dependent_serviceHandle) result = StopService(SCManager, dependent_serviceHandle);
114                 CloseServiceHandle(dependent_serviceHandle);
115                 if(!result) output_string(STRING_CANT_STOP, dependencies[counter].lpDisplayName);
116            }
117         }
118     }
119 
120     if(result) result = ControlService(serviceHandle, SERVICE_CONTROL_STOP, (LPSERVICE_STATUS)&ssp);
121     HeapFree(GetProcessHeap(), 0, dependencies);
122     return result;
123 }
124 
125 static BOOL net_service(int operation, char *service_name)
126 {
127     SC_HANDLE SCManager, serviceHandle;
128     BOOL result = 0;
129     char service_display_name[4096];
130     DWORD buffer_size = sizeof(service_display_name);
131 
132     SCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
133     if(!SCManager)
134     {
135         output_string(STRING_NO_SCM);
136         return FALSE;
137     }
138     serviceHandle = OpenService(SCManager, service_name, SC_MANAGER_ALL_ACCESS);
139     if(!serviceHandle)
140     {
141         output_string(STRING_NO_SVCHANDLE);
142         CloseServiceHandle(SCManager);
143         return FALSE;
144     }
145 
146 
147     GetServiceDisplayName(SCManager, service_name, service_display_name, &buffer_size);
148     if (!service_display_name[0]) strcpy(service_display_name, service_name);
149 
150     switch(operation)
151     {
152     case NET_START:
153         output_string(STRING_START_SVC, service_display_name);
154         result = StartService(serviceHandle, 0, NULL);
155 
156         if(result) output_string(STRING_START_SVC_SUCCESS, service_display_name);
157         else
158         {
159             if (!output_error_string(GetLastError()))
160                 output_string(STRING_START_SVC_FAIL, service_display_name);
161         }
162         break;
163     case NET_STOP:
164         output_string(STRING_STOP_SVC, service_display_name);
165         result = StopService(SCManager, serviceHandle);
166 
167         if(result) output_string(STRING_STOP_SVC_SUCCESS, service_display_name);
168         else
169         {
170             if (!output_error_string(GetLastError()))
171                 output_string(STRING_STOP_SVC_FAIL, service_display_name);
172         }
173         break;
174     }
175 
176     CloseServiceHandle(serviceHandle);
177     CloseServiceHandle(SCManager);
178     return result;
179 }
180 
181 int main(int argc, char *argv[])
182 {
183     if (argc < 2)
184     {
185         output_string(STRING_USAGE);
186         return 1;
187     }
188 
189     if(!strcasecmp(argv[1], "help"))
190     {
191         output_string(STRING_HELP_USAGE);
192     }
193 
194     if(!strcasecmp(argv[1], "start"))
195     {
196         if(argc < 3)
197         {
198             output_string(STRING_START_USAGE);
199             return 1;
200         }
201 
202         if(!net_service(NET_START, argv[2]))
203         {
204             return 1;
205         }
206         return 0;
207     }
208 
209     if(!strcasecmp(argv[1], "stop"))
210     {
211         if(argc < 3)
212         {
213             output_string(STRING_STOP_USAGE);
214             return 1;
215         }
216 
217         if(!net_service(NET_STOP, argv[2]))
218         {
219             return 1;
220         }
221         return 0;
222     }
223 
224     if(!strcasecmp(argv[1], "use"))
225     {
226         if(!net_use(argc, argv)) return 1;
227     }
228 
229     return 0;
230 }
231 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.