OpenVPN
Functions
options_util.h File Reference
#include "options.h"
Include dependency graph for options_util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

const char * parse_auth_failed_temp (struct options *o, const char *reason)
 
bool valid_integer (const char *str, bool positive)
 Checks if the string is a valid integer by checking if it can be converted to an integer.
 
int positive_atoi (const char *str, int msglevel)
 Converts a str to a positive number if the string represents a postive integer number.
 
int atoi_warn (const char *str, int msglevel)
 Converts a str to an integer if the string can be represented as an integer number.
 
bool atoi_constrained (const char *str, int *value, const char *name, int min, int max, int msglevel)
 Converts a str to an integer if the string can be represented as an integer number and is between min and max.
 
bool apply_pull_filter (const struct options *o, char *line)
 Filter an option line by all pull filters.
 
bool check_push_update_option_flags (char *line, int *i, unsigned int *flags)
 Checks the formatting and validity of options inside push-update messages.
 

Function Documentation

◆ apply_pull_filter()

bool apply_pull_filter ( const struct options o,
char *  line 
)

Filter an option line by all pull filters.

If a match is found, the line is modified depending on the filter type, and returns true. If the filter type is reject, SIGUSR1 is triggered and the return value is false. In that case the caller must end the push processing.

Definition at line 252 of file options_util.c.

References D_LOW, D_PUSH, pull_filter_list::head, M_WARN, msg, pull_filter::next, pull_filter::pattern, PUF_TYPE_ACCEPT, PUF_TYPE_IGNORE, PUF_TYPE_REJECT, options::pull_filter_list, pull_filter::size, and pull_filter::type.

Referenced by apply_push_options().

◆ atoi_constrained()

bool atoi_constrained ( const char *  str,
int *  value,
const char *  name,
int  min,
int  max,
int  msglevel 
)

Converts a str to an integer if the string can be represented as an integer number and is between min and max.

The integer is stored in value. On error, print a warning with msglevel using name. value is not changed on error.

Returns
true if the integer has been parsed and stored in value, false otherwise

Definition at line 150 of file options_util.c.

References ASSERT, i, and msg.

Referenced by add_option(), and test_atoi_variants().

◆ atoi_warn()

int atoi_warn ( const char *  str,
int  msglevel 
)

Converts a str to an integer if the string can be represented as an integer number.

Otherwise print a warning with msglevel and return 0

Definition at line 135 of file options_util.c.

References i, and msg.

Referenced by add_option(), and test_atoi_variants().

◆ check_push_update_option_flags()

bool check_push_update_option_flags ( char *  line,
int *  i,
unsigned int *  flags 
)

Checks the formatting and validity of options inside push-update messages.

This function is used to validate and process options in push-update messages. It performs the following checks:

  • Determines if the options are updatable.
  • Checks for the presence of the - flag, which indicates that the option should be removed.
  • Checks for the ? flag, which marks the option as optional and suppresses errors if the client cannot update it.
  • Increase the value pointed by 'i' when we encounter the ‘’-'and'?'flags after validating them and updating the appropriate flags in theflagsvariable. --?option,-option,?optionare valid formats,?-optionis not a valid format.
  • If the flags and the option are not consecutive, the option is invalid: - ?option,-? option,- option` are invalid formats.
Parameters
lineA pointer to an option string. This string is the option being validated.
iA pointer to an integer that represents the current index in the line string.
flagsA pointer where flags will be stored:
  • PUSH_OPT_TO_REMOVE: Set if the - flag is present.
  • PUSH_OPT_OPTIONAL: Set if the ? flag is present.
Returns
true if the flags and option combination are valid.
false if:
  • The - and ? flags are not formatted correctly.
  • The line parameter is empty or NULL.
  • The ? flag is absent and the option is not updatable.

Definition at line 190 of file options_util.c.

References D_PUSH, i, M_WARN, msg, PUSH_OPT_OPTIONAL, PUSH_OPT_TO_REMOVE, and updatable_options.

Referenced by apply_push_options().

◆ parse_auth_failed_temp()

const char * parse_auth_failed_temp ( struct options o,
const char *  reason 
)

◆ positive_atoi()

int positive_atoi ( const char *  str,
int  msglevel 
)

Converts a str to a positive number if the string represents a postive integer number.

Otherwise print a warning with msglevel and return 0

Definition at line 120 of file options_util.c.

References i, and msg.

Referenced by add_option(), and test_atoi_variants().

◆ valid_integer()

bool valid_integer ( const char *  str,
bool  positive 
)

Checks if the string is a valid integer by checking if it can be converted to an integer.

Definition at line 104 of file options_util.c.

References i.

Referenced by add_option(), and test_atoi_variants().