OpenVPN
|
#include "syshead.h"
#include "argv.h"
#include "integer.h"
#include "env_set.h"
#include "options.h"
Go to the source code of this file.
Functions | |
static void | argv_extend (struct argv *a, const size_t newcap) |
Resizes the list of arguments struct argv can carry. More... | |
static void | argv_init (struct argv *a) |
Initialise an already allocated struct argv. More... | |
struct argv | argv_new (void) |
Allocates a new struct argv and ensures it is initialised. More... | |
void | argv_free (struct argv *a) |
Frees all memory allocations allocated by the struct argv related functions. More... | |
static void | argv_reset (struct argv *a) |
Resets the struct argv to an initial state. More... | |
static void | argv_grow (struct argv *a, const size_t add) |
Extends an existing struct argv to carry minimum 'add' number of new arguments. More... | |
static void | argv_append (struct argv *a, char *str) |
Appends a string to to the list of arguments stored in a struct argv This will ensure the list size in struct argv has the needed capacity to store the value. More... | |
static struct argv | argv_clone (const struct argv *source, const size_t headroom) |
Clones a struct argv with all the contents to a new allocated struct argv. More... | |
struct argv | argv_insert_head (const struct argv *a, const char *head) |
Inserts an argument string in front of all other argument slots. More... | |
const char * | argv_str (const struct argv *a, struct gc_arena *gc, const unsigned int flags) |
Generate a single string with all the arguments in a struct argv concatenated. More... | |
void | argv_msg (const int msglev, const struct argv *a) |
Write the arguments stored in a struct argv via the msg() command. More... | |
void | argv_msg_prefix (const int msglev, const struct argv *a, const char *prefix) |
Similar to argv_msg() but prefixes the messages being written with a given string. More... | |
static char * | argv_prep_format (const char *format, const char delim, size_t *count, struct gc_arena *gc) |
Prepares argv format string for further processing. More... | |
static bool | argv_printf_arglist (struct argv *argres, const char *format, va_list arglist) |
Create a struct argv based on a format string. More... | |
bool | argv_printf (struct argv *argres, const char *format,...) |
printf() variant which populates a struct argv. More... | |
bool | argv_printf_cat (struct argv *argres, const char *format,...) |
printf() inspired argv concatenation. More... | |
void | argv_parse_cmd (struct argv *argres, const char *cmdstr) |
Parses a command string, tokenizes it and puts each element into a separate struct argv argument slot. More... | |
|
static |
Appends a string to to the list of arguments stored in a struct argv This will ensure the list size in struct argv has the needed capacity to store the value.
*a | struct argv where to append the new string value |
<em>str | Pointer to string to append. The provided string *MUST have been malloc()ed or NULL. |
Definition at line 158 of file argv.c.
References argv::argc, argv::argv, and argv_grow().
Referenced by argv_clone(), argv_parse_cmd(), and argv_printf_arglist().
Clones a struct argv with all the contents to a new allocated struct argv.
If 'headroom' is larger than 0, it will create a head-room in front of the values being copied from the source input.
*source | Valid pointer to the source struct argv to clone. It may be NULL. |
headroom | Number of slots to leave empty in front of the slots copied from the source. |
Definition at line 180 of file argv.c.
References argv::argc, argv::argv, argv_append(), argv_init(), argv::gc, and string_alloc().
Referenced by argv_insert_head().
|
static |
Resizes the list of arguments struct argv can carry.
This resize operation will only increase the size, never decrease the size.
*a | Valid pointer to a struct argv to resize |
newcap | size_t with the new size of the argument list. |
Definition at line 49 of file argv.c.
References ALLOC_ARRAY_CLEAR_GC, argv::argc, argv::argv, argv::capacity, and argv::gc.
Referenced by argv_grow(), and argv_init().
void argv_free | ( | struct argv * | a | ) |
Frees all memory allocations allocated by the struct argv related functions.
*a | Valid pointer to a struct argv to release memory from |
Definition at line 102 of file argv.c.
References argv::gc, and gc_free().
Referenced by add_route(), add_route_ipv6(), argv_insert_head__empty_argv__head_only(), argv_insert_head__non_empty_argv__head_added(), argv_parse_cmd__command_and_extra_options__argc_correct(), argv_parse_cmd__command_string__argc_correct(), argv_printf__combined_path_with_spaces__argc_correct(), argv_printf__embedded_format_directive__replaced_in_output(), argv_printf__empty_parameter__argc_correct(), argv_printf__group_sep_in_arg__fail_no_ouput(), argv_printf__long_args__data_correct(), argv_printf__multiple_spaces_in_format__parsed_as_one(), argv_printf_cat__multiple_spaces_in_format__parsed_as_one(), argv_printf_cat__used_twice__argc_correct(), argv_str__empty_argv__empty_output(), argv_str__multiple_argv__correct_output(), check_cmd_access(), cleanup(), delete_route(), delete_route_ipv6(), do_dns_domain_wmic(), do_ifconfig_ipv4(), do_ifconfig_ipv6(), do_route(), init(), ipconfig_register_dns(), learn_address_script(), link_socket_connection_initiated(), multi_client_connect_call_plugin_v1(), multi_client_connect_call_script(), multi_client_disconnect_script(), netsh_delete_address_dns(), netsh_enable_dhcp(), netsh_ifconfig(), netsh_ifconfig_options(), netsh_set_dns6_servers(), plugin_call_item(), run_up_down(), set_lladdr(), tls_crypt_v2_verify_metadata(), undo_ifconfig_ipv4(), undo_ifconfig_ipv6(), verify_cert_call_command(), verify_cert_call_plugin(), verify_crresponse_script(), and verify_user_pass_script().
|
static |
Extends an existing struct argv to carry minimum 'add' number of new arguments.
This builds on argv_extend(), which ensures the new size will only be higher than the current capacity.
The new size is also calculated based on the result of adjust_power_of_2(). This approach ensures that the list does grow bulks and only when the current limit is reached.
*a | Valid pointer to the struct argv to extend |
add | size_t with the number of elements to add. |
Definition at line 141 of file argv.c.
References adjust_power_of_2(), argv::argc, argv_extend(), and ASSERT.
Referenced by argv_append().
|
static |
Initialise an already allocated struct argv.
It is expected that the input argument is a valid pointer.
*a | Pointer to a struct argv to initialise |
Definition at line 72 of file argv.c.
References argv::argc, argv::argv, argv_extend(), argv::capacity, argv::gc, and gc_new().
Referenced by argv_clone(), and argv_new().
Inserts an argument string in front of all other argument slots.
*a | Valid pointer to the struct argv to insert the argument into |
*head | Pointer to the char * string with the argument to insert |
Definition at line 208 of file argv.c.
References argv_clone(), and string_alloc().
Referenced by argv_insert_head__empty_argv__head_only(), argv_insert_head__non_empty_argv__head_added(), and plugin_call_item().
void argv_msg | ( | const int | msglev, |
const struct argv * | a | ||
) |
Write the arguments stored in a struct argv via the msg() command.
msglev | Integer with the message level used by msg(). |
*a | Valid pointer to the struct argv with the arguments to write. |
Definition at line 243 of file argv.c.
References argv_str(), gc_free(), gc_new(), and msg.
Referenced by add_route(), add_route_ipv6(), delete_route(), delete_route_ipv6(), do_ifconfig_ipv4(), do_ifconfig_ipv6(), ipconfig_register_dns(), run_up_down(), set_lladdr(), undo_ifconfig_ipv4(), and undo_ifconfig_ipv6().
void argv_msg_prefix | ( | const int | msglev, |
const struct argv * | a, | ||
const char * | prefix | ||
) |
Similar to argv_msg() but prefixes the messages being written with a given string.
msglev | Integer with the message level used by msg(). |
*a | Valid pointer to the struct argv with the arguments to write |
*prefix | Valid char * pointer to the prefix string |
Definition at line 260 of file argv.c.
References argv_str(), gc_free(), gc_new(), and msg.
Referenced by exec_command(), tls_crypt_v2_verify_metadata(), and verify_cert_call_command().
struct argv argv_new | ( | void | ) |
Allocates a new struct argv and ensures it is initialised.
Note that it does not return a pointer, but a struct argv directly.
Definition at line 88 of file argv.c.
References argv_init().
Referenced by add_route(), add_route_ipv6(), argv_insert_head__empty_argv__head_only(), argv_insert_head__non_empty_argv__head_added(), argv_parse_cmd__command_and_extra_options__argc_correct(), argv_parse_cmd__command_string__argc_correct(), argv_printf__combined_path_with_spaces__argc_correct(), argv_printf__embedded_format_directive__replaced_in_output(), argv_printf__empty_parameter__argc_correct(), argv_printf__group_sep_in_arg__fail_no_ouput(), argv_printf__long_args__data_correct(), argv_printf__multiple_spaces_in_format__parsed_as_one(), argv_printf_cat__multiple_spaces_in_format__parsed_as_one(), argv_printf_cat__used_twice__argc_correct(), argv_str__empty_argv__empty_output(), argv_str__multiple_argv__correct_output(), check_cmd_access(), cleanup(), delete_route(), delete_route_ipv6(), do_dns_domain_wmic(), do_ifconfig_ipv4(), do_ifconfig_ipv6(), do_route(), init(), ipconfig_register_dns(), learn_address_script(), link_socket_connection_initiated(), multi_client_connect_call_plugin_v1(), multi_client_connect_call_script(), multi_client_disconnect_script(), netsh_delete_address_dns(), netsh_enable_dhcp(), netsh_ifconfig(), netsh_ifconfig_options(), netsh_set_dns6_servers(), run_up_down(), set_lladdr(), tls_crypt_v2_verify_metadata(), undo_ifconfig_ipv4(), undo_ifconfig_ipv6(), verify_cert_call_command(), verify_cert_call_plugin(), verify_crresponse_script(), and verify_user_pass_script().
void argv_parse_cmd | ( | struct argv * | argres, |
const char * | cmdstr | ||
) |
Parses a command string, tokenizes it and puts each element into a separate struct argv argument slot.
@params *argres Valid pointer to a struct argv where the parsed result will be found. @params *cmdstr Char * based string to parse
Definition at line 483 of file argv.c.
References argv_append(), argv_reset(), D_ARGV_PARSE_CMD, argv::gc, MAX_PARMS, parse_line(), and string_alloc().
Referenced by argv_parse_cmd__command_and_extra_options__argc_correct(), argv_parse_cmd__command_string__argc_correct(), check_cmd_access(), do_route(), ipchange_fmt(), learn_address_script(), multi_client_connect_call_script(), multi_client_disconnect_script(), run_up_down(), tls_crypt_v2_verify_metadata(), verify_cert_call_command(), verify_crresponse_script(), and verify_user_pass_script().
|
static |
Prepares argv format string for further processing.
Individual argument must be separated by space. Ignores leading and trailing spaces. Consecutive spaces count as one. Returns prepared format string, with space replaced by delim and adds the number of arguments to the count parameter.
*format | Pointer to a the format string to process |
delim | Char with the delimiter to use |
*count | size_t pointer used to return the number of tokens (argument slots) found in the format string. |
*gc | Pointer to a gc_arena managed buffer. |
Definition at line 288 of file argv.c.
References http-client::f, and gc_malloc().
Referenced by argv_printf_arglist().
bool argv_printf | ( | struct argv * | argres, |
const char * | format, | ||
... | |||
) |
printf() variant which populates a struct argv.
It processes the format string with the provided arguments. For each space separator found in the format string, a new argument will be added to the resulting struct argv.
This will always reset and ensure the result is based on a pristine struct argv.
*argres | Valid pointer to a struct argv where the result will be put. |
*format | printf() compliant (char *) format string. |
Definition at line 440 of file argv.c.
References argv_printf_arglist(), and argv_reset().
Referenced by add_route(), add_route_ipv6(), argv_insert_head__non_empty_argv__head_added(), argv_printf__combined_path_with_spaces__argc_correct(), argv_printf__embedded_format_directive__replaced_in_output(), argv_printf__empty_parameter__argc_correct(), argv_printf__group_sep_in_arg__fail_no_ouput(), argv_printf__long_args__data_correct(), argv_printf__multiple_spaces_in_format__parsed_as_one(), argv_printf_cat__multiple_spaces_in_format__parsed_as_one(), argv_printf_cat__used_twice__argc_correct(), argv_str__multiple_argv__correct_output(), cleanup(), delete_route(), delete_route_ipv6(), do_dns_domain_wmic(), do_ifconfig_ipv4(), do_ifconfig_ipv6(), init(), ipchange_fmt(), ipconfig_register_dns(), learn_address_script(), multi_client_connect_call_plugin_v1(), netsh_delete_address_dns(), netsh_enable_dhcp(), netsh_ifconfig(), netsh_ifconfig_options(), netsh_set_dns6_servers(), run_up_down(), set_lladdr(), undo_ifconfig_ipv4(), undo_ifconfig_ipv6(), and verify_cert_call_plugin().
|
static |
Create a struct argv based on a format string.
Instead of parsing the format string ourselves place delimiters via argv_prep_format() before we let libc's printf() do the parsing. Then split the resulting string at the injected delimiters.
*argres | Valid pointer to a struct argv where the resulting parsed arguments, based on the format string. |
<em>format | Char string with a printf() compliant format string |
arglist | A va_list with the arguments to be consumed by the format string |
Definition at line 349 of file argv.c.
References argv::argc, argv_append(), argv_prep_format(), argv_reset(), http-client::f, argv::gc, and gc_malloc().
Referenced by argv_printf(), and argv_printf_cat().
bool argv_printf_cat | ( | struct argv * | argres, |
const char * | format, | ||
... | |||
) |
printf() inspired argv concatenation.
Adds arguments to an existing struct argv and populets the argument slots based on the printf() based format string.
*argres | Valid pointer to a struct argv where the result will be put. |
*format | printf() compliant (char *) format string. |
Definition at line 464 of file argv.c.
References argv_printf_arglist().
Referenced by add_route(), add_route_ipv6(), argv_parse_cmd__command_and_extra_options__argc_correct(), argv_printf_cat__multiple_spaces_in_format__parsed_as_one(), argv_printf_cat__used_twice__argc_correct(), argv_str__multiple_argv__correct_output(), delete_route_ipv6(), ipchange_fmt(), learn_address_script(), multi_client_connect_call_script(), netsh_ifconfig_options(), netsh_set_dns6_servers(), run_up_down(), verify_cert_call_command(), verify_crresponse_script(), and verify_user_pass_script().
|
static |
Resets the struct argv to an initial state.
No memory buffers will be released by this call.
*a | Valid pointer to a struct argv to resize |
Definition at line 114 of file argv.c.
References argv::argc, and argv::argv.
Referenced by argv_parse_cmd(), argv_printf(), and argv_printf_arglist().
Generate a single string with all the arguments in a struct argv concatenated.
*a | Valid pointer to the struct argv with the arguments to list |
*gc | Pointer to a struct gc_arena managed buffer |
flags | Flags passed to the print_argv() function. |
Definition at line 231 of file argv.c.
References argv::argv, argv::gc, and print_argv().
Referenced by argv_msg(), argv_msg_prefix(), argv_str__empty_argv__empty_output(), and argv_str__multiple_argv__correct_output().