3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #ifdef HAVE_NT_SERVICE_MANAGER
15 void WINAPI ServiceMain( DWORD argc, LPTSTR *argv );
18 int srv_install( char* service, char * displayName, char* filename,
20 int srv_remove ( char* service, char* filename );
21 DWORD svc_installed (LPTSTR lpszServiceName, LPTSTR lpszBinaryPathName);
22 DWORD svc_running (LPTSTR lpszServiceName);
24 int main( int argc, LPTSTR *argv )
27 char filename[MAX_PATH], *fname_start;
28 extern int is_NT_Service;
31 * Because the service was registered as SERVICE_WIN32_OWN_PROCESS,
32 * the lpServiceName element of the SERVICE_TABLE_ENTRY will be
33 * ignored. Since we don't even know the name of the service at
34 * this point (since it could have been installed under a name
35 * different than SERVICE_NAME), we might as well just provide
36 * the parameter as "".
39 SERVICE_TABLE_ENTRY DispatchTable[] = {
40 { "", (LPSERVICE_MAIN_FUNCTION) ServiceMain },
45 // set the service's current directory to being the installation directory for the service.
46 // this way we don't have to write absolute paths in the configuration files
48 GetModuleFileName( NULL, filename, sizeof( filename ) );
49 fname_start = strrchr( filename, *LDAP_DIRSEP );
51 SetCurrentDirectory( filename );
54 if ( _stricmp( "install", argv[1] ) == 0 )
56 char *svcName = SERVICE_NAME;
57 char *displayName = "OpenLDAP Directory Service";
58 BOOL auto_start = FALSE;
60 if ( (argc > 2) && (argv[2] != NULL) )
63 if ( argc > 3 && argv[3])
64 displayName = argv[3];
66 if ( argc > 4 && stricmp(argv[4], "auto") == 0)
69 if ( (length = GetModuleFileName(NULL, filename, sizeof( filename ))) == 0 )
71 fputs( "unable to retrieve file name for the service.\n", stderr );
74 if ( !srv_install(svcName, displayName, filename, auto_start) )
76 fputs( "service failed installation ...\n", stderr );
79 fputs( "service has been installed ...\n", stderr );
83 if ( _stricmp( "remove", argv[1] ) == 0 )
85 char *svcName = SERVICE_NAME;
86 if ( (argc > 2) && (argv[2] != NULL) )
88 if ( (length = GetModuleFileName(NULL, filename, sizeof( filename ))) == 0 )
90 fputs( "unable to retrieve file name for the service.\n", stderr );
93 if ( !srv_remove(svcName, filename) )
95 fputs( "failed to remove the service ...\n", stderr );
98 fputs( "service has been removed ...\n", stderr );
103 puts( "starting slapd..." );
104 if (svc_installed(SERVICE_NAME, NULL) != 0
105 || svc_running(SERVICE_NAME) == 1
106 || StartServiceCtrlDispatcher(DispatchTable) != 0 )
109 ServiceMain( argc, argv );