Kea: isc::util::file::PathChecker Class Reference

| Kea 3.0.3-git

isc::util::file::PathChecker Class Reference

Embodies a supported path against which file paths can be validated. More...

`#include <filesystem.h>`

## Public Member Functions
| PathChecker (const std::string default_path, const std::string env_name="")
| Constructor.
virtual | ~PathChecker ()
| Destructor.
std::string | getDefaultPath () const
| Fetches the default path.
std::string | getEnvName () const
| Fetches the environment variable name.
std::string | getPath (bool reset=false, const std::string explicit_path="")
| Fetches the supported path.
bool | isDefaultOverridden ()
| Indicates if the default path has been overridden.
bool | pathHasPermissions (mode_t permissions, bool enforce_perms=shouldEnforceSecurity()) const
| Check if the path has expected permissions.
std::string | validateDirectory (const std::string input_path_str, bool enforce_path=shouldEnforceSecurity()) const
| Validates a directory against a supported path.
std::string | validatePath (const std::string input_path_str, bool enforce_path=shouldEnforceSecurity()) const
| Validates a file path against a supported path.

## Static Public Member Functions
static void | enableEnforcement (bool enable)
| Enables or disables security enforcment checks.
static bool | shouldEnforceSecurity ()
| Indicates security checks should be enforced.

## Detailed Description

Embodies a supported path against which file paths can be validated.

Definition at line 195 of file filesystem.h.

## Constructor & Destructor Documentation

## ◆ PathChecker()

isc::util::file::PathChecker::PathChecker | ( | const std::string | default_path,
|  | const std::string | env_name = "" )

Constructor.

Makes a call to getPath(true) to initialize the supported path.

Parameters

  default_path | path to use unless overridden by explicitly or via environment variable.
  env_name | name of environment variable (if one), that can override the default path.

Definition at line 250 of file filesystem.cc.

References getPath().

Here is the call graph for this function:

## ◆ ~PathChecker()

virtual isc::util::file::PathChecker::~PathChecker | ( |  | ) |
| inlinevirtual

Destructor.

Definition at line 208 of file filesystem.h.

## Member Function Documentation

## ◆ enableEnforcement()

void isc::util::file::PathChecker::enableEnforcement | ( | bool | enable | ) |
| static

Enables or disables security enforcment checks.

Parameters

  enable | true to enable security checks, false to disable.

Definition at line 352 of file filesystem.cc.

Referenced by main(), and isc::process::DControllerBase::parseArgs().

## ◆ getDefaultPath()

std::string isc::util::file::PathChecker::getDefaultPath | ( |  | ) | const
| inline

Fetches the default path.

Definition at line 276 of file filesystem.h.

## ◆ getEnvName()

std::string isc::util::file::PathChecker::getEnvName | ( |  | ) | const
| inline

Fetches the environment variable name.

Definition at line 281 of file filesystem.h.

## ◆ getPath()

std::string isc::util::file::PathChecker::getPath | ( | bool | reset = false,
|  | const std::string | explicit_path = "" )

Fetches the supported path.

When called with reset=true it will calculate the supported path as follows:

1. Use the value of explicit_path parameter if not blank
2. Use the value of the environment variable, if one is provided and it is defined in the environment
3. Use the value of default path.

Parameters

  reset | recalculate when true, defaults to false.
  explicit_path | set the default path to this value. This is for testing purposes only.

Returns
  String containing the default path.

Definition at line 258 of file filesystem.cc.

Referenced by PathChecker().

## ◆ isDefaultOverridden()

bool isc::util::file::PathChecker::isDefaultOverridden | ( |  | ) |

Indicates if the default path has been overridden.

Definition at line 344 of file filesystem.cc.

## ◆ pathHasPermissions()

bool isc::util::file::PathChecker::pathHasPermissions | ( | mode_t | permissions,
|  | bool | enforce_perms = shouldEnforceSecurity() ) const

Check if the path has expected permissions.

Parameters

  permissions | The expected permissions.
  enforce_perms | Enables permsissions check. If false the function simply returns true.

Returns
  True if the path points to a file or a directory, false otherwise.

Definition at line 338 of file filesystem.cc.

References isc::util::file::hasPermissions().

Here is the call graph for this function:

## ◆ shouldEnforceSecurity()

bool isc::util::file::PathChecker::shouldEnforceSecurity | ( |  | ) |
| static

Indicates security checks should be enforced.

Definition at line 348 of file filesystem.cc.

Referenced by main(), isc::agent::CtrlAgentProcess::run(), and isc::d2::D2Process::run().

## ◆ validateDirectory()

std::string isc::util::file::PathChecker::validateDirectory | ( | const std::string | input_path_str,
|  | bool | enforce_path = shouldEnforceSecurity() ) const

Validates a directory against a supported path.

Used to validate a string that represents a directory that may or may not end with a "/" (i.e "/foo/bar", bar is assumed to be the a directory, not a file.

If the input is empty or it matches the supported path, it returns the supported path. Otherwise it throws an error.

Parameters

  input_path_str | file path to validate.
  enforce_path | enables validation against the supported path. If it simply returns the supported path.

Returns
  validated path

Exceptions

  BadValue | if the input directory does not match the supported path.

Definition at line 313 of file filesystem.cc.

References isc_throw, and isc::util::str::trim().

Here is the call graph for this function:

## ◆ validatePath()

std::string isc::util::file::PathChecker::validatePath | ( | const std::string | input_path_str,
|  | bool | enforce_path = shouldEnforceSecurity() ) const

Validates a file path against a supported path.

If the input path specifies a parent path and file name, the parent path is validated against the supported path. If they match, the function returns the validated path. If the input path contains only a file name the function returns valid path using the supported path and the input path name.

Parameters

  input_path_str | file path to validate.
  enforce_path | enables validation against the supported path. If false verifies only that the path contains a file name.

Returns
  validated path as a string (supported path + input file name)

Exceptions

  BadValue | if the input path does not include a file name or if the it the parent path does not path the supported path.

Definition at line 283 of file filesystem.cc.

References isc::util::file::Path::filename(), isc_throw, isc::util::file::Path::parentDirectory(), isc::util::file::Path::parentPath(), isc::util::file::Path::str(), and isc::util::str::trim().

Here is the call graph for this function:

The documentation for this class was generated from the following files:

- filesystem.h
- filesystem.cc