OpenVPN
misc.h File Reference
#include "argv.h"
#include "basic.h"
#include "common.h"
#include "env_set.h"
#include "integer.h"
#include "buffer.h"
#include "platform.h"
Include dependency graph for misc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  user_pass
struct  auth_challenge_info
struct  static_challenge_info

Macros

#define USER_PASS_LEN   128
#define CR_ECHO   (1 << 0) /* echo response when typed by user */
#define CR_RESPONSE   (1 << 1) /* response needed */
#define SC_ECHO   (1 << 0) /* echo response when typed by user */
#define SC_CONCAT   (1 << 1) /* concatenate password and response and do not base64 encode */
#define GET_USER_PASS_MANAGEMENT   (1 << 0)
#define GET_USER_PASS_PASSWORD_ONLY   (1 << 2)
#define GET_USER_PASS_NEED_OK   (1 << 3)
#define GET_USER_PASS_NOFATAL   (1 << 4)
#define GET_USER_PASS_NEED_STR   (1 << 5)
#define GET_USER_PASS_PREVIOUS_CREDS_FAILED   (1 << 6)
#define GET_USER_PASS_DYNAMIC_CHALLENGE   (1 << 7)
 CRV1 protocol – dynamic challenge.
#define GET_USER_PASS_STATIC_CHALLENGE   (1 << 8)
 SCRV1 protocol – static challenge.
#define GET_USER_PASS_STATIC_CHALLENGE_ECHO   (1 << 9)
 SCRV1 protocol – echo response.
#define GET_USER_PASS_INLINE_CREDS   (1 << 10)
 indicates that auth_file is actually inline creds
#define GET_USER_PASS_STATIC_CHALLENGE_CONCAT   (1 << 11)
 indicates password and response should be concatenated
#define GET_USER_PASS_USERNAME_ONLY   (1 << 12)
 indicate that only username should be prompted for auth-user-pass
#define _STRINGIFY(S)
#define MAC_FMT   _STRINGIFY(%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx)
#define MAC_PRINT_ARG(_mac)
#define MAC_SCAN_ARG(_mac)

Functions

void set_std_files_to_null (bool stdin_only)
const char ** make_arg_array (const char *first, const char *parms, struct gc_arena *gc)
const char ** make_extended_arg_array (char **p, bool is_inline, struct gc_arena *gc)
bool get_user_pass_cr (struct user_pass *up, const char *auth_file, const char *prefix, const unsigned int flags, const char *auth_challenge)
 Retrieves the user credentials from various sources depending on the flags.
static bool get_user_pass (struct user_pass *up, const char *auth_file, const char *prefix, const unsigned int flags)
 Retrieves the user credentials from various sources depending on the flags.
void purge_user_pass (struct user_pass *up, const bool force)
void set_auth_token (struct user_pass *tk, const char *token)
 Sets the auth-token to token.
void set_auth_token_user (struct user_pass *tk, const char *username)
 Sets the auth-token username by base64 decoding the passed username.
const char * safe_print (const char *str, struct gc_arena *gc)
const char * sanitize_control_message (const char *str, struct gc_arena *gc)
bool validate_peer_info_line (char *line)
void output_peer_info_env (struct env_set *es, const char *peer_info)
struct buffer prepend_dir (const char *dir, const char *path, struct gc_arena *gc)
 Prepend a directory to a path.
void protect_user_pass (struct user_pass *up)
 Encrypt username and password buffers in user_pass.
void unprotect_user_pass (struct user_pass *up)
 Decrypt username and password buffers in user_pass.

Variables

static const char blank_up [] = "[[BLANK]]"

Macro Definition Documentation

◆ _STRINGIFY

#define _STRINGIFY ( S)
Value:
#S

Definition at line 223 of file misc.h.

◆ CR_ECHO

#define CR_ECHO   (1 << 0) /* echo response when typed by user */

Definition at line 80 of file misc.h.

Referenced by get_user_pass_cr(), and parse_auth_challenge().

◆ CR_RESPONSE

#define CR_RESPONSE   (1 << 1) /* response needed */

Definition at line 81 of file misc.h.

Referenced by parse_auth_challenge().

◆ GET_USER_PASS_DYNAMIC_CHALLENGE

#define GET_USER_PASS_DYNAMIC_CHALLENGE   (1 << 7)

CRV1 protocol – dynamic challenge.

Definition at line 121 of file misc.h.

Referenced by auth_user_pass_setup(), get_user_pass_cr(), and test_get_user_pass_dynamic_challenge().

◆ GET_USER_PASS_INLINE_CREDS

#define GET_USER_PASS_INLINE_CREDS   (1 << 10)

◆ GET_USER_PASS_MANAGEMENT

#define GET_USER_PASS_MANAGEMENT   (1 << 0)

◆ GET_USER_PASS_NEED_OK

#define GET_USER_PASS_NEED_OK   (1 << 3)

◆ GET_USER_PASS_NEED_STR

#define GET_USER_PASS_NEED_STR   (1 << 5)

Definition at line 118 of file misc.h.

Referenced by get_user_pass_cr(), and management_query_user_pass().

◆ GET_USER_PASS_NOFATAL

#define GET_USER_PASS_NOFATAL   (1 << 4)

Definition at line 117 of file misc.h.

Referenced by auth_user_pass_mgmt().

◆ GET_USER_PASS_PASSWORD_ONLY

◆ GET_USER_PASS_PREVIOUS_CREDS_FAILED

#define GET_USER_PASS_PREVIOUS_CREDS_FAILED   (1 << 6)

Definition at line 119 of file misc.h.

Referenced by auth_user_pass_mgmt(), get_user_pass_cr(), and get_user_pass_http().

◆ GET_USER_PASS_STATIC_CHALLENGE

#define GET_USER_PASS_STATIC_CHALLENGE   (1 << 8)

SCRV1 protocol – static challenge.

Definition at line 122 of file misc.h.

Referenced by auth_user_pass_mgmt(), auth_user_pass_setup(), get_user_pass_cr(), and test_get_user_pass_static_challenge().

◆ GET_USER_PASS_STATIC_CHALLENGE_CONCAT

#define GET_USER_PASS_STATIC_CHALLENGE_CONCAT   (1 << 11)

indicates password and response should be concatenated

Definition at line 128 of file misc.h.

Referenced by auth_user_pass_setup(), get_user_pass_cr(), management_query_user_pass(), and test_get_user_pass_static_challenge().

◆ GET_USER_PASS_STATIC_CHALLENGE_ECHO

#define GET_USER_PASS_STATIC_CHALLENGE_ECHO   (1 << 9)

SCRV1 protocol – echo response.

Definition at line 123 of file misc.h.

Referenced by auth_user_pass_setup(), get_user_pass_cr(), and management_query_user_pass().

◆ GET_USER_PASS_USERNAME_ONLY

#define GET_USER_PASS_USERNAME_ONLY   (1 << 12)

indicate that only username should be prompted for auth-user-pass

Definition at line 130 of file misc.h.

Referenced by auth_user_pass_setup(), get_user_pass_cr(), management_query_user_pass(), and test_get_user_pass_authfile_stdin().

◆ MAC_FMT

#define MAC_FMT   _STRINGIFY(%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx)

Definition at line 225 of file misc.h.

◆ MAC_PRINT_ARG

#define MAC_PRINT_ARG ( _mac)
Value:
_mac[0], _mac[1], _mac[2], _mac[3], _mac[4], _mac[5]

Definition at line 227 of file misc.h.

◆ MAC_SCAN_ARG

#define MAC_SCAN_ARG ( _mac)
Value:
&_mac[0], &_mac[1], &_mac[2], &_mac[3], &_mac[4], &_mac[5]

Definition at line 228 of file misc.h.

◆ SC_CONCAT

#define SC_CONCAT   (1 << 1) /* concatenate password and response and do not base64 encode */

Definition at line 95 of file misc.h.

Referenced by add_option(), and auth_user_pass_setup().

◆ SC_ECHO

#define SC_ECHO   (1 << 0) /* echo response when typed by user */

Definition at line 94 of file misc.h.

Referenced by add_option(), and auth_user_pass_setup().

◆ USER_PASS_LEN

Function Documentation

◆ get_user_pass()

bool get_user_pass ( struct user_pass * up,
const char * auth_file,
const char * prefix,
const unsigned int flags )
inlinestatic

Retrieves the user credentials from various sources depending on the flags.

Parameters
upThe user_pass structure to store the retrieved credentials.
auth_fileThe path to the authentication file. Might be NULL.
prefixThe prefix to prepend to user prompts.
flagsAdditional flags to control the behavior of the function.
Returns
true if the user credentials were successfully retrieved, false otherwise.

Definition at line 155 of file misc.h.

References get_user_pass_cr().

Referenced by auth_user_pass_setup(), context_init_1(), get_user_pass_http(), man_settings_init(), pem_password_setup(), and socks_username_password_auth().

◆ get_user_pass_cr()

bool get_user_pass_cr ( struct user_pass * up,
const char * auth_file,
const char * prefix,
const unsigned int flags,
const char * auth_challenge )

Retrieves the user credentials from various sources depending on the flags.

Parameters
upThe user_pass structure to store the retrieved credentials.
auth_fileThe path to the authentication file. Might be NULL.
prefixThe prefix to prepend to user prompts.
flagsAdditional flags to control the behavior of the function.
auth_challengeThe authentication challenge string.
Returns
true if the user credentials were successfully retrieved, false otherwise.

Definition at line 196 of file misc.c.

References alloc_buf_gc(), auth_challenge, auth_user_pass_mgmt(), blank_up, BOOL_CAST, BSTR, buf_parse(), buf_printf(), buf_set_read(), buf_set_write(), CC_CRLF, CC_PRINT, auth_challenge_info::challenge_text, chomp(), CR_ECHO, D_LOW, user_pass::defined, auth_challenge_info::flags, gc, gc_free(), gc_malloc(), gc_new(), GET_USER_PASS_DYNAMIC_CHALLENGE, GET_USER_PASS_INLINE_CREDS, GET_USER_PASS_MANAGEMENT, GET_USER_PASS_NEED_OK, GET_USER_PASS_NEED_STR, GET_USER_PASS_PASSWORD_ONLY, GET_USER_PASS_PREVIOUS_CREDS_FAILED, GET_USER_PASS_STATIC_CHALLENGE, GET_USER_PASS_STATIC_CHALLENGE_CONCAT, GET_USER_PASS_STATIC_CHALLENGE_ECHO, GET_USER_PASS_USERNAME_ONLY, M_ERR, M_FATAL, M_INFO, M_NONFATAL, M_WARN, management_query_user_pass_enabled(), msg, openvpn_base64_encode(), parse_auth_challenge(), user_pass::password, PIN, pkcs11_id_current, pkcs11_id_management, platform_fopen(), query_user_add(), query_user_clear(), query_user_exec(), query_user_SINGLE(), auth_challenge_info::state_id, streq, string_clear(), string_mod(), strlcat(), strlcpy(), unprotect_user_pass(), auth_challenge_info::user, USER_PASS_LEN, and user_pass::username.

Referenced by auth_user_pass_setup(), get_user_pass(), test_get_user_pass_authfile_file(), test_get_user_pass_authfile_file_assertions(), test_get_user_pass_authfile_stdin(), test_get_user_pass_authfile_stdin_assertions(), test_get_user_pass_defined(), test_get_user_pass_dynamic_challenge(), test_get_user_pass_inline_creds(), test_get_user_pass_inline_creds_assertions(), test_get_user_pass_needok(), and test_get_user_pass_static_challenge().

◆ make_arg_array()

const char ** make_arg_array ( const char * first,
const char * parms,
struct gc_arena * gc )

Definition at line 549 of file misc.c.

References ALLOC_ARRAY_CLEAR_GC, ASSERT, gc, M_WARN, MAX_PARMS, parse_line(), and string_alloc().

Referenced by make_extended_arg_array().

◆ make_extended_arg_array()

const char ** make_extended_arg_array ( char ** p,
bool is_inline,
struct gc_arena * gc )

Definition at line 626 of file misc.c.

References gc, make_arg_array(), make_arg_copy(), make_inline_array(), and string_array_len().

Referenced by plugin_option_list_add(), and push_options().

◆ output_peer_info_env()

void output_peer_info_env ( struct env_set * es,
const char * peer_info )

Definition at line 754 of file misc.c.

References buf_parse(), buf_set_read(), chomp(), env_set_add(), M_INFO, M_WARN, msg, and validate_peer_info_line().

Referenced by key_method_2_read().

◆ prepend_dir()

struct buffer prepend_dir ( const char * dir,
const char * path,
struct gc_arena * gc )

Prepend a directory to a path.

Definition at line 777 of file misc.c.

References alloc_buf_gc(), ASSERT, buf_printf(), gc, buffer::len, PATH_SEPARATOR_STR, and prepend_dir().

Referenced by check_file_access_chroot(), init_ssl(), and prepend_dir().

◆ protect_user_pass()

void protect_user_pass ( struct user_pass * up)

◆ purge_user_pass()

◆ safe_print()

const char * safe_print ( const char * str,
struct gc_arena * gc )

Definition at line 543 of file misc.c.

References CC_CRLF, CC_PRINT, gc, and string_mod_const().

Referenced by options_warning_safe_scan2().

◆ sanitize_control_message()

const char * sanitize_control_message ( const char * str,
struct gc_arena * gc )

Definition at line 656 of file misc.c.

References check_debug_level(), D_SHOW_KEYS, gc, and gc_malloc().

Referenced by incoming_push_message(), and send_control_channel_string_dowork().

◆ set_auth_token()

void set_auth_token ( struct user_pass * tk,
const char * token )

Sets the auth-token to token.

The method will also purge up if the auth-nocache option is active.

Parameters
tkauth-token userpass to set
tokentoken to use as password for the auth-token
Note
all parameters to this function must not be null.

Definition at line 496 of file misc.c.

References user_pass::defined, user_pass::password, protect_user_pass(), strlcpy(), user_pass::token_defined, unprotect_user_pass(), USER_PASS_LEN, and user_pass::username.

Referenced by ssl_set_auth_token().

◆ set_auth_token_user()

void set_auth_token_user ( struct user_pass * tk,
const char * username )

Sets the auth-token username by base64 decoding the passed username.

Parameters
tkauth-token userpass to set
usernamebase64 encoded username to set
Note
all parameters to this function must not be null.

Definition at line 516 of file misc.c.

References CLEAR, D_PUSH, user_pass::defined, buffer::len, msg, openvpn_base64_decode(), protect_user_pass(), unprotect_user_pass(), USER_PASS_LEN, and user_pass::username.

Referenced by ssl_set_auth_token_user().

◆ set_std_files_to_null()

void set_std_files_to_null ( bool stdin_only)

Definition at line 55 of file misc.c.

Referenced by open_syslog(), and possibly_become_daemon().

◆ unprotect_user_pass()

◆ validate_peer_info_line()

bool validate_peer_info_line ( char * line)

Definition at line 718 of file misc.c.

Referenced by man_output_peer_info_env(), and output_peer_info_env().

Variable Documentation

◆ blank_up

const char blank_up[] = "[[BLANK]]"
static

Definition at line 52 of file misc.h.

Referenced by get_user_pass_cr(), man_query_password(), and management_query_user_pass().