Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file access tests using effective UID/GID (20.08) #422

Merged
merged 2 commits into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Added
- Add function to get duplicated hosts from the hosts list. [#387](https://github.com/greenbone/gvm-libs/pull/387)
- Add file access tests using effective UID/GID [#422](https://github.com/greenbone/gvm-libs/pull/422)

### Changed
- Reduce ping timeout when using test_alive_hosts_only feature. [#400](https://github.com/greenbone/gvm-libs/pull/400)
Expand Down
54 changes: 54 additions & 0 deletions util/fileutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,60 @@ gvm_file_check_is_dir (const char *name)
return S_ISDIR (sb.st_mode);
}

/**
* @brief Checks whether a file or directory exists.
*
* Unlike g_file_test this checks the permissions based on the effective
* UID and GID instead of the real one.
*
* Symbolic links are followed.
*
* @param[in] name Name of file or directory.
*
* @return 1 if file exists, 0 if it is not.
*/
int
gvm_file_exists (const char *name)
{
return eaccess (name, F_OK) == 0;
}

/**
* @brief Checks whether a file or directory exists and is executable.
*
* Unlike g_file_test this checks the permissions based on the effective
* UID and GID instead of the real one.
*
* Symbolic links are followed.
*
* @param[in] name Name of file or directory.
*
* @return 1 if file is executable, 0 if it is not.
*/
int
gvm_file_is_executable (const char *name)
{
return eaccess (name, X_OK) == 0;
}

/**
* @brief Checks whether a file or directory exists and is readable.
*
* Unlike g_file_test this checks the permissions based on the effective
* UID and GID instead of the real one.
*
* Symbolic links are followed.
*
* @param[in] name Name of file or directory.
*
* @return 1 if file is readable, 0 if it is not.
*/
int
gvm_file_is_readable (const char *name)
{
return eaccess (name, R_OK) == 0;
}

/**
* @brief Recursively removes files and directories.
*
Expand Down
9 changes: 9 additions & 0 deletions util/fileutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@

#include <glib.h>

int
gvm_file_exists (const char *name);

int
gvm_file_is_executable (const char *name);

int
gvm_file_is_readable (const char *name);

int
gvm_file_check_is_dir (const char *name);

Expand Down