3 * Copyright 1998-1999 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 );
22 int main( int argc, LPTSTR *argv )
25 char filename[MAX_PATH], *fname_start;
26 extern int is_NT_Service;
29 * Because the service was registered as SERVICE_WIN32_OWN_PROCESS,
30 * the lpServiceName element of the SERVICE_TABLE_ENTRY will be
31 * ignored. Since we don't even know the name of the service at
32 * this point (since it could have been installed under a name
33 * different than SERVICE_NAME), we might as well just provide
34 * the parameter as "".
37 SERVICE_TABLE_ENTRY DispatchTable[] = {
38 { "", (LPSERVICE_MAIN_FUNCTION) ServiceMain },
43 // set the service's current directory to being the installation directory for the service.
44 // this way we don't have to write absolute paths in the configuration files
46 GetModuleFileName( NULL, filename, sizeof( filename ) );
47 fname_start = strrchr( filename, *LDAP_DIRSEP );
49 SetCurrentDirectory( filename );
52 if ( _stricmp( "install", argv[1] ) == 0 )
54 char *svcName = SERVICE_NAME;
55 char *displayName = "OpenLDAP Directory Service";
56 BOOL auto_start = FALSE;
58 if ( (argc > 2) && (argv[2] != NULL) )
61 if ( argc > 3 && argv[3])
62 displayName = argv[3];
64 if ( argc > 4 && stricmp(argv[4], "auto") == 0)
67 if ( (length = GetModuleFileName(NULL, filename, sizeof( filename ))) == 0 )
69 fputs( "unable to retrieve file name for the service.\n", stderr );
72 if ( !srv_install(svcName, displayName, filename, auto_start) )
74 fputs( "service failed installation ...\n", stderr );
77 fputs( "service has been installed ...\n", stderr );
81 if ( _stricmp( "remove", argv[1] ) == 0 )
83 char *svcName = SERVICE_NAME;
84 if ( (argc > 2) && (argv[2] != NULL) )
86 if ( (length = GetModuleFileName(NULL, filename, sizeof( filename ))) == 0 )
88 fputs( "unable to retrieve file name for the service.\n", stderr );
91 if ( !srv_remove(svcName, filename) )
93 fputs( "failed to remove the service ...\n", stderr );
96 fputs( "service has been removed ...\n", stderr );
101 puts( "starting slapd..." );
102 if ( !StartServiceCtrlDispatcher(DispatchTable) )
105 ServiceMain( argc, argv );