[PATCH] Adds NET START to net.exe

Rolf Kalbermatter r.kalbermatter at hccnet.nl
Mon May 7 15:37:30 CDT 2007


Tim Schwartz [tim at 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




More information about the wine-devel mailing list