OpenVPN 3 Core Library
Loading...
Searching...
No Matches
openvpn::UserPass Namespace Reference

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
 

Enumeration Type Documentation

◆ Flags

Enumerator
OPT_REQUIRED 

option must be present

OPT_OPTIONAL 

if option is not present, USERNAME_REQUIRED and PASSWORD_REQUIRED are ignored

USERNAME_REQUIRED 

username must be present

PASSWORD_REQUIRED 

password must be present

TRY_FILE 

option argument might be a filename, try to load creds from it

Definition at line 29 of file userpass.hpp.

Function Documentation

◆ OPENVPN_EXCEPTION()

openvpn::UserPass::OPENVPN_EXCEPTION ( creds_error  )

◆ parse() [1/2]

void openvpn::UserPass::parse ( const OptionList options,
const std::string &  opt_name,
const unsigned int  flags,
std::string &  user,
std::string &  pass 
)
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.

<opt_name>
username
password
</opt_name>

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.

Parameters
optionsparsed option list
opt_namename of the option to interpret
flagsopenvpn::UserPass::Flags, all flags are used
userReturns the username, if present. Otherwise empty
passReturns the password, if present. Otherwise empty

Definition at line 144 of file userpass.hpp.

◆ parse() [2/2]

bool openvpn::UserPass::parse ( const OptionList options,
const std::string &  opt_name,
const unsigned int  flags,
std::vector< std::string > *  user_pass 
)
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.

<opt_name>
username
password
</opt_name>

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.

Parameters
optionsparsed option list
opt_namename of the option to interpret
flagsopenvpn::UserPass::Flags, only OPT_REQUIRED and TRY_FILE are used
user_passvector of strings, user and password will be appended if present
Returns
bool True if the option was present, False otherwise

Definition at line 74 of file userpass.hpp.

Here is the caller graph for this function:

◆ parse_file()

void openvpn::UserPass::parse_file ( const std::string &  path,
const unsigned int  flags,
std::string &  user,
std::string &  pass 
)
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.

Parameters
pathfile path
flagsSplitLines::Flags, only *_REQUIRED flags are relevant
userReturns the username, if present. Otherwise empty
passReturns the password, if present. Otherwise empty

Definition at line 186 of file userpass.hpp.

Here is the caller graph for this function: