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