OpenVPN
service.h
Go to the documentation of this file.
1 /*
2  * OpenVPN -- An application to securely tunnel IP networks
3  * over a single TCP/UDP port, with support for SSL/TLS-based
4  * session authentication and key exchange,
5  * packet encryption, packet authentication, and
6  * packet compression.
7  *
8  * Copyright (C) 2013-2017 Heiko Hund <heiko.hund@sophos.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2
12  * as published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #ifndef _SERVICE_H
25 #define _SERVICE_H
26 
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #elif defined(_MSC_VER)
30 #include "config-msvc.h"
31 #endif
32 
33 #include <windows.h>
34 #include <stdlib.h>
35 #include <tchar.h>
36 
37 #define APPNAME TEXT(PACKAGE "serv")
38 #define SERVICE_DEPENDENCIES TAP_WIN_COMPONENT_ID "\0Dhcp\0\0"
39 
40 /*
41  * Message handling
42  */
43 #define MSG_FLAGS_ERROR (1<<0)
44 #define MSG_FLAGS_SYS_CODE (1<<1)
45 #define M_INFO (0) /* informational */
46 #define M_SYSERR (MSG_FLAGS_ERROR|MSG_FLAGS_SYS_CODE) /* error + system code */
47 #define M_ERR (MSG_FLAGS_ERROR) /* error */
48 
49 typedef enum {
54 
55 typedef struct {
57  TCHAR *name;
58  TCHAR *display_name;
59  TCHAR *dependencies;
60  DWORD start_type;
62 
63 #define MAX_NAME 256
64 typedef struct {
65  TCHAR exe_path[MAX_PATH];
66  TCHAR config_dir[MAX_PATH];
67  TCHAR ext_string[16];
68  TCHAR log_dir[MAX_PATH];
69  TCHAR ovpn_admin_group[MAX_NAME];
70  DWORD priority;
71  BOOL append;
72 } settings_t;
73 
76 
77 
78 VOID WINAPI ServiceStartAutomatic(DWORD argc, LPTSTR *argv);
79 
80 VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv);
81 
82 int openvpn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist);
83 
84 int openvpn_sntprintf(LPTSTR str, size_t size, LPCTSTR format, ...);
85 
87 
88 BOOL ReportStatusToSCMgr(SERVICE_STATUS_HANDLE service, SERVICE_STATUS *status);
89 
90 LPCTSTR GetLastErrorText();
91 
92 DWORD MsgToEventLog(DWORD flags, LPCTSTR lpszMsg, ...);
93 
94 /* Convert a utf8 string to utf16. Caller should free the result */
95 wchar_t *utf8to16(const char *utf8);
96 
97 #endif /* ifndef _SERVICE_H */
openvpn_service_type type
Definition: service.h:56
BOOL ReportStatusToSCMgr(SERVICE_STATUS_HANDLE service, SERVICE_STATUS *status)
Definition: service.c:22
VOID WINAPI ServiceStartAutomatic(DWORD argc, LPTSTR *argv)
Definition: automatic.c:215
openvpn_service_t interactive_service
Definition: interactive.c:63
int openvpn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist)
Definition: common.c:32
wchar_t * utf8to16(const char *utf8)
Definition: common.c:254
DWORD start_type
Definition: service.h:60
BOOL append
Definition: service.h:71
openvpn_service_t automatic_service
Definition: automatic.c:49
DWORD priority
Definition: service.h:70
int openvpn_sntprintf(LPTSTR str, size_t size, LPCTSTR format,...)
Definition: common.c:43
TCHAR * name
Definition: service.h:57
LPCTSTR GetLastErrorText()
Definition: common.c:188
static SERVICE_STATUS status
Definition: automatic.c:47
static SERVICE_STATUS_HANDLE service
Definition: automatic.c:46
TCHAR * dependencies
Definition: service.h:59
VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv)
Definition: interactive.c:1789
DWORD GetOpenvpnSettings(settings_t *s)
Definition: common.c:80
openvpn_service_type
Definition: service.h:49
#define MAX_NAME
Definition: service.h:63
DWORD MsgToEventLog(DWORD flags, LPCTSTR lpszMsg,...)
Definition: common.c:217
TCHAR * display_name
Definition: service.h:58
Definition: argv.h:35