]>
Commit | Line | Data |
---|---|---|
72c7b12c ABL |
1 | /* |
2 | * OpenVPN -- An application to securely tunnel IP networks | |
3 | * over a single UDP port, with support for SSL/TLS-based | |
4 | * session authentication and key exchange, | |
5 | * packet encryption, packet authentication, and | |
6 | * packet compression. | |
7 | * | |
b25c6d7e | 8 | * Copyright (C) 2002-2024 OpenVPN Inc <sales@openvpn.net> |
430ce8bd | 9 | * Copyright (C) 2014-2015 David Sommerseth <davids@redhat.com> |
b25c6d7e | 10 | * Copyright (C) 2016-2024 David Sommerseth <davids@openvpn.net> |
72c7b12c ABL |
11 | * |
12 | * This program is free software; you can redistribute it and/or modify | |
13 | * it under the terms of the GNU General Public License version 2 | |
14 | * as published by the Free Software Foundation. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | * GNU General Public License for more details. | |
20 | * | |
caa54ac3 DS |
21 | * You should have received a copy of the GNU General Public License along |
22 | * with this program; if not, write to the Free Software Foundation, Inc., | |
23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
f57431cd | 24 | */ |
72c7b12c ABL |
25 | |
26 | #ifndef CONSOLE_H | |
27 | #define CONSOLE_H | |
28 | ||
29 | #include "basic.h" | |
30 | ||
430ce8bd DS |
31 | /** |
32 | * Configuration setup for declaring what kind of information to ask a user for | |
33 | */ | |
34 | struct _query_user { | |
35 | char *prompt; /**< Prompt to present to the user */ | |
ccb636c7 | 36 | size_t prompt_len; /**< Length of the prompt string */ |
430ce8bd | 37 | char *response; /**< The user's response */ |
ccb636c7 | 38 | size_t response_len; /**< Length the of the user response */ |
430ce8bd DS |
39 | bool echo; /**< True: The user should see what is being typed, otherwise mask it */ |
40 | }; | |
41 | ||
42 | #define QUERY_USER_NUMSLOTS 10 | |
43 | extern struct _query_user query_user[]; /**< Global variable, declared in console.c */ | |
44 | ||
45 | /** | |
46 | * Wipes all data put into all of the query_user structs | |
47 | * | |
48 | */ | |
e2a0cad4 | 49 | void query_user_clear(void); |
430ce8bd DS |
50 | |
51 | ||
52 | /** | |
53 | * Adds an item to ask the user for | |
54 | * | |
55 | * @param prompt Prompt to display to the user | |
56 | * @param prompt_len Length of the prompt string | |
57 | * @param resp String containing the user response | |
ccb636c7 | 58 | * @param resp_len Length of the response string |
430ce8bd DS |
59 | * @param echo Should the user input be echoed to the user? If False, input will be masked |
60 | * | |
61 | */ | |
81d882d5 DS |
62 | void query_user_add(char *prompt, size_t prompt_len, |
63 | char *resp, size_t resp_len, | |
64 | bool echo); | |
430ce8bd DS |
65 | |
66 | ||
67 | /** | |
68 | * Executes a configured setup, using the built-in method for querying the user. | |
69 | * This method uses the console/TTY directly. | |
70 | * | |
71 | * @param setup Pointer to the setup defining what to ask the user | |
72 | * | |
73 | * @return True if executing all the defined steps completed successfully | |
74 | */ | |
e2a0cad4 | 75 | bool query_user_exec_builtin(void); |
430ce8bd DS |
76 | |
77 | ||
3280d8c8 | 78 | #if defined(ENABLE_SYSTEMD) |
430ce8bd DS |
79 | /** |
80 | * Executes a configured setup, using the compiled method for querying the user | |
81 | * | |
82 | * @param setup Pointer to the setup defining what to ask the user | |
83 | * | |
84 | * @return True if executing all the defined steps completed successfully | |
85 | */ | |
e2a0cad4 | 86 | bool query_user_exec(void); |
430ce8bd | 87 | |
3280d8c8 | 88 | #else /* ENABLE_SYSTEMD not defined*/ |
430ce8bd DS |
89 | /** |
90 | * Wrapper function enabling query_user_exec() if no alternative methods have | |
91 | * been enabled | |
92 | * | |
93 | */ | |
81d882d5 | 94 | static bool |
e2a0cad4 | 95 | query_user_exec(void) |
430ce8bd DS |
96 | { |
97 | return query_user_exec_builtin(); | |
98 | } | |
3280d8c8 | 99 | #endif /* defined(ENABLE_SYSTEMD) */ |
430ce8bd DS |
100 | |
101 | ||
102 | /** | |
103 | * A plain "make Gert happy" wrapper. Same arguments as @query_user_add | |
104 | * | |
105 | * FIXME/TODO: Remove this when refactoring the complete user query process | |
106 | * to be called at start-up initialization of OpenVPN. | |
107 | * | |
108 | */ | |
81d882d5 DS |
109 | static inline bool |
110 | query_user_SINGLE(char *prompt, size_t prompt_len, | |
111 | char *resp, size_t resp_len, | |
112 | bool echo) | |
430ce8bd DS |
113 | { |
114 | query_user_clear(); | |
115 | query_user_add(prompt, prompt_len, resp, resp_len, echo); | |
116 | return query_user_exec(); | |
117 | } | |
72c7b12c | 118 | |
81d882d5 | 119 | #endif /* ifndef CONSOLE_H */ |