src/openvpn/console.c
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
  */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #elif defined(_MSC_VER)
 #include "config-msvc.h"
 #endif
 
 #include "syshead.h"
 #include "console.h"
 #include "error.h"
 #include "buffer.h"
 #include "misc.h"
 
f33ee6bc
 #ifdef ENABLE_SYSTEMD
 #include <systemd/sd-daemon.h>
 #endif
 
72c7b12c
 
430ce8bd
 struct _query_user query_user[QUERY_USER_NUMSLOTS];  /* GLOBAL */
72c7b12c
 
 
81d882d5
 void
e2a0cad4
 query_user_clear(void)
72c7b12c
 {
430ce8bd
     int i;
72c7b12c
 
4cd4899e
     for (i = 0; i < QUERY_USER_NUMSLOTS; i++)
     {
81d882d5
         CLEAR(query_user[i]);
72c7b12c
     }
 }
 
 
81d882d5
 void
 query_user_add(char *prompt, size_t prompt_len,
                char *resp, size_t resp_len,
                bool echo)
72c7b12c
 {
430ce8bd
     int i;
72c7b12c
 
430ce8bd
     /* Ensure input is sane.  All these must be present otherwise it is
      * a programming error.
      */
     ASSERT( prompt_len > 0 && prompt != NULL && resp_len > 0 && resp != NULL );
015fe717
 
430ce8bd
     /* Seek to the last unused slot */
4cd4899e
     for (i = 0; i < QUERY_USER_NUMSLOTS; i++)
     {
81d882d5
         if (query_user[i].prompt == NULL)
         {
             break;
         }
72c7b12c
     }
430ce8bd
     ASSERT( i < QUERY_USER_NUMSLOTS );  /* Unlikely, but we want to panic if it happens */
 
     /* Save the information needed for the user interaction */
     query_user[i].prompt = prompt;
     query_user[i].prompt_len = prompt_len;
     query_user[i].response = resp;
     query_user[i].response_len = resp_len;
     query_user[i].echo = echo;
72c7b12c
 }