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-2018 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 <winsock2.h>
34 #include <windows.h>
35 #include <stdlib.h>
36 #include <tchar.h>
37 
38 #define APPNAME TEXT(PACKAGE "serv")
39 #define SERVICE_DEPENDENCIES TAP_WIN_COMPONENT_ID "\0Dhcp\0\0"
40 
41 /*
42  * Message handling
43  */
44 #define MSG_FLAGS_ERROR (1<<0)
45 #define MSG_FLAGS_SYS_CODE (1<<1)
46 #define M_INFO (0) /* informational */
47 #define M_SYSERR (MSG_FLAGS_ERROR|MSG_FLAGS_SYS_CODE) /* error + system code */
48 #define M_ERR (MSG_FLAGS_ERROR) /* error */
49 
50 typedef enum {
55 
56 typedef struct {
58  TCHAR *name;
59  TCHAR *display_name;
60  TCHAR *dependencies;
61  DWORD start_type;
63 
64 #define MAX_NAME 256
65 typedef struct {
66  TCHAR exe_path[MAX_PATH];
67  TCHAR config_dir[MAX_PATH];
68  TCHAR ext_string[16];
69  TCHAR log_dir[MAX_PATH];
70  TCHAR ovpn_admin_group[MAX_NAME];
71  DWORD priority;
72  BOOL append;
73 } settings_t;
74 
77 extern LPCTSTR service_instance;
78 
79 VOID WINAPI ServiceStartAutomaticOwn(DWORD argc, LPTSTR *argv);
80 
81 VOID WINAPI ServiceStartAutomatic(DWORD argc, LPTSTR *argv);
82 
83 VOID WINAPI ServiceStartInteractiveOwn(DWORD argc, LPTSTR *argv);
84 
85 VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv);
86 
87 BOOL openvpn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist);
88 
89 BOOL openvpn_sntprintf(LPTSTR str, size_t size, LPCTSTR format, ...);
90 
91 BOOL openvpn_swprintf(wchar_t *const str, const size_t size, const wchar_t *const format, ...);
92 
94 
95 BOOL ReportStatusToSCMgr(SERVICE_STATUS_HANDLE service, SERVICE_STATUS *status);
96 
97 LPCTSTR GetLastErrorText();
98 
99 DWORD MsgToEventLog(DWORD flags, LPCTSTR lpszMsg, ...);
100 
101 /* Convert a utf8 string to utf16. Caller should free the result */
102 wchar_t *utf8to16(const char *utf8);
103 
104 /* return windows system directory as a pointer to a static string */
105 const wchar_t *get_win_sys_path(void);
106 
107 #endif /* ifndef _SERVICE_H */
openvpn_service_type type
Definition: service.h:57
BOOL ReportStatusToSCMgr(SERVICE_STATUS_HANDLE service, SERVICE_STATUS *status)
Definition: service.c:22
VOID WINAPI ServiceStartAutomatic(DWORD argc, LPTSTR *argv)
Definition: automatic.c:199
openvpn_service_t interactive_service
Definition: interactive.c:62
wchar_t * utf8to16(const char *utf8)
Definition: common.c:293
DWORD start_type
Definition: service.h:61
BOOL append
Definition: service.h:72
openvpn_service_t automatic_service
Definition: automatic.c:45
BOOL openvpn_swprintf(wchar_t *const str, const size_t size, const wchar_t *const format,...)
Definition: buffer.c:321
DWORD priority
Definition: service.h:71
TCHAR * name
Definition: service.h:58
list flags
LPCTSTR service_instance
Definition: common.c:27
LPCTSTR GetLastErrorText()
Definition: common.c:227
static SERVICE_STATUS status
Definition: automatic.c:43
static SERVICE_STATUS_HANDLE service
Definition: automatic.c:42
BOOL openvpn_sntprintf(LPTSTR str, size_t size, LPCTSTR format,...)
Definition: common.c:47
TCHAR * dependencies
Definition: service.h:60
VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv)
Definition: interactive.c:1827
const wchar_t * get_win_sys_path(void)
Definition: win32.c:1206
DWORD GetOpenvpnSettings(settings_t *s)
Definition: common.c:101
openvpn_service_type
Definition: service.h:50
#define MAX_NAME
Definition: service.h:64
DWORD MsgToEventLog(DWORD flags, LPCTSTR lpszMsg,...)
Definition: common.c:256
TCHAR * display_name
Definition: service.h:59
Definition: argv.h:35
VOID WINAPI ServiceStartInteractiveOwn(DWORD argc, LPTSTR *argv)
Definition: interactive.c:1819
BOOL openvpn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist)
Definition: common.c:35
VOID WINAPI ServiceStartAutomaticOwn(DWORD argc, LPTSTR *argv)
Definition: automatic.c:191