OpenVPN
console.c
Go to the documentation of this file.
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 *
8 * Copyright (C) 2002-2025 OpenVPN Inc <sales@openvpn.net>
9 * Copyright (C) 2014-2015 David Sommerseth <davids@redhat.com>
10 * Copyright (C) 2016-2025 David Sommerseth <davids@openvpn.net>
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 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, see <https://www.gnu.org/licenses/>.
23 */
24
25#ifdef HAVE_CONFIG_H
26#include "config.h"
27#endif
28
29#include "syshead.h"
30#include "console.h"
31#include "error.h"
32#include "buffer.h"
33#include "misc.h"
34
35#ifdef ENABLE_SYSTEMD
36#include <systemd/sd-daemon.h>
37#endif
38
39
41
42
43void
45{
46 int i;
47
48 for (i = 0; i < QUERY_USER_NUMSLOTS; i++)
49 {
51 }
52}
53
54
55void
56query_user_add(char *prompt, size_t prompt_len, char *resp, size_t resp_len, bool echo)
57{
58 int i;
59
60 /* Ensure input is sane. All these must be present otherwise it is
61 * a programming error.
62 */
63 ASSERT(prompt_len > 0 && prompt != NULL && resp_len > 0 && resp != NULL);
64
65 /* Seek to the last unused slot */
66 for (i = 0; i < QUERY_USER_NUMSLOTS; i++)
67 {
68 if (query_user[i].prompt == NULL)
69 {
70 break;
71 }
72 }
73 ASSERT(i < QUERY_USER_NUMSLOTS); /* Unlikely, but we want to panic if it happens */
74
75 /* Save the information needed for the user interaction */
78 query_user[i].response = resp;
79 query_user[i].response_len = resp_len;
81}
void query_user_clear(void)
Wipes all data put into all of the query_user structs.
Definition console.c:44
struct _query_user query_user[QUERY_USER_NUMSLOTS]
Global variable, declared in console.c.
Definition console.c:40
void query_user_add(char *prompt, size_t prompt_len, char *resp, size_t resp_len, bool echo)
Adds an item to ask the user for.
Definition console.c:56
#define QUERY_USER_NUMSLOTS
Definition console.h:42
#define CLEAR(x)
Definition basic.h:32
#define ASSERT(x)
Definition error.h:217
Configuration setup for declaring what kind of information to ask a user for.
Definition console.h:34
char * prompt
Prompt to present to the user.
Definition console.h:35
size_t prompt_len
Length of the prompt string.
Definition console.h:36
size_t response_len
Length the of the user response.
Definition console.h:38
char * response
The user's response.
Definition console.h:37
bool echo
True: The user should see what is being typed, otherwise mask it.
Definition console.h:39