]> git.sur5r.net Git - openldap/blob - servers/slapd/nt_svc.c
Further trim_refs_url fixes from Hallvard. Need additional testing.
[openldap] / servers / slapd / nt_svc.c
1 // nt_main.c
2 #include "portable.h"
3 #include <stdio.h>
4
5 #include <ac/string.h>
6
7 #include "slap.h"
8
9 ldap_pvt_thread_cond_t  started_event,          stopped_event;
10 ldap_pvt_thread_t               start_status_tid,       stop_status_tid;
11
12
13 /* in main.c */
14 void WINAPI ServiceMain( DWORD argc, LPTSTR *argv );
15
16 /* in ntservice.c */
17 int srv_install( char* service, char* filename );
18 int srv_remove ( char* service, char* filename );
19
20 int main( DWORD argc, LPTSTR *argv )
21 {
22         int             length;
23         char    filename[MAX_PATH], *fname_start;
24         extern int is_NT_Service;
25
26         SERVICE_TABLE_ENTRY             DispatchTable[] = {
27                 {       SERVICE_NAME,   (LPSERVICE_MAIN_FUNCTION) ServiceMain   },
28                 {       NULL,                   NULL    }
29         };
30
31         /*
32         // set the service's current directory to being the installation directory for the service.
33         // this way we don't have to write absolute paths in the configuration files
34         */
35         GetModuleFileName( NULL, filename, sizeof( filename ) );
36         fname_start = strrchr( filename, *LDAP_DIRSEP );
37         *fname_start = '\0';
38         SetCurrentDirectory( filename );
39
40         if ( argc > 1 ) {
41                 if ( _stricmp( "install", argv[1] ) == 0 ) 
42                 {
43                         char *svcName = SERVICE_NAME;
44                         if ( (argc > 2) && (argv[2] != NULL) )
45                                 svcName = argv[2];
46                         if ( (length = GetModuleFileName(NULL, filename, sizeof( filename ))) == 0 ) 
47                         {
48                                 fputs( "unable to retrieve file name for the service.\n", stderr  );
49                                 return EXIT_FAILURE;
50                         }
51                         if ( !srv_install(svcName, filename) ) 
52                         {
53                                 fputs( "service failed installation ...\n", stderr  );
54                                 return EXIT_FAILURE;
55                         }
56                         fputs( "service has been installed ...\n", stderr  );
57                         return EXIT_SUCCESS;
58                 }
59
60                 if ( _stricmp( "remove", argv[1] ) == 0 ) 
61                 {
62                         char *svcName = SERVICE_NAME;
63                         if ( (argc > 2) && (argv[2] != NULL) )
64                                 svcName = argv[2];
65                         if ( (length = GetModuleFileName(NULL, filename, sizeof( filename ))) == 0 ) 
66                         {
67                                 fputs( "unable to retrieve file name for the service.\n", stderr  );
68                                 return EXIT_FAILURE;
69                         }
70                         if ( !srv_remove(svcName, filename) ) 
71                         {
72                                 fputs( "failed to remove the service ...\n", stderr  );
73                                 return EXIT_FAILURE;
74                         }
75                         fputs( "service has been removed ...\n", stderr );
76                         return EXIT_SUCCESS;
77                 }
78         }
79
80         puts( "starting slapd..." );
81         if ( !StartServiceCtrlDispatcher(DispatchTable) )
82         {
83                 is_NT_Service = 0;
84                 ServiceMain( argc, argv );
85         }
86
87         return EXIT_SUCCESS;
88 }