Kea 3.2.1-git
isc::util::file Namespace Reference

Classes

struct  Path
 Paths on a filesystem. More...
class  PathChecker
 Embodies a supported path against which file paths can be validated. More...
class  RelaxUmask
 RAII device to relax umask (adding group write for sockets). More...
class  SecurityError
 A generic exception that is thrown if a parameter given violates security and enforcement is true. More...
class  SecurityWarn
 A generic exception that is thrown if a parameter given violates security check but enforcement is lax. More...
struct  TemporaryDirectory

Typedefs

typedef boost::shared_ptr< PathChecker > PathCheckerPtr
 Defines a pointer to a PathChecker.

Functions

bool amRunningAsRoot ()
 Indicates if current user is root.
bool exists (const std::string &path)
 Check if there is a file or directory at the given path.
string getContent (const std::string &file_name)
 Get the content of a regular file.
mode_t getPermissions (const std::string path)
 Fetches the file permissions mask.
bool hasPermissions (const std::string path, const mode_t &permissions)
 Check if there if file or directory has the given permissions.
bool isDir (const std::string &path)
 Check if there is a directory at the given path.
bool isFile (const std::string &path)
 Check if there is a file at the given path.
bool isSocket (const std::string &path)
 Check if there is a socket at the given path.
void setUmask ()
 Set umask (at least 0027 i.e. no group write and no other access).

Typedef Documentation

◆ PathCheckerPtr

typedef boost::shared_ptr<PathChecker> isc::util::file::PathCheckerPtr

Defines a pointer to a PathChecker.

Definition at line 342 of file filesystem.h.

Function Documentation

◆ amRunningAsRoot()

bool isc::util::file::amRunningAsRoot ( )

Indicates if current user is root.

Returns
True if either the uid or the effective uid is root.

Definition at line 115 of file filesystem.cc.

References amRunningAsRoot().

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

Here is the call graph for this function:

◆ exists()

bool isc::util::file::exists ( const std::string & path)

Check if there is a file or directory at the given path.

Parameters
pathThe path being checked.
Returns
True if the path points to a file or a directory, false otherwise.

Definition at line 50 of file filesystem.cc.

References exists().

Referenced by exists(), and getContent().

Here is the call graph for this function:

◆ getContent()

std::string isc::util::file::getContent ( const std::string & file_name)

Get the content of a regular file.

Note
Here the content is the first line not including the final line feed character if there is one.
Parameters
file_nameThe file name.
Returns
The content of the file.
Exceptions
BadValuewhen the file can't be opened or is not a regular one.

Definition at line 33 of file filesystem.cc.

References exists(), getContent(), isc_throw, and isFile().

Referenced by getContent(), isc::http::BasicHttpAuthConfig::getFileContent(), and isc::d2::TSIGKeyInfoParser::parse().

Here is the call graph for this function:

◆ getPermissions()

mode_t isc::util::file::getPermissions ( const std::string path)

Fetches the file permissions mask.

Parameters
pathThe path being checked.
Returns
File permissios mask or 0 if the path does not exist.

Definition at line 56 of file filesystem.cc.

References getPermissions().

Referenced by getPermissions(), hasPermissions(), and isc::config::UnixCommandConfig::validatePath().

Here is the call graph for this function:

◆ hasPermissions()

bool isc::util::file::hasPermissions ( const std::string path,
const mode_t & permissions )

Check if there if file or directory has the given permissions.

Parameters
pathThe path being checked.
permissionsexpected permissions.
Returns
True if the path points to a file or a directory with given permissions, false otherwise.

Definition at line 66 of file filesystem.cc.

References getPermissions(), and hasPermissions().

Referenced by hasPermissions(), and isc::util::file::PathChecker::pathHasPermissions().

Here is the call graph for this function:

◆ isDir()

bool isc::util::file::isDir ( const std::string & path)

Check if there is a directory at the given path.

Parameters
pathThe path being checked.
Returns
True if the path points to a directory, false otherwise including if the pointed location does not exist.

Definition at line 71 of file filesystem.cc.

References isDir().

Referenced by isc::asiolink::TlsContextBase::configure(), isDir(), and isc::db::MySqlConnection::openDatabase().

Here is the call graph for this function:

◆ isFile()

bool isc::util::file::isFile ( const std::string & path)

Check if there is a file at the given path.

Parameters
pathThe path being checked.
Returns
True if the path points to a file, false otherwise including if the pointed location does not exist.

Definition at line 80 of file filesystem.cc.

References isFile().

Referenced by getContent(), isc::db::MySqlConnection::initializeSchema(), isc::db::PgSqlConnection::initializeSchema(), and isFile().

Here is the call graph for this function:

◆ isSocket()

bool isc::util::file::isSocket ( const std::string & path)

Check if there is a socket at the given path.

Parameters
pathThe path being checked.
Returns
True if the path points to a socket, false otherwise including if the pointed location does not exist.

Definition at line 89 of file filesystem.cc.

References isSocket().

Referenced by isSocket().

Here is the call graph for this function:

◆ setUmask()

void isc::util::file::setUmask ( )

Set umask (at least 0027 i.e. no group write and no other access).

Definition at line 98 of file filesystem.cc.

References setUmask().

Referenced by main(), and setUmask().

Here is the call graph for this function: