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