OpenVPN 3 Core Library
|
Enumerations | |
enum | Flags { OPT_REQUIRED = (1 << 0) , OPT_OPTIONAL = (1 << 1) , USERNAME_REQUIRED = (1 << 2) , PASSWORD_REQUIRED = (1 << 3) , TRY_FILE = (1 << 4) } |
Functions | |
OPENVPN_EXCEPTION (creds_error) | |
bool | parse (const OptionList &options, const std::string &opt_name, const unsigned int flags, std::vector< std::string > *user_pass) |
interpret user-pass option | |
void | parse (const OptionList &options, const std::string &opt_name, const unsigned int flags, std::string &user, std::string &pass) |
interpret user-pass option | |
void | parse_file (const std::string &path, const unsigned int flags, std::string &user, std::string &pass) |
read username/password from file | |
Definition at line 29 of file userpass.hpp.
openvpn::UserPass::OPENVPN_EXCEPTION | ( | creds_error | ) |
|
inline |
interpret user-pass option
If the option is present without argument, then returns true unless OPT_REQUIRED flag set. If OPT_REQUIRED flag is set, the option needs to have exactly one argument.
The argument might be specified as a multiline argument. I.e.
The multiline argument is allowed to be 1024 UTF-8 characters in length. If it is longer, the function will throw an exception.
If the TRY_FILE flag is set and the argument is not multiline, then it is interpreted as a filepath and the contents of the file will replace the argument.
Lines in the file are only allowed to be 1024 bytes in length. Longer lines will cause an exception to be thrown.
If the argument contains a newline, then the first line is used as the username and the second line is used as the password, otherwise the argument is the username.
If USERNAME_REQUIRED and/or PASSWORD_REQUIRED flag is set, and the option is present, then it will throw creds_error instead of returning empty values. If the option is not present, it will only throw if OPT_OPTIONAL flag is not set. If neither USERNAME_REQUIRED nor PASSWORD_REQUIRED flag are set, then OPT_OPTIONAL has no effect.
options | parsed option list |
opt_name | name of the option to interpret |
flags | openvpn::UserPass::Flags, all flags are used |
user | Returns the username, if present. Otherwise empty |
pass | Returns the password, if present. Otherwise empty |
Definition at line 144 of file userpass.hpp.
|
inline |
interpret user-pass option
If the option is present without argument, then returns true unless OPT_REQUIRED flag set. If OPT_REQUIRED flag is set, the option needs to have exactly one argument.
The argument might be specified as a multiline argument. I.e.
The multiline argument is allowed to be 1024 UTF-8 characters in length. If it is longer, the function will throw an exception.
If the TRY_FILE flag is set and the argument is not multiline, then it is interpreted as a filepath and the contents of the file will replace the argument.
Lines in the file are only allowed to be 1024 bytes in length. Longer lines will cause an exception to be thrown.
If the argument contains a newline, then the first line is used as the username and the second line is used as the password, otherwise the argument is the username. Note that no empty entry will be appended to the vector if the password is missing.
options | parsed option list |
opt_name | name of the option to interpret |
flags | openvpn::UserPass::Flags, only OPT_REQUIRED and TRY_FILE are used |
user_pass | vector of strings, user and password will be appended if present |
Definition at line 74 of file userpass.hpp.
|
inline |
read username/password from file
If the file contents contain a newline, then the first line is used as the username and the second line is used as the password, otherwise the content is the username.
Lines in the file are only allowed to be 1024 bytes in length. Longer lines will cause an exception to be thrown.
If USERNAME_REQUIRED and/or PASSWORD_REQUIRED flag is set, then it will throw creds_error instead of returning empty values.
path | file path |
flags | SplitLines::Flags, only *_REQUIRED flags are relevant |
user | Returns the username, if present. Otherwise empty |
pass | Returns the password, if present. Otherwise empty |
Definition at line 186 of file userpass.hpp.