Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / nt_svc.c
blob2c15c50563dcf1bb931c5574564b0a799e887683
1 /* $OpenLDAP: pkg/ldap/servers/slapd/nt_svc.c,v 1.27.2.3 2008/02/11 23:26:44 kurt Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2008 The OpenLDAP Foundation.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
9 * Public License.
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
16 #include "portable.h"
17 #include <stdio.h>
18 #include <ac/string.h>
19 #include "slap.h"
20 #include "lutil.h"
22 #ifdef HAVE_NT_SERVICE_MANAGER
24 /* in main.c */
25 void WINAPI ServiceMain( DWORD argc, LPTSTR *argv );
27 /* in ntservice.c */
28 int main( int argc, LPTSTR *argv )
30 int length;
31 char filename[MAX_PATH], *fname_start;
34 * Because the service was registered as SERVICE_WIN32_OWN_PROCESS,
35 * the lpServiceName element of the SERVICE_TABLE_ENTRY will be
36 * ignored.
39 SERVICE_TABLE_ENTRY DispatchTable[] = {
40 { "", (LPSERVICE_MAIN_FUNCTION) ServiceMain },
41 { NULL, NULL }
45 * set the service's current directory to the installation directory
46 * for the service. this way we don't have to write absolute paths
47 * in the configuration files
49 GetModuleFileName( NULL, filename, sizeof( filename ) );
50 fname_start = strrchr( filename, *LDAP_DIRSEP );
52 if ( argc > 1 ) {
53 if ( _stricmp( "install", argv[1] ) == 0 )
55 char *svcName = SERVICE_NAME;
56 char *displayName = "OpenLDAP Directory Service";
57 BOOL auto_start = FALSE;
59 if ( (argc > 2) && (argv[2] != NULL) )
60 svcName = argv[2];
62 if ( argc > 3 && argv[3])
63 displayName = argv[3];
65 if ( argc > 4 && stricmp(argv[4], "auto") == 0)
66 auto_start = TRUE;
68 strcat(filename, " service");
69 if ( !lutil_srv_install(svcName, displayName, filename, auto_start) )
71 fputs( "service failed installation ...\n", stderr );
72 return EXIT_FAILURE;
74 fputs( "service has been installed ...\n", stderr );
75 return EXIT_SUCCESS;
78 if ( _stricmp( "remove", argv[1] ) == 0 )
80 char *svcName = SERVICE_NAME;
81 if ( (argc > 2) && (argv[2] != NULL) )
82 svcName = argv[2];
83 if ( !lutil_srv_remove(svcName, filename) )
85 fputs( "failed to remove the service ...\n", stderr );
86 return EXIT_FAILURE;
88 fputs( "service has been removed ...\n", stderr );
89 return EXIT_SUCCESS;
91 if ( _stricmp( "service", argv[1] ) == 0 )
93 is_NT_Service = 1;
94 *fname_start = '\0';
95 SetCurrentDirectory( filename );
99 if (is_NT_Service)
101 StartServiceCtrlDispatcher(DispatchTable);
102 } else
104 ServiceMain( argc, argv );
107 return EXIT_SUCCESS;
110 #endif