Tim Schwartz [tim@sanityinternet.com] wrote:
diff --git a/programs/net/net.c b/programs/net/net.c index f77c820..ef08250 100644 --- a/programs/net/net.c +++ b/programs/net/net.c @@ -18,15 +18,66 @@
#include <stdio.h> #include <string.h> +#include <windows.h> + +int net_service(char *operation, char *service_name) { + SC_HANDLE SCManager, serviceHandle; + int result = 0; + unsigned int *buffer_size = NULL; + char *service_display_name = NULL; + + SCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); + if(!SCManager) + { + printf("Couldn't get handle to SCManager.\n"); + return 0; + } + serviceHandle = OpenService(SCManager, service_name, SC_MANAGER_ALL_ACCESS); + if(!serviceHandle) + { + printf("Couldn't get handle to service.\n"); + CloseServiceHandle(SCManager); + return 0; + } + + GetServiceDisplayName(SCManager, service_name, NULL, buffer_size); + if(!buffer_size) + {
Apart from GetServiceDisplayName() currently not being implemented in Wine, this won't work! *buffer_size won't be allocated by the function but has to be provided by the caller and its pointer shouldn't be NULL ever. It should and proabably will just return with an error if it is a NULL pointer.
+ service_display_name = HeapAlloc(GetProcessHeap(), 0, strlen(service_name)); + strcpy(service_display_name, service_name); + } + else + { + service_display_name = HeapAlloc(GetProcessHeap(), 0, *buffer_size);
MSDN says: When the function returns, lpcchBuffer contains the size of the service's display name, excluding the null-terminating character, so your buffer is in fact one character to small.
+ GetServiceDisplayName(SCManager, service_name, service_display_name, buffer_size); + }
Your mail client wrapped the patch again it seems. Sending as an attachment might work better.
Rolf Kalbermatter
Rolf Kalbermatter [mailto:r.kalbermatter@hccnet.nl]
- GetServiceDisplayName(SCManager, service_name, NULL, buffer_size);
- if(!buffer_size)
- {
Apart from GetServiceDisplayName() currently not being implemented in Wine,
this won't work!
*buffer_size won't be allocated by the function but has to be provided by
the caller and its
pointer shouldn't be NULL ever. It should and proabably will just return
with an error if it
is a NULL pointer.
I actually just tested this and no it does not return an error in that case but simply crashes on Windows XP SP2. As do apparantly many other service functions that take such a parameter.
service_display_name = HeapAlloc(GetProcessHeap(), 0,
strlen(service_name));
strcpy(service_display_name, service_name);
- }
- else
- {
service_display_name = HeapAlloc(GetProcessHeap(), 0,
*buffer_size);
MSDN says: When the function returns, lpcchBuffer contains the size of the
service's display
name, excluding the null-terminating character, so your buffer is in fact
one character to small.
MSDN is quite unclear here. On XP SP2 the function returns this size when the buffer was NULL or the input size was to small. Otherwise it seems to leave this parameter alone!
Seems we should start to add some tests for service functions too. This however would probably require a dummy service that can be installed for testing and removed afterwards. Are there any administrator right limitations to installing services in Wine?
Rolf Kalbermatter