]> git.sur5r.net Git - openldap/blob - servers/slapd/nt_svc.c
19d385c95cceec4f121d727561b428b196c40750
[openldap] / servers / slapd / nt_svc.c
1 /* $OpenLDAP$ */
2
3 #include "portable.h"
4
5 #include <ldap.h>
6
7 static void stubs()
8 {
9     ldap_add_s(NULL, NULL, NULL);
10     ldap_bind_s(NULL, NULL, NULL, 0);
11     ldap_delete_s(NULL, NULL);
12     ldap_first_attribute(NULL, NULL, NULL);
13     ldap_first_entry(NULL, NULL);
14     ldap_get_dn(NULL, NULL);
15     ldap_get_option(NULL, 0, NULL);
16     ldap_get_values_len(NULL, NULL, NULL);
17     ldap_init(NULL, 0);
18     ldap_modify_s(NULL, NULL, NULL);
19     ldap_modrdn_s(NULL, NULL, NULL);
20     ldap_msgfree(NULL);
21     ldap_next_attribute(NULL, NULL, NULL);
22     ldap_result(NULL, 0, 0, NULL, NULL);
23     ldap_search(NULL, NULL, 0, NULL, NULL, 0);
24     ldap_unbind(NULL);
25 }
26
27 #ifdef HAVE_NT_SERVICE_MANAGER
28
29 #include <stdio.h>
30 #include <ac/string.h>
31
32 #include "slap.h"
33
34 ldap_pvt_thread_cond_t  started_event,          stopped_event;
35 ldap_pvt_thread_t               start_status_tid,       stop_status_tid;
36
37
38 /* in main.c */
39 void WINAPI ServiceMain( DWORD argc, LPTSTR *argv );
40
41 /* in ntservice.c */
42 int srv_install( char* service, char* filename );
43 int srv_remove ( char* service, char* filename );
44
45 int main( int argc, LPTSTR *argv )
46 {
47         int             length;
48         char    filename[MAX_PATH], *fname_start;
49         extern int is_NT_Service;
50
51         SERVICE_TABLE_ENTRY             DispatchTable[] = {
52                 {       SERVICE_NAME,   (LPSERVICE_MAIN_FUNCTION) ServiceMain   },
53                 {       NULL,                   NULL    }
54         };
55
56         /*
57         // set the service's current directory to being the installation directory for the service.
58         // this way we don't have to write absolute paths in the configuration files
59         */
60         GetModuleFileName( NULL, filename, sizeof( filename ) );
61         fname_start = strrchr( filename, *LDAP_DIRSEP );
62         *fname_start = '\0';
63         SetCurrentDirectory( filename );
64
65         if ( argc > 1 ) {
66                 if ( _stricmp( "install", argv[1] ) == 0 ) 
67                 {
68                         char *svcName = SERVICE_NAME;
69                         if ( (argc > 2) && (argv[2] != NULL) )
70                                 svcName = argv[2];
71                         if ( (length = GetModuleFileName(NULL, filename, sizeof( filename ))) == 0 ) 
72                         {
73                                 fputs( "unable to retrieve file name for the service.\n", stderr  );
74                                 return EXIT_FAILURE;
75                         }
76                         if ( !srv_install(svcName, filename) ) 
77                         {
78                                 fputs( "service failed installation ...\n", stderr  );
79                                 return EXIT_FAILURE;
80                         }
81                         fputs( "service has been installed ...\n", stderr  );
82                         return EXIT_SUCCESS;
83                 }
84
85                 if ( _stricmp( "remove", argv[1] ) == 0 ) 
86                 {
87                         char *svcName = SERVICE_NAME;
88                         if ( (argc > 2) && (argv[2] != NULL) )
89                                 svcName = argv[2];
90                         if ( (length = GetModuleFileName(NULL, filename, sizeof( filename ))) == 0 ) 
91                         {
92                                 fputs( "unable to retrieve file name for the service.\n", stderr  );
93                                 return EXIT_FAILURE;
94                         }
95                         if ( !srv_remove(svcName, filename) ) 
96                         {
97                                 fputs( "failed to remove the service ...\n", stderr  );
98                                 return EXIT_FAILURE;
99                         }
100                         fputs( "service has been removed ...\n", stderr );
101                         return EXIT_SUCCESS;
102                 }
103         }
104
105         puts( "starting slapd..." );
106         if ( !StartServiceCtrlDispatcher(DispatchTable) )
107         {
108                 is_NT_Service = 0;
109                 ServiceMain( argc, argv );
110         }
111
112         return EXIT_SUCCESS;
113 }
114
115 #endif