]> git.sur5r.net Git - openldap/blob - servers/slapd/nt_svc.c
Add ldap_*2name() in <include,libldap>/schema, use them in slapd/schema
[openldap] / servers / slapd / nt_svc.c
1 // nt_main.c
2 #include "portable.h"
3 #include <stdio.h>
4
5 #include <ac/string.h>
6
7 #include "ldap_defaults.h"
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 int main( DWORD argc, LPTSTR *argv )
22 {
23         int             length;
24         char    filename[MAX_PATH], *fname_start;
25         extern int is_NT_Service;
26
27         SERVICE_TABLE_ENTRY             DispatchTable[] = {
28                 {       SERVICE_NAME,   (LPSERVICE_MAIN_FUNCTION) ServiceMain   },
29                 {       NULL,                   NULL    }
30         };
31
32         /*
33         // set the service's current directory to being the installation directory for the service.
34         // this way we don't have to write absolute paths in the configuration files
35         */
36         GetModuleFileName( NULL, filename, sizeof( filename ) );
37         fname_start = strrchr( filename, *LDAP_DIRSEP );
38         *fname_start = '\0';
39         SetCurrentDirectory( filename );
40
41         if ( argc > 1 ) {
42                 if ( _stricmp( "install", argv[1] ) == 0 ) 
43                 {
44                         char *svcName = SERVICE_NAME;
45                         if ( (argc > 2) && (argv[2] != NULL) )
46                                 svcName = argv[2];
47                         if ( (length = GetModuleFileName(NULL, filename, sizeof( filename ))) == 0 ) 
48                         {
49                                 fputs( "unable to retrieve file name for the service.\n", stderr  );
50                                 return EXIT_FAILURE;
51                         }
52                         if ( !srv_install(svcName, filename) ) 
53                         {
54                                 fputs( "service failed installation ...\n", stderr  );
55                                 return EXIT_FAILURE;
56                         }
57                         fputs( "service has been installed ...\n", stderr  );
58                         return EXIT_SUCCESS;
59                 }
60
61                 if ( _stricmp( "remove", argv[1] ) == 0 ) 
62                 {
63                         char *svcName = SERVICE_NAME;
64                         if ( (argc > 2) && (argv[2] != NULL) )
65                                 svcName = argv[2];
66                         if ( (length = GetModuleFileName(NULL, filename, sizeof( filename ))) == 0 ) 
67                         {
68                                 fputs( "unable to retrieve file name for the service.\n", stderr  );
69                                 return EXIT_FAILURE;
70                         }
71                         if ( !srv_remove(svcName, filename) ) 
72                         {
73                                 fputs( "failed to remove the service ...\n", stderr  );
74                                 return EXIT_FAILURE;
75                         }
76                         fputs( "service has been removed ...\n", stderr );
77                         return EXIT_SUCCESS;
78                 }
79         }
80
81         puts( "starting slapd..." );
82         if ( !StartServiceCtrlDispatcher(DispatchTable) )
83         {
84                 is_NT_Service = 0;
85                 ServiceMain( argc, argv );
86         }
87
88         return EXIT_SUCCESS;
89 }