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-2023 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 /* We do not support non-unicode builds */
28 #ifndef UNICODE
29 #define UNICODE
30 #endif
31 
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35 
36 #include <winsock2.h>
37 #include <windows.h>
38 #include <stdlib.h>
39 #include <tchar.h>
40 
41 #define APPNAME TEXT(PACKAGE "serv")
42 #define SERVICE_DEPENDENCIES TAP_WIN_COMPONENT_ID "\0Dhcp\0\0"
43 
44 /*
45  * Message handling
46  */
47 #define MSG_FLAGS_ERROR (1<<0)
48 #define MSG_FLAGS_SYS_CODE (1<<1)
49 #define M_INFO (0) /* informational */
50 #define M_SYSERR (MSG_FLAGS_ERROR|MSG_FLAGS_SYS_CODE) /* error + system code */
51 #define M_ERR (MSG_FLAGS_ERROR) /* error */
52 
53 typedef enum {
57 
58 typedef struct {
60  TCHAR *name;
61  TCHAR *display_name;
62  TCHAR *dependencies;
63  DWORD start_type;
65 
66 #define MAX_NAME 256
67 typedef struct {
68  TCHAR exe_path[MAX_PATH];
69  TCHAR config_dir[MAX_PATH];
70  TCHAR ext_string[16];
71  TCHAR log_dir[MAX_PATH];
72  TCHAR ovpn_admin_group[MAX_NAME];
73  DWORD priority;
74  BOOL append;
75 } settings_t;
76 
78 extern LPCTSTR service_instance;
79 
80 VOID WINAPI ServiceStartInteractiveOwn(DWORD argc, LPTSTR *argv);
81 
82 VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv);
83 
84 BOOL openvpn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist);
85 
86 BOOL openvpn_sntprintf(LPTSTR str, size_t size, LPCTSTR format, ...);
87 
88 BOOL openvpn_swprintf(wchar_t *const str, const size_t size, const wchar_t *const format, ...);
89 
91 
92 BOOL ReportStatusToSCMgr(SERVICE_STATUS_HANDLE service, SERVICE_STATUS *status);
93 
94 LPCTSTR GetLastErrorText();
95 
96 DWORD MsgToEventLog(DWORD flags, LPCTSTR lpszMsg, ...);
97 
98 /* Convert a utf8 string to utf16. Caller should free the result */
99 wchar_t *utf8to16(const char *utf8);
100 
101 /* return windows system directory as a pointer to a static string */
102 const wchar_t *get_win_sys_path(void);
103 
104 #endif /* ifndef _SERVICE_H */
openvpn_vsntprintf
BOOL openvpn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist)
interactive_service
openvpn_service_t interactive_service
Definition: interactive.c:60
settings_t::append
BOOL append
Definition: service.h:74
settings_t::priority
DWORD priority
Definition: service.h:73
ServiceStartInteractiveOwn
VOID WINAPI ServiceStartInteractiveOwn(DWORD argc, LPTSTR *argv)
Definition: interactive.c:2267
_service_max
@ _service_max
Definition: service.h:55
argv
Definition: argv.h:35
openvpn_swprintf
BOOL openvpn_swprintf(wchar_t *const str, const size_t size, const wchar_t *const format,...)
Definition: win32.c:1486
utf8to16
wchar_t * utf8to16(const char *utf8)
Definition: common.c:282
openvpn_service_t
Definition: service.h:58
service_instance
LPCTSTR service_instance
Definition: common.c:27
openvpn_service_t::name
TCHAR * name
Definition: service.h:60
openvpn_service_t::type
openvpn_service_type type
Definition: service.h:59
get_win_sys_path
const wchar_t * get_win_sys_path(void)
Definition: win32.c:1110
settings_t
Definition: service.h:67
GetLastErrorText
LPCTSTR GetLastErrorText()
Definition: common.c:214
ServiceStartInteractive
VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv)
Definition: interactive.c:2275
openvpn_sntprintf
BOOL openvpn_sntprintf(LPTSTR str, size_t size, LPCTSTR format,...)
service
static SERVICE_STATUS_HANDLE service
Definition: interactive.c:51
GetOpenvpnSettings
DWORD GetOpenvpnSettings(settings_t *s)
Definition: common.c:86
status
static SERVICE_STATUS status
Definition: interactive.c:52
openvpn_service_type
openvpn_service_type
Definition: service.h:53
config.h
interactive
@ interactive
Definition: service.h:54
ReportStatusToSCMgr
BOOL ReportStatusToSCMgr(SERVICE_STATUS_HANDLE service, SERVICE_STATUS *status)
Definition: service.c:22
openvpn_service_t::dependencies
TCHAR * dependencies
Definition: service.h:62
MsgToEventLog
DWORD MsgToEventLog(DWORD flags, LPCTSTR lpszMsg,...)
Definition: common.c:245
openvpn_service_t::display_name
TCHAR * display_name
Definition: service.h:61
MAX_NAME
#define MAX_NAME
Definition: service.h:66
openvpn_service_t::start_type
DWORD start_type
Definition: service.h:63