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