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