]> git.sur5r.net Git - openldap/blobdiff - libraries/liblutil/ntservice.c
Output from ldif_fetch_url() is expected to be \0-terminated.
[openldap] / libraries / liblutil / ntservice.c
index 657974ae7c9b0152e0f250c2d2e2b723b416c83e..9bd27b7065837dfaab261b7564f97324eb8cdaf2 100644 (file)
@@ -1,6 +1,6 @@
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
 
 #include <ldap.h>
 
+/*
+ * The whole debug implementation is a bit of a hack.
+ * We have to define this LDAP_SLAPD_V macro here since the slap.h
+ * header file isn't included (and really shouldn't be).
+ * TODO: re-implement debug functions so that the debug level can
+ * be passed around instead of having to count on the existence of
+ * ldap_debug, slap_debug, etc.
+ */
 #define ldap_debug slap_debug
-extern int slap_debug;
+LDAP_SLAPD_V (int) slap_debug;
 
 #include "ldap_log.h"
 #include "ldap_pvt_thread.h"
@@ -75,7 +83,8 @@ int srv_install(LPCTSTR lpszServiceName, LPCTSTR lpszDisplayName,
                        CloseServiceHandle(schService);
                        CloseServiceHandle(schSCManager);
 
-                       sprintf( regpath, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s",
+                       snprintf( regpath, sizeof regpath,
+                               "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s",
                                lpszServiceName );
                        /* Create the registry key for event logging to the Windows NT event log. */
                        if ( RegCreateKeyEx(HKEY_LOCAL_MACHINE, 
@@ -150,6 +159,57 @@ int srv_remove(LPCTSTR lpszServiceName, LPCTSTR lpszBinaryPathName)
 }
 
 
+DWORD
+svc_installed (LPTSTR lpszServiceName, LPTSTR lpszBinaryPathName)
+{
+       char buf[256];
+       HKEY key;
+       DWORD rc;
+       DWORD type;
+       long len;
+
+       strcpy(buf, TEXT("SYSTEM\\CurrentControlSet\\Services\\"));
+       strcat(buf, lpszServiceName);
+       if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, buf, 0, KEY_QUERY_VALUE, &key) != ERROR_SUCCESS)
+               return(-1);
+
+       rc = 0;
+       if (lpszBinaryPathName) {
+               len = sizeof(buf);
+               if (RegQueryValueEx(key, "ImagePath", NULL, &type, buf, &len) == ERROR_SUCCESS) {
+                       if (strcmp(lpszBinaryPathName, buf))
+                               rc = -1;
+               }
+       }
+       RegCloseKey(key);
+       return(rc);
+}
+
+
+DWORD
+svc_running (LPTSTR lpszServiceName)
+{
+       SC_HANDLE service;
+       SC_HANDLE scm;
+       DWORD rc;
+       SERVICE_STATUS ss;
+
+       if (!(scm = OpenSCManager(NULL, NULL, GENERIC_READ)))
+               return(GetLastError());
+
+       rc = 1;
+       service = OpenService(scm, lpszServiceName, SERVICE_QUERY_STATUS);
+       if (service) {
+               if (!QueryServiceStatus(service, &ss))
+                       rc = GetLastError();
+               else if (ss.dwCurrentState != SERVICE_STOPPED)
+                       rc = 0;
+               CloseServiceHandle(service);
+       }
+       CloseServiceHandle(scm);
+       return(rc);
+}
+
 
 static void *start_status_routine( void *ptr )
 {
@@ -298,9 +358,9 @@ void *getRegParam( char *svc, char *value )
        DWORD valLen = sizeof( vValue );
 
        if ( svc != NULL )
-               sprintf ( path, "SOFTWARE\\%s", svc );
+               snprintf ( path, sizeof path, "SOFTWARE\\%s", svc );
        else
-               strcpy (path, "SOFTWARE\\OpenLDAP\\Parameters" );
+               snprintf ( path, sizeof path, "SOFTWARE\\OpenLDAP\\Parameters" );
        
        if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, path, 0, KEY_READ, &hkey ) != ERROR_SUCCESS )
        {