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-2025 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, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef _SERVICE_H
24#define _SERVICE_H
25
26#ifdef HAVE_CONFIG_H
27#include "config.h"
28#endif
29
30#include <winsock2.h>
31#include <windows.h>
32#include <stdlib.h>
33#include <wchar.h>
34#include "../tapctl/basic.h"
35
36#define APPNAME _L(PACKAGE) L"serv"
37#define SERVICE_DEPENDENCIES _L(TAP_WIN_COMPONENT_ID) L"\0Dhcp\0\0"
38
39/*
40 * Message handling
41 */
42#define MSG_FLAGS_ERROR (1 << 0)
43#define MSG_FLAGS_SYS_CODE (1 << 1)
44#define M_INFO (0) /* informational */
45#define M_SYSERR (MSG_FLAGS_ERROR | MSG_FLAGS_SYS_CODE) /* error + system code */
46#define M_ERR (MSG_FLAGS_ERROR) /* error */
47
53
62
63#define MAX_NAME 256
64typedef struct
65{
66 WCHAR exe_path[MAX_PATH];
67 WCHAR config_dir[MAX_PATH];
68 WCHAR bin_dir[MAX_PATH];
69 WCHAR ext_string[16];
70 WCHAR log_dir[MAX_PATH];
71 WCHAR ovpn_admin_group[MAX_NAME];
72 WCHAR ovpn_service_user[MAX_NAME];
73 DWORD priority;
74 BOOL append;
76
78extern LPCWSTR service_instance;
79
80VOID WINAPI ServiceStartInteractiveOwn(DWORD argc, LPWSTR *argv);
81
82VOID WINAPI ServiceStartInteractive(DWORD argc, LPWSTR *argv);
83
85
86BOOL ReportStatusToSCMgr(SERVICE_STATUS_HANDLE service, SERVICE_STATUS *status);
87
88LPCWSTR GetLastErrorText(void);
89
90DWORD MsgToEventLog(DWORD flags, LPCWSTR lpszMsg, ...);
91
109wchar_t *utf8to16_size(const char *utf8, int size);
110
121static inline wchar_t *
122utf8to16(const char *utf8)
123{
124 return utf8to16_size(utf8, -1);
125}
126
127/* return windows system directory as a pointer to a static string */
128const wchar_t *get_win_sys_path(void);
129
130#endif /* ifndef _SERVICE_H */
static SERVICE_STATUS status
Definition interactive.c:51
static SERVICE_STATUS_HANDLE service
Definition interactive.c:50
const wchar_t * get_win_sys_path(void)
Definition win32.c:1108
VOID WINAPI ServiceStartInteractiveOwn(DWORD argc, LPWSTR *argv)
wchar_t * utf8to16_size(const char *utf8, int size)
Convert a UTF-8 string to UTF-16.
Definition common.c:265
DWORD MsgToEventLog(DWORD flags, LPCWSTR lpszMsg,...)
Definition common.c:230
BOOL ReportStatusToSCMgr(SERVICE_STATUS_HANDLE service, SERVICE_STATUS *status)
Definition service.c:22
LPCWSTR service_instance
Definition common.c:26
openvpn_service_t interactive_service
Definition interactive.c:60
DWORD GetOpenvpnSettings(settings_t *s)
Definition common.c:57
#define MAX_NAME
Definition service.h:63
VOID WINAPI ServiceStartInteractive(DWORD argc, LPWSTR *argv)
LPCWSTR GetLastErrorText(void)
Definition common.c:198
openvpn_service_type
Definition service.h:49
@ _service_max
Definition service.h:51
@ interactive
Definition service.h:50
static wchar_t * utf8to16(const char *utf8)
Convert a zero terminated UTF-8 string to UTF-16.
Definition service.h:122
Definition argv.h:35
WCHAR * dependencies
Definition service.h:59
openvpn_service_type type
Definition service.h:56
WCHAR * display_name
Definition service.h:58
BOOL append
Definition service.h:74
DWORD priority
Definition service.h:73