57#if defined(HAVE_DUP) && defined(HAVE_DUP2)
59 if ((fd = open(
"/dev/null", O_RDWR, 0)) != -1)
75#ifdef ENABLE_MANAGEMENT
81 const char *sc = NULL;
101 "ERROR: could not read %s username/password/ok/string from management interface",
131 const int work_len = (int)len + 1;
132 char *work = (
char *)
gc_malloc(work_len,
false,
gc);
145 if (strcmp(work,
"CRV1"))
155 for (
const char *cp = work; *cp !=
'\0'; ++cp)
203 bool from_authfile = (auth_file && !
streq(auth_file,
"stdin"));
204 bool username_from_stdin =
false;
205 bool password_from_stdin =
false;
206 bool response_from_stdin =
true;
211 msg(
M_WARN,
"Note: previous '%s' credentials failed", prefix);
213#ifdef ENABLE_MANAGEMENT
220 response_from_stdin =
false;
238 msg(
M_FATAL,
"ERROR: could not read %s ok-confirmation from stdin", prefix);
254 const char *password =
strchr(auth_file,
'\n');
255 password = password ? password + 1 :
"";
279 msg(
M_ERR,
"Error opening '%s' auth file: %s", prefix, auth_file);
287 msg(
M_FATAL,
"Error reading username from %s authfile: %s", prefix,
308 msg(
M_FATAL,
"Error reading password from %s authfile: %s", prefix, auth_file);
324 msg(
M_FATAL,
"ERROR: username from %s authfile '%s' is empty", prefix,
339#ifdef ENABLE_MANAGEMENT
350 "No '%s' password found in authfile or inline. Querying the management interface",
372 msg(
M_FATAL,
"ERROR: could not read challenge response from stdin");
379 msg(
M_FATAL,
"ERROR: received malformed challenge request from server");
404 msg(
M_FATAL,
"ERROR: Failed retrieving username or password");
411 msg(
M_FATAL,
"ERROR: %s username is empty", prefix);
415#ifdef ENABLE_MANAGEMENT
429 msg(
M_FATAL,
"ERROR: could not retrieve static challenge response");
436 msg(
M_FATAL,
"ERROR: could not base64-encode password/static_response");
450 "ERROR: could not concatenate password/static_response: string too long");
482 const bool nocache = up->
nocache;
484 if (nocache ||
force)
501 "WARNING: this configuration may cache passwords in memory -- use the auth-nocache option to prevent this");
514 tk->token_defined =
true;
538 tk->defined =
len > 0;
541 msg(
D_PUSH,
"Error decoding auth-token-username");
584 return (
const char **)
ret;
615 return (
const char **)
ret;
634 return (
const char **)
ret;
740 if (
c ==
'=' && state == 1)
783 msg(
M_WARN,
"validation failed on peer_info line received");
const char * skip_leading_whitespace(const char *str)
Return a pointer past any leading whitespace in a string.
bool buf_printf(struct buffer *buf, const char *format,...)
printf-style append to a buffer with overflow check.
void string_clear(char *str)
Securely clear a null-terminated string.
void chomp(char *str)
Remove trailing newline and carriage-return characters from a string.
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
Allocate memory and, optionally, zero it.
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Allocate a buffer of the given size under garbage collection.
bool string_mod(char *str, const unsigned int inclusive, const unsigned int exclusive, const char replace)
Modifies a string in place by replacing certain classes of characters of it with a specified characte...
const char * string_mod_const(const char *str, const unsigned int inclusive, const unsigned int exclusive, const char replace, struct gc_arena *gc)
Returns a copy of a string with certain classes of characters of it replaced with a specified charact...
int string_array_len(const char **array)
Return the number of elements in a NULL-terminated array of strings.
bool buf_parse(struct buffer *buf, const int delim, char *line, const int size)
Extract the next token from a buffer, delimited by a given character.
char * string_alloc(const char *str, struct gc_arena *gc)
Duplicate a string, allocating memory under garbage collection.
Buffer management functions and garbage collection.
static bool buf_size_valid(const size_t size)
Return true iff size is within the allowed buffer size range.
#define BSTR(buf)
Return the buffer content pointer cast to char *.
#define streq(x, y)
helper to work around the semantics of the strcmp() return value
#define ALLOC_ARRAY_CLEAR_GC(dptr, type, n, gc)
Allocate and zero-initialise a garbage-collected array of n elements.
#define CC_CRLF
carriage return or newline
static void buf_set_write(struct buffer *buf, uint8_t *data, int size)
Initialise a buffer with an externally provided writable memory region.
static void buf_set_read(struct buffer *buf, const uint8_t *data, size_t size)
Initialise a buffer with an externally provided read-only memory region.
static void secure_memzero(void *data, size_t len)
Securely zeroise memory.
#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc)
Allocate and zero-initialise a garbage-collected object of the given type.
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
#define CC_PRINT
printable (>= 32, != 127)
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
size_t strlcpy(char *dest, const char *src, size_t maxlen)
size_t strlcat(char *dest, const char *src, size_t maxlen)
void query_user_clear(void)
Wipes all data put into all of the query_user structs.
void query_user_add(char *prompt, char *resp, int resp_len, bool echo)
Adds an item to ask the user for.
static bool query_user_SINGLE(char *prompt, char *resp, int resp_len, bool echo)
A plain "make Gert happy" wrapper.
static bool query_user_exec(void)
Wrapper function enabling query_user_exec() if no alternative methods have been enabled.
Data Channel Cryptography Module.
void env_set_add(struct env_set *es, const char *str)
bool management_query_user_pass(struct management *man, struct user_pass *up, const char *type, const unsigned int flags, const char *static_challenge)
void management_auth_failure(const struct management *man, const char *type, const char *reason)
static bool management_query_user_pass_enabled(const struct management *man)
static const char ** make_inline_array(const char *str, struct gc_arena *gc)
void unprotect_user_pass(struct user_pass *up)
Decrypt username and password buffers in user_pass.
bool get_user_pass_cr(struct user_pass *up, const char *auth_file, const char *prefix, const unsigned int flags, const char *auth_challenge)
Retrieves the user credentials from various sources depending on the flags.
const char ** make_arg_array(const char *first, const char *parms, struct gc_arena *gc)
void purge_user_pass(struct user_pass *up, const bool force)
bool validate_peer_info_line(char *line)
void set_auth_token_user(struct user_pass *tk, const char *username)
Sets the auth-token username by base64 decoding the passed username.
void set_std_files_to_null(bool stdin_only)
void output_peer_info_env(struct env_set *es, const char *peer_info)
struct buffer prepend_dir(const char *dir, const char *path, struct gc_arena *gc)
Prepend a directory to a path.
static struct auth_challenge_info * parse_auth_challenge(const char *auth_challenge, struct gc_arena *gc)
Parses an authentication challenge string and returns an auth_challenge_info structure.
void protect_user_pass(struct user_pass *up)
Encrypt username and password buffers in user_pass.
const char ** make_extended_arg_array(char **p, bool is_inline, struct gc_arena *gc)
static const char ** make_arg_copy(char **p, struct gc_arena *gc)
const char * safe_print(const char *str, struct gc_arena *gc)
const char * sanitize_control_message(const char *src, 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)
void set_auth_token(struct user_pass *tk, const char *token)
Sets the auth-token to token.
#define GET_USER_PASS_STATIC_CHALLENGE_CONCAT
indicates password and response should be concatenated
#define GET_USER_PASS_MANAGEMENT
#define GET_USER_PASS_PASSWORD_ONLY
#define GET_USER_PASS_USERNAME_ONLY
indicate that only username should be prompted for auth-user-pass
#define GET_USER_PASS_STATIC_CHALLENGE_ECHO
SCRV1 protocol – echo response.
#define GET_USER_PASS_INLINE_CREDS
indicates that auth_file is actually inline creds
#define GET_USER_PASS_STATIC_CHALLENGE
SCRV1 protocol – static challenge.
#define GET_USER_PASS_NEED_OK
#define GET_USER_PASS_NOFATAL
static const char blank_up[]
#define GET_USER_PASS_PREVIOUS_CREDS_FAILED
#define GET_USER_PASS_DYNAMIC_CHALLENGE
CRV1 protocol – dynamic challenge.
static bool check_debug_level(msglvl_t level)
int parse_line(const char *line, char *p[], const int n, const char *file, const int line_num, msglvl_t msglevel, struct gc_arena *gc)
int openvpn_base64_decode(const char *str, void *data, int size)
int openvpn_base64_encode(const void *data, int size, char **str)
static char * auth_challenge
const char * challenge_text
Wrapper structure for dynamically allocated memory.
int len
Length in bytes of the actual content within the allocated memory.
Garbage collection arena used to keep track of dynamically allocated memory.
char password[USER_PASS_LEN]
char username[USER_PASS_LEN]
#define PATH_SEPARATOR_STR
bool protect_buffer_win32(char *buf, DWORD len)
Encrypt a region of memory using CryptProtectMemory() with access restricted to the current process.
bool unprotect_buffer_win32(char *buf, DWORD len)
Decrypt a previously encrypted region of memory using CryptUnProtectMemory() with access restricted t...