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

Conversation

timopollmeier
Copy link
Member

@timopollmeier timopollmeier commented Jan 15, 2021

What:
The new functions gvm_file_exists, gvm_file_is_executable and
gvm_file_is_readable are added as an alternative to g_file_test that
tests the file access according to the effective user and group ID
instead of the real one.

Why:
The change is required for gvmd to work properly with the file flags
to set the UID and GID

How:
I tested the functions with a small test program like this:

#define _GNU_SOURCE

#include <stdio.h>
#include <unistd.h>
#include <gvm/util/fileutils.h>

int main ()
{
  const char *fname = "./test.txt";
  printf ("File: %s\n", fname);
  printf (" - exists: %d\n", gvm_file_exists (fname));
  printf (" - readable: %d\n", gvm_file_is_readable (fname));
  printf (" - executable: %d\n", gvm_file_is_executable (fname));
  printf ("eUID: %d, eGID: %d\n", geteuid(), getegid());
}

The cases I checked were:

  • the file test.txt not existing
  • the user running the test executable (without any special flags), owning the text file
  • the user running the not having any permissions for text file
  • running the executable as a user that normally has no permissions for the text file
    but setting the setuid and setgid flags of the executable so it is run as a user with
    access to the file.

Checklist:

The new functions gvm_file_exists, gvm_file_is_executable and
gvm_file_is_readable are added as an alternative to g_file_test that
tests the file access according to the effective user and group ID
instead of the real one.
@timopollmeier timopollmeier marked this pull request as ready for review January 15, 2021 09:42
@mattmundell mattmundell merged commit e335110 into greenbone:gvm-libs-20.08 Jan 15, 2021
@timopollmeier timopollmeier deleted the file-tests-20.08 branch October 15, 2021 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants