src/openvpn/console.h
72c7b12c
 /*
  *  OpenVPN -- An application to securely tunnel IP networks
  *             over a single UDP port, with support for SSL/TLS-based
  *             session authentication and key exchange,
  *             packet encryption, packet authentication, and
  *             packet compression.
  *
49979459
  *  Copyright (C) 2002-2018 OpenVPN Inc <sales@openvpn.net>
430ce8bd
  *  Copyright (C) 2014-2015 David Sommerseth <davids@redhat.com>
49979459
  *  Copyright (C) 2016-2018 David Sommerseth <davids@openvpn.net>
72c7b12c
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2
  *  as published by the Free Software Foundation.
  *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
caa54ac3
  *  You should have received a copy of the GNU General Public License along
  *  with this program; if not, write to the Free Software Foundation, Inc.,
  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
72c7b12c
 
 #ifndef CONSOLE_H
 #define CONSOLE_H
 
 #include "basic.h"
 
430ce8bd
 /**
  *  Configuration setup for declaring what kind of information to ask a user for
  */
 struct _query_user {
     char *prompt;             /**< Prompt to present to the user */
     size_t prompt_len;        /**< Lenght of the prompt string */
     char *response;           /**< The user's response */
     size_t response_len;      /**< Lenght the of the user reposone */
     bool echo;                /**< True: The user should see what is being typed, otherwise mask it */
 };
 
 #define QUERY_USER_NUMSLOTS 10
 extern struct _query_user query_user[];  /**< Global variable, declared in console.c */
 
 /**
  * Wipes all data put into all of the query_user structs
  *
  */
e2a0cad4
 void query_user_clear(void);
430ce8bd
 
 
 /**
  * Adds an item to ask the user for
  *
  * @param prompt     Prompt to display to the user
  * @param prompt_len Length of the prompt string
  * @param resp       String containing the user response
  * @param resp_len   Lenght of the response string
  * @param echo       Should the user input be echoed to the user?  If False, input will be masked
  *
  */
81d882d5
 void query_user_add(char *prompt, size_t prompt_len,
                     char *resp, size_t resp_len,
                     bool echo);
430ce8bd
 
 
 /**
  * Executes a configured setup, using the built-in method for querying the user.
  * This method uses the console/TTY directly.
  *
  * @param setup    Pointer to the setup defining what to ask the user
  *
  * @return True if executing all the defined steps completed successfully
  */
e2a0cad4
 bool query_user_exec_builtin(void);
430ce8bd
 
 
3280d8c8
 #if defined(ENABLE_SYSTEMD)
430ce8bd
 /**
  * Executes a configured setup, using the compiled method for querying the user
  *
  * @param setup    Pointer to the setup defining what to ask the user
  *
  * @return True if executing all the defined steps completed successfully
  */
e2a0cad4
 bool query_user_exec(void);
430ce8bd
 
3280d8c8
 #else  /* ENABLE_SYSTEMD not defined*/
430ce8bd
 /**
  * Wrapper function enabling query_user_exec() if no alternative methods have
  * been enabled
  *
  */
81d882d5
 static bool
e2a0cad4
 query_user_exec(void)
430ce8bd
 {
     return query_user_exec_builtin();
 }
3280d8c8
 #endif  /* defined(ENABLE_SYSTEMD) */
430ce8bd
 
 
 /**
  * A plain "make Gert happy" wrapper.  Same arguments as @query_user_add
  *
  * FIXME/TODO: Remove this when refactoring the complete user query process
  *             to be called at start-up initialization of OpenVPN.
  *
  */
81d882d5
 static inline bool
 query_user_SINGLE(char *prompt, size_t prompt_len,
                   char *resp, size_t resp_len,
                   bool echo)
430ce8bd
 {
     query_user_clear();
     query_user_add(prompt, prompt_len, resp, resp_len, echo);
     return query_user_exec();
 }
72c7b12c
 
81d882d5
 #endif /* ifndef CONSOLE_H */