2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2014 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
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>.
18 #include <ac/string.h>
22 #ifdef HAVE_NT_SERVICE_MANAGER
25 void WINAPI ServiceMain( DWORD argc, LPTSTR *argv );
28 int main( int argc, LPTSTR *argv )
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
39 SERVICE_TABLE_ENTRY DispatchTable[] = {
40 { "", (LPSERVICE_MAIN_FUNCTION) ServiceMain },
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 );
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) )
62 if ( argc > 3 && argv[3])
63 displayName = argv[3];
65 if ( argc > 4 && stricmp(argv[4], "auto") == 0)
68 strcat(filename, " service");
69 if ( !lutil_srv_install(svcName, displayName, filename, auto_start) )
71 fputs( "service failed installation ...\n", stderr );
74 fputs( "service has been installed ...\n", stderr );
78 if ( _stricmp( "remove", argv[1] ) == 0 )
80 char *svcName = SERVICE_NAME;
81 if ( (argc > 2) && (argv[2] != NULL) )
83 if ( !lutil_srv_remove(svcName, filename) )
85 fputs( "failed to remove the service ...\n", stderr );
88 fputs( "service has been removed ...\n", stderr );
91 if ( _stricmp( "service", argv[1] ) == 0 )
95 SetCurrentDirectory( filename );
101 StartServiceCtrlDispatcher(DispatchTable);
104 ServiceMain( argc, argv );