OpenVPN
Macros | Functions
check_file_access.c File Reference
#include "syshead.h"
#include "check_file_access.h"
#include "argv.h"
#include "buffer.h"
#include "error.h"
#include "options.h"
#include "platform.h"
#include "ssl_common.h"
#include <string.h>
Include dependency graph for check_file_access.c:

Go to the source code of this file.

Macros

#define CHKACC_FILE   (1 << 0)
 Check for a file/directory presence.
 
#define CHKACC_DIRPATH   (1 << 1)
 Check for directory presence where a file should reside.
 
#define CHKACC_FILEXSTWR   (1 << 2)
 If file exists, is it writable?
 
#define CHKACC_ACPTSTDIN   (1 << 3)
 If filename is stdin, it's allowed and "exists".
 
#define CHKACC_PRIVATE   (1 << 4)
 Warn if this (private) file is group/others accessible.
 
#define CHKACC_ACCEPT_URI   (1 << 5)
 Do not check URIs, unless they start with file:
 

Functions

static bool check_file_access (const int type, const char *file, const int mode, const char *opt)
 
static bool check_file_access_chroot (const char *chroot, const int type, const char *file, const int mode, const char *opt)
 A wrapper for check_file_access() which also takes a chroot directory.
 
static bool check_file_access_chroot_inline (bool is_inline, const char *chroot, const int type, const char *file, const int mode, const char *opt)
 A wrapper for check_file_access_chroot() that returns false immediately if the file is inline (and therefore there is no access to check)
 
static bool check_file_access_inline (bool is_inline, const int type, const char *file, const int mode, const char *opt)
 A wrapper for check_file_access() that returns false immediately if the file is inline (and therefore there is no access to check)
 
bool check_cmd_access (const char *command, const char *opt, const char *chroot)
 Verifies that the path in the "command" that comes after certain script options (e.g., –up) is a valid file with appropriate permissions.
 
void options_postprocess_filechecks (struct options *options)
 Sanity check of all file/dir options.
 

Macro Definition Documentation

◆ CHKACC_ACCEPT_URI

#define CHKACC_ACCEPT_URI   (1 << 5)

Do not check URIs, unless they start with file:

Definition at line 53 of file check_file_access.c.

◆ CHKACC_ACPTSTDIN

#define CHKACC_ACPTSTDIN   (1 << 3)

If filename is stdin, it's allowed and "exists".

Definition at line 51 of file check_file_access.c.

◆ CHKACC_DIRPATH

#define CHKACC_DIRPATH   (1 << 1)

Check for directory presence where a file should reside.

Definition at line 49 of file check_file_access.c.

◆ CHKACC_FILE

#define CHKACC_FILE   (1 << 0)

Check for a file/directory presence.

Definition at line 48 of file check_file_access.c.

◆ CHKACC_FILEXSTWR

#define CHKACC_FILEXSTWR   (1 << 2)

If file exists, is it writable?

Definition at line 50 of file check_file_access.c.

◆ CHKACC_PRIVATE

#define CHKACC_PRIVATE   (1 << 4)

Warn if this (private) file is group/others accessible.

Definition at line 52 of file check_file_access.c.

Function Documentation

◆ check_cmd_access()

bool check_cmd_access ( const char *  command,
const char *  opt,
const char *  chroot 
)

Verifies that the path in the "command" that comes after certain script options (e.g., –up) is a valid file with appropriate permissions.

"command" consists of a path, optionally followed by a space, which may be followed by arbitrary arguments. It is NOT a full shell command line – shell expansion is not performed.

The path and arguments in "command" may be single- or double-quoted or escaped.

The path is extracted from "command", then check_file_access() is called to check it. The arguments, if any, are ignored.

Note that the type, mode, and opt arguments to this routine are the same as the corresponding check_file_access() arguments.

Definition at line 214 of file check_file_access.c.

References argv::argv, argv_free(), argv_new(), argv_parse_cmd(), check_file_access_chroot(), CHKACC_FILE, M_NOPREFIX, M_OPTERR, and msg.

Referenced by set_user_script().

◆ check_file_access()

static bool check_file_access ( const int  type,
const char *  file,
const int  mode,
const char *  opt 
)
static

◆ check_file_access_chroot()

static bool check_file_access_chroot ( const char *  chroot,
const int  type,
const char *  file,
const int  mode,
const char *  opt 
)
static

A wrapper for check_file_access() which also takes a chroot directory.

If chroot is NULL, behaviour is exactly the same as calling check_file_access() directly, otherwise it will look for the file inside the given chroot directory instead.

Definition at line 152 of file check_file_access.c.

References BSTR, check_file_access(), gc, gc_free(), gc_new(), buffer::len, and prepend_dir().

Referenced by check_cmd_access(), check_file_access_chroot_inline(), and options_postprocess_filechecks().

◆ check_file_access_chroot_inline()

static bool check_file_access_chroot_inline ( bool  is_inline,
const char *  chroot,
const int  type,
const char *  file,
const int  mode,
const char *  opt 
)
static

A wrapper for check_file_access_chroot() that returns false immediately if the file is inline (and therefore there is no access to check)

Definition at line 186 of file check_file_access.c.

References check_file_access_chroot(), and buffer::len.

Referenced by options_postprocess_filechecks().

◆ check_file_access_inline()

static bool check_file_access_inline ( bool  is_inline,
const int  type,
const char *  file,
const int  mode,
const char *  opt 
)
static

A wrapper for check_file_access() that returns false immediately if the file is inline (and therefore there is no access to check)

Definition at line 202 of file check_file_access.c.

References check_file_access(), and buffer::len.

Referenced by options_postprocess_filechecks().

◆ options_postprocess_filechecks()

void options_postprocess_filechecks ( struct options options)

Sanity check of all file/dir options.

Checks that file/dir is accessible by OpenVPN

Definition at line 250 of file check_file_access.c.

References connection_list::array, ASSERT, options::auth_user_pass_file, options::auth_user_pass_file_inline, options::ca_file, options::ca_file_inline, options::ca_path, options::cert_file, options::cert_file_inline, check_file_access(), check_file_access_chroot(), check_file_access_chroot_inline(), check_file_access_inline(), CHKACC_ACCEPT_URI, CHKACC_ACPTSTDIN, CHKACC_DIRPATH, CHKACC_FILE, CHKACC_FILEXSTWR, CHKACC_PRIVATE, options::chroot_dir, options::client_config_dir, options::connection_list, options::crl_file, options::crl_file_inline, options::dh_file, options::dh_file_inline, options::extra_certs_file, options::key_pass_file, connection_list::len, M_USAGE, options::management_flags, options::management_user_pass, MF_EXTERNAL_KEY, msg, options::packet_id_file, options::pkcs12_file, options::pkcs12_file_inline, options::priv_key_file, options::priv_key_file_inline, options::shared_secret_file, options::shared_secret_file_inline, options::ssl_flags, SSLF_CRL_VERIFY_DIR, options::status_file, connection_entry::tls_auth_file, connection_entry::tls_auth_file_inline, connection_entry::tls_crypt_file, connection_entry::tls_crypt_file_inline, connection_entry::tls_crypt_v2_file, connection_entry::tls_crypt_v2_file_inline, options::tls_export_peer_cert_dir, options::tmp_dir, options::verify_hash_no_ca, and options::writepid.

Referenced by options_postprocess().