Go to the documentation of this file.
58 #if defined(HAVE_DUP) && defined(HAVE_DUP2)
60 if ((fd = open(
"/dev/null", O_RDWR, 0)) != -1)
91 rnd_str =
format_hex_ex(rnd_bytes,
sizeof(rnd_bytes), 40, 0, NULL, gc);
92 buf_printf(&hname,
"%s.%s", rnd_str, hostname);
97 #ifdef ENABLE_MANAGEMENT
103 const char *sc = NULL;
122 msg(
M_FATAL,
"ERROR: could not read %s username/password/ok/string from management interface", prefix);
147 char *work = (
char *)
gc_malloc(len+1,
false, gc);
160 if (strcmp(work,
"CRV1"))
170 for (cp = work; *cp !=
'\0'; ++cp)
212 const char *auth_file,
214 const unsigned int flags,
221 bool from_authfile = (auth_file && !
streq(auth_file,
"stdin"));
222 bool username_from_stdin =
false;
223 bool password_from_stdin =
false;
224 bool response_from_stdin =
true;
228 msg(
M_WARN,
"Note: previous '%s' credentials failed", prefix);
231 #ifdef ENABLE_MANAGEMENT
239 response_from_stdin =
false;
258 msg(
M_FATAL,
"ERROR: could not read %s ok-confirmation from stdin", prefix);
269 buf_set_read(&buf, (uint8_t *) auth_file, strlen(auth_file) + 1);
278 password_from_stdin = 1;
295 msg(
M_ERR,
"Error opening '%s' auth file: %s", prefix, auth_file);
303 msg(
M_FATAL,
"Error reading username from %s authfile: %s",
317 msg(
M_FATAL,
"Error reading password from %s authfile: %s", prefix, auth_file);
328 #if defined(ENABLE_MANAGEMENT)
333 msg(
D_LOW,
"No password found in %s authfile '%s'. Querying the management interface", prefix, auth_file);
343 password_from_stdin = 1;
350 msg(
M_FATAL,
"ERROR: username from %s authfile '%s' is empty", prefix, auth_file);
355 username_from_stdin =
true;
356 password_from_stdin =
true;
362 if (username_from_stdin || password_from_stdin || response_from_stdin)
364 #ifdef ENABLE_MANAGEMENT
371 struct buffer packed_resp, challenge;
380 msg(
M_FATAL,
"ERROR: could not read challenge response from stdin");
387 msg(
M_FATAL,
"ERROR: received malformed challenge request from server");
397 buf_printf(&user_prompt,
"Enter %s Username:", prefix);
398 buf_printf(&pass_prompt,
"Enter %s Password:", prefix);
406 if (password_from_stdin)
414 msg(
M_FATAL,
"ERROR: Failed retrieving username or password");
421 msg(
M_FATAL,
"ERROR: %s username is empty", prefix);
425 #ifdef ENABLE_MANAGEMENT
429 struct buffer packed_resp, challenge;
430 char *pw64 = NULL, *resp64 = NULL;
439 msg(
M_FATAL,
"ERROR: could not retrieve static challenge response");
444 msg(
M_FATAL,
"ERROR: could not base64-encode password/static_response");
447 buf_printf(&packed_resp,
"SCRV1:%s:%s", pw64, resp64);
475 const bool nocache = up->
nocache;
476 static bool warn_shown =
false;
477 if (nocache || force)
486 else if (!warn_shown)
488 msg(
M_WARN,
"WARNING: this configuration may cache passwords in memory -- use the auth-nocache option to prevent this");
514 if (strlen(username))
524 msg(
D_PUSH,
"Error decoding auth-token-username");
561 n =
parse_line(parms, &ret[base], max_parms - base - 1,
"make_arg_array", 0,
M_WARN, gc);
562 ASSERT(n >= 0 && n + base + 1 <= max_parms);
564 ret[base + n] = NULL;
566 return (
const char **)ret;
579 while (
buf_parse(&buf,
'\n', line,
sizeof(line)))
588 while (
buf_parse(&buf,
'\n', line,
sizeof(line)))
597 return (
const char **)ret;
605 const int max_parms =
len + 1;
611 for (i = 0; i <
len; ++i)
616 return (
const char **)ret;
652 char *ret =
gc_malloc(strlen(src)+1,
false, gc);
664 if (c ==
'S' && !strncmp(src,
"SESS_ID_", 8))
669 else if (c ==
'e' && !strncmp(src,
"echo ", 5))
675 && (c ==
'a' && !strncmp(src,
"auth-token ", 11)))
724 if (c ==
'=' && state == 1)
728 else if (isalnum(c) || c ==
'_')
739 if (!isprint(c) || isspace(c)
740 || c ==
'$' || c ==
'(' || c ==
'`')
755 buf_set_read(&buf, (
const uint8_t *) peer_info, strlen(peer_info));
756 while (
buf_parse(&buf,
'\n', line,
sizeof(line)))
760 && (strncmp(line,
"IV_", 3) == 0 || strncmp(line,
"UV_", 3) == 0) )
767 msg(
M_WARN,
"validation failed on peer_info line received from client");
780 return combined_path;
void output_peer_info_env(struct env_set *es, const char *peer_info)
int openvpn_base64_decode(const char *str, void *data, int size)
void set_auth_token_user(struct user_pass *tk, const char *username)
Sets the auth-token username by base64 decoding the passed username.
#define GET_USER_PASS_PREVIOUS_CREDS_FAILED
static struct gc_arena gc_new(void)
int string_array_len(const char **array)
static const char ** make_arg_copy(char **p, struct gc_arena *gc)
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.
int len
Length in bytes of the actual content within the allocated memory.
struct buffer prepend_dir(const char *dir, const char *path, struct gc_arena *gc)
Prepend a directory to a path.
#define GET_USER_PASS_STATIC_CHALLENGE_ECHO
void management_auth_failure(struct management *man, const char *type, const char *reason)
void set_auth_token(struct user_pass *tk, const char *token)
Sets the auth-token to token.
char username[USER_PASS_LEN]
bool management_query_user_pass(struct management *man, struct user_pass *up, const char *type, const unsigned int flags, const char *static_challenge)
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.
const char ** make_extended_arg_array(char **p, bool is_inline, struct gc_arena *gc)
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
#define CC_CRLF
carriage return or newline
int openvpn_base64_encode(const void *data, int size, char **str)
const char * safe_print(const char *str, struct gc_arena *gc)
int parse_line(const char *line, char *p[], const int n, const char *file, const int line_num, int msglevel, struct gc_arena *gc)
void prng_bytes(uint8_t *output, int len)
char * format_hex_ex(const uint8_t *data, int size, int maxoutput, unsigned int space_break_flags, const char *separator, struct gc_arena *gc)
#define GET_USER_PASS_MANAGEMENT
void env_set_add(struct env_set *es, const char *str)
static bool query_user_SINGLE(char *prompt, size_t prompt_len, char *resp, size_t resp_len, bool echo)
A plain "make Gert happy" wrapper.
char * string_alloc(const char *str, struct gc_arena *gc)
static void secure_memzero(void *data, size_t len)
Securely zeroise memory.
void string_clear(char *str)
void query_user_add(char *prompt, size_t prompt_len, char *resp, size_t resp_len, bool echo)
Adds an item to ask the user for.
static bool query_user_exec(void)
Wrapper function enabling query_user_exec() if no alternative methods have been enabled.
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)
const char * challenge_text
static char * auth_challenge
#define CC_PRINT
printable (>= 32, != 127)
#define GET_USER_PASS_DYNAMIC_CHALLENGE
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...
#define ALLOC_ARRAY_CLEAR_GC(dptr, type, n, gc)
static const char ** make_inline_array(const char *str, struct gc_arena *gc)
#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc)
#define GET_USER_PASS_NOFATAL
Wrapper structure for dynamically allocated memory.
void query_user_clear(void)
Wipes all data put into all of the query_user structs.
static bool management_query_user_pass_enabled(const struct management *man)
Garbage collection arena used to keep track of dynamically allocated memory.
static void buf_set_write(struct buffer *buf, uint8_t *data, int size)
static void strncpynt(char *dest, const char *src, size_t maxlen)
static bool check_debug_level(unsigned int level)
void set_std_files_to_null(bool stdin_only)
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
static void gc_free(struct gc_arena *a)
#define GET_USER_PASS_PASSWORD_ONLY
#define GET_USER_PASS_NEED_OK
bool validate_peer_info_line(char *line)
const char * sanitize_control_message(const char *src, struct gc_arena *gc)
char password[USER_PASS_LEN]
#define GET_USER_PASS_INLINE_CREDS
#define PATH_SEPARATOR_STR
static bool auth_user_pass_mgmt(struct user_pass *up, const char *prefix, const unsigned int flags, const char *auth_challenge)
const char * skip_leading_whitespace(const char *str)
#define GET_USER_PASS_STATIC_CHALLENGE
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...
bool buf_printf(struct buffer *buf, const char *format,...)
static void buf_set_read(struct buffer *buf, const uint8_t *data, size_t size)
const char * hostname_randomize(const char *hostname, struct gc_arena *gc)
bool buf_parse(struct buffer *buf, const int delim, char *line, const int size)