OpenVPN
Data Structures | Macros | Functions
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 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 _STRINGIFY(S)   #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)
 
const char * hostname_randomize (const char *hostname, struct gc_arena *gc)
 
struct auth_challenge_infoget_auth_challenge (const char *auth_challenge, 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)
 
static bool get_user_pass (struct user_pass *up, const char *auth_file, const char *prefix, const unsigned int flags)
 
void fail_user_pass (const char *prefix, const unsigned int flags, const char *reason)
 
void purge_user_pass (struct user_pass *up, const bool force)
 
void set_auth_token (struct user_pass *up, struct user_pass *tk, const char *token)
 Sets the auth-token to token. More...
 
void set_auth_token_user (struct user_pass *tk, const char *username)
 Sets the auth-token username by base64 decoding the passed username. More...
 
const char * safe_print (const char *str, struct gc_arena *gc)
 
void configure_path (void)
 
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)
 
int get_num_elements (const char *string, char delimiter)
 Returns the occurrences of 'delimiter' in a string +1 This is typically used to find out the number elements in a cipher string or similar that is separated by : like. More...
 
struct buffer prepend_dir (const char *dir, const char *path, struct gc_arena *gc)
 Prepend a directory to a path. More...
 

Macro Definition Documentation

◆ _STRINGIFY

#define _STRINGIFY (   S)    #S

Definition at line 214 of file misc.h.

◆ CR_ECHO

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

Definition at line 79 of file misc.h.

Referenced by get_auth_challenge(), and get_user_pass_cr().

◆ CR_RESPONSE

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

Definition at line 80 of file misc.h.

Referenced by get_auth_challenge().

◆ GET_USER_PASS_DYNAMIC_CHALLENGE

#define GET_USER_PASS_DYNAMIC_CHALLENGE   (1<<7) /* CRV1 protocol -- dynamic challenge */

Definition at line 116 of file misc.h.

Referenced by auth_user_pass_setup(), and get_user_pass_cr().

◆ GET_USER_PASS_INLINE_CREDS

#define GET_USER_PASS_INLINE_CREDS   (1<<10) /* indicates that auth_file is actually inline creds */

Definition at line 120 of file misc.h.

Referenced by get_user_pass_cr(), and get_user_pass_http().

◆ GET_USER_PASS_MANAGEMENT

#define GET_USER_PASS_MANAGEMENT   (1<<0)

◆ GET_USER_PASS_NEED_OK

#define GET_USER_PASS_NEED_OK   (1<<3)

Definition at line 111 of file misc.h.

Referenced by context_init_1(), get_user_pass_cr(), man_io_error(), and management_query_user_pass().

◆ GET_USER_PASS_NEED_STR

#define GET_USER_PASS_NEED_STR   (1<<5)

Definition at line 113 of file misc.h.

Referenced by management_query_user_pass().

◆ GET_USER_PASS_NOFATAL

#define GET_USER_PASS_NOFATAL   (1<<4)

Definition at line 112 of file misc.h.

Referenced by auth_user_pass_mgmt().

◆ GET_USER_PASS_PASSWORD_ONLY

#define GET_USER_PASS_PASSWORD_ONLY   (1<<2)

◆ GET_USER_PASS_PREVIOUS_CREDS_FAILED

#define GET_USER_PASS_PREVIOUS_CREDS_FAILED   (1<<6)

Definition at line 114 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 117 of file misc.h.

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

◆ GET_USER_PASS_STATIC_CHALLENGE_ECHO

#define GET_USER_PASS_STATIC_CHALLENGE_ECHO   (1<<9) /* SCRV1 protocol -- echo response */

Definition at line 118 of file misc.h.

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

◆ MAC_FMT

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

Definition at line 215 of file misc.h.

Referenced by set_lladdr().

◆ MAC_PRINT_ARG

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

Definition at line 216 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 218 of file misc.h.

Referenced by set_lladdr().

◆ 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

#define USER_PASS_LEN   128

Function Documentation

◆ configure_path()

void configure_path ( void  )

Referenced by get_user_pass().

◆ fail_user_pass()

void fail_user_pass ( const char *  prefix,
const unsigned int  flags,
const char *  reason 
)

Referenced by get_user_pass().

◆ get_auth_challenge()

struct auth_challenge_info* get_auth_challenge ( const char *  auth_challenge,
struct gc_arena gc 
)

◆ get_num_elements()

int get_num_elements ( const char *  string,
char  delimiter 
)

Returns the occurrences of 'delimiter' in a string +1 This is typically used to find out the number elements in a cipher string or similar that is separated by : like.

X25519:secp256r1:X448:secp512r1:secp384r1:brainpoolP384r1

Parameters
stringthe string to work on
delimiterthe delimiter to count, typically ':'
Returns
occrrences of delimiter + 1

Definition at line 779 of file misc.c.

References ASSERT.

Referenced by get_user_pass(), and tls_ctx_set_tls_groups().

◆ get_user_pass()

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

◆ 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 
)

◆ hostname_randomize()

const char* hostname_randomize ( const char *  hostname,
struct gc_arena gc 
)

Definition at line 84 of file misc.c.

References alloc_buf_gc(), BSTR, buf_printf(), format_hex_ex(), n_rnd_bytes, and prng_bytes().

Referenced by openvpn_getaddrinfo().

◆ 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, 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 
)

◆ output_peer_info_env()

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

◆ 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 799 of file misc.c.

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

Referenced by check_file_access_chroot(), and init_ssl().

◆ purge_user_pass()

void purge_user_pass ( struct user_pass up,
const bool  force 
)

◆ 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, and string_mod_const().

Referenced by get_user_pass(), and options_warning_safe_scan2().

◆ sanitize_control_message()

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

◆ set_auth_token()

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

Sets the auth-token to token.

If a username is available from either up or already present in tk that will be used as default username for the token. The method will also purge up if the auth-nocache option is active.

Parameters
up(non Auth-token) Username/password
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 490 of file misc.c.

References user_pass::defined, user_pass::password, purge_user_pass(), strncpynt(), user_pass::token_defined, USER_PASS_LEN, and user_pass::username.

Referenced by get_user_pass(), and 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 518 of file misc.c.

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

Referenced by get_user_pass(), and ssl_set_auth_token_user().

◆ set_std_files_to_null()

void set_std_files_to_null ( bool  stdin_only)

Definition at line 58 of file misc.c.

Referenced by open_syslog(), and possibly_become_daemon().

◆ validate_peer_info_line()

bool validate_peer_info_line ( char *  line)

Definition at line 719 of file misc.c.

Referenced by get_user_pass(), man_output_peer_info_env(), and output_peer_info_env().