OpenVPN
Macros | Functions
misc.c File Reference
#include "syshead.h"
#include "buffer.h"
#include "misc.h"
#include "base64.h"
#include "tun.h"
#include "error.h"
#include "otime.h"
#include "plugin.h"
#include "options.h"
#include "manage.h"
#include "crypto.h"
#include "route.h"
#include "console.h"
#include "win32.h"
#include "memdbg.h"
Include dependency graph for misc.c:

Go to the source code of this file.

Macros

#define n_rnd_bytes   6
 

Functions

void set_std_files_to_null (bool stdin_only)
 
const char * hostname_randomize (const char *hostname, struct gc_arena *gc)
 
static bool auth_user_pass_mgmt (struct user_pass *up, const char *prefix, const unsigned int flags, const char *auth_challenge)
 
bool get_user_pass_cr (struct user_pass *up, const char *auth_file, const char *prefix, const unsigned int flags, const char *auth_challenge)
 
struct auth_challenge_infoget_auth_challenge (const char *auth_challenge, struct gc_arena *gc)
 
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)
 
const char ** make_arg_array (const char *first, const char *parms, struct gc_arena *gc)
 
static const char ** make_inline_array (const char *str, struct gc_arena *gc)
 
static const char ** make_arg_copy (char **p, struct gc_arena *gc)
 
const char ** make_extended_arg_array (char **p, bool is_inline, struct gc_arena *gc)
 
const char * sanitize_control_message (const char *src, 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

◆ n_rnd_bytes

#define n_rnd_bytes   6

Referenced by hostname_randomize().

Function Documentation

◆ auth_user_pass_mgmt()

static bool auth_user_pass_mgmt ( struct user_pass up,
const char *  prefix,
const unsigned int  flags,
const char *  auth_challenge 
)
static

◆ 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_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_arg_copy()

static const char** make_arg_copy ( char **  p,
struct gc_arena gc 
)
static

Definition at line 607 of file misc.c.

References ALLOC_ARRAY_CLEAR_GC, buffer::len, and string_array_len().

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 
)

◆ make_inline_array()

static const char** make_inline_array ( const char *  str,
struct gc_arena gc 
)
static

◆ 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 *  src,
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().