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

repo: Don't try to perform labeling if SELinux is disabled #1667

Merged
merged 1 commit into from
Jun 24, 2024
Merged
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
50 changes: 26 additions & 24 deletions libdnf/repo/Repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,34 +676,36 @@ static int create_temporary_directory(char *name_template) {
int old_default_context_was_retrieved= 0;
struct selabel_handle *labeling_handle = NULL;

/* A purpose of this piece of code is to deal with applications whose
* security policy overrides a file context for temporary files but don't
* know that libdnf executes GnuPG which expects a default file context. */
if (0 == getfscreatecon(&old_default_context)) {
old_default_context_was_retrieved = 1;
} else {
logger->debug(tfm::format("Failed to retrieve a default SELinux context"));
}
if (is_selinux_enabled()) {
/* A purpose of this piece of code is to deal with applications whose
* security policy overrides a file context for temporary files but don't
* know that libdnf executes GnuPG which expects a default file context. */
if (0 == getfscreatecon(&old_default_context)) {
old_default_context_was_retrieved = 1;
} else {
logger->debug(tfm::format("Failed to retrieve a default SELinux context"));
}

labeling_handle = selabel_open(SELABEL_CTX_FILE, NULL, 0);
if (NULL == labeling_handle) {
logger->debug(tfm::format("Failed to open a SELinux labeling handle: %s",
strerror(errno)));
} else {
if (selabel_lookup(labeling_handle, &new_default_context, name_template, 0700)) {
/* Here we could hard-code "system_u:object_r:user_tmp_t:s0", but
* that value should be really defined in default file context
* SELinux policy. Only log that the policy is incpomplete. */
logger->debug(tfm::format("Failed to look up a default SELinux label for \"%s\"",
name_template));
labeling_handle = selabel_open(SELABEL_CTX_FILE, NULL, 0);
if (NULL == labeling_handle) {
logger->debug(tfm::format("Failed to open a SELinux labeling handle: %s",
strerror(errno)));
} else {
if (setfscreatecon(new_default_context)) {
logger->debug(tfm::format("Failed to set default SELinux context to \"%s\"",
new_default_context));
if (selabel_lookup(labeling_handle, &new_default_context, name_template, 0700)) {
/* Here we could hard-code "system_u:object_r:user_tmp_t:s0", but
* that value should be really defined in default file context
* SELinux policy. Only log that the policy is incpomplete. */
logger->debug(tfm::format("Failed to look up a default SELinux label for \"%s\"",
name_template));
} else {
if (setfscreatecon(new_default_context)) {
logger->debug(tfm::format("Failed to set default SELinux context to \"%s\"",
new_default_context));
}
freecon(new_default_context);
}
freecon(new_default_context);
selabel_close(labeling_handle);
}
selabel_close(labeling_handle);
}
#endif

Expand Down
Loading