From patchwork Sun Mar 28 17:23:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Selva Nair X-Patchwork-Id: 1675 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director12.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id UE7mEaVWYWBqTgAAIUCqbw (envelope-from ) for ; Mon, 29 Mar 2021 00:25:09 -0400 Received: from proxy9.mail.iad3b.rsapps.net ([172.31.255.6]) by director12.mail.ord1d.rsapps.net with LMTP id IMfoEaVWYWBZZQAAIasKDg (envelope-from ) for ; Mon, 29 Mar 2021 00:25:09 -0400 Received: from smtp10.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy9.mail.iad3b.rsapps.net with LMTPS id aAOQCaVWYWCRJgAAC4PSzw (envelope-from ) for ; Mon, 29 Mar 2021 00:25:09 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp10.gate.iad3b.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=gmail.com; dmarc=fail (p=none; dis=none) header.from=gmail.com X-Suspicious-Flag: YES X-Classification-ID: be5f2346-9046-11eb-94fb-52540055034d-1-1 Received: from [216.105.38.7] ([216.105.38.7:45116] helo=lists.sourceforge.net) by smtp10.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id CD/5E-26872-4A651606; Mon, 29 Mar 2021 00:25:08 -0400 Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1lQjRV-0000e8-Da; Mon, 29 Mar 2021 04:23:57 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lQjRS-0000dj-SA for openvpn-devel@lists.sourceforge.net; Mon, 29 Mar 2021 04:23:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=f7/hBq/YLMAsy1Y19awWzwZUEVBW2ToLiptYH6hBG5w=; b=iCtbPA0CO6S37D5pvh18WrqCy9 uAcK5dWvgSv0AGi+qBhAYJd0YoX9LVnnwGGM9HwKE8sva8NxnntlbBIdsWHVtDMzK9GgRdn4Aa0+y A9G5yVZOHnpAGfO96d3TPv7NatUA04lDD56CgWbECEQYmU/m/3D0Y/o057O5FNlwEip4=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version: Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=f7/hBq/YLMAsy1Y19awWzwZUEVBW2ToLiptYH6hBG5w=; b=IL4qoNs0s4ZFC74yyI5jKv/QD/ jCWssgZZk2OYa3eCA0i+l8+MpAgJSq3XVrHGS27ii9GVrQ6uqPbwq95YTrzmmfc/UeK808rJPZ3Xa hYWcx44O0BxIrZ4ZexGx3tgELevDaHqkGfD+gmH6jnnbdPoAnv1sEthfOVi7pFJAQs6M=; Received: from mail-qt1-f172.google.com ([209.85.160.172]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92.3) id 1lQjRH-0007YS-3M for openvpn-devel@lists.sourceforge.net; Mon, 29 Mar 2021 04:23:54 +0000 Received: by mail-qt1-f172.google.com with SMTP id h7so8519144qtx.3 for ; Sun, 28 Mar 2021 21:23:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=f7/hBq/YLMAsy1Y19awWzwZUEVBW2ToLiptYH6hBG5w=; b=n5AgpJWlSQ7RRZ3bwv2w+X/TXkozIX3KWQm8oeKAqWP+ov2oQZF9el9x+ewCPajbxd CBuMUeS+Lwg2kVWH0GdK4KGRV3v/o2jWIuBswRz/MKcxDA4XtsudbOu0LoJ5fsHgmWrs /Oq+vjep4cUVdWe48IBwL+pu5u56sN0K/NXXRIoW+Am3dxdhAPoUEQoMnB88ybvtTbu8 A+aYeZBOMGGuTTlkoBMvx5yN2glkZj2SWAViaoM83V1vD2fL9kTBojf/xtmlzeCOMIJU iSvkSj1ywzzqwEUxCppb9cXVgQl3RKSJaz6GyKLhPDVQAVSzITIvO8AlzQ7NBgEa02nA J3kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=f7/hBq/YLMAsy1Y19awWzwZUEVBW2ToLiptYH6hBG5w=; b=g2+ZDR/m8USvMQdl3qxdyufE91cIjqWguI30GF0HqZ1xAPqVf/H0JB+9RZujCCSnlQ MPimQjt//+/Rb56F/tgqtwTIFlff+jb7sZ/4BB/4tBB1S1sSeEZc8p8rKp7ALnmjW0cQ +uVOZMgGc8LTbf0znqeVJtGxkXMrDZUZN8zvluANd2MWV/64yplo/EJxU241a52nisNa vM32+yhfvgXhqD7JCfFuE1afPLFFIr+x5LaMu+HtfrfeiAoB8SBteJhAGIH101Bs2ze2 PXeCkOV0tB8EV/J4b/sy9Z8i4A9bxZ0z7XJzoYHnWqSHdA0L4eE5cY48fsxRN4eLQZLb xIow== X-Gm-Message-State: AOAM530Yy7Wx2NPAlvSJCmUMO1Txnd43Iz8gfraU8Ht221wWEAVbu2kh JjcJqChRSpsdhWV5MtN7C/o4PmlPrcLYqQ== X-Google-Smtp-Source: ABdhPJwDXtoFafTfDTOBY9vTKNM8X8/T0xit2pUWPTUKC/Tkda1cGMd0kPx7jq2zFiY+kYg1YBLqNg== X-Received: by 2002:a05:622a:1486:: with SMTP id t6mr21010097qtx.112.1616991816811; Sun, 28 Mar 2021 21:23:36 -0700 (PDT) Received: from saturn.home.sansel.ca (cpe14cc20d50937-cm788df74daaa0.cpe.net.cable.rogers.com. [173.33.101.123]) by smtp.gmail.com with ESMTPSA id g7sm10340739qti.20.2021.03.28.21.23.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Mar 2021 21:23:36 -0700 (PDT) From: selva.nair@gmail.com To: openvpn-devel@lists.sourceforge.net Date: Mon, 29 Mar 2021 00:23:18 -0400 Message-Id: <1616991798-7179-1-git-send-email-selva.nair@gmail.com> X-Mailer: git-send-email 2.1.4 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (selva.nair[at]gmail.com) -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.160.172 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.160.172 listed in wl.mailspike.net] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-Headers-End: 1lQjRH-0007YS-3M Subject: [Openvpn-devel] [PATCH] Remove automatic service X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Selva Nair This has been replaced by openvpnserv2 since 2.4.0 and we have stopped setting up this service in the installer since 2.5.0. Get rid of the unused code. The mechanics of supporting multiple services with the same executable is retained for possible future use. For backwards compatibility, the command line option -instance is unchanged as "-instance id" although ="interactive" is the only supported value now. Signed-off-by: Selva Nair --- src/openvpnserv/Makefile.am | 1 - src/openvpnserv/automatic.c | 434 -------------------------------------------- src/openvpnserv/service.c | 46 +++-- src/openvpnserv/service.h | 6 - 4 files changed, 21 insertions(+), 466 deletions(-) delete mode 100644 src/openvpnserv/automatic.c diff --git a/src/openvpnserv/Makefile.am b/src/openvpnserv/Makefile.am index 5dc38c9..3e69125 100644 --- a/src/openvpnserv/Makefile.am +++ b/src/openvpnserv/Makefile.am @@ -31,7 +31,6 @@ endif openvpnserv_SOURCES = \ common.c \ - automatic.c \ interactive.c \ service.c service.h \ validate.c validate.h \ diff --git a/src/openvpnserv/automatic.c b/src/openvpnserv/automatic.c deleted file mode 100644 index 0ba222a..0000000 --- a/src/openvpnserv/automatic.c +++ /dev/null @@ -1,434 +0,0 @@ -/* - * OpenVPN -- An application to securely tunnel IP networks - * over a single TCP/UDP port, with support for SSL/TLS-based - * session authentication and key exchange, - * packet encryption, packet authentication, and - * packet compression. - * - * Copyright (C) 2002-2018 OpenVPN Inc - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/* - * This program allows one or more OpenVPN processes to be started - * as a service. To build, you must get the service sample from the - * Platform SDK and replace Simple.c with this file. - * - * You should also apply service.patch to - * service.c and service.h from the Platform SDK service sample. - * - * This code is designed to be built with the mingw compiler. - */ - -#include "service.h" - -#include -#include -#include -#include - -static SERVICE_STATUS_HANDLE service; -static SERVICE_STATUS status = { .dwServiceType = SERVICE_WIN32_SHARE_PROCESS }; - -openvpn_service_t automatic_service = { - automatic, - TEXT(PACKAGE_NAME "ServiceLegacy"), - TEXT(PACKAGE_NAME " Legacy Service"), - TEXT(SERVICE_DEPENDENCIES), - SERVICE_DEMAND_START -}; - -struct security_attributes -{ - SECURITY_ATTRIBUTES sa; - SECURITY_DESCRIPTOR sd; -}; - -static HANDLE exit_event = NULL; - -/* clear an object */ -#define CLEAR(x) memset(&(x), 0, sizeof(x)) - - -bool -init_security_attributes_allow_all(struct security_attributes *obj) -{ - CLEAR(*obj); - - obj->sa.nLength = sizeof(SECURITY_ATTRIBUTES); - obj->sa.lpSecurityDescriptor = &obj->sd; - obj->sa.bInheritHandle = TRUE; - if (!InitializeSecurityDescriptor(&obj->sd, SECURITY_DESCRIPTOR_REVISION)) - { - return false; - } - if (!SetSecurityDescriptorDacl(&obj->sd, TRUE, NULL, FALSE)) - { - return false; - } - return true; -} - -HANDLE -create_event(LPCTSTR name, bool allow_all, bool initial_state, bool manual_reset) -{ - if (allow_all) - { - struct security_attributes sa; - if (!init_security_attributes_allow_all(&sa)) - { - return NULL; - } - return CreateEvent(&sa.sa, (BOOL)manual_reset, (BOOL)initial_state, name); - } - else - { - return CreateEvent(NULL, (BOOL)manual_reset, (BOOL)initial_state, name); - } -} - -void -close_if_open(HANDLE h) -{ - if (h != NULL) - { - CloseHandle(h); - } -} - -static bool -match(const WIN32_FIND_DATA *find, LPCTSTR ext) -{ - if (find->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - { - return false; - } - - if (*ext == TEXT('\0')) - { - return true; - } - - /* find the pointer to that last '.' in filename and match ext against the rest */ - - const TCHAR *p = _tcsrchr(find->cFileName, TEXT('.')); - return p && p != find->cFileName && _tcsicmp(p + 1, ext) == 0; -} - -/* - * Modify the extension on a filename. - */ -static bool -modext(LPTSTR dest, size_t size, LPCTSTR src, LPCTSTR newext) -{ - size_t i; - - if (size > 0 && (_tcslen(src) + 1) <= size) - { - _tcscpy_s(dest, size, src); - dest [size - 1] = TEXT('\0'); - i = _tcslen(dest); - while (i-- > 0) - { - if (dest[i] == TEXT('\\')) - { - break; - } - if (dest[i] == TEXT('.')) - { - dest[i] = TEXT('\0'); - break; - } - } - if (_tcslen(dest) + _tcslen(newext) + 2 <= size) - { - _tcscat_s(dest, size, TEXT(".")); - _tcscat_s(dest, size, newext); - return true; - } - dest[0] = TEXT('\0'); - } - return false; -} - -static DWORD WINAPI -ServiceCtrlAutomatic(DWORD ctrl_code, DWORD event, LPVOID data, LPVOID ctx) -{ - SERVICE_STATUS *status = ctx; - switch (ctrl_code) - { - case SERVICE_CONTROL_STOP: - status->dwCurrentState = SERVICE_STOP_PENDING; - ReportStatusToSCMgr(service, status); - if (exit_event) - { - SetEvent(exit_event); - } - return NO_ERROR; - - case SERVICE_CONTROL_INTERROGATE: - return NO_ERROR; - - default: - return ERROR_CALL_NOT_IMPLEMENTED; - } -} - - -VOID WINAPI -ServiceStartAutomaticOwn(DWORD dwArgc, LPTSTR *lpszArgv) -{ - status.dwServiceType = SERVICE_WIN32_OWN_PROCESS; - ServiceStartAutomatic(dwArgc, lpszArgv); -} - - -VOID WINAPI -ServiceStartAutomatic(DWORD dwArgc, LPTSTR *lpszArgv) -{ - DWORD error = NO_ERROR; - settings_t settings; - TCHAR event_name[256]; - - service = RegisterServiceCtrlHandlerEx(automatic_service.name, ServiceCtrlAutomatic, &status); - if (!service) - { - return; - } - - status.dwCurrentState = SERVICE_START_PENDING; - status.dwServiceSpecificExitCode = NO_ERROR; - status.dwWin32ExitCode = NO_ERROR; - status.dwWaitHint = 3000; - - if (!ReportStatusToSCMgr(service, &status)) - { - MsgToEventLog(M_ERR, TEXT("ReportStatusToSCMgr #1 failed")); - goto finish; - } - - /* - * Create our exit event - * This event is initially created in the non-signaled - * state. It will transition to the signaled state when - * we have received a terminate signal from the Service - * Control Manager which will cause an asynchronous call - * of ServiceStop below. - */ - - openvpn_sntprintf(event_name, _countof(event_name), TEXT(PACKAGE "%s_exit_1"), service_instance); - exit_event = create_event(event_name, false, false, true); - if (!exit_event) - { - MsgToEventLog(M_ERR, TEXT("CreateEvent failed")); - goto finish; - } - - /* - * If exit event is already signaled, it means we were not - * shut down properly. - */ - if (WaitForSingleObject(exit_event, 0) != WAIT_TIMEOUT) - { - MsgToEventLog(M_ERR, TEXT("Exit event is already signaled -- we were not shut down properly")); - goto finish; - } - - if (!ReportStatusToSCMgr(service, &status)) - { - MsgToEventLog(M_ERR, TEXT("ReportStatusToSCMgr #2 failed")); - goto finish; - } - - /* - * Read info from registry in key HKLM\SOFTWARE\OpenVPN - */ - error = GetOpenvpnSettings(&settings); - if (error != ERROR_SUCCESS) - { - goto finish; - } - - /* - * Instantiate an OpenVPN process for each configuration - * file found. - */ - { - WIN32_FIND_DATA find_obj; - HANDLE find_handle; - BOOL more_files; - TCHAR find_string[MAX_PATH]; - - openvpn_sntprintf(find_string, _countof(find_string), TEXT("%s\\*"), settings.config_dir); - - find_handle = FindFirstFile(find_string, &find_obj); - if (find_handle == INVALID_HANDLE_VALUE) - { - MsgToEventLog(M_ERR, TEXT("Cannot get configuration file list using: %s"), find_string); - goto finish; - } - - /* - * Loop over each config file - */ - do - { - HANDLE log_handle = NULL; - STARTUPINFO start_info; - PROCESS_INFORMATION proc_info; - struct security_attributes sa; - TCHAR log_file[MAX_PATH]; - TCHAR log_path[MAX_PATH]; - TCHAR command_line[256]; - - CLEAR(start_info); - CLEAR(proc_info); - CLEAR(sa); - - if (!ReportStatusToSCMgr(service, &status)) - { - MsgToEventLog(M_ERR, TEXT("ReportStatusToSCMgr #3 failed")); - FindClose(find_handle); - goto finish; - } - - /* does file have the correct type and extension? */ - if (match(&find_obj, settings.ext_string)) - { - /* get log file pathname */ - if (!modext(log_file, _countof(log_file), find_obj.cFileName, TEXT("log"))) - { - MsgToEventLog(M_ERR, TEXT("Cannot construct logfile name based on: %s"), find_obj.cFileName); - FindClose(find_handle); - goto finish; - } - openvpn_sntprintf(log_path, _countof(log_path), - TEXT("%s\\%s"), settings.log_dir, log_file); - - /* construct command line */ - openvpn_sntprintf(command_line, _countof(command_line), TEXT("openvpn --service \"" PACKAGE "%s_exit_1\" 1 --config \"%s\""), - service_instance, - find_obj.cFileName); - - /* Make security attributes struct for logfile handle so it can - * be inherited. */ - if (!init_security_attributes_allow_all(&sa)) - { - error = MsgToEventLog(M_SYSERR, TEXT("InitializeSecurityDescriptor start_" PACKAGE " failed")); - goto finish; - } - - /* open logfile as stdout/stderr for soon-to-be-spawned subprocess */ - log_handle = CreateFile(log_path, - GENERIC_WRITE, - FILE_SHARE_READ, - &sa.sa, - settings.append ? OPEN_ALWAYS : CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (log_handle == INVALID_HANDLE_VALUE) - { - error = MsgToEventLog(M_SYSERR, TEXT("Cannot open logfile: %s"), log_path); - FindClose(find_handle); - goto finish; - } - - /* append to logfile? */ - if (settings.append) - { - if (SetFilePointer(log_handle, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER) - { - error = MsgToEventLog(M_SYSERR, TEXT("Cannot seek to end of logfile: %s"), log_path); - FindClose(find_handle); - goto finish; - } - } - - /* fill in STARTUPINFO struct */ - GetStartupInfo(&start_info); - start_info.cb = sizeof(start_info); - start_info.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW; - start_info.wShowWindow = SW_HIDE; - start_info.hStdInput = GetStdHandle(STD_INPUT_HANDLE); - start_info.hStdOutput = start_info.hStdError = log_handle; - - /* create an OpenVPN process for one config file */ - if (!CreateProcess(settings.exe_path, - command_line, - NULL, - NULL, - TRUE, - settings.priority | CREATE_NEW_CONSOLE, - NULL, - settings.config_dir, - &start_info, - &proc_info)) - { - error = MsgToEventLog(M_SYSERR, TEXT("CreateProcess failed, exe='%s' cmdline='%s' dir='%s'"), - settings.exe_path, - command_line, - settings.config_dir); - - FindClose(find_handle); - CloseHandle(log_handle); - goto finish; - } - - /* close unneeded handles */ - Sleep(1000); /* try to prevent race if we close logfile - * handle before child process DUPs it */ - if (!CloseHandle(proc_info.hProcess) - || !CloseHandle(proc_info.hThread) - || !CloseHandle(log_handle)) - { - error = MsgToEventLog(M_SYSERR, TEXT("CloseHandle failed")); - goto finish; - } - } - - /* more files to process? */ - more_files = FindNextFile(find_handle, &find_obj); - - } while (more_files); - - FindClose(find_handle); - } - - /* we are now fully started */ - status.dwCurrentState = SERVICE_RUNNING; - status.dwWaitHint = 0; - if (!ReportStatusToSCMgr(service, &status)) - { - MsgToEventLog(M_ERR, TEXT("ReportStatusToSCMgr SERVICE_RUNNING failed")); - goto finish; - } - - /* wait for our shutdown signal */ - if (WaitForSingleObject(exit_event, INFINITE) != WAIT_OBJECT_0) - { - MsgToEventLog(M_ERR, TEXT("wait for shutdown signal failed")); - } - -finish: - if (exit_event) - { - CloseHandle(exit_event); - } - - status.dwCurrentState = SERVICE_STOPPED; - status.dwWin32ExitCode = error; - ReportStatusToSCMgr(service, &status); -} diff --git a/src/openvpnserv/service.c b/src/openvpnserv/service.c index 8101f83..9566f99 100644 --- a/src/openvpnserv/service.c +++ b/src/openvpnserv/service.c @@ -224,21 +224,14 @@ int _tmain(int argc, TCHAR *argv[]) { /* - * Automatic + Interactive service (as a SERVICE_WIN32_SHARE_PROCESS) + * Interactive service (as a SERVICE_WIN32_SHARE_PROCESS) * This is the default. */ const SERVICE_TABLE_ENTRY dispatchTable_shared[] = { - { automatic_service.name, ServiceStartAutomatic }, { interactive_service.name, ServiceStartInteractive }, { NULL, NULL } }; - /* Automatic service only (as a SERVICE_WIN32_OWN_PROCESS) */ - const SERVICE_TABLE_ENTRY dispatchTable_automatic[] = { - { TEXT(""), ServiceStartAutomaticOwn }, - { NULL, NULL } - }; - /* Interactive service only (as a SERVICE_WIN32_OWN_PROCESS) */ const SERVICE_TABLE_ENTRY dispatchTable_interactive[] = { { TEXT(""), ServiceStartInteractiveOwn }, @@ -247,8 +240,7 @@ _tmain(int argc, TCHAR *argv[]) const SERVICE_TABLE_ENTRY *dispatchTable = dispatchTable_shared; - openvpn_service[0] = automatic_service; - openvpn_service[1] = interactive_service; + openvpn_service[interactive] = interactive_service; for (int i = 1; i < argc; i++) { @@ -264,29 +256,33 @@ _tmain(int argc, TCHAR *argv[]) } else if (_tcsicmp(TEXT("start"), argv[i] + 1) == 0) { - BOOL is_auto = argc < i + 2 || _tcsicmp(TEXT("interactive"), argv[i + 1]) != 0; - return CmdStartService(is_auto ? automatic : interactive); + return CmdStartService(interactive); } else if (argc > i + 2 && _tcsicmp(TEXT("instance"), argv[i] + 1) == 0) { - dispatchTable = _tcsicmp(TEXT("interactive"), argv[i + 1]) != 0 ? - dispatchTable_automatic : - dispatchTable_interactive; - - service_instance = argv[i + 2]; - i += 2; + if (_tcsicmp(TEXT("interactive"), argv[i+1]) == 0) + { + dispatchTable = dispatchTable_interactive; + service_instance = argv[i + 2]; + i += 2; + } + else + { + MsgToEventLog(M_ERR, L"Invalid argument to -instance <%s>. Service not started.", argv[i+1]); + return 1; + } } else { - _tprintf(TEXT("%s -install to install the services\n"), APPNAME); - _tprintf(TEXT("%s -start to start a service (\"automatic\" or \"interactive\")\n"), APPNAME); - _tprintf(TEXT("%s -remove to remove the services\n"), APPNAME); + _tprintf(TEXT("%s -install to install the interactive service\n"), APPNAME); + _tprintf(TEXT("%s -start [name] to start the service (name = \"interactive\" is optional)\n"), APPNAME); + _tprintf(TEXT("%s -remove to remove the service\n"), APPNAME); _tprintf(TEXT("\nService run-time parameters:\n")); - _tprintf(TEXT("-instance \n") - TEXT(" Runs the service as an alternate instance. can be \"automatic\" or\n") - TEXT(" \"interactive\". The service settings will be loaded from\n") - TEXT(" HKLM\\Software\\" PACKAGE_NAME " registry key, and the interactive service will accept\n") + _tprintf(TEXT("-instance interactive \n") + TEXT(" Runs the service as an alternate instance.\n") + TEXT(" The service settings will be loaded from\n") + TEXT(" HKLM\\Software\\" PACKAGE_NAME " registry key, and the service will accept\n") TEXT(" requests on \\\\.\\pipe\\" PACKAGE "\\service named pipe.\n")); return 0; diff --git a/src/openvpnserv/service.h b/src/openvpnserv/service.h index f5afe2f..32a721f 100644 --- a/src/openvpnserv/service.h +++ b/src/openvpnserv/service.h @@ -48,7 +48,6 @@ #define M_ERR (MSG_FLAGS_ERROR) /* error */ typedef enum { - automatic, interactive, _service_max } openvpn_service_type; @@ -72,14 +71,9 @@ typedef struct { BOOL append; } settings_t; -extern openvpn_service_t automatic_service; extern openvpn_service_t interactive_service; extern LPCTSTR service_instance; -VOID WINAPI ServiceStartAutomaticOwn(DWORD argc, LPTSTR *argv); - -VOID WINAPI ServiceStartAutomatic(DWORD argc, LPTSTR *argv); - VOID WINAPI ServiceStartInteractiveOwn(DWORD argc, LPTSTR *argv); VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv);