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