]> git.sur5r.net Git - openldap/blob - servers/slapd/nt_svc.c
5c2a07deb4b23595018e32780906f3a3a4980b17
[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 ldap_pvt_thread_cond_t  started_event,          stopped_event;
24 ldap_pvt_thread_t               start_status_tid,       stop_status_tid;
25
26
27 // in main.c
28 void WINAPI ServiceMain( DWORD argc, LPTSTR *argv );
29
30
31 // in wsa_err.c
32 char *WSAGetLastErrorString( void );
33
34 // in nt_err.c
35 char *GetLastErrorString( void );
36
37 // in ntservice.c
38 int srv_install( char* service, char* filename );
39 int srv_remove ( char* service, char* filename );
40
41 void main( DWORD argc, LPTSTR *argv )
42 {
43         int             length;
44         char    filename[MAX_PATH], *fname_start;
45         extern int is_NT_Service;
46
47         SERVICE_TABLE_ENTRY             DispatchTable[] = {
48                 {       SERVICE_NAME,   (LPSERVICE_MAIN_FUNCTION) ServiceMain   },
49                 {       NULL,                   NULL    }
50         };
51
52         // set the service's current directory to being the installation directory for the service.
53         // this way we don't have to write absolute paths in the configuration files
54         GetModuleFileName( NULL, filename, sizeof( filename ) );
55         fname_start = strrchr( filename, *LDAP_DIRSEP );
56         *fname_start = '\0';
57         SetCurrentDirectory( filename );
58
59         if ( argc > 1 ) {
60                 if ( _stricmp( "install", 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;
69                         }
70                         if ( !srv_install(svcName, filename) ) 
71                         {
72                                 fputs( "service failed installation ...\n", stderr  );
73                                 return;
74                         }
75                         fputs( "service has been installed ...\n", stderr  );
76                         return;
77                 }
78
79                 if ( _stricmp( "remove", argv[1] ) == 0 ) 
80                 {
81                         char *svcName = SERVICE_NAME;
82                         if ( (argc > 2) && (argv[2] != NULL) )
83                                 svcName = argv[2];
84                         if ( (length = GetModuleFileName(NULL, filename, sizeof( filename ))) == 0 ) 
85                         {
86                                 fputs( "unable to retrieve file name for the service.\n", stderr  );
87                                 return;
88                         }
89                         if ( !srv_remove(svcName, filename) ) 
90                         {
91                                 fputs( "failed to remove the service ...\n", stderr  );
92                                 return;
93                         }
94                         fputs( "service has been removed ...\n", stderr );
95                         return;
96                 }
97         }
98
99         puts( "starting slapd..." );
100         if ( !StartServiceCtrlDispatcher(DispatchTable) )
101         {
102                 is_NT_Service = 0;
103                 ServiceMain( argc, argv );
104         }
105 }